public final class utf util extends test case public void test fake utfutil testcase testfake private filename generator fg public temp bucket migration test throws io exception fg new filename generator weakprng false null junit filenamegenerator tempbucketmigrationtest ioexception filenamegenerator public void test ram limit create throws io exception temp bucket factory tbf new temp bucket factory exec fg 16 128 strongprng weakprng false int max ram bucket 128 16 create excess max total ram size last one should be on disk temp bucket b new temp bucket max ram bucket 1 for int i 0 i max ram bucket 1 i b i temp bucket tbf make bucket 16 output stream os b i get output stream os write new byte 16 os close try assert true b 0 isram bucket assert false b max ram bucket isram bucket free some reused the space b 0 free b max ram bucket free b 0 temp bucket tbf make bucket 8 b max ram bucket temp bucket tbf make bucket 8 assert true b 0 isram bucket assert true b max ram bucket isram bucket finally for bucket bb b bb free testramlimitcreate ioexception tempbucketfactory tempbucketfactory maxrambucket maxtotalramsize tempbucket tempbucket maxrambucket maxrambucket tempbucket makebucket outputstream getoutputstream asserttrue isrambucket assertfalse maxrambucket isrambucket maxrambucket tempbucket makebucket maxrambucket tempbucket makebucket asserttrue isrambucket asserttrue maxrambucket isrambucket public void test write excess conversion factor throws io exception temp bucket factory tbf new temp bucket factory exec fg 16 128 strongprng weakprng false temp bucket b temp bucket tbf make bucket 16 try assert true b isram bucket output stream os b get output stream os write new byte 16 assert true b isram bucket for int i 0 i temp bucket factory rambucket conversion factor 1 i os write new byte 16 assert false b isram bucket finally b free testwriteexcessconversionfactor ioexception tempbucketfactory tempbucketfactory tempbucket tempbucket makebucket asserttrue isrambucket outputstream getoutputstream asserttrue isrambucket tempbucketfactory rambucket_conversion_factor assertfalse isrambucket public void test write excess limit throws io exception temp bucket factory tbf new temp bucket factory exec fg 16 17 strongprng weakprng false temp bucket b temp bucket tbf make bucket 16 try assert true b isram bucket output stream os b get output stream os write new byte 16 assert true b isram bucket os write new byte 2 assert false b isram bucket finally b free testwriteexcesslimit ioexception tempbucketfactory tempbucketfactory tempbucket tempbucket makebucket asserttrue isrambucket outputstream getoutputstream asserttrue isrambucket assertfalse isrambucket this can happen due to memory pressure public void test conversion while reading throws io exception temp bucket factory tbf new temp bucket factory exec fg 1024 65536 strongprng weakprng false temp bucket bucket temp bucket tbf make bucket 64 output stream os bucket get output stream os write new byte 16 input stream is bucket get input stream bucket migrate to file bucket byte read to new byte 16 assert true is read read to 0 16 16 for int i 0 i read to length i assert true read to i 0 is close os close testconversionwhilereading ioexception tempbucketfactory tempbucketfactory tempbucket tempbucket makebucket outputstream getoutputstream inputstream getinputstream migratetofilebucket readto asserttrue readto readto asserttrue readto do a bigger read verify contents public void test big conversion while reading throws io exception temp bucket factory tbf new temp bucket factory exec fg 4096 65536 strongprng weakprng false temp bucket bucket temp bucket tbf make bucket 2048 output stream os bucket get output stream byte data new byte 2048 new random 89 next bytes data os write data input stream is bucket get input stream bucket migrate to file bucket byte read to new byte 2048 new data input stream is read fully read to for int i 0 i read to length i assert true read to i data i is close os close testbigconversionwhilereading ioexception tempbucketfactory tempbucketfactory tempbucket tempbucket makebucket outputstream getoutputstream nextbytes inputstream getinputstream migratetofilebucket readto datainputstream readfully readto readto asserttrue readto public realtempbuckettest int max ram size int max total ram size boolean encrypted throws io exception fg new filename generator weakprng false null junit tbf new temp bucket factory exec fg max ram size max total ram size strongprng weakprng encrypted can overwrite false realtempbuckettest_ maxramsize maxtotalramsize ioexception filenamegenerator tempbucketfactory maxramsize maxtotalramsize canoverwrite override protected void free bucket bucket bucket throws io exception bucket free freebucket ioexception override protected bucket make bucket long size throws io exception return tbf make bucket 1 temp bucket allow resize makebucket ioexception makebucket tempbucket public static class realtempbuckettest 8 16 f extends realtempbuckettest public realtempbuckettest 8 16 f throws io exception super 8 16 false realtempbuckettest_8_16_f realtempbuckettest_ realtempbuckettest_8_16_f ioexception public static class realtempbuckettest 64 128 f extends realtempbuckettest public realtempbuckettest 64 128 f throws io exception super 64 128 false realtempbuckettest_64_128_f realtempbuckettest_ realtempbuckettest_64_128_f ioexception public static class realtempbuckettest 64k 128k f extends realtempbuckettest public realtempbuckettest 64k 128k f throws io exception super 64 1024 128 1024 false realtempbuckettest_64k_128k_f realtempbuckettest_ realtempbuckettest_64k_128k_f ioexception public static class realtempbuckettest 8 16 t extends realtempbuckettest public realtempbuckettest 8 16 t throws io exception super 8 16 true realtempbuckettest_8_16_t realtempbuckettest_ realtempbuckettest_8_16_t ioexception public static class realtempbuckettest 64k 128k t extends realtempbuckettest public realtempbuckettest 64k 128k t throws io exception super 64 1024 128 1024 true realtempbuckettest_64k_128k_t realtempbuckettest_ realtempbuckettest_64k_128k_t ioexception public temp bucket test super temp bucket test add test new test suite realtempbuckettest 8 16 f class add test new test suite realtempbuckettest 64 128 f class add test new test suite realtempbuckettest 64k 128k f class add test new test suite realtempbuckettest 8 16 t class add test new test suite realtempbuckettest 64k 128k t class add test new test suite temp bucket migration test class tempbuckettest tempbuckettest addtest testsuite realtempbuckettest_8_16_f addtest testsuite realtempbuckettest_64_128_f addtest testsuite realtempbuckettest_64k_128k_f addtest testsuite realtempbuckettest_8_16_t addtest testsuite realtempbuckettest_64k_128k_t addtest testsuite tempbucketmigrationtest public static test suite test suite suite new test suite temp bucket test suite add test new test suite realtempbuckettest 8 16 f class suite add test new test suite realtempbuckettest 64 128 f class suite add test new test suite realtempbuckettest 64k 128k f class suite add test new test suite realtempbuckettest 8 16 t class suite add test new test suite realtempbuckettest 64k 128k t class suite add test new test suite temp bucket migration test class return suite testsuite testsuite tempbuckettest addtest testsuite realtempbuckettest_8_16_f addtest testsuite realtempbuckettest_64_128_f addtest testsuite realtempbuckettest_64k_128k_f addtest testsuite realtempbuckettest_8_16_t addtest testsuite realtempbuckettest_64k_128k_t addtest testsuite tempbucketmigrationtest byte 0xd6 byte 0xe7 byte 0xf8 protected abstract bucket make bucket long size throws io exception makebucket ioexception protected abstract bucket make bucket long size throws io exception protected abstract void free bucket bucket bucket throws io exception makebucket ioexception freebucket ioexception public void test read empty throws io exception bucket bucket make bucket 3 try assert equals size 0 0 bucket size output stream os bucket get output stream os close read byte input stream is bucket get input stream byte data new byte 10 int read is read data 0 10 is close assert equals read empty 1 read finally free bucket bucket testreadempty ioexception makebucket assertequals outputstream getoutputstream inputstream getinputstream assertequals freebucket public void test read excess throws io exception bucket bucket make bucket math max data1 length data2 length try assert equals size 0 0 bucket size write output stream os bucket get output stream os write new byte 5 os close assert equals read excess size 1 bucket size read byte input stream is bucket get input stream byte data new byte 10 int read is read data 0 10 assert equals read excess 1 read assert equals read excess 5 5 data 0 read is read data 0 10 assert equals read excess eof 1 read is close finally free bucket bucket testreadexcess ioexception makebucket assertequals outputstream getoutputstream assertequals inputstream getinputstream assertequals assertequals assertequals freebucket public void test read write throws io exception bucket bucket make bucket math max data1 length data2 length try assert equals size 0 0 bucket size write output stream os bucket get output stream os write data1 os close assert equals size 1 data1 length bucket size read byte input stream is bucket get input stream byte data new byte data1 length int read is read data 0 data1 length is close assert equals simple read 1 size data1 length read assert equals simple read 1 new byte array wrapper data1 new byte array wrapper data read byte is bucket get input stream for byte b data1 assert equals simple read 2 b byte is read eof assert equals simple read eof0 1 is read new byte 4 assert equals simple read eof1 1 is read assert equals simple read eof2 1 is read is close finally free bucket bucket testreadwrite ioexception makebucket assertequals outputstream getoutputstream assertequals inputstream getinputstream assertequals simpleread assertequals simpleread bytearraywrapper bytearraywrapper getinputstream assertequals simpleread assertequals simpleread assertequals simpleread assertequals simpleread freebucket write twice should overwrite not append public void test reuse throws io exception if can overwrite return bucket bucket make bucket math max data1 length data2 length try write output stream os bucket get output stream os write data1 os close read byte input stream is bucket get input stream byte data new byte data1 length int read is read data 0 data1 length is close assert equals read 1 size data1 length read assert equals read 1 new byte array wrapper data1 new byte array wrapper data write again os bucket get output stream os write data2 os close read byte is bucket get input stream data new byte data2 length read is read data 0 data2 length is close assert equals read 2 size data2 length read assert equals read 2 new byte array wrapper data2 new byte array wrapper data finally free bucket bucket testreuse ioexception canoverwrite makebucket outputstream getoutputstream inputstream getinputstream assertequals assertequals bytearraywrapper bytearraywrapper getoutputstream getinputstream assertequals assertequals bytearraywrapper bytearraywrapper freebucket public void test negative throws io exception bucket bucket make bucket math max data1 length data2 length try write output stream os bucket get output stream os write 0 os write 1 os write 2 os write 123 os close read byte input stream is bucket get input stream assert equals write 0 0xff byte 0 is read assert equals write 1 0xff byte 1 is read assert equals write 2 0xff byte 2 is read assert equals write 123 0xff byte 123 is read assert equals eof 1 is read is close finally free bucket bucket testnegative ioexception makebucket outputstream getoutputstream inputstream getinputstream assertequals assertequals assertequals assertequals assertequals freebucket public void test large data throws io exception bucket bucket make bucket data long length 16 try write output stream os bucket get output stream for int i 0 i 16 i os write data long os close read byte input stream is bucket get input stream for int i 0 i 16 i byte buf new byte data long length int read is read buf assert equals read long size data long length read assert equals read long new byte array wrapper data long new byte array wrapper buf int read is read new byte 1 assert equals read long size 1 read is close finally free bucket bucket testlargedata ioexception makebucket data_long outputstream getoutputstream data_long inputstream getinputstream data_long assertequals data_long assertequals bytearraywrapper data_long bytearraywrapper assertequals freebucket public void test read line without marking throws exception try utf8 input stream is new byte array input stream stressed line get bytes utf 8 line reading input stream instance new line reading input stream is assert equals instance read line without marking max length buffer size true assert equals u0114 instance read line without marking max length buffer size true assert null instance read line without marking max length buffer size true try iso 8859 1 is new byte array input stream block get bytes iso 8859 1 instance new line reading input stream is for string expected line lines assert equals expected line instance read line without marking max length buffer size false assert null instance read line without marking max length buffer size false is it returning null is new mock input stream instance new line reading input stream is assert null instance read line without marking 0 buffer size false assert null instance read line without marking 0 0 false is it throwing is new byte array input stream length checking line get bytes instance new line reading input stream is try instance read line without marking length checking line lf 1 buffer size true fail catch too long exception e same test shouldn t throw is new byte array input stream length checking line get bytes instance new line reading input stream is assert equals length checking line substring 0 length checking line lf instance read line without marking length checking line lf buffer size true is it handling nulls properly see 2501 is new byte array input stream null line get bytes instance new line reading input stream is assert equals null line substring 0 5 instance read line without marking buffer size 1 true testreadlinewithoutmarking inputstream bytearrayinputstream stressed_line getbytes linereadinginputstream linereadinginputstream assertequals readlinewithoutmarking max_length buffer_size assertequals readlinewithoutmarking max_length buffer_size assertnull readlinewithoutmarking max_length buffer_size bytearrayinputstream getbytes linereadinginputstream expectedline assertequals expectedline readlinewithoutmarking max_length buffer_size assertnull readlinewithoutmarking max_length buffer_size mockinputstream linereadinginputstream assertnull readlinewithoutmarking buffer_size assertnull readlinewithoutmarking bytearrayinputstream length_checking_line getbytes linereadinginputstream readlinewithoutmarking length_checking_line_lf buffer_size toolongexception bytearrayinputstream length_checking_line getbytes linereadinginputstream assertequals length_checking_line length_checking_line_lf readlinewithoutmarking length_checking_line_lf buffer_size bytearrayinputstream null_line getbytes linereadinginputstream assertequals null_line readlinewithoutmarking buffer_size public void test read line throws exception try utf8 input stream is new byte array input stream stressed line get bytes utf 8 line reading input stream instance new line reading input stream is assert equals instance read line max length buffer size true assert equals u0114 instance read line max length buffer size true assert null instance read line max length buffer size true try iso 8859 1 is new byte array input stream block get bytes iso 8859 1 instance new line reading input stream is for string expected line lines assert equals expected line instance read line max length buffer size false assert null instance read line max length buffer size false is it returning null and blocking when it should be is new mock input stream instance new line reading input stream is assert null instance read line 0 buffer size false assert null instance read line 0 0 false is it throwing is new byte array input stream length checking line get bytes instance new line reading input stream is try instance read line length checking line lf 1 buffer size true fail catch too long exception e same test shouldn t throw is new byte array input stream length checking line get bytes instance new line reading input stream is assert equals length checking line substring 0 length checking line lf instance read line length checking line lf buffer size true is it handling nulls properly see 2501 is new byte array input stream null line get bytes instance new line reading input stream is assert equals null line substring 0 5 instance read line buffer size 1 true testreadline inputstream bytearrayinputstream stressed_line getbytes linereadinginputstream linereadinginputstream assertequals readline max_length buffer_size assertequals readline max_length buffer_size assertnull readline max_length buffer_size bytearrayinputstream getbytes linereadinginputstream expectedline assertequals expectedline readline max_length buffer_size assertnull readline max_length buffer_size mockinputstream linereadinginputstream assertnull readline buffer_size assertnull readline bytearrayinputstream length_checking_line getbytes linereadinginputstream readline length_checking_line_lf buffer_size toolongexception bytearrayinputstream length_checking_line getbytes linereadinginputstream assertequals length_checking_line length_checking_line_lf readline length_checking_line_lf buffer_size bytearrayinputstream null_line getbytes linereadinginputstream assertequals null_line readline buffer_size public void test both implementation throws exception cwd is either the node s or the build tree file f new file freenet ini if f exists f new file build xml buffered input stream bis1 new buffered input stream new file input stream f buffered input stream bis2 new buffered input stream new file input stream f line reading input stream lris1 new line reading input stream bis1 line reading input stream lris2 new line reading input stream bis2 while bis1 available 0 bis2 available 0 string string without mark lris2 read line without marking max length 10 buffer size true string string with mark lris1 read line max length 10 buffer size true assert equals string with mark string without mark assert null lris1 read line max length buffer size true assert null lris2 read line without marking max length buffer size true testbothimplementation bufferedinputstream bufferedinputstream fileinputstream bufferedinputstream bufferedinputstream fileinputstream linereadinginputstream linereadinginputstream linereadinginputstream linereadinginputstream stringwithoutmark readlinewithoutmarking max_length buffer_size stringwithmark readline max_length buffer_size assertequals stringwithmark stringwithoutmark assertnull readline max_length buffer_size assertnull readlinewithoutmarking max_length buffer_size test gzip compressor s identity and functionality public void test gzip compressor compressor compressor type gzip compressor compressor compressor type gzip compressor compressor zero compressor compressor type get compressor by metadataid short 0 check gzip is the first compressor assert equals gzip compressor compressor zero testgzipcompressor compressor_type gzipcompressor compressor_type compressorzero compressor_type getcompressorbymetadataid assertequals gzipcompressor compressorzero public void test compress do gzip compression byte compressed data do compress uncompressed data 1 get bytes output size same as expected assert equals compressed data length compressed data 1 length check each byte is exactly as expected for int i 0 i compressed data length i assert equals compressed data 1 i compressed data i testcompress compresseddata docompress uncompressed_data_1 getbytes assertequals compresseddata compressed_data_1 compresseddata assertequals compressed_data_1 compresseddata public void test bucket decompress byte compressed data compressed data 1 do gzip decompression with buckets byte uncompressed data do bucket decompress compressed data is the round tripped uncompressed string the same as the original string uncompressed string new string uncompressed data assert equals uncompressed string uncompressed data 1 testbucketdecompress compresseddata compressed_data_1 uncompresseddata dobucketdecompress compresseddata uncompressedstring uncompresseddata assertequals uncompressedstring uncompressed_data_1 public void test byte array decompress build 5k array byte original uncompressed data new byte 5 1024 for int i 0 i original uncompressed data length i original uncompressed data i 1 byte compressed data do compress original uncompressed data byte out uncompressed data new byte 5 1024 int written bytes 0 try written bytes compressor compressor type gzip decompress compressed data 0 compressed data length out uncompressed data catch compression output size exception e fail unexpected exception thrown e get message assert equals written bytes original uncompressed data length assert equals original uncompressed data length out uncompressed data length check each byte is exactly as expected for int i 0 i out uncompressed data length i assert equals original uncompressed data i out uncompressed data i testbytearraydecompress originaluncompresseddata originaluncompresseddata originaluncompresseddata compresseddata docompress originaluncompresseddata outuncompresseddata writtenbytes writtenbytes compressor_type compresseddata compresseddata outuncompresseddata compressionoutputsizeexception getmessage assertequals writtenbytes originaluncompresseddata assertequals originaluncompresseddata outuncompresseddata outuncompresseddata assertequals originaluncompresseddata outuncompresseddata public void test compress exception byte uncompressed data uncompressed data 1 get bytes bucket in bucket new array bucket uncompressed data bucket factory factory new array bucket factory try compressor compressor type gzip compress in bucket factory 32 32 catch io exception e fail unexpected exception thrown e get message catch compression output size exception e expect this testcompressexception uncompresseddata uncompressed_data_1 getbytes inbucket arraybucket uncompresseddata bucketfactory arraybucketfactory compressor_type inbucket ioexception getmessage compressionoutputsizeexception public void test decompress exception build 5k array byte uncompressed data new byte 5 1024 for int i 0 i uncompressed data length i uncompressed data i 1 byte compressed data do compress uncompressed data bucket in bucket new array bucket compressed data bucket factory factory new array bucket factory try compressor compressor type gzip decompress in bucket factory 4096 10 4096 20 null catch io exception e fail unexpected exception thrown e get message catch compression output size exception e expect this testdecompressexception uncompresseddata uncompresseddata uncompresseddata compresseddata docompress uncompresseddata inbucket arraybucket compresseddata bucketfactory arraybucketfactory compressor_type inbucket ioexception getmessage compressionoutputsizeexception private byte do bucket decompress byte compressed data bucket in bucket new array bucket compressed data bucket factory factory new array bucket factory bucket out bucket null try out bucket compressor compressor type gzip decompress in bucket factory 32768 32768 2 null catch io exception e fail unexpected exception thrown e get message catch compression output size exception e fail unexpected exception thrown e get message input stream in null try in out bucket get input stream catch io exception e1 fail unexpected exception thrown e1 get message long size out bucket size byte out buf new byte int size try in read out buf catch io exception e fail unexpected exception thrown e get message return out buf dobucketdecompress compresseddata inbucket arraybucket compresseddata bucketfactory arraybucketfactory outbucket outbucket compressor_type inbucket ioexception getmessage compressionoutputsizeexception getmessage inputstream outbucket getinputstream ioexception getmessage outbucket outbuf outbuf ioexception getmessage outbuf private byte do compress byte uncompressed data bucket in bucket new array bucket uncompressed data bucket factory factory new array bucket factory bucket out bucket null try out bucket compressor compressor type gzip compress in bucket factory 32768 32768 catch io exception e fail unexpected exception thrown e get message catch compression output size exception e fail unexpected exception thrown e get message input stream in null try in out bucket get input stream catch io exception e1 fail unexpected exception thrown e1 get message long size out bucket size byte out buf new byte int size try in read out buf catch io exception e fail unexpected exception thrown e get message return out buf docompress uncompresseddata inbucket arraybucket uncompresseddata bucketfactory arraybucketfactory outbucket outbucket compressor_type inbucket ioexception getmessage compressionoutputsizeexception getmessage inputstream outbucket getinputstream ioexception getmessage outbucket outbuf outbuf ioexception getmessage outbuf test bzip2 compressor s identity and functionality public void test bzip2 compressor compressor compressor type bz2compressor compressor compressor type bzip2 compressor compressor zero compressor compressor type get compressor by metadataid short 1 check bzip2 is the second compressor assert equals bz2compressor compressor zero testbzip2compressor compressor_type compressor_type compressorzero compressor_type getcompressorbymetadataid assertequals compressorzero public void test compress do bzip2 compression byte compressed data do compress uncompressed data 1 get bytes output size same as expected assert equals compressed data length compressed data 1 length check each byte is exactly as expected for int i 0 i compressed data length i assert equals compressed data 1 i compressed data i testcompress compresseddata docompress uncompressed_data_1 getbytes assertequals compresseddata compressed_data_1 compresseddata assertequals compressed_data_1 compresseddata public void test bucket decompress byte compressed data compressed data 1 do bzip2 decompression with buckets byte uncompressed data do bucket decompress compressed data is the round tripped uncompressed string the same as the original string uncompressed string new string uncompressed data assert equals uncompressed string uncompressed data 1 testbucketdecompress compresseddata compressed_data_1 uncompresseddata dobucketdecompress compresseddata uncompressedstring uncompresseddata assertequals uncompressedstring uncompressed_data_1 public void test byte array decompress build 5k array byte original uncompressed data new byte 5 1024 for int i 0 i original uncompressed data length i original uncompressed data i 1 byte compressed data do compress original uncompressed data byte out uncompressed data new byte 5 1024 int written bytes 0 try written bytes compressor compressor type bzip2 decompress compressed data 0 compressed data length out uncompressed data catch compression output size exception e fail unexpected exception thrown e get message assert equals written bytes original uncompressed data length assert equals original uncompressed data length out uncompressed data length check each byte is exactly as expected for int i 0 i out uncompressed data length i assert equals original uncompressed data i out uncompressed data i testbytearraydecompress originaluncompresseddata originaluncompresseddata originaluncompresseddata compresseddata docompress originaluncompresseddata outuncompresseddata writtenbytes writtenbytes compressor_type compresseddata compresseddata outuncompresseddata compressionoutputsizeexception getmessage assertequals writtenbytes originaluncompresseddata assertequals originaluncompresseddata outuncompresseddata outuncompresseddata assertequals originaluncompresseddata outuncompresseddata public void test compress exception byte uncompressed data uncompressed data 1 get bytes bucket in bucket new array bucket uncompressed data bucket factory factory new array bucket factory try compressor compressor type bzip2 compress in bucket factory 32 32 catch io exception e fail unexpected exception thrown e get message catch compression output size exception e expect this testcompressexception uncompresseddata uncompressed_data_1 getbytes inbucket arraybucket uncompresseddata bucketfactory arraybucketfactory compressor_type inbucket ioexception getmessage compressionoutputsizeexception public void test decompress exception build 5k array byte uncompressed data new byte 5 1024 for int i 0 i uncompressed data length i uncompressed data i 1 byte compressed data do compress uncompressed data bucket in bucket new array bucket compressed data bucket factory factory new array bucket factory try compressor compressor type bzip2 decompress in bucket factory 4096 10 4096 20 null catch io exception e fail unexpected exception thrown e get message catch compression output size exception e expect this testdecompressexception uncompresseddata uncompresseddata uncompresseddata compresseddata docompress uncompresseddata inbucket arraybucket compresseddata bucketfactory arraybucketfactory compressor_type inbucket ioexception getmessage compressionoutputsizeexception private byte do bucket decompress byte compressed data bucket in bucket new array bucket compressed data bucket factory factory new array bucket factory bucket out bucket null try out bucket compressor compressor type bzip2 decompress in bucket factory 32768 32768 2 null catch io exception e fail unexpected exception thrown e get message catch compression output size exception e fail unexpected exception thrown e get message input stream in null try in out bucket get input stream catch io exception e1 fail unexpected exception thrown e1 get message long size out bucket size byte out buf new byte int size try in read out buf catch io exception e fail unexpected exception thrown e get message return out buf dobucketdecompress compresseddata inbucket arraybucket compresseddata bucketfactory arraybucketfactory outbucket outbucket compressor_type inbucket ioexception getmessage compressionoutputsizeexception getmessage inputstream outbucket getinputstream ioexception getmessage outbucket outbuf outbuf ioexception getmessage outbuf private byte do compress byte uncompressed data bucket in bucket new array bucket uncompressed data bucket factory factory new array bucket factory bucket out bucket null try out bucket compressor compressor type bzip2 compress in bucket factory 32768 32768 catch io exception e fail unexpected exception thrown e get message catch compression output size exception e fail unexpected exception thrown e get message input stream in null try in out bucket get input stream catch io exception e1 fail unexpected exception thrown e1 get message long size out bucket size byte out buf new byte int size try in read out buf catch io exception e fail unexpected exception thrown e get message return out buf docompress uncompresseddata inbucket arraybucket uncompresseddata bucketfactory arraybucketfactory outbucket outbucket compressor_type inbucket ioexception getmessage compressionoutputsizeexception getmessage inputstream outbucket getinputstream ioexception getmessage outbucket outbuf outbuf ioexception getmessage outbuf creates an array of objects with a specified size param size the array size return the objects array private object create sample objects int size object sample objects new object size for int i 0 i sample objects length i sample objects i new object return sample objects createsampleobjects sampleobjects sampleobjects sampleobjects sampleobjects creates a lru queue filled with the specified objects number param size queue size return the created lru queue private lru queue object create sample queue int size lru queue object methodlru queue new lru queue object object sample objects create sample objects size for int i 0 i sample objects length i methodlru queue push sample objects i return methodlru queue lruqueue lruqueue lruqueue createsamplequeue lruqueue methodlruqueue lruqueue sampleobjects createsampleobjects sampleobjects methodlruqueue sampleobjects methodlruqueue verifies if an element is present in an array param an array the array to search into param a element to search the object that must be found return true if there is at least one reference to the object private boolean is present object an array object a element to search for int i 0 i an array length i if an array i equals a element to search return true return false anarray aelementtosearch ispresent anarray aelementtosearch anarray anarray aelementtosearch verifies if the order of the last two elements in the queue is correct param alru queue the lru queue to check param next to last the next to last element expected param last the last element expected return true if the order is correct private boolean verify last elems order lru queue object alru queue object next to last object last boolean ret val true int size alru queue size enumeration object method enum alru queue elements int counter 0 while method enum has more elements next to last object if counter size 2 ret val method enum next element equals next to last last object else if counter size 1 ret val method enum next element equals last else method enum next element counter return ret val alruqueue lruqueue nexttolast verifylastelemsorder lruqueue alruqueue nexttolast retval alruqueue methodenum alruqueue methodenum hasmoreelements retval methodenum nextelement nexttolast retval methodenum nextelement methodenum nextelement retval tests link lru queue push object method providing a null object as argument after setting up a sample queue and verifying if the correct exception is raised public void test push null lru queue object methodlru queue this create sample queue sample elems number try methodlru queue push null fail expected exception error not thrown catch null pointer exception an exception assert not null an exception try methodlru queue push least null fail expected exception error not thrown catch null pointer exception an exception assert not null an exception lruqueue testpushnull lruqueue methodlruqueue createsamplequeue sampleelemsnumber methodlruqueue nullpointerexception anexception assertnotnull anexception methodlruqueue pushleast nullpointerexception anexception assertnotnull anexception tests link lru queue push object method and verifies the behaviour when pushing the same object more than one time public void test push same obj twice lru queue object methodlru queue this create sample queue sample elems number object sample obj new object new object methodlru queue push sample obj 0 methodlru queue push sample obj 1 check size assert equals sample elems number 2 methodlru queue size check order assert true verify last elems order methodlru queue sample obj 0 sample obj 1 methodlru queue push sample obj 0 check size assert equals sample elems number 2 methodlru queue size check order assert true verify last elems order methodlru queue sample obj 1 sample obj 0 lruqueue testpushsameobjtwice lruqueue methodlruqueue createsamplequeue sampleelemsnumber sampleobj methodlruqueue sampleobj methodlruqueue sampleobj assertequals sampleelemsnumber methodlruqueue asserttrue verifylastelemsorder methodlruqueue sampleobj sampleobj methodlruqueue sampleobj assertequals sampleelemsnumber methodlruqueue asserttrue verifylastelemsorder methodlruqueue sampleobj sampleobj tests link lru queue push least object method public void test push least lru queue object methodlru queue new lru queue object object sample obj new object new object methodlru queue push sample obj 0 methodlru queue push least sample obj 1 assert equals 2 methodlru queue size assert true verify last elems order methodlru queue sample obj 1 sample obj 0 same element methodlru queue push least sample obj 0 assert equals 2 methodlru queue size assert true verify last elems order methodlru queue sample obj 0 sample obj 1 lruqueue pushleast testpushleast lruqueue methodlruqueue lruqueue sampleobj methodlruqueue sampleobj methodlruqueue pushleast sampleobj assertequals methodlruqueue asserttrue verifylastelemsorder methodlruqueue sampleobj sampleobj methodlruqueue pushleast sampleobj assertequals methodlruqueue asserttrue verifylastelemsorder methodlruqueue sampleobj sampleobj tests link lru queue pop method pushing and popping objects and verifying if they are correctly in a fifo manner fetched and deleted public void test pop lru queue object methodlru queue new lru queue object object sample objects create sample objects sample elems number pushing objects for int i 0 i sample objects length i methodlru queue push sample objects i getting objects for int i 0 i sample objects length i assert equals sample objects i methodlru queue pop the queue must be empty assert null methodlru queue pop lruqueue testpop lruqueue methodlruqueue lruqueue sampleobjects createsampleobjects sampleelemsnumber sampleobjects methodlruqueue sampleobjects sampleobjects assertequals sampleobjects methodlruqueue assertnull methodlruqueue tests link lru queue size method checking size when empty when putting each object and when popping each object public void test size object sample objects create sample objects sample elems number lru queue object methodlru queue new lru queue object assert equals 0 methodlru queue size pushing objects for int i 0 i sample objects length i methodlru queue push sample objects i assert equals i 1 methodlru queue size getting all objects for int i sample objects length 1 i 0 i methodlru queue pop assert equals i methodlru queue size assert equals 0 methodlru queue size lruqueue testsize sampleobjects createsampleobjects sampleelemsnumber lruqueue methodlruqueue lruqueue assertequals methodlruqueue sampleobjects methodlruqueue sampleobjects assertequals methodlruqueue sampleobjects methodlruqueue assertequals methodlruqueue assertequals methodlruqueue tests link lru queue remove object method verifies if all objects are correctly removed checking the method return value if the object is still contained and the queue size public void test remove lru queue object methodlru queue new lru queue object object sample objects create sample objects sample elems number for int i 0 i sample objects length i methodlru queue push sample objects i removing all objects in the opposite way used by pop method for int i sample objects length 1 i 0 i assert true methodlru queue remove sample objects i assert false methodlru queue contains sample objects i assert equals i methodlru queue size lruqueue testremove lruqueue methodlruqueue lruqueue sampleobjects createsampleobjects sampleelemsnumber sampleobjects methodlruqueue sampleobjects sampleobjects asserttrue methodlruqueue sampleobjects assertfalse methodlruqueue sampleobjects assertequals methodlruqueue tests link lru queue remove object providing a null argument and trying to remove it after setting up a sample queue public void test remove null lru queue object methodlru queue create sample queue sample elems number try methodlru queue remove null fail expected exception error not thrown catch null pointer exception an exception assert not null an exception lruqueue testremovenull lruqueue methodlruqueue createsamplequeue sampleelemsnumber methodlruqueue nullpointerexception anexception assertnotnull anexception tests link lru queue remove object method trying to remove a not present object after setting up a sample queue public void test remove not present lru queue object methodlru queue create sample queue sample elems number assert false methodlru queue remove new object lruqueue testremovenotpresent lruqueue methodlruqueue createsamplequeue sampleelemsnumber assertfalse methodlruqueue tests link lru queue contains object method trying to find a not present object after setting up a sample queue then it search a present object public void test contains lru queue object methodlru queue create sample queue sample elems number assert false methodlru queue contains new object object method sample obj new object methodlru queue push method sample obj assert true methodlru queue contains method sample obj lruqueue testcontains lruqueue methodlruqueue createsamplequeue sampleelemsnumber assertfalse methodlruqueue methodsampleobj methodlruqueue methodsampleobj asserttrue methodlruqueue methodsampleobj tests link lru queue elements method verifying if the enumeration provided is correct public void test elements object sample objects create sample objects sample elems number lru queue object methodlru queue new lru queue object pushing objects for int i 0 i sample objects length i methodlru queue push sample objects i enumeration object method enumeration methodlru queue elements int j 0 while method enumeration has more elements assert equals sample objects j method enumeration next element j lruqueue testelements sampleobjects createsampleobjects sampleelemsnumber lruqueue methodlruqueue lruqueue sampleobjects methodlruqueue sampleobjects methodenumeration methodlruqueue methodenumeration hasmoreelements assertequals sampleobjects methodenumeration nextelement tests link lru queue to array method verifying if the array generated has the same object that are put into the created lru queue public void test to array lru queue object methodlru queue new lru queue object object sample objects create sample objects sample elems number pushing objects for int i 0 i sample objects length i methodlru queue push sample objects i object resulting array methodlru queue to array assert equals sample objects length resulting array length for int i 0 i sample objects length i assert true is present resulting array sample objects i lruqueue toarray lruqueue testtoarray lruqueue methodlruqueue lruqueue sampleobjects createsampleobjects sampleelemsnumber sampleobjects methodlruqueue sampleobjects resultingarray methodlruqueue toarray assertequals sampleobjects resultingarray sampleobjects asserttrue ispresent resultingarray sampleobjects tests link lru queue to array object method public void test to array2 lru queue object methodlru queue new lru queue object object sample objects create sample objects sample elems number pushing objects for int i 0 i sample objects length i methodlru queue push sample objects i object resulting array new object sample objects length methodlru queue to array resulting array assert equals sample objects length resulting array length for int i 0 i sample objects length i assert true is present resulting array sample objects i lruqueue toarray testtoarray2 lruqueue methodlruqueue lruqueue sampleobjects createsampleobjects sampleelemsnumber sampleobjects methodlruqueue sampleobjects resultingarray sampleobjects methodlruqueue toarray resultingarray assertequals sampleobjects resultingarray sampleobjects asserttrue ispresent resultingarray sampleobjects tests link lru queue to array ordered method public void test to array ordered lru queue object methodlru queue new lru queue object object sample objects create sample objects sample elems number pushing objects for int i 0 i sample objects length i methodlru queue push sample objects i object resulting array methodlru queue to array ordered assert equals sample objects length resulting array length for int i 0 i sample objects length i assert equals sample objects i resulting array i lruqueue toarrayordered testtoarrayordered lruqueue methodlruqueue lruqueue sampleobjects createsampleobjects sampleelemsnumber sampleobjects methodlruqueue sampleobjects resultingarray methodlruqueue toarrayordered assertequals sampleobjects resultingarray sampleobjects assertequals sampleobjects resultingarray tests code to array ordered object code method public void test to array ordered2 lru queue object methodlru queue new lru queue object object sample objects create sample objects sample elems number pushing objects for int i 0 i sample objects length i methodlru queue push sample objects i object resulting array new object sample objects length methodlru queue to array ordered resulting array assert equals resulting array length sample objects length for int i 0 i sample objects length i assert equals sample objects i resulting array i toarrayordered testtoarrayordered2 lruqueue methodlruqueue lruqueue sampleobjects createsampleobjects sampleelemsnumber sampleobjects methodlruqueue sampleobjects resultingarray sampleobjects methodlruqueue toarrayordered resultingarray assertequals resultingarray sampleobjects sampleobjects assertequals sampleobjects resultingarray tests to array method when the queue is empty public void test to array empty queue lru queue object methodlru queue new lru queue object assert equals 0 methodlru queue to array length toarray testtoarrayemptyqueue lruqueue methodlruqueue lruqueue assertequals methodlruqueue toarray tests is empty method trying it with an empty queue and then with a sample queue public void test is empty lru queue object methodlru queue new lru queue object assert true methodlru queue is empty methodlru queue create sample queue sample elems number assert false methodlru queue is empty emptying the queue for int i 0 i sample elems number i methodlru queue pop assert true methodlru queue is empty isempty testisempty lruqueue methodlruqueue lruqueue asserttrue methodlruqueue isempty methodlruqueue createsamplequeue sampleelemsnumber assertfalse methodlruqueue isempty sampleelemsnumber methodlruqueue asserttrue methodlruqueue isempty public void test loader object o null try o loader get instance java lang string catch invocation target exception e fail unexpected exception e get message catch no such method exception e fail unexpected exception e get message catch instantiation exception e fail unexpected exception e get message catch illegal access exception e fail unexpected exception e get message catch class not found exception e fail unexpected exception e get message assert true o instanceof java lang string testloader getinstance invocationtargetexception getmessage nosuchmethodexception getmessage instantiationexception getmessage illegalaccessexception getmessage classnotfoundexception getmessage asserttrue public void test wrapper byte data1 data string 1 get bytes byte data2 data string 2 get bytes byte array wrapper wrapper1 new byte array wrapper data1 byte array wrapper wrapper2 new byte array wrapper data1 byte array wrapper wrapper3 new byte array wrapper data2 assert equals wrapper1 wrapper2 assert true wrapper1 equals wrapper2 assert false wrapper2 equals wrapper3 assert false wrapper1 equals new string map byte array wrapper byte array wrapper map new hash map byte array wrapper byte array wrapper map put wrapper1 wrapper1 map put wrapper2 wrapper2 should clobber 1 by hashcode map put wrapper3 wrapper3 object o1 map get wrapper1 object o2 map get wrapper2 object o3 map get wrapper3 assert equals o1 o2 are wrapper1 and wrapper2 considered equivalent by hashcode assert false o1 wrapper1 did wrapper1 survive assert true o1 wrapper2 did wrapper1 get replaced by 2 assert true o3 wrapper3 did wrapper3 get returned by hashcode correctly testwrapper data_string_1 getbytes data_string_2 getbytes bytearraywrapper bytearraywrapper bytearraywrapper bytearraywrapper bytearraywrapper bytearraywrapper assertequals asserttrue assertfalse assertfalse bytearraywrapper bytearraywrapper hashmap bytearraywrapper bytearraywrapper assertequals assertfalse asserttrue asserttrue public void test format size long long method long method long long value of val and expected 0 0 assert equals size util format size method long long value 1 val and expected 0 1 for int i 1 i val and expected length i method long long value of val and expected i 0 assert equals size util format size method long long value 1 0 val and expected i 1 testformatsizelong methodlong methodlong valueof valandexpected assertequals sizeutil formatsize methodlong longvalue valandexpected valandexpected methodlong valueof valandexpected assertequals sizeutil formatsize methodlong longvalue valandexpected tests if format size long method works correctly with intermediate values i e 1 4 1 2 3 4 public void testformatsizelong withintermediatevalues long method long string actual value 1 0 1 25 1 5 1 75 for int i 1 i val and expected length i method long long value of val and expected i 0 for int j 0 j 4 j assert equals size util format size method long long value method long long value j 4 actual value j val and expected i 1 formatsize testformatsizelong_withintermediatevalues methodlong actualvalue valandexpected methodlong valueof valandexpected assertequals sizeutil formatsize methodlong longvalue methodlong longvalue actualvalue valandexpected private long one for term long 694861001 override protected void set up throws exception locale set default locale us onefortermlong setup setdefault tests format time long int boolean method trying the biggest long value public void testformattime longintboolean maxvalue string expected for max long value 15250284452w3d7h12m55 807s assert equals time util format time long max value 6 true expected for max long value formattime testformattime_longintboolean_maxvalue expectedformaxlongvalue assertequals timeutil formattime max_value expectedformaxlongvalue tests format time long int method trying the biggest long value public void testformattime longint string expected for max long value 15250284452w3d7h12m55s assert equals time util format time long max value 6 expected for max long value formattime testformattime_longint expectedformaxlongvalue assertequals timeutil formattime max_value expectedformaxlongvalue tests format time long method trying the biggest long value public void testformattime long it uses two terms by default string expected for max long value 15250284452w3d assert equals time util format time long max value expected for max long value formattime testformattime_long expectedformaxlongvalue assertequals timeutil formattime max_value expectedformaxlongvalue tests format time long method using known values they could be checked using google calculator http www google com intl en help features html calculator public void testformattime knownvalues long method long string val and expected one week 604800000 1w one day 86400000 1d one hour 3600000 1h one minute 60000 1m one second 1000 1s for int i 0 i val and expected length i method long long value of val and expected i 0 assert equals time util format time method long long value val and expected i 1 formattime testformattime_knownvalues methodlong valandexpected valandexpected methodlong valueof valandexpected assertequals timeutil formattime methodlong longvalue valandexpected tests format time long int method using a long value that generate every possible term kind it tests if the max terms arguments works correctly public void testformattime longintboolean maxterms string val and expected 0 terms 1 term 1w 2 terms 1w1d 3 terms 1w1d1h 4 terms 1w1d1h1m 5 terms 1w1d1h1m1s 6 terms 1w1d1h1m1 001s for int i 0 i val and expected length i assert equals time util format time one for term long i true val and expected i formattime maxterms testformattime_longintboolean_maxterms valandexpected valandexpected assertequals timeutil formattime onefortermlong valandexpected tests format time long int method using one millisecond time interval it tests if the with second fractions argument works correctly public void testformattime longintboolean milliseconds long method value 1 1ms assert equals time util format time method value 6 false 0 assert equals time util format time method value 6 true 0 001s formattime withsecondfractions testformattime_longintboolean_milliseconds methodvalue assertequals timeutil formattime methodvalue assertequals timeutil formattime methodvalue tests format time long int method using a long value that generate every possible term kind it tests if the max terms arguments works correctly public void testformattime longintboolean toomanyterms try time util format time one for term long 7 fail expected illegal argument exception not thrown catch illegal argument exception an exception assert not null an exception formattime maxterms testformattime_longintboolean_toomanyterms timeutil formattime onefortermlong illegalargumentexception illegalargumentexception anexception assertnotnull anexception creates a double array of objects with a specified size where object i 0 is the key and is an integer and object i 1 is the value param size the array size return the objects double array private object create sample key val int size object sample objects new object size 2 for int i 0 i sample objects length i key sample objects i 0 new integer i value sample objects i 1 new object return sample objects createsamplekeyval sampleobjects sampleobjects sampleobjects sampleobjects sampleobjects creates a lru hashtable filled with the specified objects number param size hash table size return the created lru hashtable private lru hashtable object object create sample hash table int size lru hashtable object object methodlr uht new lru hashtable object object object sample objects create sample key val size for int i 0 i sample objects length i methodlr uht push sample objects i 0 sample objects i 1 return methodlr uht lruhashtable hashtable lruhashtable lruhashtable createsamplehashtable lruhashtable methodlruht lruhashtable sampleobjects createsamplekeyval sampleobjects methodlruht sampleobjects sampleobjects methodlruht it verifies if a key value pair is present in a lru hashtable param alr uht a lru hashtable to check in param a key a key to find param a value the correspondent value return true if the key is present and returned value is the same as in the argument private boolean verify key val presence lru hashtable object object alr uht object a key object a value if alr uht contains key a key return alr uht get a key equals a value return false lruhashtable alruht lruhashtable akey avalue verifykeyvalpresence lruhashtable alruht akey avalue alruht containskey akey alruht akey avalue tests push object object method providing null object as arguments after setting up a sample hash table and verifying if the correct exception is raised public void test push null lru hashtable object object methodlr uht create sample hash table sample elems number try a null value is admitted methodlr uht push new object null catch null pointer exception an exception fail not expected exception thrown an exception get message try methodlr uht push null null fail expected exception error not thrown catch null pointer exception an exception assert not null an exception try methodlr uht push null new object fail expected exception error not thrown catch null pointer exception an exception assert not null an exception hashtable testpushnull lruhashtable methodlruht createsamplehashtable sampleelemsnumber methodlruht nullpointerexception anexception anexception getmessage methodlruht nullpointerexception anexception assertnotnull anexception methodlruht nullpointerexception anexception assertnotnull anexception tests push object object method and verifies the behaviour when pushing the same object more than one time public void test push same obj twice lru hashtable object object methodlr uht create sample hash table sample elems number object sample obj new integer sample elems number new object new integer sample elems number 1 new object methodlr uht push sample obj 0 0 sample obj 0 1 methodlr uht push sample obj 1 0 sample obj 1 1 check presence assert true verify key val presence methodlr uht sample obj 0 0 sample obj 0 1 assert true verify key val presence methodlr uht sample obj 1 0 sample obj 1 1 check size assert true methodlr uht size sample elems number 2 push the same object another time methodlr uht push sample obj 0 0 sample obj 0 1 assert true verify key val presence methodlr uht sample obj 0 0 sample obj 0 1 assert true verify key val presence methodlr uht sample obj 1 0 sample obj 1 1 assert true methodlr uht size sample elems number 2 testpushsameobjtwice lruhashtable methodlruht createsamplehashtable sampleelemsnumber sampleobj sampleelemsnumber sampleelemsnumber methodlruht sampleobj sampleobj methodlruht sampleobj sampleobj asserttrue verifykeyvalpresence methodlruht sampleobj sampleobj asserttrue verifykeyvalpresence methodlruht sampleobj sampleobj asserttrue methodlruht sampleelemsnumber methodlruht sampleobj sampleobj asserttrue verifykeyvalpresence methodlruht sampleobj sampleobj asserttrue verifykeyvalpresence methodlruht sampleobj sampleobj asserttrue methodlruht sampleelemsnumber tests push object object method and verifies the behaviour when pushing the same key with two different values public void test push same key lru hashtable object object methodlr uht create sample hash table sample elems number object sample obj new integer sample elems number new object new integer sample elems number 1 new object methodlr uht push sample obj 0 0 sample obj 0 1 methodlr uht push sample obj 1 0 sample obj 1 1 check presence assert true verify key val presence methodlr uht sample obj 0 0 sample obj 0 1 assert true verify key val presence methodlr uht sample obj 1 0 sample obj 1 1 check size assert true methodlr uht size sample elems number 2 creating and pushing a different value sample obj 0 1 new object methodlr uht push sample obj 0 0 sample obj 0 1 assert true verify key val presence methodlr uht sample obj 0 0 sample obj 0 1 assert true verify key val presence methodlr uht sample obj 1 0 sample obj 1 1 assert true methodlr uht size sample elems number 2 testpushsamekey lruhashtable methodlruht createsamplehashtable sampleelemsnumber sampleobj sampleelemsnumber sampleelemsnumber methodlruht sampleobj sampleobj methodlruht sampleobj sampleobj asserttrue verifykeyvalpresence methodlruht sampleobj sampleobj asserttrue verifykeyvalpresence methodlruht sampleobj sampleobj asserttrue methodlruht sampleelemsnumber sampleobj methodlruht sampleobj sampleobj asserttrue verifykeyvalpresence methodlruht sampleobj sampleobj asserttrue verifykeyvalpresence methodlruht sampleobj sampleobj asserttrue methodlruht sampleelemsnumber tests pop key method pushing and popping objects and verifying if their keys are correctly in a fifo manner fetched and the hash table entry deleted public void test pop key lru hashtable object object methodlr uht new lru hashtable object object object sample objects create sample key val sample elems number pushing objects for int i 0 i sample objects length i methodlr uht push sample objects i 0 sample objects i 1 getting keys for int i 0 i sample objects length i assert equals sample objects i 0 methodlr uht pop key the hash table must be empty assert null methodlr uht pop key popkey hashtable testpopkey lruhashtable methodlruht lruhashtable sampleobjects createsamplekeyval sampleelemsnumber sampleobjects methodlruht sampleobjects sampleobjects sampleobjects assertequals sampleobjects methodlruht popkey hashtable assertnull methodlruht popkey tests pop value method pushing and popping objects and verifying if their values are correctly in a fifo manner fetched and the hash table entry deleted public void test pop value lru hashtable object object methodlr uht new lru hashtable object object object sample objects create sample key val sample elems number pushing objects for int i 0 i sample objects length i methodlr uht push sample objects i 0 sample objects i 1 getting values for int i 0 i sample objects length i assert equals sample objects i 1 methodlr uht pop value the hash table must be empty assert null methodlr uht pop key popvalue hashtable testpopvalue lruhashtable methodlruht lruhashtable sampleobjects createsamplekeyval sampleelemsnumber sampleobjects methodlruht sampleobjects sampleobjects sampleobjects assertequals sampleobjects methodlruht popvalue hashtable assertnull methodlruht popkey tests pop value method popping a value from an empty lru hashtable public void test pop value from empty lru hashtable methodlr uht new lru hashtable object object assert null methodlr uht pop value popvalue lruhashtable testpopvaluefromempty lruhashtable methodlruht lruhashtable assertnull methodlruht popvalue tests peek value method pushing and popping objects and verifying if their peek value is correct public void test peek value lru hashtable object object methodlr uht new lru hashtable object object object sample objects create sample key val sample elems number pushing objects for int i 0 i sample objects length i methodlr uht push sample objects i 0 sample objects i 1 getting values for int i 0 i sample objects length i assert equals sample objects i 1 methodlr uht peek value methodlr uht pop key the hash table must be empty assert null methodlr uht peek value insert and fetch a null value methodlr uht push new object null assert null methodlr uht peek value peekvalue peekvalue testpeekvalue lruhashtable methodlruht lruhashtable sampleobjects createsamplekeyval sampleelemsnumber sampleobjects methodlruht sampleobjects sampleobjects sampleobjects assertequals sampleobjects methodlruht peekvalue methodlruht popkey hashtable assertnull methodlruht peekvalue methodlruht assertnull methodlruht peekvalue tests size method pushing and popping elements into the lru hash table public void test size lru hashtable object object methodlr uht new lru hashtable object object object sample objects create sample key val sample elems number assert true methodlr uht size 0 pushing objects for int i 0 i sample objects length i methodlr uht push sample objects i 0 sample objects i 1 assert true methodlr uht size i 1 popping keys for int i sample objects length 1 i 0 i methodlr uht pop key assert true methodlr uht size i lruhashtable testsize lruhashtable methodlruht lruhashtable sampleobjects createsamplekeyval sampleelemsnumber asserttrue methodlruht sampleobjects methodlruht sampleobjects sampleobjects asserttrue methodlruht sampleobjects methodlruht popkey asserttrue methodlruht tests remove key object method verifies if all elements are correctly removed checking the method return value if the element is still contained and the hash table size public void test remove key lru hashtable object object methodlr uht new lru hashtable object object object sample objects create sample key val sample elems number pushing objects for int i 0 i sample objects length i methodlr uht push sample objects i 0 sample objects i 1 popping keys for int i sample objects length 1 i 0 i assert true methodlr uht remove key sample objects i 0 assert false methodlr uht contains key sample objects i 0 assert true methodlr uht size i removekey hashtable testremovekey lruhashtable methodlruht lruhashtable sampleobjects createsamplekeyval sampleelemsnumber sampleobjects methodlruht sampleobjects sampleobjects sampleobjects asserttrue methodlruht removekey sampleobjects assertfalse methodlruht containskey sampleobjects asserttrue methodlruht tests remove key object providing a null key and trying to remove it after setting up a sample queue public void test remove null key lru hashtable object object methodlr uht create sample hash table sample elems number try methodlr uht remove key null fail expected exception error not thrown catch null pointer exception an exception assert not null an exception removekey testremovenullkey lruhashtable methodlruht createsamplehashtable sampleelemsnumber methodlruht removekey nullpointerexception anexception assertnotnull anexception tests remove key object method trying to remove a not present key after setting up a sample lru hashtable public void test remove not present lru hashtable object object methodlr uht create sample hash table sample elems number assert false methodlr uht remove key new object removekey lruhashtable testremovenotpresent lruhashtable methodlruht createsamplehashtable sampleelemsnumber assertfalse methodlruht removekey tests contains key object method trying to find a not present key after setting up a sample queue then it search for a present one public void test contains key lru hashtable object object methodlr uht create sample hash table sample elems number assert false methodlr uht contains key new object object method sample obj new object methodlr uht push method sample obj null assert true methodlr uht contains key method sample obj containskey testcontainskey lruhashtable methodlruht createsamplehashtable sampleelemsnumber assertfalse methodlruht containskey methodsampleobj methodlruht methodsampleobj asserttrue methodlruht containskey methodsampleobj tests get object method trying to find a not present key after setting up a sample hash table then it search a present key public void test get lru hashtable object object methodlr uht create sample hash table sample elems number assert null methodlr uht get new object object method sample key new object object method sample value new object methodlr uht push method sample key method sample value assert equals methodlr uht get method sample key method sample value hashtable testget lruhashtable methodlruht createsamplehashtable sampleelemsnumber assertnull methodlruht methodsamplekey methodsamplevalue methodlruht methodsamplekey methodsamplevalue assertequals methodlruht methodsamplekey methodsamplevalue tests get object trying to fetch a null key public void test get null key lru hashtable object object methodlr uht create sample hash table sample elems number try methodlr uht get null fail expected exception error not thrown catch null pointer exception an exception assert not null an exception testgetnullkey lruhashtable methodlruht createsamplehashtable sampleelemsnumber methodlruht nullpointerexception anexception assertnotnull anexception tests keys method verifying if the enumeration provided is correct public void test keys lru hashtable object object methodlr uht new lru hashtable object object object sample objects create sample key val sample elems number pushing objects for int i 0 i sample objects length i methodlr uht push sample objects i 0 sample objects i 1 enumeration object method enumeration methodlr uht keys int j 0 while method enumeration has more elements assert equals method enumeration next element sample objects j 0 j testkeys lruhashtable methodlruht lruhashtable sampleobjects createsamplekeyval sampleelemsnumber sampleobjects methodlruht sampleobjects sampleobjects methodenumeration methodlruht methodenumeration hasmoreelements assertequals methodenumeration nextelement sampleobjects tests is empty method trying it with a new generated hash table and after popping out all keys in a sample lru hash table public void test is empty lru hashtable object object methodlr uht new lru hashtable object object assert true methodlr uht is empty methodlr uht create sample hash table sample elems number popping keys for int i 0 i sample elems number i methodlr uht pop key assert true methodlr uht is empty isempty hashtable lruhashtable testisempty lruhashtable methodlruht lruhashtable asserttrue methodlruht isempty methodlruht createsamplehashtable sampleelemsnumber sampleelemsnumber methodlruht popkey asserttrue methodlruht isempty public void test hex to long long l1 fields hex to long 0 assert equals l1 0 l1 fields hex to long 000000 assert equals l1 0 l1 fields hex to long 1 assert equals l1 1 l1 fields hex to long a assert equals l1 10 l1 fields hex to long ff assert equals l1 255 l1 fields hex to long ffffffff assert equals l1 4294967295l l1 fields hex to long 7fffffffffffffff assert equals l1 long max value l1 fields hex to long 8000000000000000 assert equals l1 long min value l1 fields hex to long f ffff fff mix case assert equals l1 4294967295l try l1 fields hex to long abcdef123456789aa 17 chars fail catch number format exception e expect this try l1 fields hex to long deadc0der invalid char fail catch number format exception e expect this see javadoc l1 fields hex to long long to hex string 20 assert equals 20 l1 l1 fields hex to long long to hex string long min value assert equals long min value l1 see javadoc try string long as string long to string 1 16 l1 fields hex to long long as string fail catch number format exception e expect this testhextolong hextolong assertequals hextolong assertequals hextolong assertequals hextolong assertequals hextolong assertequals hextolong assertequals hextolong assertequals max_value hextolong assertequals min_value hextolong ffffffff assertequals hextolong numberformatexception hextolong numberformatexception hextolong tohexstring assertequals hextolong tohexstring min_value assertequals min_value longasstring tostring hextolong longasstring numberformatexception public void test hex to int int i1 fields hex to int 0 assert equals i1 0 i1 fields hex to int 000000 assert equals i1 0 i1 fields hex to int 1 assert equals i1 1 i1 fields hex to int a assert equals i1 10 i1 fields hex to int ff assert equals i1 255 i1 fields hex to int 80000000 assert equals i1 integer min value i1 fields hex to int 0000000080000000 16 chars assert equals i1 integer min value i1 fields hex to int 7fffffff assert equals i1 integer max value try i1 fields hex to int 0123456789abcdef0 17 chars fail catch number format exception e expect this try i1 fields hex to int c0der invalid char fail catch number format exception e expect this see javadoc i1 fields hex to int integer to hex string 20 assert equals 20 i1 i1 fields hex to int long to hex string integer min value assert equals integer min value i1 see javadoc try string integer as string integer to string 1 16 i1 fields hex to int integer as string fail catch number format exception e expect this testhextoint hextoint assertequals hextoint assertequals hextoint assertequals hextoint assertequals hextoint assertequals hextoint assertequals min_value hextoint assertequals min_value hextoint assertequals max_value hextoint numberformatexception hextoint numberformatexception hextoint tohexstring assertequals hextoint tohexstring min_value assertequals min_value integerasstring tostring hextoint integerasstring numberformatexception public void test string to bool assert true fields string to bool true assert true fields string to bool true assert false fields string to bool false assert false fields string to bool false try fields string to bool free tibet fail catch number format exception e expect this try fields string to bool null fail catch number format exception e expect this teststringtobool asserttrue stringtobool asserttrue stringtobool assertfalse stringtobool assertfalse stringtobool stringtobool numberformatexception stringtobool numberformatexception public void test string to bool with default assert true fields string to bool true false assert false fields string to bool false true assert true fields string to bool true false assert false fields string to bool false true assert true fields string to bool truexxx true assert false fields string to bool xxx false false assert true fields string to bool null true teststringtoboolwithdefault asserttrue stringtobool assertfalse stringtobool asserttrue stringtobool assertfalse stringtobool asserttrue stringtobool assertfalse stringtobool xxxfalse asserttrue stringtobool public void test bool to string assert equals fields bool to string true true assert equals fields bool to string false false testbooltostring assertequals booltostring assertequals booltostring public void test comma list from string string expected new string one two three four string actual fields comma list one two three four for int i 0 i expected length i assert equals expected i actual i null assert null fields comma list string null no items expected new string actual fields comma list assert true expected length actual length testcommalistfromstring commalist assertequals assertnull commalist commalist asserttrue public void test string array to comma list string input new string one two three four string expected one two three four string actual fields comma list input assert equals expected actual empty input new string expected actual fields comma list input assert equals expected actual teststringarraytocommalist commalist assertequals commalist assertequals public void test hashcode for byte array byte input new byte 0 1 2 3 4 5 6 7 assert equals 67372036 fields hash code input empty input new byte assert equals 0 fields hash code input testhashcodeforbytearray assertequals hashcode assertequals hashcode public void test long hashcode byte b1 new byte 1 1 2 2 3 3 byte b2 new byte 2 2 3 3 4 4 byte b3 new byte 1 1 2 2 3 3 long l1 new long fields long hash code b1 long l2 new long fields long hash code b2 long l3 new long fields long hash code b3 assert false l1 equals l2 assert false l2 equals l3 assert true l3 equals l1 should be same due to fields long hashcode testlonghashcode longhashcode longhashcode longhashcode assertfalse assertfalse asserttrue longhashcode public void test ints to bytes int longs new int do round trip ints array to bytes array longs longs new int integer min value do round trip ints array to bytes array longs longs new int 0 integer max value integer min value do round trip ints array to bytes array longs longs new int 33685760 51511577 do round trip ints array to bytes array longs testintstobytes doroundtripintsarraytobytesarray min_value doroundtripintsarraytobytesarray max_value min_value doroundtripintsarraytobytesarray doroundtripintsarraytobytesarray private void do round trip ints array to bytes array int ints byte bytes fields ints to bytes ints assert bytes length ints length 8 int out longs fields bytes to ints bytes for int i 0 i ints length i assert true out longs i ints i assert equals out longs length ints length doroundtripintsarraytobytesarray intstobytes outlongs bytestoints asserttrue outlongs assertequals outlongs public void test bytes to longs exception byte bytes new byte 3 try fields bytes to longs bytes 0 bytes length fail catch illegal argument exception e expect this testbytestolongsexception bytestolongs illegalargumentexception public void test bytes to int byte bytes new byte 0 1 2 2 int out long fields bytes to int bytes 0 we did dupplicate the code to avoid cross dependancies todo will need to be updated when next ext is released int out longmt mersenne twister bytes to int bytes 0 assert equals out long out longmt assert equals out long 33685760 do test round trip bytes array to int bytes bytes new byte try do test round trip bytes array to int bytes fail catch illegal argument exception e expect this bytes new byte 1 1 1 1 do test round trip bytes array to int bytes testbytestoint outlong bytestoint outlongmt mersennetwister bytestoint assertequals outlong outlongmt assertequals outlong dotestroundtripbytesarraytoint dotestroundtripbytesarraytoint illegalargumentexception dotestroundtripbytesarraytoint private void do test round trip bytes array to int byte in bytes int out long fields bytes to int in bytes 0 assert equals out long mersenne twister bytes to int in bytes 0 byte out bytes fields int to bytes out long for int i 0 i in bytes length i assert equals out bytes i in bytes i assert equals out bytes length in bytes length dotestroundtripbytesarraytoint inbytes outlong bytestoint inbytes assertequals outlong mersennetwister bytestoint inbytes outbytes inttobytes outlong inbytes assertequals outbytes inbytes assertequals outbytes inbytes public void test longs to bytes long longs new long do round trip longs array to bytes array longs longs new long long min value do round trip longs array to bytes array longs longs new long 0l long max value long min value do round trip longs array to bytes array longs longs new long 3733393793879837l do round trip longs array to bytes array longs testlongstobytes doroundtriplongsarraytobytesarray min_value doroundtriplongsarraytobytesarray max_value min_value doroundtriplongsarraytobytesarray doroundtriplongsarraytobytesarray private void do round trip longs array to bytes array long longs byte bytes fields longs to bytes longs assert bytes length longs length 8 long out longs fields bytes to longs bytes for int i 0 i longs length i assert true out longs i longs i assert equals out longs length longs length doroundtriplongsarraytobytesarray longstobytes outlongs bytestolongs asserttrue outlongs assertequals outlongs public void test bytes to long exception byte bytes new byte 3 try fields bytes to longs bytes 0 bytes length fail catch illegal argument exception e expect this testbytestolongexception bytestolongs illegalargumentexception public void test bytes to long byte bytes new byte 0 1 2 2 1 3 6 7 long out long fields bytes to long bytes assert equals out long 506095310989295872l do test round trip bytes array to long bytes bytes new byte try do test round trip bytes array to long bytes fail catch illegal argument exception e expect this bytes new byte 1 1 1 1 1 1 1 1 do test round trip bytes array to long bytes testbytestolong outlong bytestolong assertequals outlong dotestroundtripbytesarraytolong dotestroundtripbytesarraytolong illegalargumentexception dotestroundtripbytesarraytolong private void do test round trip bytes array to long byte in bytes long out long fields bytes to long in bytes byte out bytes fields long to bytes out long for int i 0 i in bytes length i assert equals out bytes i in bytes i assert equals out bytes length in bytes length dotestroundtripbytesarraytolong inbytes outlong bytestolong inbytes outbytes longtobytes outlong inbytes assertequals outbytes inbytes assertequals outbytes inbytes private int value public t int v this value v public doubly linked list get parent return parent doublylinkedlist getparent public doubly linked list set parent doubly linked list l doubly linked list old parent parent l return old doublylinkedlist setparent doublylinkedlist doublylinkedlist public int compare to object o t t t o return t value value 0 t value value 1 1 compareto void assertv int v assert equals v value assertequals override public boolean equals object o if o null return false if o get class this get class return false t t t o return t value value getclass getclass override public int hash code return value hashcode public string to string return value tostring public void test add1 throws updatable sorted linked list killed exception updatable sorted linked list l new updatable sorted linked list l debug true assert true is empty l is empty assert equals size 0 l size l add new t 2 assert false is empty l is empty l add new t 5 l add new t 1 l add new t 5 l add new t 3 l add new t 0 l add new t 1 l add new t 3 l add new t 2 l add new t 4 l add new t 4 assert equals size 11 l size updatable sorted linked list item a l to array assert equals t a 0 value 5 assert equals t a 1 value 4 assert equals t a 2 value 3 assert equals t a 3 value 2 assert equals t a 4 value 1 assert equals t a 5 value 0 assert equals t a 6 value 1 assert equals t a 7 value 2 assert equals t a 8 value 3 assert equals t a 9 value 4 assert equals t a 10 value 5 t l get lowest assertv 5 t l remove lowest assertv 5 assert false is empty l is empty assert equals size 10 l size t l remove lowest assertv 4 t l remove lowest assertv 3 t l get lowest assertv 2 t l remove lowest assertv 2 t l remove lowest assertv 1 t l remove lowest assertv 0 t l remove lowest assertv 1 t l remove lowest assertv 2 t l remove lowest assertv 3 t l remove lowest assertv 4 t l remove lowest assertv 5 assert true is empty l is empty assert equals size 0 l size testadd1 updatablesortedlinkedlistkilledexception updatablesortedlinkedlist updatablesortedlinkedlist asserttrue isempty isempty assertequals assertfalse isempty isempty assertequals updatablesortedlinkedlistitem toarray assertequals assertequals assertequals assertequals assertequals assertequals assertequals assertequals assertequals assertequals assertequals getlowest removelowest assertfalse isempty isempty assertequals removelowest removelowest getlowest removelowest removelowest removelowest removelowest removelowest removelowest removelowest removelowest asserttrue isempty isempty assertequals public void test update throws updatable sorted linked list killed exception updatable sorted linked list l new updatable sorted linked list l debug true t t new t new t 0 new t 1 new t 2 new t 3 new t 4 l add t 0 l add t 1 l add t 2 l add t 3 l add t 4 t 1 value 99 l update t 1 t 0 value 99 l update t 0 t 4 value 98 l update t 4 t 2 value 98 l update t 2 l update t 0 l update t 1 l update t 4 assert same t 1 l remove lowest assert same t 4 l remove lowest assert same t 3 l remove lowest assert same t 2 l remove lowest assert same t 0 l remove lowest testupdate updatablesortedlinkedlistkilledexception updatablesortedlinkedlist updatablesortedlinkedlist assertsame removelowest assertsame removelowest assertsame removelowest assertsame removelowest assertsame removelowest public void test clear kill throws updatable sorted linked list killed exception updatable sorted linked list l new updatable sorted linked list l debug true l add new t 2 l add new t 5 l add new t 1 l add new t 5 l clear assert equals l size 0 l add new t 3 l add new t 0 l add new t 1 l add new t 3 l add new t 2 l add new t 4 assert equals l size 6 updatable sorted linked list item a l to array assert equals t a 0 value 3 assert equals t a 1 value 2 assert equals t a 2 value 0 assert equals t a 3 value 1 assert equals t a 4 value 3 assert equals t a 5 value 4 l kill assert equals l size 0 try l add new t 4 fail no updatable sorted linked list killed exception on add catch updatable sorted linked list killed exception usllke try l remove new t 4 fail no updatable sorted linked list killed exception on remove catch updatable sorted linked list killed exception usllke try l update new t 4 fail no updatable sorted linked list killed exception on update catch updatable sorted linked list killed exception usllke try l to array fail no updatable sorted linked list killed exception on to array catch updatable sorted linked list killed exception usllke try l remove lowest should it throw catch updatable sorted linked list killed exception usllke fail updatable sorted linked list killed exception on remove lowest testclearkill updatablesortedlinkedlistkilledexception updatablesortedlinkedlist updatablesortedlinkedlist assertequals assertequals updatablesortedlinkedlistitem toarray assertequals assertequals assertequals assertequals assertequals assertequals assertequals updatablesortedlinkedlistkilledexception updatablesortedlinkedlistkilledexception updatablesortedlinkedlistkilledexception updatablesortedlinkedlistkilledexception updatablesortedlinkedlistkilledexception updatablesortedlinkedlistkilledexception toarray updatablesortedlinkedlistkilledexception toarray updatablesortedlinkedlistkilledexception removelowest updatablesortedlinkedlistkilledexception updatablesortedlinkedlistkilledexception removelowest test the bytes to hex byte method against every possible single byte value public void testbytestohex byte byte method byte array new byte 1 string expected result for int i 255 i 0 i method byte array 0 byte i integer to hex string works with int so it doesn t return always a two digit hex for this reason we need the next switch case expected result i 15 0 integer to hex string i integer to hex string i assert equals expected result hex util bytes to hex method byte array bytestohex testbytestohex_byte methodbytearray expectedresult methodbytearray tohexstring expectedresult tohexstring tohexstring assertequals expectedresult hexutil bytestohex methodbytearray test the hex to bytes string method against the hex representation of every possible single byte the starting offset is always 0 public void testhextobytes string byte expected byte array new byte 1 string method hex string for int i 255 i 0 i expected byte array 0 byte i integer to hex string works with int so it doesn t return always a two digit hex for this reason we need the next switch case method hex string i 15 0 integer to hex string i integer to hex string i assert true arrays equals expected byte array hex util hex to bytes method hex string hextobytes testhextobytes_string expectedbytearray methodhexstring expectedbytearray tohexstring methodhexstring tohexstring tohexstring asserttrue expectedbytearray hexutil hextobytes methodhexstring test the hex to bytes string int method against the hex representation of every possible single byte the starting offset is always 0 public void testhextobytes stringint byte expected byte array new byte 1 string method hex string for int i 255 i 0 i expected byte array 0 byte i integer to hex string works with int so it doesn t return always a two digit hex for this reason we need the next switch case method hex string i 15 0 integer to hex string i integer to hex string i assert true arrays equals expected byte array hex util hex to bytes method hex string 0 hextobytes testhextobytes_stringint expectedbytearray methodhexstring expectedbytearray tohexstring methodhexstring tohexstring tohexstring asserttrue expectedbytearray hexutil hextobytes methodhexstring test the hex to bytes string byte int method against the hex representation of every possible single byte public void testhextobytes stringbyteint byte expected byte array new byte 1 byte output array new byte 1 string method hex string for int i 255 i 0 i expected byte array 0 byte i integer to hex string works with int so it doesn t return always a two digit hex for this reason we need the next switch case method hex string i 15 0 integer to hex string i integer to hex string i hex util hex to bytes method hex string output array 0 assert true arrays equals expected byte array output array hextobytes testhextobytes_stringbyteint expectedbytearray outputarray methodhexstring expectedbytearray tohexstring methodhexstring tohexstring tohexstring hexutil hextobytes methodhexstring outputarray asserttrue expectedbytearray outputarray test the bits to byte bit set int method against the bit representation of every possible single byte public void testbitstobytes bitsetint byte expected byte array new byte 1 byte output array new byte 1 bit set method bit set new bit set 8 for int i 0 i 256 i output array hex util bits to bytes method bit set 8 expected byte array 0 byte i assert true arrays equals expected byte array output array add one method bit set bitstobyte bitset testbitstobytes_bitsetint expectedbytearray outputarray bitset methodbitset bitset outputarray hexutil bitstobytes methodbitset expectedbytearray asserttrue expectedbytearray outputarray addone methodbitset it adds 1 to a given bit set param a bit set private void add one bit set a bit set int bit set index 0 while a bit set get bit set index true a bit set flip bit set index bit set index a bit set flip bit set index bitset abitset addone bitset abitset bitsetindex abitset bitsetindex abitset bitsetindex bitsetindex abitset bitsetindex test count bytes for bits int method against all possible values until 256 bytes public void testcountbytesforbits int border case assert equals hex util count bytes for bits 0 0 for int expected bytes count 1 expected bytes count 256 expected bytes count for int bits expected bytes count 1 8 1 bits expected bytes count 8 bits assert equals hex util count bytes for bits bits expected bytes count countbytesforbits testcountbytesforbits_int assertequals hexutil countbytesforbits expectedbytescount expectedbytescount expectedbytescount expectedbytescount expectedbytescount assertequals hexutil countbytesforbits expectedbytescount test bytes to bits byte bit set int method against all possible single byte value it uses hex util bits to bytes method for the check so be sure that method works correctly public void testbytestobits bytebitsetint byte method byte array new byte 1 bit set method bit set new bit set 8 for int i 0 i 255 i method byte array 0 byte i hex util bytes to bits method byte array method bit set 7 assert true arrays equals method byte array hex util bits to bytes method bit set 8 bytestobits bitset hexutil bitstobytes testbytestobits_bytebitsetint methodbytearray bitset methodbitset bitset methodbytearray hexutil bytestobits methodbytearray methodbitset asserttrue methodbytearray hexutil bitstobytes methodbitset test bi to hex big integer method comparing its results to results provided by different scientific valid calculators public void testbitohex biginteger big integer method big integer new big integer 999999999999999 string expected hex value 038d7ea4c67fff assert equals hex util bi to hex method big integer expected hex value method big integer new big integer 0 expected hex value 00 assert equals hex util bi to hex method big integer expected hex value method big integer new big integer 72057594037927935 expected hex value 00ffffffffffffff assert equals hex util bi to hex method big integer expected hex value bitohex biginteger testbitohex_biginteger biginteger methodbiginteger biginteger expectedhexvalue assertequals hexutil bitohex methodbiginteger expectedhexvalue methodbiginteger biginteger expectedhexvalue assertequals hexutil bitohex methodbiginteger expectedhexvalue methodbiginteger biginteger expectedhexvalue assertequals hexutil bitohex methodbiginteger expectedhexvalue test bits to hex string bit set int method comparing its results to results provided by different scientific valid calculators public void test bits to hex string bit set method bit set new bit set 8 string expected string 00 assert equals hex util bits to hex string method bit set 8 expected string method bit set set 0 7 true 0x7f expected string 7f assert equals hex util bits to hex string method bit set 8 expected string method bit set set 0 9 true 0xff expected string ff assert equals hex util bits to hex string method bit set 8 expected string bitstohexstring bitset testbitstohexstring bitset methodbitset bitset expectedstring assertequals hexutil bitstohexstring methodbitset expectedstring methodbitset expectedstring assertequals hexutil bitstohexstring methodbitset expectedstring methodbitset expectedstring assertequals hexutil bitstohexstring methodbitset expectedstring tests hex to bits string bit set int method public void test hex to bits string method string to store 00 bit set method bit set new bit set 8 hex util hex to bits method string to store method bit set method bit set size assert true method bit set cardinality 0 bit set expected bit set new bit set 8 expected bit set set 0 7 true 0x7f method string to store 7f method bit set new bit set 8 hex util hex to bits method string to store method bit set method bit set size assert true method bit set intersects expected bit set expected bit set set 0 9 true 0xff method string to store ff method bit set new bit set 8 hex util hex to bits method string to store method bit set method bit set size assert true method bit set intersects expected bit set hextobits bitset testhextobits methodstringtostore bitset methodbitset bitset hexutil hextobits methodstringtostore methodbitset methodbitset asserttrue methodbitset bitset expectedbitset bitset expectedbitset methodstringtostore methodbitset bitset hexutil hextobits methodstringtostore methodbitset methodbitset asserttrue methodbitset expectedbitset expectedbitset methodstringtostore methodbitset bitset hexutil hextobits methodstringtostore methodbitset methodbitset asserttrue methodbitset expectedbitset tests write big integer big integer data output stream and read big integer data input stream comparing a big integer after writing it to a stream and reading it from the writing result public void test write and read big integer big integer method big integer new big integer 999999999999999 byte array output stream method byte array out stream new byte array output stream data output stream method data out stream new data output stream method byte array out stream try hex util write big integer method big integer method data out stream byte array input stream method byte array in stream new byte array input stream method byte array out stream to byte array data input stream method data in stream new data input stream method byte array in stream assert true method big integer compare to hex util read big integer method data in stream 0 catch io exception a exception fail not expected exception thrown a exception get message writebiginteger biginteger dataoutputstream readbiginteger datainputstream biginteger testwriteandreadbiginteger biginteger methodbiginteger biginteger bytearrayoutputstream methodbytearrayoutstream bytearrayoutputstream dataoutputstream methoddataoutstream dataoutputstream methodbytearrayoutstream hexutil writebiginteger methodbiginteger methoddataoutstream bytearrayinputstream methodbytearrayinstream bytearrayinputstream methodbytearrayoutstream tobytearray datainputstream methoddatainstream datainputstream methodbytearrayinstream asserttrue methodbiginteger compareto hexutil readbiginteger methoddatainstream ioexception aexception aexception getmessage test bytes to hex byte int int method with a too long starting offset the tested method should raise an exception public void testbytestohex byteintint withlongoffset try int array length 3 byte method bytes array new byte array length hex util bytes to hex method bytes array array length 1 1 fail expected exception error not thrown catch illegal argument exception an exception assert not null an exception bytestohex testbytestohex_byteintint_withlongoffset arraylength methodbytesarray arraylength hexutil bytestohex methodbytesarray arraylength illegalargumentexception anexception assertnotnull anexception test bytes to hex byte int int method with asking to read too many bytes the tested method should raise an exception public void testbytestohex byteintint withlongreading try int array length 3 byte method bytes array new byte array length hex util bytes to hex method bytes array 0 array length 1 fail expected exception error not thrown catch illegal argument exception an exception assert not null an exception bytestohex testbytestohex_byteintint_withlongreading arraylength methodbytesarray arraylength hexutil bytestohex methodbytesarray arraylength illegalargumentexception anexception assertnotnull anexception test bytes to hex byte int int method with a 0 length public void testbytestohex byteintint withzerolength int length 0 byte method bytes array 1 2 3 a non zero bytes array assert equals hex util bytes to hex method bytes array 0 length bytestohex testbytestohex_byteintint_withzerolength methodbytesarray assertequals hexutil bytestohex methodbytesarray test hex to bytes string byte int method with a too long offset the method should raise an exception public void testhextobytes stringbyteint withlongoffset try string method string 0 byte method byte array new byte 1 hex util hex to bytes method string method byte array method byte array length fail expected exception error not thrown catch array index out of bounds exception an exception assert not null an exception hextobytes testhextobytes_stringbyteint_withlongoffset methodstring methodbytearray hexutil hextobytes methodstring methodbytearray methodbytearray arrayindexoutofboundsexception anexception assertnotnull anexception test hex to bytes string byte int method with a too short byte to put the result the method should raise an exception public void testhextobytes stringbyteint withshortarray try string method string 0000 byte method byte array new byte 1 hex util hex to bytes method string method byte array 0 fail expected exception error not thrown catch index out of bounds exception an exception assert not null an exception hextobytes testhextobytes_stringbyteint_withshortarray methodstring methodbytearray hexutil hextobytes methodstring methodbytearray indexoutofboundsexception anexception assertnotnull anexception test all hex to bytes methods with a not valid character the method should raise an exception public void testhextobytes withbaddigit string method string 00 0 try byte method byte array new byte method string length hex util hex to bytes method string method byte array 0 fail expected exception error not thrown catch number format exception an exception assert not null an exception try hex util hex to bytes method string 0 fail expected exception error not thrown catch number format exception an exception assert not null an exception try hex util hex to bytes method string fail expected exception error not thrown catch number format exception an exception assert not null an exception hextobytes testhextobytes_withbaddigit methodstring methodbytearray methodstring hexutil hextobytes methodstring methodbytearray numberformatexception anexception assertnotnull anexception hexutil hextobytes methodstring numberformatexception anexception assertnotnull anexception hexutil hextobytes methodstring numberformatexception anexception assertnotnull anexception test the bits to byte bit set int method using a size smaller than the actual number of bits in the bit set public void testbitstobytes withshortsize byte expected byte array new byte 1 byte output array new byte 1 bit set method bit set new bit set 8 0x01 method bit set flip 0 expected byte array 0 byte 1 0x01 0x00 0x01 output array hex util bits to bytes method bit set 0 assert false arrays equals expected byte array output array 0x01 0x01 0x01 output array hex util bits to bytes method bit set 1 assert true arrays equals expected byte array output array 0x80 method bit set flip 7 0x08 method bit set flip 3 expected byte array 0 byte 128 8 1 0x89 0x08 0x89 output array hex util bits to bytes method bit set 3 assert false arrays equals expected byte array output array 0x89 0xff 0x89 output array hex util bits to bytes method bit set 8 assert true arrays equals expected byte array output array bitstobyte bitset bitset testbitstobytes_withshortsize expectedbytearray outputarray bitset methodbitset bitset methodbitset expectedbytearray outputarray hexutil bitstobytes methodbitset assertfalse expectedbytearray outputarray outputarray hexutil bitstobytes methodbitset asserttrue expectedbytearray outputarray methodbitset methodbitset expectedbytearray outputarray hexutil bitstobytes methodbitset assertfalse expectedbytearray outputarray outputarray hexutil bitstobytes methodbitset asserttrue expectedbytearray outputarray override protected void set up throws exception super set up example node null try example node new html node sample okay node name catch illegal argument exception iae1 fail unexpected exception thrown assert not null example node assert equals 0 example node children size setup setup examplenode examplenode htmlnode sample_okay_node_name illegalargumentexception assertnotnull examplenode assertequals examplenode tests html node string string string string constructor using non ascii chars public void testhtmlnode stringstringstringstring wrongnodename try new html node sample wrong node name sample okay attribute name sample attribute value sample node content fail expected exception not thrown catch illegal argument exception iae1 try new html node sample okay node name sample okay attribute name sample attribute value sample node content catch illegal argument exception iae1 fail unexpected exception thrown htmlnode testhtmlnode_stringstringstringstring_wrongnodename htmlnode sample_wrong_node_name sample_okay_attribute_name sample_attribute_value sample_node_content illegalargumentexception htmlnode sample_okay_node_name sample_okay_attribute_name sample_attribute_value sample_node_content illegalargumentexception public void testhtmlnode stringstringstringstring wrongattributename try new html node sample okay node name sample wrong attribute name sample attribute value sample node content fail expected exception not thrown catch illegal argument exception iae1 try new html node sample okay node name sample okay attribute name sample attribute value sample node content catch illegal argument exception iae1 fail unexpected exception thrown testhtmlnode_stringstringstringstring_wrongattributename htmlnode sample_okay_node_name sample_wrong_attribute_name sample_attribute_value sample_node_content illegalargumentexception htmlnode sample_okay_node_name sample_okay_attribute_name sample_attribute_value sample_node_content illegalargumentexception tests html node string string string string constructor verifying if all attributes are correctly inserted public void testhtmlnode attributesarray int size 100 string method attributes name new string size string method attributes value new string size for int i 0 i size i method attributes name i attribute name i method attributes value i value i html node methodhtml node new html node sample okay node name method attributes name method attributes value sample node content checks presence for int i 0 i size i assert equals method attributes value i methodhtml node get attribute method attributes name i checks size assert equals size methodhtml node get attributes size htmlnode testhtmlnode_attributesarray methodattributesname methodattributesvalue methodattributesname attributename methodattributesvalue htmlnode methodhtmlnode htmlnode sample_okay_node_name methodattributesname methodattributesvalue sample_node_content assertequals methodattributesvalue methodhtmlnode getattribute methodattributesname assertequals methodhtmlnode getattributes tests add attribute string string method adding the same attribute many times and verifying it keeps only one reference to it public void test same attribute many times int times 100 string method attribute name example attribute name string method attribute value example attribute value for int i 0 i times i example node add attribute method attribute name method attribute value assert equals example node get attributes size 1 addattribute testsameattributemanytimes methodattributename exampleattributename methodattributevalue exampleattributevalue examplenode addattribute methodattributename methodattributevalue assertequals examplenode getattributes tests add child html node method adding the node itself as its child the method should rise an exception public void test add child using the node itself as child try example node add child example node fail expected exception error not thrown catch illegal argument exception an exception assert not null an exception addchild htmlnode testaddchildusingthenodeitselfaschild examplenode addchild examplenode illegalargumentexception anexception assertnotnull anexception tests add children html node method adding the node itself as its child the method should rise an exception public void test add children using the node itself as child html node methodhtml nodes array new html node sample okay node name example node new html node sample okay node name 1 try example node add children methodhtml nodes array fail expected exception error not thrown catch illegal argument exception an exception assert not null an exception addchildren htmlnode testaddchildrenusingthenodeitselfaschild htmlnode methodhtmlnodesarray htmlnode sample_okay_node_name examplenode htmlnode sample_okay_node_name examplenode addchildren methodhtmlnodesarray illegalargumentexception anexception assertnotnull anexception tests add child string method using the same name every time and verifying that a real new html is always added public void test add child same name int times 100 for int i 1 i times i example node add child sample okay node name assert equals example node children size i addchild testaddchildsamename examplenode addchild sample_okay_node_name assertequals examplenode tests add child html node method verifying the behavior when adding the same html node instance two times it should raise an illegal argument exception public void test add child same object html node methodhtml node new html node sample okay node name example node add child methodhtml node try example node add child methodhtml node fail expected exception error not thrown catch illegal argument exception an exception assert not null an exception addchild htmlnode htmlnode illegalargument testaddchildsameobject htmlnode methodhtmlnode htmlnode sample_okay_node_name examplenode addchild methodhtmlnode examplenode addchild methodhtmlnode illegalargumentexception anexception assertnotnull anexception tests add children html node method verifying the behavior when adding the same html node instance two times public void test add children same object html node methodhtml node new html node sample okay node name html node methodhtml nodes array methodhtml node methodhtml node try example node add children methodhtml nodes array fail expected exception error not thrown catch illegal argument exception an exception assert not null an exception addchildren htmlnode htmlnode testaddchildrensameobject htmlnode methodhtmlnode htmlnode sample_okay_node_name htmlnode methodhtmlnodesarray methodhtmlnode methodhtmlnode examplenode addchildren methodhtmlnodesarray illegalargumentexception anexception assertnotnull anexception tests add children string string string method verifying if the child is correctly added and if it generates good output using generate method public void testaddchild stringstringstring html node methodhtml node new html node sample okay node name methodhtml node add child sample okay node name sample okay attribute name sample attribute value list html node children list methodhtml node children assert equals 1 children list size assert equals generate no content node output sample okay node name sample okay attribute name sample attribute value children list get 0 generate addchildren testaddchild_stringstringstring htmlnode methodhtmlnode htmlnode sample_okay_node_name methodhtmlnode addchild sample_okay_node_name sample_okay_attribute_name sample_attribute_value htmlnode childrenlist methodhtmlnode assertequals childrenlist assertequals generatenocontentnodeoutput sample_okay_node_name sample_okay_attribute_name sample_attribute_value childrenlist tests add children string string string string method verifying if the child is correctly added and if it generates good output using generate method public void testaddchild stringstringstringstring html node methodhtml node new html node sample okay node name methodhtml node add child sample okay node name sample okay attribute name sample attribute value sample node content list html node children list methodhtml node children assert equals 1 children list size assert equals generate full node output sample okay node name sample okay attribute name sample attribute value sample node content children list get 0 generate addchildren testaddchild_stringstringstringstring htmlnode methodhtmlnode htmlnode sample_okay_node_name methodhtmlnode addchild sample_okay_node_name sample_okay_attribute_name sample_attribute_value sample_node_content htmlnode childrenlist methodhtmlnode assertequals childrenlist assertequals generatefullnodeoutput sample_okay_node_name sample_okay_attribute_name sample_attribute_value sample_node_content childrenlist tests add children string string string method verifying if the child is correctly added and the child attributes are corrects public void testaddchild stringarrayarray string method attributes names array first name second name third name string method attributes values array first value second value third value html node methodhtml node new html node sample okay node name methodhtml node add child sample okay node name method attributes names array method attributes values array test single child attributes methodhtml node method attributes names array method attributes values array addchildren testaddchild_stringarrayarray methodattributesnamesarray firstname secondname thirdname methodattributesvaluesarray firstvalue secondvalue thirdvalue htmlnode methodhtmlnode htmlnode sample_okay_node_name methodhtmlnode addchild sample_okay_node_name methodattributesnamesarray methodattributesvaluesarray testsinglechildattributes methodhtmlnode methodattributesnamesarray methodattributesvaluesarray tests add children string string string string method verifying if the child is correctly added and the child attributes are corrects public void testaddchild stringarrayarraystring string method attributes names array first name second name third name string method attributes values array first value second value third value html node methodhtml node new html node sample okay node name methodhtml node add child sample okay node name method attributes names array method attributes values array sample node content test single child attributes methodhtml node method attributes names array method attributes values array addchildren testaddchild_stringarrayarraystring methodattributesnamesarray firstname secondname thirdname methodattributesvaluesarray firstvalue secondvalue thirdvalue htmlnode methodhtmlnode htmlnode sample_okay_node_name methodhtmlnode addchild sample_okay_node_name methodattributesnamesarray methodattributesvaluesarray sample_node_content testsinglechildattributes methodhtmlnode methodattributesnamesarray methodattributesvaluesarray check the passed html node only child attributes param ahtml node where we fetch the only child param attibutes names the attributes names to check param attributes values the attributes values to check private void test single child attributes html node ahtml node string attibutes names string attributes values list html node children list ahtml node children assert equals 1 children list size html node childhtml node children list get 0 assert equals attibutes names length childhtml node get attributes size for int i 0 i attibutes names length i assert equals attributes values i childhtml node get attribute attibutes names i htmlnode ahtmlnode attibutesnames attributesvalues testsinglechildattributes htmlnode ahtmlnode attibutesnames attributesvalues htmlnode childrenlist ahtmlnode assertequals childrenlist htmlnode childhtmlnode childrenlist assertequals attibutesnames childhtmlnode getattributes attibutesnames assertequals attributesvalues childhtmlnode getattribute attibutesnames tests get content method using common sample html node and named nodes public void test get content html node methodhtml node new html node sample okay node name assert null methodhtml node get content methodhtml node new html node sample okay node name sample node content since the html node name is not or the content will be a new child with the name assert equals sample node content methodhtml node children get 0 get content assert null methodhtml node get content methodhtml node new html node sample node content assert equals sample node content methodhtml node get content methodhtml node new html node sample node content assert equals sample node content methodhtml node get content getcontent htmlnode testgetcontent htmlnode methodhtmlnode htmlnode sample_okay_node_name assertnull methodhtmlnode getcontent methodhtmlnode htmlnode sample_okay_node_name sample_node_content htmlnode assertequals sample_node_content methodhtmlnode getcontent assertnull methodhtmlnode getcontent methodhtmlnode htmlnode sample_node_content assertequals sample_node_content methodhtmlnode getcontent methodhtmlnode htmlnode sample_node_content assertequals sample_node_content methodhtmlnode getcontent tests get attribute method using common sample html node and named nodes public void test get attribute html node methodhtml node new html node sample okay node name assert null methodhtml node get attribute sample okay attribute name methodhtml node new html node sample okay node name sample okay attribute name sample attribute value assert equals sample attribute value methodhtml node get attribute sample okay attribute name methodhtml node new html node sample okay attribute name sample attribute value assert equals sample attribute value methodhtml node get attribute sample okay attribute name methodhtml node new html node sample okay attribute name sample attribute value assert equals sample attribute value methodhtml node get attribute sample okay attribute name getattribute htmlnode testgetattribute htmlnode methodhtmlnode htmlnode sample_okay_node_name assertnull methodhtmlnode getattribute sample_okay_attribute_name methodhtmlnode htmlnode sample_okay_node_name sample_okay_attribute_name sample_attribute_value assertequals sample_attribute_value methodhtmlnode getattribute sample_okay_attribute_name methodhtmlnode htmlnode sample_okay_attribute_name sample_attribute_value assertequals sample_attribute_value methodhtmlnode getattribute sample_okay_attribute_name methodhtmlnode htmlnode sample_okay_attribute_name sample_attribute_value assertequals sample_attribute_value methodhtmlnode getattribute sample_okay_attribute_name tests get attributes and set attribute string string methods verifying if attributes are correctly inserted and fetched public void test add get attributes int attributes number 100 string method attribute name string counter string html node methodhtml node new html node sample okay node name for int i 0 i attributes number i counter string string value of i method attribute name attribute counter string assert equals i methodhtml node get attributes size methodhtml node add attribute method attribute name counter string assert equals counter string methodhtml node get attribute method attribute name assert equals counter string methodhtml node get attributes get method attribute name getattributes setattribute testaddgetattributes attributesnumber methodattributename counterstring htmlnode methodhtmlnode htmlnode sample_okay_node_name attributesnumber counterstring valueof methodattributename counterstring assertequals methodhtmlnode getattributes methodhtmlnode addattribute methodattributename counterstring assertequals counterstring methodhtmlnode getattribute methodattributename assertequals counterstring methodhtmlnode getattributes methodattributename tests add attribute string string method trying to insert an attribute with a null as name value it should rise an illegal argument exception public void testaddattribute nullattributename html node methodhtml node new html node sample okay node name try methodhtml node add attribute null sample attribute value fail expected exception error not thrown catch illegal argument exception an exception assert not null an exception addattribute illegalargument testaddattribute_nullattributename htmlnode methodhtmlnode htmlnode sample_okay_node_name methodhtmlnode addattribute sample_attribute_value illegalargumentexception anexception assertnotnull anexception tests add attribute string string method trying to insert an attribute with a null as attribute value it should rise an illegal argument exception public void testaddattribute nullattributevalue html node methodhtml node new html node sample okay node name try methodhtml node add attribute sample wrong attribute name null fail expected exception error not thrown catch illegal argument exception an exception assert not null an exception addattribute illegalargument testaddattribute_nullattributevalue htmlnode methodhtmlnode htmlnode sample_okay_node_name methodhtmlnode addattribute sample_wrong_attribute_name illegalargumentexception anexception assertnotnull anexception tests html node string string string string and html node string string string constructors trying to create a node that has attribute name null it should raise an illegal argument exception public void testhtmlnode nullattributename try new html node sample okay node name null sample attribute value sample node content fail expected exception error not thrown catch illegal argument exception an exception assert not null an exception try new html node sample okay node name null sample attribute value fail expected exception error not thrown catch illegal argument exception an exception assert not null an exception htmlnode htmlnode illegalargument testhtmlnode_nullattributename htmlnode sample_okay_node_name sample_attribute_value sample_node_content illegalargumentexception anexception assertnotnull anexception htmlnode sample_okay_node_name sample_attribute_value illegalargumentexception anexception assertnotnull anexception tests html node string string string string and html node string string string constructors trying to create a node that has attribute value null it should raise an illegal argument exception public void testhtmlnode nullattributevalue try new html node sample okay node name sample wrong attribute name null sample node content fail expected exception error not thrown catch illegal argument exception an exception assert not null an exception try new html node sample okay node name sample wrong attribute name null fail expected exception error not thrown catch illegal argument exception an exception assert not null an exception htmlnode htmlnode illegalargument testhtmlnode_nullattributevalue htmlnode sample_okay_node_name sample_wrong_attribute_name sample_node_content illegalargumentexception anexception assertnotnull anexception htmlnode sample_okay_node_name sample_wrong_attribute_name illegalargumentexception anexception assertnotnull anexception tests html node string string string string constructor trying to create a node that has attributes name null it should raise an illegal argument exception public void testhtmlnodearray nullattributename string method attributes name array first null after string method attributes value array sample attribute value sample attribute value sample attribute value testhtmlnodearray null method attributes name array method attributes value array htmlnode illegalargument testhtmlnodearray_nullattributename methodattributesnamearray methodattributesvaluearray sample_attribute_value sample_attribute_value sample_attribute_value testhtmlnodearray_null methodattributesnamearray methodattributesvaluearray tests html node string string string string constructor trying to create a node that has attributes value null it should raise an illegal argument exception public void testhtmlnodearray nullattributevalue string method attributes name array sample wrong attribute name sample wrong attribute name sample wrong attribute name string method attributes value array first null after testhtmlnodearray null method attributes name array method attributes value array htmlnode illegalargument testhtmlnodearray_nullattributevalue methodattributesnamearray sample_wrong_attribute_name sample_wrong_attribute_name sample_wrong_attribute_name methodattributesvaluearray testhtmlnodearray_null methodattributesnamearray methodattributesvaluearray tests html node string string string string constructor trying to create a node that has different length for attributes names array and attributes values array it should raise an illegal argument exception public void testhtmlnode attributearrays differentlengths string method attributes name array sample wrong attribute name sample wrong attribute name string method attributes value array sample attribute value sample attribute value sample attribute value testhtmlnodearray null method attributes name array method attributes value array htmlnode illegalargument testhtmlnode_attributearrays_differentlengths methodattributesnamearray sample_wrong_attribute_name sample_wrong_attribute_name methodattributesvaluearray sample_attribute_value sample_attribute_value sample_attribute_value testhtmlnodearray_null methodattributesnamearray methodattributesvaluearray tests if the passed arrays raise an illegal argument exception using them to create a new html node i e one of the name or value must be null param attributes names the array of attribute names param attributes values the array of attribute values private void testhtmlnodearray null string attributes names string attributes values try new html node sample okay node name attributes names attributes values sample node content fail expected exception error not thrown catch illegal argument exception an exception assert not null an exception illegalargumentexception htmlnode attributesnames attributesvalues testhtmlnodearray_null attributesnames attributesvalues htmlnode sample_okay_node_name attributesnames attributesvalues sample_node_content illegalargumentexception anexception assertnotnull anexception fetches the first line of a string param a string the string to consider return the first line of the string private string read first line string a string int new line index a string index of n if new line index 1 return a string return a string substring 0 new line index astring readfirstline astring newlineindex astring indexof newlineindex astring astring newlineindex tests generate method with a html node that has textarea div a as node name since they generates a different output from all other names public void testgenerate fromhtmlnode textareadiva html node methodhtml node string node names array textarea div a for int i 0 i node names array length i methodhtml node new html node node names array i sample okay attribute name sample attribute value assert equals generate full node output node names array i sample okay attribute name sample attribute value methodhtml node generate htmlnode testgenerate_fromhtmlnode_textareadiva htmlnode methodhtmlnode nodenamesarray nodenamesarray methodhtmlnode htmlnode nodenamesarray sample_okay_attribute_name sample_attribute_value assertequals generatefullnodeoutput nodenamesarray sample_okay_attribute_name sample_attribute_value methodhtmlnode tests generate method when the node has a special name i e div form input script table tr td and a child public void testgenerate fromhtmlnodewithchild specialnames html node methodhtml node string node names array div form input script table tr td html node method child node new html node sample okay node name sample okay attribute name sample attribute value sample node content for int i 0 i node names array length i methodhtml node new html node node names array i sample okay attribute name sample attribute value sample node content methodhtml node add child method child node assert equals node names array i to lower case sample okay attribute name sample attribute value n sample node content child generate full node output sample okay node name sample okay attribute name sample attribute value sample node content node names array i to lower case n methodhtml node generate testgenerate_fromhtmlnodewithchild_specialnames htmlnode methodhtmlnode nodenamesarray htmlnode methodchildnode htmlnode sample_okay_node_name sample_okay_attribute_name sample_attribute_value sample_node_content nodenamesarray methodhtmlnode htmlnode nodenamesarray sample_okay_attribute_name sample_attribute_value sample_node_content methodhtmlnode addchild methodchildnode assertequals nodenamesarray tolowercase sample_okay_attribute_name sample_attribute_value sample_node_content generatefullnodeoutput sample_okay_node_name sample_okay_attribute_name sample_attribute_value sample_node_content nodenamesarray tolowercase methodhtmlnode tests generate method with a html node with only the name the resulting string should be in the form node name public void testgenerate fromhtmlnode string html node methodhtml node new html node sample okay node name assert equals sample okay node name to lower case methodhtml node generate htmlnode node_name testgenerate_fromhtmlnode_string htmlnode methodhtmlnode htmlnode sample_okay_node_name assertequals sample_okay_node_name tolowercase methodhtmlnode tests generate method with a html node with the name and content the resulting string should be in the form node name node content node name public void testgenerate fromhtmlnode stringstring html node methodhtml node new html node sample okay node name sample node content assert equals sample okay node name to lower case sample node content sample okay node name to lower case methodhtml node generate htmlnode node_name node_content node_name testgenerate_fromhtmlnode_stringstring htmlnode methodhtmlnode htmlnode sample_okay_node_name sample_node_content assertequals sample_okay_node_name tolowercase sample_node_content sample_okay_node_name tolowercase methodhtmlnode tests generate method with a html node with the name an attribute and its value the resulting string should be in the form node name attribute name attribute value public void testgenerate fromhtmlnode stringstringstring html node methodhtml node new html node sample okay node name sample okay attribute name sample attribute value assert equals generate no content node output sample okay node name sample okay attribute name sample attribute value methodhtml node generate htmlnode node_name attribute_name attribute_value testgenerate_fromhtmlnode_stringstringstring htmlnode methodhtmlnode htmlnode sample_okay_node_name sample_okay_attribute_name sample_attribute_value assertequals generatenocontentnodeoutput sample_okay_node_name sample_okay_attribute_name sample_attribute_value methodhtmlnode tests generate method with a html node with the name an attribute and its value the resulting string should be in the form node name attribute name attribute value node content node name public void testgenerate fromhtmlnode stringstringstringstring html node methodhtml node new html node sample okay node name sample okay attribute name sample attribute value sample node content assert equals generate full node output sample okay node name sample okay attribute name sample attribute value sample node content methodhtml node generate htmlnode node_name attribute_name attribute_value node_content node_name testgenerate_fromhtmlnode_stringstringstringstring htmlnode methodhtmlnode htmlnode sample_okay_node_name sample_okay_attribute_name sample_attribute_value sample_node_content assertequals generatefullnodeoutput sample_okay_node_name sample_okay_attribute_name sample_attribute_value sample_node_content methodhtmlnode generates the correct output for the html node generate method when called from a single node having only a name and an attribute name and value param a name the html node name param a attribute name the html node attribute name param a attribute value the html node attribute value return the correct output expected by html node generate method private string generate no content node output string a name string a attribute name string a attribute value return a name to lower case a attribute name a attribute value htmlnode aname htmlnode aattributename htmlnode aattributevalue htmlnode htmlnode generatenocontentnodeoutput aname aattributename aattributevalue aname tolowercase aattributename aattributevalue generates the correct output for the html node generate method when called from a single node having the specified parameters param a name the html node name param a attribute name the html node attribute name param a attribute value the html node attribute value param a content the html node content return the correct output expected by html node generate method private string generate full node output string a name string a attribute name string a attribute value string a content return a name to lower case a attribute name a attribute value a content a name to lower case htmlnode aname htmlnode aattributename htmlnode aattributevalue htmlnode acontent htmlnode htmlnode generatefullnodeoutput aname aattributename aattributevalue acontent aname tolowercase aattributename aattributevalue acontent aname tolowercase tests generate method with a html node that has a child node name attribute name attribute value node content child node name child attribute name child attribute value child node content child node name node name public void testgenerate htmlnode withchild html node methodhtml node new html node sample okay node name sample okay attribute name sample attribute value sample node content html node methodhtml node child new html node sample okay node name sample okay attribute name sample attribute value sample node content methodhtml node add child methodhtml node child assert equals sample okay node name to lower case sample okay attribute name sample attribute value sample node content child generate full node output sample okay node name sample okay attribute name sample attribute value sample node content sample okay node name to lower case methodhtml node generate htmlnode node_name attribute_name attribute_value node_content child_node_name child_attribute_name child_attribute_value child_node_content child_node_name node_name testgenerate_htmlnode_withchild htmlnode methodhtmlnode htmlnode sample_okay_node_name sample_okay_attribute_name sample_attribute_value sample_node_content htmlnode methodhtmlnodechild htmlnode sample_okay_node_name sample_okay_attribute_name sample_attribute_value sample_node_content methodhtmlnode addchild methodhtmlnodechild assertequals sample_okay_node_name tolowercase sample_okay_attribute_name sample_attribute_value sample_node_content generatefullnodeoutput sample_okay_node_name sample_okay_attribute_name sample_attribute_value sample_node_content sample_okay_node_name tolowercase methodhtmlnode tests generate method with a html node that has as name the expected output is just the html node content public void testgenerate fromhtmlnode percentname html node methodhtml node new html node sample okay attribute name sample attribute value sample node content assert equals sample node content methodhtml node generate htmlnode htmlnode testgenerate_fromhtmlnode_percentname htmlnode methodhtmlnode htmlnode sample_okay_attribute_name sample_attribute_value sample_node_content assertequals sample_node_content methodhtmlnode tests html doctype generate method comparing the result with the expected string it is useful for regression tests public void testhtmldoctype generate string sample doc type html string sample system uri w3c dtd xhtml 1 1 en html node methodhtml node doc new html node html doctype sample doc type sample system uri methodhtml node doc add child sample okay node name string generated string methodhtml node doc generate consider only the html doc type generated text assert equals doctype sample doc type public sample system uri read first line generated string htmldoctype testhtmldoctype_generate sampledoctype samplesystemuri htmlnode methodhtmlnodedoc htmlnode htmldoctype sampledoctype samplesystemuri methodhtmlnodedoc addchild sample_okay_node_name generatedstring methodhtmlnodedoc htmldoctype assertequals sampledoctype samplesystemuri readfirstline generatedstring protected sorted long set perpare long array sorted long set set new sorted long set for int i 0 i array length i set add array i return set sortedlongset sortedlongset sortedlongset public void test get first construction and get sorted long set set perpare test array assert equals long min value set get first assert equals long min value set get first make sure not removed testgetfirst sortedlongset testarray assertequals min_value getfirst assertequals min_value getfirst test method for link freenet support sorted long set is empty public void test is empty emptiness sorted long set set1 perpare new long assert true set1 is empty sorted long set set2 perpare test array assert false set2 is empty remove and is empty for int i 0 i test array length i set2 remove test array i assert true set2 is empty sortedlongset isempty testisempty sortedlongset asserttrue isempty sortedlongset testarray assertfalse isempty isempty testarray testarray asserttrue isempty test method for link freenet support sorted long set contains long public void test contains construction and get sorted long set set perpare test array contain assert true set contains 0l assert true set contains 3l assert true set contains long max value assert true set contains long min value not contain assert false set contains 13l assert false set contains 13l remove and not contain set remove 0l assert false set contains 0l sortedlongset testcontains sortedlongset testarray asserttrue asserttrue asserttrue max_value asserttrue min_value assertfalse assertfalse assertfalse test method for link freenet support sorted long set remove long public void test remove construction and get sorted long set set perpare test array remove assert true set contains 0l set remove 0l assert false set contains 0l construction and get sorted long set set2 perpare test array remove non exist assert false set2 contains 101l set remove 101l make sure no other element removed for int i 0 i test array length i assert true set2 contains test array i sortedlongset testremove sortedlongset testarray asserttrue assertfalse sortedlongset testarray assertfalse testarray asserttrue testarray test method for link freenet support sorted long set push long public void test push sorted long set set perpare test array assert true set push 100l assert true set contains 100l assert false set push 100l sortedlongset testpush sortedlongset testarray asserttrue asserttrue assertfalse test method for link freenet support sorted long set add long public void test add sorted long set set perpare test array set add 100l assert true set contains 100l boolean ok false try set add 100l catch illegal argument exception iae good ok true assert true exception not thrown ok sortedlongset testadd sortedlongset testarray asserttrue illegalargumentexception asserttrue test method for link freenet support sorted long set remove first public void test remove first construction and get sorted long set set perpare test array assert equals long min value set remove first assert equals 0l set remove first sortedlongset removefirst testremovefirst sortedlongset testarray assertequals min_value removefirst assertequals removefirst test method for link freenet support sorted long set clear public void test clear sorted long set set perpare test array assert false set is empty set clear assert true set is empty assert false set contains 0l sortedlongset testclear sortedlongset testarray assertfalse isempty asserttrue isempty assertfalse test method for link freenet support sorted long set to array public void test to array sorted long set set perpare test array long sorted array new long test array length system arraycopy test array 0 sorted array 0 test array length arrays sort sorted array assert true arrays equals sorted array set to array sorted long set set0 new sorted long set assert true arrays equals new long set0 to array sortedlongset toarray testtoarray sortedlongset testarray sortedarray testarray testarray sortedarray testarray sortedarray asserttrue sortedarray toarray sortedlongset sortedlongset asserttrue toarray public void test grown and scale sorted long set set new sorted long set for long i 1 i 512 i set add i set add i for long i 1 i 512 i assert true set contains i assert true set contains i remove and shink for long i 1 i 512 i set remove i assert false set contains i assert true set contains i set remove i assert false set contains i testgrownandscale sortedlongset sortedlongset asserttrue asserttrue assertfalse asserttrue assertfalse public class time sorted hashtable test extends test case public void test add remove time sorted hashtable string tsh new time sorted hashtable string assert false tsh contains value key1 assert equals 0 tsh count values after 0 assert equals 0 tsh size tsh push key1 100 assert equals 1 tsh count values after 0 assert equals 1 tsh size assert equals 1 tsh count values after 99 assert equals 0 tsh count values after 100 assert equals 0 tsh count values after 101 assert true tsh contains value key1 tsh push key2 100 assert equals 2 tsh count values after 0 assert equals 2 tsh size assert equals 0 tsh count values after 100 assert equals 0 tsh count values after 101 assert true tsh contains value key1 assert true tsh contains value key2 tsh push key3 300 assert equals 3 tsh count values after 0 assert equals 3 tsh size assert equals 1 tsh count values after 100 assert equals 1 tsh count values after 101 assert true tsh contains value key1 assert true tsh contains value key2 assert true tsh contains value key3 tsh push key1 200 assert equals 3 tsh count values after 0 assert equals 3 tsh size assert equals 2 tsh count values after 100 assert equals 2 tsh count values after 101 assert true tsh contains value key1 assert true tsh contains value key2 assert true tsh contains value key3 assert true tsh remove value key1 assert equals 2 tsh count values after 0 assert equals 2 tsh size assert equals 1 tsh count values after 100 assert equals 1 tsh count values after 101 assert false tsh contains value key1 assert true tsh contains value key2 assert true tsh contains value key3 tsh remove before 105 assert equals 1 tsh count values after 0 assert equals 1 tsh size assert equals 1 tsh count values after 100 assert equals 1 tsh count values after 101 assert false tsh contains value key1 assert false tsh contains value key2 assert true tsh contains value key3 timesortedhashtabletest testcase testaddremove timesortedhashtable timesortedhashtable assertfalse containsvalue assertequals countvaluesafter assertequals assertequals countvaluesafter assertequals assertequals countvaluesafter assertequals countvaluesafter assertequals countvaluesafter asserttrue containsvalue assertequals countvaluesafter assertequals assertequals countvaluesafter assertequals countvaluesafter asserttrue containsvalue asserttrue containsvalue assertequals countvaluesafter assertequals assertequals countvaluesafter assertequals countvaluesafter asserttrue containsvalue asserttrue containsvalue asserttrue containsvalue assertequals countvaluesafter assertequals assertequals countvaluesafter assertequals countvaluesafter asserttrue containsvalue asserttrue containsvalue asserttrue containsvalue asserttrue removevalue assertequals countvaluesafter assertequals assertequals countvaluesafter assertequals countvaluesafter assertfalse containsvalue asserttrue containsvalue asserttrue containsvalue removebefore assertequals countvaluesafter assertequals assertequals countvaluesafter assertequals countvaluesafter assertfalse containsvalue assertfalse containsvalue asserttrue containsvalue public void test add removets time sorted hashtable string tsh new time sorted hashtable string tsh push key1 100 100 key1 tsh push key2 100 100 key1 100 key2 tsh push key3 300 100 key1 100 key2 300 key3 tsh push key1 200 100 key2 200 key1 300 key3 tsh remove before 105 200 key1 300 key3 assert equals 2 tsh size assert equals 2 tsh count values after 0 assert equals 2 tsh count values after 100 assert equals 1 tsh count values after 201 assert equals 0 tsh count values after 301 assert true tsh contains value key1 assert false tsh contains value key2 assert true tsh contains value key3 assert equals 200 tsh get time key1 assert equals 1 tsh get time key2 assert equals 300 tsh get time key3 testaddremovets timesortedhashtable timesortedhashtable removebefore assertequals assertequals countvaluesafter assertequals countvaluesafter assertequals countvaluesafter assertequals countvaluesafter asserttrue containsvalue assertfalse containsvalue asserttrue containsvalue assertequals gettime assertequals gettime assertequals gettime public void test before inclusive time sorted hashtable string tsh new time sorted hashtable string tsh push key1 100 100 key1 tsh push key2 100 100 key1 100 key2 tsh push key3 300 100 key1 100 key2 300 key3 tsh remove before 100 assert equals 1 tsh size testbeforeinclusive timesortedhashtable timesortedhashtable removebefore assertequals public void test pairs time sorted hashtable string tsh new time sorted hashtable string tsh push key1 100 100 key1 tsh push key2 100 100 key1 100 key2 tsh push key3 300 100 key1 100 key2 300 key3 object p tsh pairs after 1 new string 3 assert equals 100 long long p 1 0 assert equals key1 string p 0 0 assert equals 100 long long p 1 1 assert equals key2 string p 0 1 assert equals 300 long long p 1 2 assert equals key3 string p 0 2 tsh push key1 200 100 key2 200 key1 300 key3 p tsh pairs after 1 new string 3 assert equals 100 long long p 1 0 assert equals key2 string p 0 0 assert equals 200 long long p 1 1 assert equals key1 string p 0 1 assert equals 300 long long p 1 2 assert equals key3 string p 0 2 tsh remove before 105 200 key1 300 key3 p tsh pairs after 1 new string 2 assert equals 200 long long p 1 0 assert equals key1 string p 0 0 assert equals 300 long long p 1 1 assert equals key3 string p 0 1 testpairs timesortedhashtable timesortedhashtable pairsafter assertequals assertequals assertequals assertequals assertequals assertequals pairsafter assertequals assertequals assertequals assertequals assertequals assertequals removebefore pairsafter assertequals assertequals assertequals assertequals private boolean contains only valid chars string a string char each char for int i 0 i a string length i each char a string char at i if uri pre encoder allowed chars index of each char 0 return false return true containsonlyvalidchars astring eachchar astring eachchar astring charat uripreencoder allowedchars indexof eachchar tests encode string method to verify if it converts all not safe chars into safe chars public void test encode string to encode prtbl ascii stressedutf 8chars string encoded uri pre encoder encode to encode assert true contains only valid chars encoded testencode toencode prtblascii stressedutf_8chars uripreencoder toencode asserttrue containsonlyvalidchars tests encodeuri string method to verify if it converts all not safe chars into safe chars public void test encodeuri string to encode prtbl ascii stressedutf 8chars uri encoded try encoded uri pre encoder encodeuri to encode this method will throw a not expected exception because is included as a valid char assert true contains only valid chars encoded to string catch uri syntax exception an exception fail not expected exception thrown an exception get message testencodeuri toencode prtblascii stressedutf_8chars uripreencoder toencode asserttrue containsonlyvalidchars tostring urisyntaxexception anexception anexception getmessage public void test byte array buffer byte data data string 1 get bytes buffer buffer new buffer data assert equals data buffer get data do test buffer data buffer testbytearraybuffer data_string_1 getbytes assertequals getdata dotestbuffer public void test byte array index buffer get content byte data data string 1 get bytes byte data sub new byte 5 prepare substring system arraycopy data 4 data sub 0 5 buffer buffer new buffer data 4 5 assert false data sub equals buffer get data do test buffer data sub buffer testbytearrayindexbuffer data_string_1 getbytes datasub datasub assertfalse datasub getdata dotestbuffer datasub public void test data input stream buffer byte data data string 1 get bytes get some content byte data2 new byte data length 4 make room for 4 byte length indicator int length data string 1 get bytes length populate length as first 4 bytes data2 0 byte length 0xff000000 24 data2 1 byte length 0xff0000 16 data2 2 byte length 0xff00 8 data2 3 byte length 0xff system arraycopy data 0 data2 4 data length populate rest of content data input stream dis new data input stream new byte array input stream data2 buffer buffer null try buffer new buffer dis catch io exception e fail unexpected exception e get message perform rest of test with the original array because buffer data input stream chomps first 4 bytes do test buffer data buffer testdatainputstreambuffer data_string_1 getbytes data_string_1 getbytes datainputstream datainputstream bytearrayinputstream ioexception getmessage datainputstream dotestbuffer private void do test buffer byte data buffer buffer assert equals data length buffer get length for int i 0 i buffer get length i assert equals data i buffer byte at i try buffer byte at data length 1 expect exception fail catch array index out of bounds exception e expect this dotestbuffer assertequals getlength getlength assertequals byteat byteat arrayindexoutofboundsexception public void test long buffer to string buffer buffer new buffer data string 1 get bytes string long string buffer to string assert equals buffer buffer get length long string testlongbuffertostring data_string_1 getbytes longstring tostring assertequals getlength longstring public void test short buffer to string string short string feep buffer short buffer new buffer short string get bytes string out string short buffer to string assert equals out string 4 102 101 101 112 fixme final brace testshortbuffertostring shortstring shortbuffer shortstring getbytes outstring shortbuffer tostring assertequals outstring public void test equals buffer b1 new buffer buffer1 get bytes buffer b2 new buffer buffer2 get bytes buffer b3 new buffer buffer1 get bytes assert false b1 equals b2 assert true b1 equals b3 assert false b2 equals b3 assert true b1 equals b1 assert true b2 equals b2 assert true b3 equals b1 testequals getbytes getbytes getbytes assertfalse asserttrue assertfalse asserttrue asserttrue asserttrue public void test hashcode buffer b1 new buffer buffer1 get bytes buffer b2 new buffer buffer2 get bytes buffer b3 new buffer buffer1 get bytes map buffer buffer hash map new hash map buffer buffer hash map put b1 b1 hash map put b2 b2 hash map put b3 b3 should clobber b1 due to content see if b3 survived object o hash map get b3 assert false o b1 assert true o b3 see if b1 survived o hash map get b1 assert false o b1 assert true o b3 testhashcode getbytes getbytes getbytes hashmap hashmap hashmap hashmap hashmap hashmap assertfalse asserttrue hashmap assertfalse asserttrue public void test copy byte old buf data string 1 get bytes buffer b new buffer old buf byte new buf new byte b get length b copy to new buf 0 for int i 0 i old buf length i assert equals new buf i old buf i testcopy oldbuf data_string_1 getbytes oldbuf newbuf getlength copyto newbuf oldbuf assertequals newbuf oldbuf public void test mutable boolean mutable boolean bool new mutable boolean bool value false assert false bool value bool value true assert true bool value testmutableboolean mutableboolean mutableboolean assertfalse asserttrue private string name j string name int prio this name name this prio prio public int get priority return prio getpriority public void run synchronized this notify all try assert true exec on thread completing job put name catch interrupted exception e fail e to string notifyall asserttrue onthread completingjob interruptedexception tostring override protected void set up throws exception super set up real exec new pooled executor completed jobs new array list string completing job new synchronous queue string exec new prioritized serial executor native thread max priority 10 5 true setup setup realexec pooledexecutor completedjobs arraylist completingjob synchronousqueue prioritizedserialexecutor nativethread max_priority private void q string j int i boolean wait for start throws interrupted exception j job new j j i synchronized job exec execute job j if wait for start job wait 5000 waitforstart interruptedexception waitforstart private void wait for int count throws interrupted exception int completed 0 while completed count string s completing job poll 5 time unit seconds if s null fail hang completed completed jobs add s system out println completed jobs waitfor interruptedexception completingjob timeunit completedjobs completedjobs public void test run throws interrupted exception assert true completed jobs is empty q j1 0 false q j2 0 false q j3 0 false q j4 0 false thread yield thread sleep 10 assert true completed jobs is empty not started yet exec start real exec test run start wait for 4 assert true completed jobs contains j1 assert true completed jobs contains j2 assert true completed jobs contains j3 assert true completed jobs contains j4 assert false exec on thread testrun interruptedexception asserttrue completedjobs isempty asserttrue completedjobs isempty realexec testrun waitfor asserttrue completedjobs asserttrue completedjobs asserttrue completedjobs asserttrue completedjobs assertfalse onthread public void test run prio throws interrupted exception assert true completed jobs is empty q jm 9 false q j8 8 false assert true completed jobs is empty not started yet assert equals 0 exec get waiting threads count exec start real exec test run prio start wait for 1 jm q j2 2 false q jn 4 false q jo 2 false q jp 3 false assert equals 0 exec get queue size 9 assert equals 1 exec get queue size 3 assert equals 2 exec get queue size 2 wait for 2 j8 jn assert equals 0 exec get queue size 9 assert equals 0 exec get queue size 4 assert equals 2 exec get queue size 2 thread yield thread sleep 10 q jq 4 false q jr 0 false assert equals 1 exec get queue size 4 assert equals 2 exec get queue size 2 assert equals 0 exec get queue size 1 assert equals 1 exec get queue size 0 int r exec queued jobs assert true arrays equals new int 1 0 2 0 1 0 0 0 0 0 r arrays equals new int 1 0 2 1 1 0 0 0 0 0 r wait for 5 jp jq j2 jo jr int i 0 for string s new string jm j8 jn jp jq j2 jo jr assert equals s s completed jobs get i testrunprio interruptedexception asserttrue completedjobs isempty asserttrue completedjobs isempty assertequals getwaitingthreadscount realexec testrunprio waitfor assertequals getqueuesize assertequals getqueuesize assertequals getqueuesize waitfor assertequals getqueuesize assertequals getqueuesize assertequals getqueuesize assertequals getqueuesize assertequals getqueuesize assertequals getqueuesize assertequals getqueuesize queuedjobs asserttrue waitfor assertequals completedjobs private void testfilterpositive bloom filter filter byte list new byte pass pos for int i 0 i pass pos i byte b new byte 32 rand next bytes b filter add key b list i b for byte b list assert true filter check filter b _testfilterpositive bloomfilter pass_pos pass_pos nextbytes addkey asserttrue checkfilter public void test counting filter positive int k bloom filter optimialk filter size pass pos bloom filter filter bloom filter create filter filter size k true testfilterpositive filter testcountingfilterpositive bloomfilter filter_size pass_pos bloomfilter bloomfilter createfilter filter_size _testfilterpositive public void test binary filter positive int k bloom filter optimialk filter size pass pos bloom filter filter bloom filter create filter filter size k false testfilterpositive filter testbinaryfilterpositive bloomfilter filter_size pass_pos bloomfilter bloomfilter createfilter filter_size _testfilterpositive public void test counting filter remove int k bloom filter optimialk filter size pass bloom filter filter bloom filter create filter filter size k true map byte array wrapper byte base list new hash map byte array wrapper byte add keys for int i 0 i pass i byte b new byte 32 do rand next bytes b while base list contains key new byte array wrapper b filter add key b base list put new byte array wrapper b b assert true check add base filter check filter b add some false pass keys map byte array wrapper byte new list new hash map byte array wrapper byte int f pos 0 for int i 0 i pass remove i byte b new byte 64 byte array wrapper wrapper do rand next bytes b wrapper new byte array wrapper b while new list contains key wrapper filter add key b new list put wrapper b assert true check add new filter check filter b remove the new keys and count false positive for byte b new list values filter remove key b for byte b new list values if filter check filter b f pos check if some should were removed assert false 100 false positive f pos pass remove check if old keys still here for byte b base list values assert true check original filter check filter b testcountingfilterremove bloomfilter filter_size bloomfilter bloomfilter createfilter filter_size bytearraywrapper baselist hashmap bytearraywrapper nextbytes baselist containskey bytearraywrapper addkey baselist bytearraywrapper asserttrue checkfilter false_pass bytearraywrapper newlist hashmap bytearraywrapper fpos pass_remove bytearraywrapper nextbytes bytearraywrapper newlist containskey addkey newlist asserttrue checkfilter newlist removekey newlist checkfilter fpos assertfalse fpos pass_remove baselist asserttrue checkfilter private void testfilterfalsepositive bloom filter filter set byte array wrapper list new hash set byte array wrapper add keys for int i 0 i pass i byte b new byte 32 do rand next bytes b while list contains new byte array wrapper b filter add key b list add new byte array wrapper b assert true check add filter check filter b system out println filter int f pos 0 for int i 0 i pass false i byte b new byte 64 64 bytes sure not exist rand next bytes b if filter check filter b f pos final int k filter getk final double q 1 math pow 1 1 0 filter size k pass final double p math pow q k final double actual double f pos pass false final double limit p 1 05 1 0 pass false system out println k k system out println q q system out println p p system out println limit limit system out println actual actual system out println actual p actual p assert false false positive p p actual actual actual limit _testfilterfalsepositive bloomfilter bytearraywrapper hashset bytearraywrapper nextbytes bytearraywrapper addkey bytearraywrapper asserttrue checkfilter fpos pass_false nextbytes checkfilter fpos filter_size fpos pass_false pass_false assertfalse public void test counting filter false positive int k bloom filter optimialk filter size pass bloom filter filter bloom filter create filter filter size k true testfilterfalsepositive filter testcountingfilterfalsepositive bloomfilter filter_size bloomfilter bloomfilter createfilter filter_size _testfilterfalsepositive public void test binary filter false positive int k bloom filter optimialk filter size pass bloom filter filter bloom filter create filter filter size k false testfilterfalsepositive filter testbinaryfilterfalsepositive bloomfilter filter_size bloomfilter bloomfilter createfilter filter_size _testfilterfalsepositive tests decode string method trying to decode entity by entity public void test decode single entities for int i 0 i utf util html entities utf length i assert equals html decoder decode utf util html entities utf i 1 utf util html entities utf i 0 testdecodesingleentities utfutil html_entities_utf assertequals htmldecoder utfutil html_entities_utf utfutil html_entities_utf tests decode string method trying to decode a long string with all possible entity appended public void test decode appended entities string builder to decode new string builder string builder expected new string builder for int i 0 i utf util html entities utf length i to decode append utf util html entities utf i 1 expected append utf util html entities utf i 0 assert equals html decoder decode to decode to string expected to string testdecodeappendedentities stringbuilder todecode stringbuilder stringbuilder stringbuilder utfutil html_entities_utf todecode utfutil html_entities_utf utfutil html_entities_utf assertequals htmldecoder todecode tostring tostring tests decode string method trying to decode incomplete entities the incomplete entity must remain the same as before encoding public void test decode incomplete without ending semicolon assert equals html decoder decode phi phi an entity without a char which means a not existing entity assert equals html decoder decode ph ph without ash assert equals html decoder decode 1234 1234 without ampersand assert equals html decoder decode phi phi emtpy string assert equals html decoder decode testdecodeincomplete assertequals htmldecoder assertequals htmldecoder assertequals htmldecoder assertequals htmldecoder assertequals htmldecoder tests compact string method trying to compact string with repeated whitespaces of every kind e g tabs newline space public void test compact repeated string builder str buffer new string builder 6 for int i 0 i str buffer length i str buffer i new string builder for int i 0 i 100 i adding different whitespaces str buffer 0 append whitespace str buffer 1 append tab str buffer 2 append unix newline str buffer 3 append mac newline str buffer 4 append control str buffer 5 append zerowidthspace for int j 0 j str buffer length j assert equals html decoder compact str buffer j to string testcompactrepeated stringbuilder strbuffer stringbuilder strbuffer strbuffer stringbuilder strbuffer strbuffer strbuffer unix_newline strbuffer mac_newline strbuffer strbuffer strbuffer assertequals htmldecoder strbuffer tostring tests compact string method with each kind of whitespace public void test compact mixed string to compact u0020 t n r u200b u000c assert equals html decoder compact to compact testcompactmixed tocompact assertequals htmldecoder tocompact tests is white space method against all possible html white space type public void test is white space assert true html decoder is whitespace whitespace assert true html decoder is whitespace tab assert true html decoder is whitespace unix newline assert true html decoder is whitespace mac newline assert true html decoder is whitespace control assert true html decoder is whitespace zerowidthspace iswhitespace testiswhitespace asserttrue htmldecoder iswhitespace asserttrue htmldecoder iswhitespace asserttrue htmldecoder iswhitespace unix_newline asserttrue htmldecoder iswhitespace mac_newline asserttrue htmldecoder iswhitespace asserttrue htmldecoder iswhitespace tests put single string string method trying to store a key with two paired multi level chars i e public void testsimplefieldsetputsingle stringstring withtwopairedmultilevelchars simple field set methodsfs new simple field set true string method key foo bar string method value foobar methodsfs put single method key method value assert equals methodsfs subset foo subset subset bar get method value assert equals methodsfs get method key method value putsingle multi_level_chars testsimplefieldsetputsingle_stringstring_withtwopairedmultilevelchars simplefieldset simplefieldset methodkey methodvalue putsingle methodkey methodvalue assertequals methodvalue assertequals methodkey methodvalue tests put append string string method trying to store a key with two paired multi level chars i e public void testsimplefieldsetputappend stringstring withtwopairedmultilevelchars simple field set methodsfs new simple field set true string method key foo bar string method value foobar methodsfs put append method key method value assert equals methodsfs get method key method value putappend multi_level_chars testsimplefieldsetputappend_stringstring_withtwopairedmultilevelchars simplefieldset simplefieldset methodkey methodvalue putappend methodkey methodvalue assertequals methodkey methodvalue tests put and get methods using a normal map behaviour and without multi level chars public void testsimplefieldsetputandget nomultilevel string method pairs array a a b b c c d d e e f f assert true check put and get pairs method pairs array multi_level_chars testsimplefieldsetputandget_nomultilevel methodpairsarray asserttrue checkputandgetpairs methodpairsarray tests put and get methods using a normal map behaviour and with multi level chars public void testsimplefieldsetputandget multilevel string methodpairsarray doublelevel a a aa a b ab a c ac a d ad a e ae a f af string methodpairsarray multilevel a a a a aa a b a ab a c cc ac a d f ad a e g ae a f j ii ui boo af assert true check put and get pairs methodpairsarray doublelevel assert true check put and get pairs methodpairsarray multilevel multi_level_chars testsimplefieldsetputandget_multilevel methodpairsarray_doublelevel methodpairsarray_multilevel asserttrue checkputandgetpairs methodpairsarray_doublelevel asserttrue checkputandgetpairs methodpairsarray_multilevel it puts key value pairs in a simple field set and verify if it can do the correspondant get correctly param a pairs array return true if it is correct private boolean check put and get pairs string a pairs array boolean ret value true simple field set methodsfs new simple field set true putting values for int i 0 i a pairs array length i methodsfs put single a pairs array i 0 a pairs array i 1 for int i 0 i a pairs array length i getting values ret value methodsfs get a pairs array i 0 equals a pairs array i 1 ret value check simple field set size methodsfs a pairs array length return ret value simplefieldset apairsarray checkputandgetpairs apairsarray retvalue simplefieldset simplefieldset apairsarray putsingle apairsarray apairsarray apairsarray retvalue apairsarray apairsarray retvalue checksimplefieldsetsize apairsarray retvalue tests subset string method putting two levels keys and fetching it through subset method on the first level and then get on the second public void testsimplefieldsetsubset string simple field set methodsfs new simple field set true string methodpairsarray multilevel a a aa a b ab a c ac a d ad a e ae a f af putting values for int i 0 i methodpairsarray multilevel length i methodsfs put single methodpairsarray multilevel i 0 simple field set multi level char methodpairsarray multilevel i 1 methodpairsarray multilevel i 2 getting subsets and then values for int i 0 i methodpairsarray multilevel length i assert equals methodsfs subset methodpairsarray multilevel i 0 get methodpairsarray multilevel i 1 methodpairsarray multilevel i 2 assert true check simple field set size methodsfs methodpairsarray multilevel length testsimplefieldsetsubset_string simplefieldset simplefieldset methodpairsarray_multilevel methodpairsarray_multilevel putsingle methodpairsarray_multilevel simplefieldset multi_level_char methodpairsarray_multilevel methodpairsarray_multilevel methodpairsarray_multilevel assertequals methodpairsarray_multilevel methodpairsarray_multilevel methodpairsarray_multilevel asserttrue checksimplefieldsetsize methodpairsarray_multilevel tests put all overwrite simple field set method trying to overwrite a whole simple field set with another with same keys but different values public void test put all overwrite string method appended string buu simple field set methodsfs sfs from sample string pairs simple field set method newsfs this sfs from string pairs method appended string methodsfs put all overwrite method newsfs for int i 0 i sample string pairs length i assert equals methodsfs get sample string pairs i 0 sample string pairs i 1 method appended string simple field set nullsfs new simple field set false nullsfs put all overwrite method newsfs for int i 0 i sample string pairs length i assert equals nullsfs get sample string pairs i 0 sample string pairs i 1 method appended string putalloverwrite simplefieldset simplefieldset testputalloverwrite methodappendedstring simplefieldset sfsfromsamplestringpairs simplefieldset methodnewsfs sfsfromstringpairs methodappendedstring putalloverwrite methodnewsfs sample_string_pairs assertequals sample_string_pairs sample_string_pairs methodappendedstring simplefieldset simplefieldset putalloverwrite methodnewsfs sample_string_pairs assertequals sample_string_pairs sample_string_pairs methodappendedstring tests put string simple field set method public void testput stringsimplefieldset string method key prefix simple field set methodsfs new simple field set true methodsfs put method key sfs from sample string pairs for int i 0 i sample string pairs length i assert equals methodsfs get method key simple field set multi level char sample string pairs i 0 sample string pairs i 1 simplefieldset testput_stringsimplefieldset methodkey simplefieldset simplefieldset methodkey sfsfromsamplestringpairs sample_string_pairs assertequals methodkey simplefieldset multi_level_char sample_string_pairs sample_string_pairs tests put string simple field set method public void testtput stringsimplefieldset string method key prefix simple field set methodsfs new simple field set true methodsfs tput method key sfs from sample string pairs for int i 0 i sample string pairs length i assert equals methodsfs get method key simple field set multi level char sample string pairs i 0 sample string pairs i 1 simplefieldset testtput_stringsimplefieldset methodkey simplefieldset simplefieldset methodkey sfsfromsamplestringpairs sample_string_pairs assertequals methodkey simplefieldset multi_level_char sample_string_pairs sample_string_pairs tests put string simple field set and tput string simple field set trying to add empty data structures public void testputandtput withempty simple field set method emptysfs new simple field set true simple field set method samplesfs sfs from sample string pairs try method samplesfs put sample method emptysfs fail expected exception error not thrown catch illegal argument exception an exception assert not null an exception try method samplesfs tput sample method samplesfs catch illegal argument exception a exception fail not expected exception thrown a exception get message simplefieldset simplefieldset testputandtput_withempty simplefieldset methodemptysfs simplefieldset simplefieldset methodsamplesfs sfsfromsamplestringpairs methodsamplesfs methodemptysfs illegalargumentexception anexception assertnotnull anexception methodsamplesfs methodsamplesfs illegalargumentexception aexception aexception getmessage it creates a sfs from the sample string pairs and putting a suffix after every value param a suffix to put after every value return the simple field set created private simple field set sfs from string pairs string a suffix simple field set methodsfs new simple field set true creating new for int i 0 i sample string pairs length i methodsfs put single sample string pairs i 0 sample string pairs i 1 a suffix return methodsfs sample_string_pairs asuffix simplefieldset simplefieldset sfsfromstringpairs asuffix simplefieldset simplefieldset sample_string_pairs putsingle sample_string_pairs sample_string_pairs asuffix tests put string boolean and get boolean string boolean methods consistency the default value returned if the key is not found is set to false and the real value is always set to true so we are sure if it finds the right value or not and does not use the default public void testput stringboolean simple field set methodsfs new simple field set true int length 15 for int i 0 i length i methodsfs put integer to string i true for int i 0 i length i assert equals methodsfs get boolean integer to string i false true assert true check simple field set size methodsfs length getboolean testput_stringboolean simplefieldset simplefieldset tostring assertequals getboolean tostring asserttrue checksimplefieldsetsize checks if the provided simple field set has the right size param a simple field set param expected size return true if the size is the expected private boolean check simple field set size simple field set a simple field set int expected size int actual size 0 iterator method key iterator a simple field set key iterator while method key iterator has next method key iterator next actual size return expected size actual size simplefieldset asimplefieldset expectedsize checksimplefieldsetsize simplefieldset asimplefieldset expectedsize actualsize methodkeyiterator asimplefieldset keyiterator methodkeyiterator hasnext methodkeyiterator actualsize expectedsize actualsize tests put string int and get int string get int string int methods consistency the default value returned if the key is not found is set to a not present int value so we are sure if it finds the right value or not and does not use the default public void testput stringint simple field set methodsfs new simple field set true int method pairs array 1 1 2 2 3 3 4 4 for int i 0 i method pairs array length i methodsfs put integer to string method pairs array i 0 method pairs array i 1 assert true check simple field set size methodsfs method pairs array length for int i 0 i method pairs array length i try assert equals methodsfs get int integer to string method pairs array i 0 method pairs array i 1 assert equals methodsfs get int integer to string method pairs array i 0 5 method pairs array i 1 catch fs parse exception a exception fail not expected exception thrown a exception get message getint getint testput_stringint simplefieldset simplefieldset methodpairsarray methodpairsarray tostring methodpairsarray methodpairsarray asserttrue checksimplefieldsetsize methodpairsarray methodpairsarray assertequals getint tostring methodpairsarray methodpairsarray assertequals getint tostring methodpairsarray methodpairsarray fsparseexception aexception aexception getmessage tests put string long and get long string get long string long methods consistency the default value returned if the key is not found is set to a not present long value so we are sure if it finds the right value or not and does not use the default public void testput stringlong simple field set methodsfs new simple field set true long method pairs array 1 1 2 2 3 3 4 4 for int i 0 i method pairs array length i methodsfs put long to string method pairs array i 0 method pairs array i 1 assert true check simple field set size methodsfs method pairs array length for int i 0 i method pairs array length i try assert equals methodsfs get long long to string method pairs array i 0 method pairs array i 1 assert equals methodsfs get long long to string method pairs array i 0 5 method pairs array i 1 catch fs parse exception a exception fail not expected exception thrown a exception get message getlong getlong testput_stringlong simplefieldset simplefieldset methodpairsarray methodpairsarray tostring methodpairsarray methodpairsarray asserttrue checksimplefieldsetsize methodpairsarray methodpairsarray assertequals getlong tostring methodpairsarray methodpairsarray assertequals getlong tostring methodpairsarray methodpairsarray fsparseexception aexception aexception getmessage tests put string char and get char string get char string char methods consistency the default value returned if the key is not found is set to a not present char value so we are sure if it finds the right value or not and does not use the default public void testput stringchar simple field set methodsfs new simple field set true char method pairs array 1 1 2 2 3 3 4 4 for int i 0 i method pairs array length i methodsfs put string value of method pairs array i 0 method pairs array i 1 assert true check simple field set size methodsfs method pairs array length for int i 0 i method pairs array length i try assert equals methodsfs get char string value of method pairs array i 0 method pairs array i 1 assert equals methodsfs get char string value of method pairs array i 0 5 method pairs array i 1 catch fs parse exception a exception fail not expected exception thrown a exception get message getchar getchar testput_stringchar simplefieldset simplefieldset methodpairsarray methodpairsarray valueof methodpairsarray methodpairsarray asserttrue checksimplefieldsetsize methodpairsarray methodpairsarray assertequals getchar valueof methodpairsarray methodpairsarray assertequals getchar valueof methodpairsarray methodpairsarray fsparseexception aexception aexception getmessage tests put string short and get short string get short string short methods consistency the default value returned if the key is not found is set to a not present short value so we are sure if it finds the right value or not and does not use the default public void testput stringshort simple field set methodsfs new simple field set true short method pairs array 1 1 2 2 3 3 4 4 for int i 0 i method pairs array length i methodsfs put short to string method pairs array i 0 method pairs array i 1 assert true check simple field set size methodsfs method pairs array length for int i 0 i method pairs array length i try assert equals methodsfs get short short to string method pairs array i 0 method pairs array i 1 assert equals methodsfs get short short to string method pairs array i 0 short 5 method pairs array i 1 catch fs parse exception a exception fail not expected exception thrown a exception get message getshort getshort testput_stringshort simplefieldset simplefieldset methodpairsarray methodpairsarray tostring methodpairsarray methodpairsarray asserttrue checksimplefieldsetsize methodpairsarray methodpairsarray assertequals getshort tostring methodpairsarray methodpairsarray assertequals getshort tostring methodpairsarray methodpairsarray fsparseexception aexception aexception getmessage tests put string double and get double string get double string double methods consistency the default value returned if the key is not found is set to a not present double value so we are sure if it finds the right value or not and does not use the default public void testput stringdouble simple field set methodsfs new simple field set true double method pairs array 1 1 2 2 3 3 4 4 for int i 0 i method pairs array length i methodsfs put double to string method pairs array i 0 method pairs array i 1 assert true check simple field set size methodsfs method pairs array length for int i 0 i method pairs array length i try there is no assert equals double double so we are obliged to do this way assert equals double compare methodsfs get double double to string method pairs array i 0 method pairs array i 1 0 assert equals double compare methodsfs get double double to string method pairs array i 0 double 5 method pairs array i 1 0 catch fs parse exception a exception fail not expected exception thrown a exception get message getdouble getdouble testput_stringdouble simplefieldset simplefieldset methodpairsarray methodpairsarray tostring methodpairsarray methodpairsarray asserttrue checksimplefieldsetsize methodpairsarray methodpairsarray assertequals _ assertequals getdouble tostring methodpairsarray methodpairsarray assertequals getdouble tostring methodpairsarray methodpairsarray fsparseexception aexception aexception getmessage generates a string for the sfs parser in the canonical form key value end param a string pairs array return a string ready to be read by a sfs parser private string sfs ready string string a string pairs array string method string to return for int i 0 i a string pairs array length i method string to return a string pairs array i 0 key value separator a string pairs array i 1 n method string to return sample end marker return method string to return astringpairsarray sfsreadystring astringpairsarray methodstringtoreturn astringpairsarray methodstringtoreturn astringpairsarray key_value_separator astringpairsarray methodstringtoreturn sample_end_marker methodstringtoreturn tests simple field set string boolean boolean constructor with simple and border cases of the canonical form public void testsimplefieldset stringbooleanboolean string method string pairs sample string pairs string method string to parse sfs ready string method string pairs try simple field set methodsfs new simple field set method string to parse false false for int i 0 i method string pairs length i assert equals methodsfs get method string pairs i 0 method string pairs i 1 catch io exception a exception fail not expected exception thrown a exception get message simplefieldset testsimplefieldset_stringbooleanboolean methodstringpairs sample_string_pairs methodstringtoparse sfsreadystring methodstringpairs simplefieldset simplefieldset methodstringtoparse methodstringpairs assertequals methodstringpairs methodstringpairs ioexception aexception aexception getmessage tests simple field set buffered reader boolean boolean constructor with simple and border cases of the canonical form public void testsimplefieldset bufferedreaderbooleanboolean string method string pairs sample string pairs buffered reader method buffered reader new buffered reader new string reader sfs ready string method string pairs try simple field set methodsfs new simple field set method buffered reader false false for int i 0 i method string pairs length i assert equals methodsfs get method string pairs i 0 method string pairs i 1 catch io exception a exception fail not expected exception thrown a exception get message simplefieldset bufferedreader testsimplefieldset_bufferedreaderbooleanboolean methodstringpairs sample_string_pairs bufferedreader methodbufferedreader bufferedreader stringreader sfsreadystring methodstringpairs simplefieldset simplefieldset methodbufferedreader methodstringpairs assertequals methodstringpairs methodstringpairs ioexception aexception aexception getmessage generates a simple field set using the sample string pairs and sfs put method return a simple field set private simple field set sfs from sample string pairs simple field set methodsfs new simple field set true for int i 0 i sample string pairs length i methodsfs put single sample string pairs i 0 sample string pairs i 1 assert true check simple field set size methodsfs sample string pairs length return methodsfs simplefieldset sample_string_pairs simplefieldset simplefieldset sfsfromsamplestringpairs simplefieldset simplefieldset sample_string_pairs putsingle sample_string_pairs sample_string_pairs asserttrue checksimplefieldsetsize sample_string_pairs tests simple field set simple field set constructor with simple and border cases of the canonical form public void testsimplefieldset simplefieldset simple field set methodsfs new simple field set sfs from sample string pairs string method string pairs sample string pairs for int i 0 i method string pairs length i assert equals methodsfs get method string pairs i 0 method string pairs i 1 simplefieldset simplefieldset testsimplefieldset_simplefieldset simplefieldset simplefieldset sfsfromsamplestringpairs methodstringpairs sample_string_pairs methodstringpairs assertequals methodstringpairs methodstringpairs tests get set end marker string methods using them after a string parsing public void test end marker string method end marker another ending string method string to parse sfs ready string sample string pairs try simple field set methodsfs new simple field set method string to parse false false assert equals methodsfs get end marker sample end marker methodsfs set end marker method end marker assert equals methodsfs get end marker method end marker catch io exception a exception fail not expected exception thrown a exception get message endmarker testendmarker methodendmarker methodstringtoparse sfsreadystring sample_string_pairs simplefieldset simplefieldset methodstringtoparse assertequals getendmarker sample_end_marker setendmarker methodendmarker assertequals getendmarker methodendmarker ioexception aexception aexception getmessage tests is empty method public void test is empty simple field set methodsfs sfs from sample string pairs assert false methodsfs is empty methodsfs new simple field set true assert true methodsfs is empty isempty testisempty simplefieldset sfsfromsamplestringpairs assertfalse isempty simplefieldset asserttrue isempty tests direct subset name iterator method it uses sample string pairs and for this reason the expected subset is foo public void test direct subset name iterator simple field set methodsfs sfs from sample string pairs string expected subset sample string pairs 0 0 foo iterator method iter methodsfs direct subset name iterator while method iter has next assert equals method iter next expected subset methodsfs new simple field set true method iter methodsfs direct subset name iterator assert null method iter directsubsetnameiterator sample_string_pairs testdirectsubsetnameiterator simplefieldset sfsfromsamplestringpairs expectedsubset sample_string_pairs methoditer directsubsetnameiterator methoditer hasnext assertequals methoditer expectedsubset simplefieldset methoditer directsubsetnameiterator assertnull methoditer tests name of direct subsets method public void test names of direct subsets string expected result sample string pairs 0 0 simple field set methodsfs sfs from sample string pairs assert true arrays equals methodsfs names of direct subsets expected result methodsfs new simple field set true assert true arrays equals methodsfs names of direct subsets new string 0 nameofdirectsubsets testnamesofdirectsubsets expectedresult sample_string_pairs simplefieldset sfsfromsamplestringpairs asserttrue namesofdirectsubsets expectedresult simplefieldset asserttrue namesofdirectsubsets test the put overwrite string string method public void testputoverwrite string string method key foo bar string method values boo bar zoo string expected result zoo simple field set methodsfs new simple field set true for int i 0 i method values length i methodsfs put overwrite method key method values i assert equals methodsfs get method key expected result putoverwrite testputoverwrite_string methodkey methodvalues expectedresult simplefieldset simplefieldset methodvalues putoverwrite methodkey methodvalues assertequals methodkey expectedresult test the put overwrite string string method public void testputoverwrite stringarray string method key foo bar string method values boo bar zoo simple field set methodsfs new simple field set true methodsfs put overwrite method key method values assert true arrays equals methodsfs get all method key method values putoverwrite testputoverwrite_stringarray methodkey methodvalues simplefieldset simplefieldset putoverwrite methodkey methodvalues asserttrue getall methodkey methodvalues test the put append string string method public void test put append string method key foo bar string method values boo bar zoo string expected result boo simple field set multi value char bar simple field set multi value char zoo simple field set methodsfs new simple field set true for int i 0 i method values length i methodsfs put append method key method values i assert equals methodsfs get method key expected result putappend testputappend methodkey methodvalues expectedresult simplefieldset multi_value_char simplefieldset multi_value_char simplefieldset simplefieldset methodvalues putappend methodkey methodvalues assertequals methodkey expectedresult tests the get all string method public void test get all string method key foo bar string method values boo bar zoo simple field set methodsfs new simple field set true for int i 0 i method values length i methodsfs put append method key method values i assert true arrays equals methodsfs get all method key method values getall testgetall methodkey methodvalues simplefieldset simplefieldset methodvalues putappend methodkey methodvalues asserttrue getall methodkey methodvalues tests the get int array string method public void test get int array simple field set methodsfs new simple field set true string key prefix foo for int i 0 i 15 i methodsfs put append key prefix string value of i int result methodsfs get int array key prefix for int i 0 i 15 i assert true result i i getintarray testgetintarray simplefieldset simplefieldset keyprefix putappend keyprefix valueof getintarray keyprefix asserttrue tests the get double array string method public void test get double array simple field set methodsfs new simple field set true string key prefix foo for int i 0 i 15 i methodsfs put append key prefix string value of double i double result methodsfs get double array key prefix for int i 0 i 15 i assert true result i double i getdoublearray testgetdoublearray simplefieldset simplefieldset keyprefix putappend keyprefix valueof getdoublearray keyprefix asserttrue tests remove value string method public void test remove value simple field set methodsfs sfs from sample string pairs methodsfs remove value foo assert null methodsfs get sample string pairs 0 0 for int i 1 i sample string pairs length i assert equals methodsfs get sample string pairs i 0 sample string pairs i 1 removevalue testremovevalue simplefieldset sfsfromsamplestringpairs removevalue assertnull sample_string_pairs sample_string_pairs assertequals sample_string_pairs sample_string_pairs tests remove subset string method public void test remove subset simple field set methodsfs sfs from sample string pairs methodsfs remove subset foo for int i 1 i 4 i assert null methodsfs get sample string pairs i 0 assert equals methodsfs get sample string pairs 0 0 sample string pairs 0 1 for int i 4 i 6 i assert equals methodsfs get sample string pairs i 0 sample string pairs i 1 removesubset testremovesubset simplefieldset sfsfromsamplestringpairs removesubset assertnull sample_string_pairs assertequals sample_string_pairs sample_string_pairs assertequals sample_string_pairs sample_string_pairs searches for a key in a given string array we consider that keys are stored in string x 0 param a string pairs array param a prefix that could be put before found key param a key to be searched return true if there is the key private boolean isa key string a string pairs array string a prefix string a key for int i 0 i a string pairs array length i if a key equals a prefix a string pairs array i 0 return true return false astringpairsarray aprefix akey isakey astringpairsarray aprefix akey astringpairsarray akey aprefix astringpairsarray verifies if all keys in a string we consider that keys are stored in string x 0 are the same that the iterator provides in this way both has next and next methods are tested param a string pairs array param a prefix that could be put before found key param a iterator return true if they have the same key set private boolean are all contained keys string a string pairs array string a prefix iterator a iterator boolean ret value true int actual length 0 while a iterator has next actual length ret value isa key a string pairs array a prefix string a iterator next ret value actual length a string pairs array length return ret value hasnext astringpairsarray aprefix aiterator areallcontainedkeys astringpairsarray aprefix aiterator retvalue actuallength aiterator hasnext actuallength retvalue isakey astringpairsarray aprefix aiterator retvalue actuallength astringpairsarray retvalue tests the iterator given for the simple field set class it tests has next and next methods public void test key iterator simple field set methodsfs sfs from sample string pairs iterator itr methodsfs key iterator assert true are all contained keys sample string pairs itr simplefieldset hasnext testkeyiterator simplefieldset sfsfromsamplestringpairs keyiterator asserttrue areallcontainedkeys sample_string_pairs tests the iterator created using prefix given for the simple field set class public void testkeyiterator string string method prefix bob simple field set methodsfs sfs from sample string pairs iterator itr methodsfs key iterator method prefix assert true are all contained keys sample string pairs method prefix itr simplefieldset testkeyiterator_string methodprefix simplefieldset sfsfromsamplestringpairs keyiterator methodprefix asserttrue areallcontainedkeys sample_string_pairs methodprefix tests the toplevel iterator given for the simple field set class it tests has next and next methods todo improve the test public void test toplevel key iterator simple field set methodsfs sfs from sample string pairs iterator itr methodsfs toplevel key iterator for int i 0 i 3 i assert true itr has next assert true isa key sample string pairs string itr next assert false itr has next topleveliterator simplefieldset hasnext testtoplevelkeyiterator simplefieldset sfsfromsamplestringpairs toplevelkeyiterator asserttrue hasnext asserttrue isakey sample_string_pairs assertfalse hasnext boolean is clone t int v value v isclone override public t clone t c new t value c is clone true return c isclone override public string to string if is clone return value else return value tostring isclone void assertv int v assert equals v value assertequals public void assert is clone assert true is clone is clone assertisclone asserttrue isclone isclone public void assert is not clone assert false is clone is clone assertisnotclone assertfalse isclone isclone override public boolean equals object o if o null return false if o get class this get class return false t t t o return t value value t is clone is clone getclass getclass isclone isclone override public int hash code return value hashcode public void test forward push pop doubly linked list t list new doubly linked list impl t list push new t 0 list push new t 1 list push new t 2 list push new t 3 assert false is empty list is empty list pop assertv 3 assert false is empty list is empty list pop assertv 2 assert false is empty list is empty add again list push new t 4 list push new t 5 list pop assertv 5 assert false is empty list is empty list pop assertv 4 assert false is empty list is empty list pop assertv 1 assert false is empty list is empty list pop assertv 0 assert true is empty list is empty assert null pop list pop testforwardpushpop doublylinkedlist doublylinkedlistimpl assertfalse isempty isempty assertfalse isempty isempty assertfalse isempty isempty assertfalse isempty isempty assertfalse isempty isempty assertfalse isempty isempty asserttrue isempty isempty assertnull public void test forward shift unshift doubly linked list t list new doubly linked list impl t list unshift new t 0 list unshift new t 1 list unshift new t 2 list unshift new t 3 assert false is empty list is empty list shift assertv 3 assert false is empty list is empty list shift assertv 2 assert false is empty list is empty add again list unshift new t 4 list unshift new t 5 list shift assertv 5 assert false is empty list is empty list shift assertv 4 assert false is empty list is empty list shift assertv 1 assert false is empty list is empty list shift assertv 0 assert true is empty list is empty assert null shift list shift testforwardshiftunshift doublylinkedlist doublylinkedlistimpl assertfalse isempty isempty assertfalse isempty isempty assertfalse isempty isempty assertfalse isempty isempty assertfalse isempty isempty assertfalse isempty isempty asserttrue isempty isempty assertnull public void test clear size doubly linked list t list new doubly linked list impl t list unshift new t 0 list unshift new t 1 list unshift new t 2 list unshift new t 3 assert equals size 4 list size assert false is empty list is empty list shift assertv 3 assert equals size 3 list size assert false is empty list is empty list shift assertv 2 assert equals size 2 list size assert false is empty list is empty list clear assert equals size 0 list size assert true is empty list is empty add again list unshift new t 4 list unshift new t 5 assert equals size 2 list size assert false is empty list is empty list shift assertv 5 list shift assertv 4 assert equals size 0 list size assert true is empty list is empty testclearsize doublylinkedlist doublylinkedlistimpl assertequals assertfalse isempty isempty assertequals assertfalse isempty isempty assertequals assertfalse isempty isempty assertequals asserttrue isempty isempty assertequals assertfalse isempty isempty assertequals asserttrue isempty isempty public void test shiftn doubly linked list t list new doubly linked list impl t for int i 0 i 5 i list push new t i doubly linked list t list2 list shift 2 assert equals list2 size 2 list2 size list2 shift assertv 0 list2 shift assertv 1 assert true list2 is empty list2 is empty assert equals list size 3 list size list shift assertv 2 list2 list shift 20 assert true list is empty list is empty list2 shift assertv 3 list2 shift assertv 4 assert true list2 is empty list2 is empty list2 list shift 20 assert true list2 is empty list2 is empty testshiftn doublylinkedlist doublylinkedlistimpl doublylinkedlist assertequals asserttrue isempty isempty assertequals asserttrue isempty isempty asserttrue isempty isempty asserttrue isempty isempty public void test popn doubly linked list t list new doubly linked list impl t for int i 0 i 5 i list unshift new t i doubly linked list t list2 list pop 2 assert equals list2 size 2 list2 size list2 pop assertv 0 list2 pop assertv 1 assert true list2 is empty list2 is empty assert equals list size 3 list size list pop assertv 2 list2 list pop 20 assert true list is empty list is empty list2 pop assertv 3 list2 pop assertv 4 assert true list2 is empty list2 is empty list2 list pop 20 assert true list2 is empty list2 is empty testpopn doublylinkedlist doublylinkedlistimpl doublylinkedlist assertequals asserttrue isempty isempty assertequals asserttrue isempty isempty asserttrue isempty isempty asserttrue isempty isempty public void test head tail doubly linked list t list new doubly linked list impl t assert null head null list head assert null tail null list tail t array new t 5 for int i 0 i 5 i array i new t i list push array i assert true head 0 array 0 list head assert true tail 4 array 4 list tail list shift assert true head 1 array 1 list head assert true tail 4 array 4 list tail list pop assert true head 1 array 1 list head assert true tail 3 array 3 list tail list clear assert null head null list head assert null tail null list tail testheadtail doublylinkedlist doublylinkedlistimpl assertnull assertnull asserttrue asserttrue asserttrue asserttrue asserttrue asserttrue assertnull assertnull public void test iternator doubly linked list t list new doubly linked list impl t t array new t 5 for int i 0 i 5 i array i new t i list push array i manual forward t h list head for int i 0 i 5 i assert equals manual iternate forward array i h assert equals doubly linked list next item next h get next list next h assert equals has next i 4 list has next h assert equals has prev i 0 list has prev h h assertv i h list next h assert equals h null null h manual reverse t t list tail for int i 4 i 0 i assert equals manual iternate reverse array i t assert equals doubly linked list prev item get prev tail get prev list prev tail assert equals has next i 4 list has next t assert equals has prev i 0 list has prev t t assertv i t list prev t assert null t null t enumeration t e list elements for int i 0 i 5 i assert true has more elements e has more elements t n e next element n assertv i assert equals has more elements i 4 e has more elements try e next element fail no such element exception catch no such element exception nsee testiternator doublylinkedlist doublylinkedlistimpl assertequals assertequals doublylinkedlist getnext assertequals hasnext hasnext assertequals hasprev hasprev assertequals assertequals assertequals doublylinkedlist getprev getprev assertequals hasnext hasnext assertequals hasprev hasprev assertnull asserttrue hasmoreelements hasmoreelements nextelement assertequals hasmoreelements hasmoreelements nextelement nosuchelementexception nosuchelementexception public void test random remove push doubly linked list t list new doubly linked list impl t t array new t 5 for int i 0 i 5 i array i new t i list push array i assert true list remove array 3 array 3 list push array 3 remove non exist item give null assert null list remove new t 1 remove non identical but equal item give null assert null list remove new t 2 list shift assertv 0 list shift assertv 1 list shift assertv 2 list shift assertv 4 list shift assertv 3 assert null list remove new t 1 testrandomremovepush doublylinkedlist doublylinkedlistimpl asserttrue assertnull assertnull assertnull public void test random shift push doubly linked list t list new doubly linked list impl t list push new t 0 list push new t 1 list unshift new t 2 list push new t 3 list unshift new t 4 list unshift new t 5 list shift assertv 5 list pop assertv 3 list pop assertv 1 list pop assertv 0 list shift assertv 4 list shift assertv 2 testrandomshiftpush doublylinkedlist doublylinkedlistimpl public void test random insert doubly linked list t list new doubly linked list impl t t array new t 5 for int i 0 i 5 i array i new t i list push array i list insert prev array 0 new t 100 list insert prev array 2 new t 102 list insert next array 4 new t 104 list insert next array 4 new t 105 doubly linked list t list2 new doubly linked list impl t t l2 new t 9999 list2 push l2 try already exist list2 insert next l2 l2 fail promiscuous item exception catch promiscuous item exception pie try already exist list2 insert next l2 l2 fail promiscuous item exception catch promiscuous item exception pie try bad position list2 insert prev array 3 new t 8888 fail promiscuous item exception catch promiscuous item exception pie try bad position list2 insert next array 3 new t 8888 fail promiscuous item exception catch promiscuous item exception pie try item in other list list2 insert prev l2 array 3 fail promiscuous item exception catch promiscuous item exception pie try item in other list list2 insert next l2 array 3 fail promiscuous item exception catch promiscuous item exception pie t l3 new t 9999 list2 push l3 try virgin item exception l3 set prev null corrupt it list2 insert prev l3 new t 8888 fail virgin item exception catch virgin item exception vie try virgin item exception l2 set next null corrupt it list2 insert next l2 new t 8888 fail virgin item exception catch virgin item exception vie list shift assertv 100 list shift assertv 0 list shift assertv 1 list shift assertv 102 list shift assertv 2 list shift assertv 3 list shift assertv 4 list shift assertv 105 list shift assertv 104 testrandominsert doublylinkedlist doublylinkedlistimpl insertprev insertprev insertnext insertnext doublylinkedlist doublylinkedlistimpl insertnext promiscuousitemexception promiscuousitemexception insertnext promiscuousitemexception promiscuousitemexception insertprev promiscuousitemexception promiscuousitemexception insertnext promiscuousitemexception promiscuousitemexception insertprev promiscuousitemexception promiscuousitemexception insertnext promiscuousitemexception promiscuousitemexception virginitemexception setprev insertprev virginitemexception virginitemexception virginitemexception setnext insertnext virginitemexception virginitemexception create a object filled with increasing integers as keys and a list of generic objects as values param keys number the number of keys to create param value number the maximum value number per key param is random if true each key could have 1 values number values chosen randomly if false each key will have values number values return the object created private object create sample key multi val int keys number int values number boolean is random object sample objects new object keys number values number int method values number values number for int i 0 i sample objects length i if is random method values number 1 rnd next int values number sample objects i 0 i sample objects i 1 fill sample values list method values number return sample objects keysnumber valuenumber israndom valuesnumber valuesnumber createsamplekeymultival keysnumber valuesnumber israndom sampleobjects keysnumber valuesnumber methodvaluesnumber valuesnumber sampleobjects israndom methodvaluesnumber nextint valuesnumber sampleobjects sampleobjects fillsamplevalueslist methodvaluesnumber sampleobjects create a sample list filled with the specified number of generic objects param values number number of objects to create return the sample list private list object fill sample values list int values number list object sample values new linked list object for int i 0 i values number i sample values add new object return sample values valuesnumber fillsamplevalueslist valuesnumber samplevalues linkedlist valuesnumber samplevalues samplevalues create a sample multi value table param key number the number of key to insert in the multi value table param max value number the maximum number of value for each key param is random true if the max value number is an upper bound false if it is the actual value return the sample multi value table created private multi value table object object create sample multi value table int key number int max value number boolean is random object sample objects create sample key multi val key number max value number is random return fill multi value table sample objects multivaluetable keynumber multivaluetable maxvaluenumber israndom maxvaluenumber multivaluetable multivaluetable createsamplemultivaluetable keynumber maxvaluenumber israndom sampleobjects createsamplekeymultival keynumber maxvaluenumber israndom fillmultivaluetable sampleobjects given an enumeration it returns the number of present objects param an enumeration return the number of present objects private int enumeration size enumeration object an enumeration int counter 0 while an enumeration has more elements an enumeration next element counter return counter anenumeration enumerationsize anenumeration anenumeration hasmoreelements anenumeration nextelement fill a new multi value table from a object provided the object must be in the same form generated by create sample key multi val method param sample objects object array with i 0 as key and i 1 as list of values return the created multi value table suppress warnings unchecked private multi value table object object fill multi value table object sample objects multi value table object object methodmv table new multi value table object object iterator object itr for int i 0 i sample key number i itr list object sample objects i 1 iterator while itr has next methodmv table put sample objects i 0 itr next return methodmv table multivaluetable createsamplekeymultival sampleobjects multivaluetable suppresswarnings multivaluetable fillmultivaluetable sampleobjects multivaluetable methodmvtable multivaluetable samplekeynumber sampleobjects hasnext methodmvtable sampleobjects methodmvtable tests if there are problems when putting values in a sample multi value table public void test put assert not null create sample multi value table sample key number sample max value number sample is random multivaluetable testput assertnotnull createsamplemultivaluetable samplekeynumber samplemaxvaluenumber sampleisrandom tests get object method with both present keys and not present suppress warnings unchecked public void test get multi value table object object methodmv table new multi value table object object assert null methodmv table get new object object sample objects create sample key multi val sample key number sample max value number sample is random methodmv table fill multi value table sample objects for int i 0 i sample objects length i assert equals methodmv table get sample objects i 0 list object sample objects i 1 get 0 suppresswarnings testget multivaluetable methodmvtable multivaluetable assertnull methodmvtable sampleobjects createsamplekeymultival samplekeynumber samplemaxvaluenumber sampleisrandom methodmvtable fillmultivaluetable sampleobjects sampleobjects assertequals methodmvtable sampleobjects sampleobjects tests contains key object method verifying if all keys inserted are correctly found it verifies the correct behavior with empty multi value table and not present keys too public void test contains key multi value table object object methodmv table new multi value table object object assert false methodmv table contains key new object object sample objects create sample key multi val sample key number sample max value number sample is random methodmv table fill multi value table sample objects for int i 0 i sample objects length i assert true methodmv table contains key sample objects i 0 assert false methodmv table contains key new object containskey multivaluetable testcontainskey multivaluetable methodmvtable multivaluetable assertfalse methodmvtable containskey sampleobjects createsamplekeymultival samplekeynumber samplemaxvaluenumber sampleisrandom methodmvtable fillmultivaluetable sampleobjects sampleobjects asserttrue methodmvtable containskey sampleobjects assertfalse methodmvtable containskey tests contains element object object method verifying if all values inserted are correctly found it verifies the correct behavior with empty multi value table and not present elements too suppress warnings unchecked public void test contains element multi value table object object methodmv table new multi value table object object assert false methodmv table contains element new object new object object sample objects create sample key multi val sample key number sample max value number sample is random methodmv table fill multi value table sample objects iterator object iter for int i 0 i sample objects length i iter list object sample objects i 1 iterator assert false methodmv table contains element sample objects i 0 new object while iter has next assert true methodmv table contains element sample objects i 0 iter next containselement multivaluetable suppresswarnings testcontainselement multivaluetable methodmvtable multivaluetable assertfalse methodmvtable containselement sampleobjects createsamplekeymultival samplekeynumber samplemaxvaluenumber sampleisrandom methodmvtable fillmultivaluetable sampleobjects sampleobjects sampleobjects assertfalse methodmvtable containselement sampleobjects hasnext asserttrue methodmvtable containselement sampleobjects tests get all method suppress warnings unchecked public void test get all multi value table object object methodmv table new multi value table object object todo verifies if an exception is necessary methodmv table get all new object object sample objects create sample key multi val sample key number sample max value number sample is random methodmv table fill multi value table sample objects iterator object iter enumeration object method enumeration for int i 0 i sample objects length i iter list object sample objects i 1 iterator method enumeration methodmv table get all sample objects i 0 while iter has next assert equals method enumeration next element iter next getall suppresswarnings testgetall multivaluetable methodmvtable multivaluetable methodmvtable getall sampleobjects createsamplekeymultival samplekeynumber samplemaxvaluenumber sampleisrandom methodmvtable fillmultivaluetable sampleobjects methodenumeration sampleobjects sampleobjects methodenumeration methodmvtable getall sampleobjects hasnext assertequals methodenumeration nextelement tests count all method suppress warnings unchecked public void test count all multi value table object object methodmv table new multi value table object object assert equals methodmv table count all new object 0 object sample objects create sample key multi val sample key number sample max value number sample is random methodmv table fill multi value table sample objects for int i 0 i sample objects length i assert equals list object sample objects i 1 size methodmv table count all sample objects i 0 countall suppresswarnings testcountall multivaluetable methodmvtable multivaluetable assertequals methodmvtable countall sampleobjects createsamplekeymultival samplekeynumber samplemaxvaluenumber sampleisrandom methodmvtable fillmultivaluetable sampleobjects sampleobjects assertequals sampleobjects methodmvtable countall sampleobjects tests get sync object method fetching both present and not present keys suppress warnings cast unchecked public void test get sync multi value table object object methodmv table new multi value table object object assert null methodmv table get sync new object object sample objects create sample key multi val sample key number sample max value number sample is random methodmv table fill multi value table sample objects for int i 0 i sample objects length i assert equals methodmv table get sync sample objects i 0 list object sample objects i 1 getsync suppresswarnings testgetsync multivaluetable methodmvtable multivaluetable assertnull methodmvtable getsync sampleobjects createsamplekeymultival samplekeynumber samplemaxvaluenumber sampleisrandom methodmvtable fillmultivaluetable sampleobjects sampleobjects assertequals methodmvtable getsync sampleobjects sampleobjects tests get array object method both with a present key and a not present key suppress warnings unchecked public void test get array multi value table object object methodmv table new multi value table object object assert null methodmv table get array new object object sample objects create sample key multi val sample key number sample max value number sample is random methodmv table fill multi value table sample objects for int i 0 i sample objects length i assert true arrays equals list object sample objects i 1 to array methodmv table get array sample objects i 0 getarray suppresswarnings testgetarray multivaluetable methodmvtable multivaluetable assertnull methodmvtable getarray sampleobjects createsamplekeymultival samplekeynumber samplemaxvaluenumber sampleisrandom methodmvtable fillmultivaluetable sampleobjects sampleobjects asserttrue sampleobjects toarray methodmvtable getarray sampleobjects tests remove object method trying to remove all keys inserted in a multi value table it verifies the behavior when removing a not present key too public void test remove multi value table object object methodmv table new multi value table object object todo shouldn t it raise an exception methodmv table remove new object object sample objects create sample key multi val sample key number sample max value number sample is random methodmv table fill multi value table sample objects for int i 0 i sample objects length i methodmv table remove sample objects i 0 assert true methodmv table is empty multivaluetable testremove multivaluetable methodmvtable multivaluetable methodmvtable sampleobjects createsamplekeymultival samplekeynumber samplemaxvaluenumber sampleisrandom methodmvtable fillmultivaluetable sampleobjects sampleobjects methodmvtable sampleobjects asserttrue methodmvtable isempty tests is empty method with an empty multi value table after putting objects and after removing all of them public void test is empty multi value table object object methodmv table new multi value table object object assert true methodmv table is empty object sample objects create sample key multi val sample key number sample max value number sample is random methodmv table fill multi value table sample objects assert false methodmv table is empty for int i 0 i sample objects length i methodmv table remove sample objects i 0 assert true methodmv table is empty isempty multivaluetable testisempty multivaluetable methodmvtable multivaluetable asserttrue methodmvtable isempty sampleobjects createsamplekeymultival samplekeynumber samplemaxvaluenumber sampleisrandom methodmvtable fillmultivaluetable sampleobjects assertfalse methodmvtable isempty sampleobjects methodmvtable sampleobjects asserttrue methodmvtable isempty tests clear method filling a multi value table and verifying if all keys are correctly removed finally it verifies the result of is empty method public void test clear object sample objects create sample key multi val sample key number sample max value number sample is random multi value table object object methodmv table fill multi value table sample objects methodmv table clear for int i 0 i sample objects length i assert false methodmv table contains key sample objects i 0 assert true methodmv table is empty multivaluetable isempty testclear sampleobjects createsamplekeymultival samplekeynumber samplemaxvaluenumber sampleisrandom multivaluetable methodmvtable fillmultivaluetable sampleobjects methodmvtable sampleobjects assertfalse methodmvtable containskey sampleobjects asserttrue methodmvtable isempty tests remove element object object removing all elements from a sample multi value table and verifying if they are correctly removed and if the result of is empty method is correct suppress warnings unchecked public void test remove element object sample objects create sample key multi val sample key number sample max value number sample is random multi value table object object methodmv table fill multi value table sample objects object method value iterator object iter for int i 0 i sample objects length i iter list object sample objects i 1 iterator assert false methodmv table remove element sample objects i 0 new object while iter has next method value iter next assert true methodmv table remove element sample objects i 0 method value assert false methodmv table contains element sample objects i 0 method value assert true methodmv table is empty removeelement multivaluetable isempty suppresswarnings testremoveelement sampleobjects createsamplekeymultival samplekeynumber samplemaxvaluenumber sampleisrandom multivaluetable methodmvtable fillmultivaluetable sampleobjects methodvalue sampleobjects sampleobjects assertfalse methodmvtable removeelement sampleobjects hasnext methodvalue asserttrue methodmvtable removeelement sampleobjects methodvalue assertfalse methodmvtable containselement sampleobjects methodvalue asserttrue methodmvtable isempty tests keys method verifying if all keys inserted are correctly present in the resulting enumeration public void test keys object sample objects create sample key multi val sample key number sample max value number sample is random multi value table object object methodmv table fill multi value table sample objects todo shouldn t it respect keys order int j sample objects length 1 enumeration object method enumeration methodmv table keys while method enumeration has more elements assert equals sample objects j 0 method enumeration next element j testkeys sampleobjects createsamplekeymultival samplekeynumber samplemaxvaluenumber sampleisrandom multivaluetable methodmvtable fillmultivaluetable sampleobjects sampleobjects methodenumeration methodmvtable methodenumeration hasmoreelements assertequals sampleobjects methodenumeration nextelement tests elements and keys method verifying their behavior when putting the same value for different keys public void test different keys same element int keys number 2 multi value table object object methodmv table new multi value table object object string sample value sample value putting the same value for different keys for int i 0 i keys number i methodmv table put new object sample value assert equals enumeration size methodmv table elements 1 assert equals enumeration size methodmv table keys keys number testdifferentkeyssameelement keysnumber multivaluetable methodmvtable multivaluetable samplevalue samplevalue keysnumber methodmvtable samplevalue assertequals enumerationsize methodmvtable assertequals enumerationsize methodmvtable keysnumber tests if url encode encode string and url decode decode string boolean methods work correctly together both with safe characters and not safe base i e ascii chars public void testencodedecodestring notsafebasechars string to encode safe chars url encoder safeurl characters prtbl ascii triple char if badly encoded it will generate an exception no chars try assert true are correctly encoded decoded to encode true assert true are correctly encoded decoded to encode false catch url encoded format exception an exception fail not expected exception thrown an exception get message urlencode urldecode testencodedecodestring_notsafebasechars toencode urlencoder safeurlcharacters prtblascii asserttrue arecorrectlyencodeddecoded toencode asserttrue arecorrectlyencodeddecoded toencode urlencodedformatexception anexception anexception getmessage tests if url encode encode string and url decode decode string boolean methods work correctly together both with safe characters and not safe advanced i e not ascii chars public void testencodedecodestring notsafeadvchars string to encode stressedutf 8chars try assert true are correctly encoded decoded to encode true assert true are correctly encoded decoded to encode false catch url encoded format exception an exception fail not expected exception thrown an exception get message urlencode urldecode testencodedecodestring_notsafeadvchars toencode stressedutf_8chars asserttrue arecorrectlyencodeddecoded toencode asserttrue arecorrectlyencodeddecoded toencode urlencodedformatexception anexception anexception getmessage verifies if a string is the same after being processed by encoding and decoding methods param to encode string to encode return true means to be tolerant of bogus escapes throws url encoded format exception private boolean are correctly encoded decoded string to encode boolean with letters throws url encoded format exception boolean ret value true string encoded new string to encode length encoding for int i 0 i encoded length i encoded i url encoder encode to encode i with letters decoding for int i 0 i encoded length i ret value url decoder decode encoded i with letters equals to encode i return ret value toencode urlencodedformatexception arecorrectlyencodeddecoded toencode withletters urlencodedformatexception retvalue toencode urlencoder toencode withletters retvalue urldecoder withletters toencode retvalue tests encode string string boolean method to verify if the force parameter is well managed for each safeurl character with both true and false ascii flag public void test encode forced string to encode expected result char each char for int i 0 i url encoder safeurl characters length i each char url encoder safeurl characters char at i to encode string value of each char try expected result hex util bytes to hex since safe chars are only us ascii to encode get bytes us ascii assert equals url encoder encode to encode to encode false expected result assert equals url encoder encode to encode to encode true expected result catch unsupported encoding exception an exception fail not expected exception thrown an exception get message safeurlcharacter testencodeforced toencode expectedresult eachchar urlencoder safeurlcharacters eachchar urlencoder safeurlcharacters charat toencode valueof eachchar expectedresult hexutil bytestohex toencode getbytes assertequals urlencoder toencode toencode expectedresult assertequals urlencoder toencode toencode expectedresult unsupportedencodingexception anexception anexception getmessage verifies if a url encoded format exception is raised when decoding the provided string param to decode the string to decode param tolerant whether the decoding should be tolerant with return private boolean is decode raising encoded exception string to decode boolean tolerant boolean ret value false try system out println url decoder decode to decode false catch url encoded format exception an exception ret value true return ret value urlencodedformatexception todecode isdecoderaisingencodedexception todecode retvalue urldecoder todecode urlencodedformatexception anexception retvalue retvalue tests decode string boolean method using not valid encoded string to verifies if it raises an exception public void test decode wrong string string to decode 00 assert true is decode raising encoded exception to decode false testdecodewrongstring todecode asserttrue isdecoderaisingencodedexception todecode tests decode string boolean method using not valid hex values string to verifies if it raises an exception public void test decode wrong hex string to decode 123456789abcde prtbl ascii stressedutf 8chars for int i 0 i to decode length i assert true is decode raising encoded exception to decode substring i i 1 false testdecodewronghex todecode prtblascii stressedutf_8chars todecode asserttrue isdecoderaisingencodedexception todecode tests decode string boolean method trying the boolean argument to verify if it work correctly as a hack to allow users to paste in ur ls containing s public void test tolerant decoding string to decode try assert equals url decoder decode to decode true to decode catch url encoded format exception an exception fail not expected exception thrown an exception get message urls testtolerantdecoding todecode assertequals urldecoder todecode todecode urlencodedformatexception anexception anexception getmessage creates a bit array with all values set to the boolean argument param array size the size of the bit array param value the value for each bit return the set bit array private bit array create all equals bit array int array size boolean value bit array method bit array new bit array array size setting all bits true for int i 0 i method bit array get size i method bit array set bit i value return method bit array bitarray arraysize bitarray bitarray bitarray createallequalsbitarray arraysize bitarray methodbitarray bitarray arraysize methodbitarray getsize methodbitarray setbit methodbitarray creates a string of to repeat string as long as needed param string size length requested param to repeat string to repeat string size times return the string of to repeat private string create all one string int string size string to repeat string builder method string builder new string builder for int i 0 i string size i method string builder append to repeat return method string builder to string torepeat stringsize torepeat stringsize torepeat createallonestring stringsize torepeat stringbuilder methodstringbuilder stringbuilder stringsize methodstringbuilder torepeat methodstringbuilder tostring tests bit array int constructor and verifies if the instance is well created all values must be readables and false and the length has to be correct public void testbitarray int bit array method bit array new bit array sample bits number for int i 0 i sample bits number i assert false method bit array bit at i assert equals method bit array get size sample bits number bitarray testbitarray_int bitarray methodbitarray bitarray samplebitsnumber samplebitsnumber assertfalse methodbitarray bitat assertequals methodbitarray getsize samplebitsnumber tests to string method creating bit arrays with same value bits public void test to string all equals bit array method bit array create all equals bit array sample bits number true string expected string create all one string sample bits number 1 assert equals method bit array to string expected string method bit array create all equals bit array sample bits number false expected string create all one string sample bits number 0 assert equals method bit array to string expected string tostring bitarrays testtostringallequals bitarray methodbitarray createallequalsbitarray samplebitsnumber expectedstring createallonestring samplebitsnumber assertequals methodbitarray tostring expectedstring methodbitarray createallequalsbitarray samplebitsnumber expectedstring createallonestring samplebitsnumber assertequals methodbitarray tostring expectedstring tests to string method with a bit array with size zero public void test to string empty bit array method bit array new bit array 0 assert equals method bit array to string length 0 tostring bitarray testtostringempty bitarray methodbitarray bitarray assertequals methodbitarray tostring tests set bit int boolean method trying to set a bit out of bounds public void testsetbit outofbounds bit array method bit array new bit array sample bits number try method bit array set bit sample bits number true fail expected exception error not thrown catch array index out of bounds exception an exception assert not null an exception setbit testsetbit_outofbounds bitarray methodbitarray bitarray samplebitsnumber methodbitarray setbit samplebitsnumber arrayindexoutofboundsexception anexception assertnotnull anexception tests set bit int boolean method using get at int to verify if they are consistent public void test set and get bit bit array method bit array new bit array sample bits number setting true even bits for int i 0 i method bit array get size i i 2 method bit array set bit i true checking even bits for int i 0 i method bit array get size i i 2 assert true method bit array bit at i checking odd bits for int i 1 i method bit array get size i i 2 assert false method bit array bit at i setbit getat testsetandgetbit bitarray methodbitarray bitarray samplebitsnumber methodbitarray getsize methodbitarray setbit methodbitarray getsize asserttrue methodbitarray bitat methodbitarray getsize assertfalse methodbitarray bitat tests unsigned byte to int byte method trying it correctness for every possible i e 256 byte value public void test unsigned byte to int byte sample byte for int i 0 i 256 i sample byte byte i assert equals i bit array unsigned byte to int sample byte unsignedbytetoint testunsignedbytetoint samplebyte samplebyte assertequals bitarray unsignedbytetoint samplebyte tests get size method public void test get size bit array method bit array new bit array 0 assert equals method bit array get size 0 method bit array create all equals bit array sample bits number true assert equals method bit array get size sample bits number getsize testgetsize bitarray methodbitarray bitarray assertequals methodbitarray getsize methodbitarray createallequalsbitarray samplebitsnumber assertequals methodbitarray getsize samplebitsnumber tests set all ones method comparing the result to a bit array with already all ones set public void test set all ones bit array method bit array create all equals bit array sample bits number true bit array method bit array to verify new bit array sample bits number method bit array to verify set all ones assert equals method bit array method bit array to verify setallones bitarray testsetallones bitarray methodbitarray createallequalsbitarray samplebitsnumber bitarray methodbitarraytoverify bitarray samplebitsnumber methodbitarraytoverify setallones assertequals methodbitarray methodbitarraytoverify tests first one method far all possible first one position in a bit array with as many bits as in a single byte public void test first one bit array method bit array new bit array one byte bits only one 1 for int i 0 i one byte bits i method bit array new bit array one byte bits method bit array set bit i true assert equals method bit array first one i method bit array set all ones augmenting zeros for int i 0 i one byte bits 1 i method bit array set bit i false assert equals method bit array first one i 1 all zeros method bit array set bit one byte bits 1 false assert equals method bit array first one 1 firstone bitarray testfirstone bitarray methodbitarray bitarray onebytebits onebytebits methodbitarray bitarray onebytebits methodbitarray setbit assertequals methodbitarray firstone methodbitarray setallones onebytebits methodbitarray setbit assertequals methodbitarray firstone methodbitarray setbit onebytebits assertequals methodbitarray firstone test the encode byte method against a well known example see http en wikipedia org wiki base 64 as reference to verify if it encode works correctly public void test encode string to encode man is distinguished not only by his reason but by this singular passion from other animals which is a lust of the mind that by a perseverance of delight in the continued and indefatigable generation of knowledge exceeds the short vehemence of any carnal pleasure string expected result tw fui glzig rpc3 rpbmd1ax nozw qsig5vdc bvbmx5igj5i ghpcy byzw fzb24sigj 1dc biesb0a glzih npbmd1bg fyih bhc3 npb24g zn jvbs bvd ghlci bhbmlty wxzlcb3a gljac bpcy bhig x1c3 qgb2 ygd ghlig1pbm qsih royx qg ynkgys bwzx jzzx zlcm fuy2 ugb2 ygzg vsa wdodc bpbib0ag ugy 29ud gludw vkig fuzc bpbm rl zmf0a wdh ymxli gdlbm vyyx rpb24gb2 yga25vd2xlz gdllc bleg nlzw rz ih rozs bzag9ydcb2z whlbw vuy2 ugb2 ygyw55ig nhcm5hbc bwbg vhc3 vyzs4 byte a byte array to encode to encode get bytes assert equals base64 encode a byte array to encode expected result base_64 testencode toencode expectedresult twfuiglzigrpc3rpbmd1axnozwqsig5vdcbvbmx5igj5ighpcybyzwfzb24sigj 1dcbiesb0aglzihnpbmd1bgfyihbhc3npb24gznjvbsbvdghlcibhbmltywxzlcb3agljacbpcybhig x1c3qgb2ygdghlig1pbmqsihroyxqgynkgysbwzxjzzxzlcmfuy2ugb2ygzgvsawdodcbpbib0agugy 29udgludwvkigfuzcbpbmrlzmf0awdhymxligdlbmvyyxrpb24gb2yga25vd2xlzgdllcblegnlzwrz ihrozsbzag9ydcb2zwhlbwvuy2ugb2ygyw55ignhcm5hbcbwbgvhc3vyzs4 abytearraytoencode toencode getbytes assertequals abytearraytoencode expectedresult test the decode string method against a well known example see http en wikipedia org wiki base 64 as reference to verify if it decode an already encoded string correctly public void test decode string to decode tw fui glzig rpc3 rpbmd1ax nozw qsig5vdc bvbmx5igj5i ghpcy byzw fzb24sigj 1dc biesb0a glzih npbmd1bg fyih bhc3 npb24g zn jvbs bvd ghlci bhbmlty wxzlcb3a gljac bpcy bhig x1c3 qgb2 ygd ghlig1pbm qsih royx qg ynkgys bwzx jzzx zlcm fuy2 ugb2 ygzg vsa wdodc bpbib0ag ugy 29ud gludw vkig fuzc bpbm rl zmf0a wdh ymxli gdlbm vyyx rpb24gb2 yga25vd2xlz gdllc bleg nlzw rz ih rozs bzag9ydcb2z whlbw vuy2 ugb2 ygyw55ig nhcm5hbc bwbg vhc3 vyzs4 string expected result man is distinguished not only by his reason but by this singular passion from other animals which is a lust of the mind that by a perseverance of delight in the continued and indefatigable generation of knowledge exceeds the short vehemence of any carnal pleasure try string decoded string new string base64 decode to decode assert equals decoded string expected result catch illegal base64 exception a exception fail not expected exception thrown a exception get message base_64 testdecode todecode twfuiglzigrpc3rpbmd1axnozwqsig5vdcbvbmx5igj5ighpcybyzwfzb24sigj 1dcbiesb0aglzihnpbmd1bgfyihbhc3npb24gznjvbsbvdghlcibhbmltywxzlcb3agljacbpcybhig x1c3qgb2ygdghlig1pbmqsihroyxqgynkgysbwzxjzzxzlcmfuy2ugb2ygzgvsawdodcbpbib0agugy 29udgludwvkigfuzcbpbmrlzmf0awdhymxligdlbmvyyxrpb24gb2yga25vd2xlzgdllcblegnlzwrz ihrozsbzag9ydcb2zwhlbwvuy2ugb2ygyw55ignhcm5hbcbwbgvhc3vyzs4 expectedresult decodedstring todecode assertequals decodedstring expectedresult illegalbase64exception aexception aexception getmessage test encode byte in and decode string in str methods to verify if they work correctly together it compares the string before encoding and with the one after decoding public void test encode decode byte bytes decoded byte bytes to encode new byte 5 byte upper bound bytes to encode 0 127 bytes to encode 1 64 bytes to encode 2 0 bytes to encode 3 64 byte lower bound bytes to encode 4 128 string a base64 encoded string base64 encode bytes to encode try bytes decoded base64 decode a base64 encoded string assert true arrays equals bytes to encode bytes decoded catch illegal base64 exception a exception fail not expected exception thrown a exception get message instr testencodedecode bytesdecoded bytestoencode bytestoencode bytestoencode bytestoencode bytestoencode bytestoencode abase64encodedstring bytestoencode bytesdecoded abase64encodedstring asserttrue bytestoencode bytesdecoded illegalbase64exception aexception aexception getmessage test the encode string boolean method to verify if the padding character is correctly placed public void test encode padding byte method bytes array three byte array no padding char expected 4 4 4 two byte array one padding char expected 4 4 one byte array two padding chars expected 4 string encoded for int i 0 i method bytes array length i encoded base64 encode method bytes array i true if i 0 no occurrences expected assert equals encoded index of 1 else assert equals encoded index of encoded length i testencodepadding methodbytesarray methodbytesarray methodbytesarray assertequals indexof assertequals indexof test if the decode string method raise correctly an exception when providing a string with non base64 characters public void test illegal base character todo check many other possibile cases string illegal char string abcd fghilmn try base64 decode illegal char string fail expected illegal base64 exception not thrown catch illegal base64 exception exception assert same illegal base64 character exception get message testillegalbasecharacter illegalcharstring illegalcharstring illegalbase64exception illegalbase64exception assertsame getmessage test if the decode string method raise correctly an exception when providing a string with a wrong base64 length as we can consider not padded strings too the only wrong lengths are the ones where number mod 4 1 public void test illegal base length most interesting case string illegal length string a try base64 decode illegal length string fail expected illegal base64 exception not thrown catch illegal base64 exception exception assert same illegal base64 length exception get message testillegalbaselength illegallengthstring illegallengthstring illegalbase64exception illegalbase64exception assertsame getmessage random test throws illegal base64 exception public void test random throws illegal base64 exception int iter random r new random 1234 for iter 0 iter 1000 iter byte b new byte r next int 64 for int i 0 i b length i b i byte r next int 256 string encoded base64 encode b byte decoded base64 decode encoded assert equals length mismatch decoded length b length for int i 0 i b length i assert equals data mismatch index i of b length should be 0x integer to hex string b i 0xff was 0x integer to hex string decoded i 0xff b i decoded i illegalbase64exception testrandom illegalbase64exception nextint nextint assertequals assertequals tohexstring tohexstring public void test ssk forusk throws malformedurl exception freeneturi uri1 new freeneturi wanna usk 1 freeneturi uri2 new freeneturi wanna ssk 1 assert equals uri2 uri1 ssk forusk assert equals uri1 uri2 usk forssk try uri1 usk forssk fail no excpetion throw catch illegal state exception e pass try uri2 ssk forusk fail no excpetion throw catch illegal state exception e pass try new freeneturi wanna chk 1 ssk forusk fail no excpetion throw catch illegal state exception e pass try new freeneturi wanna chk 1 usk forssk fail no excpetion throw catch illegal state exception e pass try new freeneturi ssk 5hh 39 ftja7a9 vx wtbki prud tujzu ruddg0x fn3ka g dgr gt5f6xqbmo wra qtu54x4h 871 sho9 hz6hc 0ra aqacaae search 17xxxx index d51 xml ssk forusk fail no excpetion throw catch illegal state exception e pass try new freeneturi ssk 5hh 39 ftja7a9 vx wtbki prud tujzu ruddg0x fn3ka g dgr gt5f6xqbmo wra qtu54x4h 871 sho9 hz6hc 0ra aqacaae search17 index d51 xml ssk forusk fail no excpetion throw catch illegal state exception e pass testsskforusk malformedurlexception wanna_usk_1 wanna_ssk_1 assertequals sskforusk assertequals uskforssk uskforssk illegalstateexception sskforusk illegalstateexception wanna_chk_1 sskforusk illegalstateexception wanna_chk_1 uskforssk illegalstateexception 39ftja7a9 vxwtbki prudtujzuruddg0xfn3ka gdgrgt5f6xqbmo wraqtu54x4h 871sho9hz6hc index_d51 sskforusk illegalstateexception 39ftja7a9 vxwtbki prudtujzuruddg0xfn3ka gdgrgt5f6xqbmo wraqtu54x4h 871sho9hz6hc index_d51 sskforusk illegalstateexception public void test throws exception inet4 address matcher matcher new inet4 address matcher 192 168 1 2 assert equals false matcher matches inet address get by name 192 168 1 1 assert equals true matcher matches inet address get by name 192 168 1 2 assert equals false matcher matches inet address get by name 127 0 0 1 assert equals false matcher matches inet address get by name 0 0 0 0 matcher new inet4 address matcher 192 168 1 2 8 assert equals true matcher matches inet address get by name 192 168 1 1 assert equals true matcher matches inet address get by name 192 168 1 2 assert equals true matcher matches inet address get by name 192 168 2 1 assert equals true matcher matches inet address get by name 192 16 81 1 assert equals true matcher matches inet address get by name 192 255 255 255 assert equals false matcher matches inet address get by name 172 16 1 1 assert equals false matcher matches inet address get by name 127 0 0 1 assert equals false matcher matches inet address get by name 0 0 0 0 assert equals true matcher matches inet address get by name 192 0 0 0 some fancy matching matcher new inet4 address matcher 192 168 1 1 255 0 255 0 assert equals true matcher matches inet address get by name 192 168 1 1 assert equals true matcher matches inet address get by name 192 16 1 1 assert equals false matcher matches inet address get by name 192 168 2 1 assert equals false matcher matches inet address get by name 192 16 2 1 assert equals false matcher matches inet address get by name 127 0 0 1 matcher new inet4 address matcher 127 0 0 1 8 assert equals true matcher matches inet address get by name 127 0 0 1 assert equals true matcher matches inet address get by name 127 23 42 64 assert equals true matcher matches inet address get by name 127 0 0 0 assert equals true matcher matches inet address get by name 127 255 255 255 assert equals false matcher matches inet address get by name 28 0 0 1 matcher new inet4 address matcher 0 0 0 0 0 assert equals true matcher matches inet address get by name 127 0 0 1 assert equals true matcher matches inet address get by name 192 168 1 1 assert equals true matcher matches inet address get by name 192 168 2 1 assert equals true matcher matches inet address get by name 172 16 42 23 assert equals true matcher matches inet address get by name 10 0 0 1 assert equals true matcher matches inet address get by name 224 0 0 1 inet4addressmatcher inet4addressmatcher assertequals inetaddress getbyname assertequals inetaddress getbyname assertequals inetaddress getbyname assertequals inetaddress getbyname inet4addressmatcher assertequals inetaddress getbyname assertequals inetaddress getbyname assertequals inetaddress getbyname assertequals inetaddress getbyname assertequals inetaddress getbyname assertequals inetaddress getbyname assertequals inetaddress getbyname assertequals inetaddress getbyname assertequals inetaddress getbyname inet4addressmatcher assertequals inetaddress getbyname assertequals inetaddress getbyname assertequals inetaddress getbyname assertequals inetaddress getbyname assertequals inetaddress getbyname inet4addressmatcher assertequals inetaddress getbyname assertequals inetaddress getbyname assertequals inetaddress getbyname assertequals inetaddress getbyname assertequals inetaddress getbyname inet4addressmatcher assertequals inetaddress getbyname assertequals inetaddress getbyname assertequals inetaddress getbyname assertequals inetaddress getbyname assertequals inetaddress getbyname assertequals inetaddress getbyname public void test throws exception inet6 address matcher matcher new inet6 address matcher 0 0 0 0 0 0 0 0 0 assert equals true matcher matches inet address get by name fe80 0 0 0 203 dff fe22 420f matcher new inet6 address matcher fe80 0 0 0 203 dff fe22 420f 64 assert equals true matcher matches inet address get by name fe80 0 0 0 203 dff fe22 420f assert equals true matcher matches inet address get by name fe80 0 0 0 0203 0dff fe22 420f assert equals true matcher matches inet address get by name fe80 0 0 0 0204 0dff fe22 420f assert equals false matcher matches inet address get by name fe81 0 0 0 0203 0dff fe22 420f assert equals false matcher matches inet address get by name 0 0 0 0 0 0 0 1 assert equals true matcher matches inet address get by name fe80 0 0 0 0 0 0 1 matcher new inet6 address matcher fe80 0 0 0 203 dff fe22 420f ffff ffff ffff ffff 0 0 0 0 assert equals true matcher matches inet address get by name fe80 0 0 0 203 dff fe22 420f assert equals true matcher matches inet address get by name fe80 0 0 0 0203 0dff fe22 420f assert equals true matcher matches inet address get by name fe80 0 0 0 0204 0dff fe22 420f assert equals false matcher matches inet address get by name fe81 0 0 0 0203 0dff fe22 420f assert equals false matcher matches inet address get by name 0 0 0 0 0 0 0 1 assert equals true matcher matches inet address get by name fe80 0 0 0 0 0 0 1 matcher new inet6 address matcher fe80 0 0 0 203 dff fe22 420f 128 assert equals true matcher matches inet address get by name fe80 0 0 0 203 dff fe22 420f assert equals true matcher matches inet address get by name fe80 0 0 0 0203 0dff fe22 420f assert equals false matcher matches inet address get by name fe80 0 0 0 0204 0dff fe22 420f assert equals false matcher matches inet address get by name fe81 0 0 0 0203 0dff fe22 420f assert equals false matcher matches inet address get by name 0 0 0 0 0 0 0 1 assert equals false matcher matches inet address get by name fe80 0 0 0 0 0 0 1 inet6addressmatcher inet6addressmatcher assertequals inetaddress getbyname inet6addressmatcher assertequals inetaddress getbyname assertequals inetaddress getbyname assertequals inetaddress getbyname assertequals inetaddress getbyname assertequals inetaddress getbyname assertequals inetaddress getbyname inet6addressmatcher assertequals inetaddress getbyname assertequals inetaddress getbyname assertequals inetaddress getbyname assertequals inetaddress getbyname assertequals inetaddress getbyname assertequals inetaddress getbyname inet6addressmatcher assertequals inetaddress getbyname assertequals inetaddress getbyname assertequals inetaddress getbyname assertequals inetaddress getbyname assertequals inetaddress getbyname assertequals inetaddress getbyname public void test test real i pv4 addresses assert equals address type i pv4 address identifier get address type 0 0 0 0 assert equals address type i pv4 address identifier get address type 127 0 0 1 assert equals address type i pv4 address identifier get address type 255 255 255 255 in case you didn t know 183 24 17 183 24 0 17 assert equals address type i pv4 address identifier get address type 183 24 17 and 127 1 127 0 0 1 assert equals address type i pv4 address identifier get address type 127 1 test fake i pv4 addresses assert equals address type other address identifier get address type 192 168 370 12 assert equals address type other address identifier get address type 127 0 0 0 1 test real unabridged i pv6 addresses assert equals address type i pv6 address identifier get address type 0 0 0 0 0 0 0 1 assert equals address type i pv6 address identifier get address type fe80 0 0 0 203 dff fe22 420f test fake i pv6 addresses assert equals address type other address identifier get address type 1 2 3 4 5 6 7 8 9 assert equals address type other address identifier get address type 12345 6 7 8 9 ipv4 assertequals addresstype ipv4 addressidentifier getaddresstype assertequals addresstype ipv4 addressidentifier getaddresstype assertequals addresstype ipv4 addressidentifier getaddresstype assertequals addresstype ipv4 addressidentifier getaddresstype assertequals addresstype ipv4 addressidentifier getaddresstype ipv4 assertequals addresstype addressidentifier getaddresstype assertequals addresstype addressidentifier getaddresstype ipv6 assertequals addresstype ipv6 addressidentifier getaddresstype assertequals addresstype ipv6 addressidentifier getaddresstype ipv6 assertequals addresstype addressidentifier getaddresstype assertequals addresstype addressidentifier getaddresstype public void test is anisatapi pv6 address assert false address identifier is anisatapi pv6 address fe80 0 0 0 203 dff fe22 420f assert false address identifier is anisatapi pv6 address fe80 0 5efe 0 203 dff fe22 420f assert true address identifier is anisatapi pv6 address 2001 1 2 3 0 5efe c801 20a testisanisatapipv6address assertfalse addressidentifier isanisatapipv6address assertfalse addressidentifier isanisatapipv6address asserttrue addressidentifier isanisatapipv6address public void test known value throws unsupported cipher exception rijndael aes128 new rijndael 128 128 byte res128 new byte 128 8 aes128 initialize key128 1 aes128 encipher plaintxt128 1 res128 assert true 128 128 encipher arrays equals res128 cipher128 1 byte des128 new byte 128 8 aes128 decipher res128 des128 assert true 128 128 decipher arrays equals des128 plaintxt128 1 rijndael aes192 new rijndael 192 192 byte res192 new byte 192 8 aes192 initialize key192 1 aes192 encipher plaintxt192 1 res192 assert true 192 192 encipher arrays equals res192 cipher192 1 byte des192 new byte 192 8 aes192 decipher res192 des192 assert true 192 192 decipher arrays equals des192 plaintxt192 1 rijndael aes256 new rijndael 256 256 byte res256 new byte 256 8 aes256 initialize key256 1 aes256 encipher plaintxt256 1 res256 assert true 256 256 encipher arrays equals res256 cipher256 1 byte des256 new byte 256 8 aes256 decipher res256 des256 assert true 256 256 decipher arrays equals des256 plaintxt256 1 testknownvalue unsupportedcipherexception key128_1 plaintxt128_1 asserttrue cipher128_1 asserttrue plaintxt128_1 key192_1 plaintxt192_1 asserttrue cipher192_1 asserttrue plaintxt192_1 key256_1 plaintxt256_1 asserttrue cipher256_1 asserttrue plaintxt256_1 public void test standard testvk throws unsupported cipher exception keysize 128 rijndael aes128 new rijndael 128 128 for int i 0 i test vk128 length i aes128 initialize test vk128 i 0 byte cipher new byte 128 8 aes128 encipher test vk pt cipher assert true ecb vk keysize 128 i i 1 arrays equals cipher test vk128 i 1 keysize 192 this case would fail rijndael aes192 new rijndael 192 128 for int i 0 i test vk192 length i aes192 initialize test vk192 i 0 byte cipher new byte 192 8 aes192 encipher test vk pt cipher assert true ecb vk keysize 192 i i 1 arrays equals cipher test vk192 i 1 teststandardtestvk unsupportedcipherexception test_vk128 test_vk128 test_vk_pt asserttrue ecb_vk test_vk128 test_vk192 test_vk192 test_vk_pt asserttrue ecb_vk test_vk192 public void test random throws unsupported cipher exception final int size new int 128 192 256 for int k 0 k size length k int size size k rijndael aes new rijndael size size byte key new byte size 8 rand next bytes key aes initialize key for int i 0 i 1024 i byte plain new byte size 8 rand next bytes plain byte cipher new byte size 8 aes encipher plain cipher byte plain2 new byte size 8 aes decipher cipher plain2 assert true size size key hex util bytes to hex key plain hex util bytes to hex plain cipher hex util bytes to hex cipher plain2 hex util bytes to hex plain2 arrays equals plain plain2 testrandom unsupportedcipherexception nextbytes nextbytes asserttrue hexutil bytestohex hexutil bytestohex hexutil bytestohex hexutil bytestohex private random source random source public dsa test string test name super test name randomsource randomsource dsatest testname testname override protected void set up throws exception random source new dummy random source setup randomsource dummyrandomsource override protected void tear down throws exception teardown test of verify and sign method consistency using fips examples public void test sign and verify dsa signature a signature dsa sign fips dsa group fips dsa private key fips k fips sha1 m random source assert true dsa verify fips dsa public key a signature fips sha1 m false testsignandverify dsasignature asignature fips_dsa_group fips_dsa_private_key fips_k fips_sha1_m randomsource asserttrue fips_dsa_public_key asignature fips_sha1_m test of verify dsa public key kp dsa signature sig big integer m boolean force mod method comparing it with the dsa values based on fips examples public void test verify assert true dsa verify fips dsa public key fips dsa signature fips sha1 m false dsapublickey dsasignature biginteger forcemod testverify asserttrue fips_dsa_public_key fips_dsa_signature fips_sha1_m test sign method consistency it performs two signature of the same message and verifies if they are identical public void test same sign consistency dsa signature first signature dsa sign fips dsa group fips dsa private key fips k fips sha1 m random source dsa signature second signature dsa sign fips dsa group fips dsa private key fips k fips sha1 m random source assert equals first signature getr second signature getr assert equals first signature gets second signature gets testsamesignconsistency dsasignature firstsignature fips_dsa_group fips_dsa_private_key fips_k fips_sha1_m randomsource dsasignature secondsignature fips_dsa_group fips_dsa_private_key fips_k fips_sha1_m randomsource assertequals firstsignature secondsignature assertequals firstsignature secondsignature test sign dsa group g dsa private key x big integer m random source r method using a q value that is too small shorter than dsa group q bit length to generate a correct k value public void test sign smallq value try dsa sign fips dsa group fips dsa private key fips sha1 m random source fail exception error not thrown catch illegal argument exception an exception assert not null an exception dsagroup dsaprivatekey biginteger randomsource dsagroup q_bit_length testsignsmallqvalue fips_dsa_group fips_dsa_private_key fips_sha1_m randomsource illegalargumentexception anexception assertnotnull anexception test sign dsa group g dsa private key x big integer r big integer k inv big integer m random source random method comparing it with the dsa signature based on fips examples public void testsign grp pvtkey r kinv m rand dsa signature a signature dsa sign fips dsa group fips dsa private key fips r fips k inv fips sha1 m random source assert equals a signature getr fips r assert equals a signature gets fips s dsagroup dsaprivatekey biginteger biginteger kinv biginteger randomsource dsasignature testsign_grp_pvtkey_r_kinv_m_rand dsasignature asignature fips_dsa_group fips_dsa_private_key fips_r fips_k_inv fips_sha1_m randomsource assertequals asignature fips_r assertequals asignature fips_s test sign dsa group g dsa private key x big integer k big integer m random source random method comparing it with the dsa signature based on fips examples public void testsign grp pvtkey k m rand big integer x fips x dsa private key a test private key dsa signature another signature dsa signature a signature dsa sign fips dsa group fips dsa private key fips k fips sha1 m random source big integer generatedr a signature getr big integer generateds a signature gets assert equals generatedr fips r assert equals generateds fips s for int i 0 i fips x bit count i x x flip bit i if x compare to fips x 0 a test private key new dsa private key x fips dsa group another signature dsa sign fips dsa group a test private key fips k fips sha1 m random source assert false generatedr compare to another signature getr 0 generateds compare to another signature gets 0 dsagroup dsaprivatekey biginteger biginteger randomsource dsasignature testsign_grp_pvtkey_k_m_rand biginteger fips_x dsaprivatekey atestprivatekey dsasignature anothersignature dsasignature asignature fips_dsa_group fips_dsa_private_key fips_k fips_sha1_m randomsource biginteger asignature biginteger asignature assertequals fips_r assertequals fips_s fips_x bitcount flipbit compareto fips_x atestprivatekey dsaprivatekey fips_dsa_group anothersignature fips_dsa_group atestprivatekey fips_k fips_sha1_m randomsource assertfalse compareto anothersignature compareto anothersignature test sign dsa group g dsa private key x big integer m random source r method using verify method as the verify test passed then we can consider it a tested way to verify this sign method accuracy since it is impossible to test it using fips examples as they are based on sha1 and thus they use q values that are shorter than current dsa group q bit length public void testsign grp pvtkey m rand dsa group ads agroup global ds agroup biga dsa private key adsa priv key new dsa private key ads agroup random source dsa public key adsa pub key new dsa public key ads agroup adsa priv key dsa signature a signature dsa sign ads agroup adsa priv key adsa priv key getx random source assert true dsa verify adsa pub key a signature adsa priv key getx false dsagroup dsaprivatekey biginteger randomsource dsagroup q_bit_length testsign_grp_pvtkey_m_rand dsagroup adsagroup dsagroupbiga dsaprivatekey adsaprivkey dsaprivatekey adsagroup randomsource dsapublickey adsapubkey dsapublickey adsagroup adsaprivkey dsasignature asignature adsagroup adsaprivkey adsaprivkey randomsource asserttrue adsapubkey asignature adsaprivkey override protected void set up throws exception super set up file writer fw new file writer seed file for int i 0 i 256 i fw write i fw flush fw close setup setup filewriter filewriter seed_file override protected void tear down throws exception super tear down assert true seed file delete teardown teardown asserttrue seed_file public void test double yarrow y new yarrow seed file sha1 rijndael false false false scalar sample statistics sample new scalar sample statistics for int i 0 i 10000 i sample add y next double assert equals 0 5 sample get mean 0 02 assert equals 1 0 2 0 math sqrt 3 0 sample get standard deviation 0 002 testdouble seed_file scalarsamplestatistics scalarsamplestatistics nextdouble assertequals getmean assertequals getstandarddeviation public void test next int yarrow y new yarrow seed file sha1 rijndael false false false for int n 1 n 20 n int count new int n for int k 0 k 10000 k int l y next int n count l assert true l 0 assert true l n for int i 0 i n i assert true n count i 8800 assert true n count i 11100 testnextint seed_file nextint asserttrue asserttrue asserttrue asserttrue public void test next boolean yarrow y new yarrow seed file sha1 rijndael false false false int results new int 2 int runs 1000000 for int i 0 i runs i if y next boolean results 0 else results 1 assert equals runs results 0 results 1 assert true results 0 runs 2 runs 1000 assert true results 1 runs 2 runs 1000 testnextboolean seed_file nextboolean assertequals asserttrue asserttrue sub config sc public config test string name super name subconfig configtest override protected void set up throws exception super set up conf new config sc new sub config testing conf setup setup subconfig public void test config assert not null new config testconfig assertnotnull public void test register test if we can register string builder sb new string builder for int i 0 i utf util printable ascii length i sb append utf util printable ascii i for int i 0 i utf util stressed utf length i sb append utf util stressed utf i assert not null new sub config sb to string conf test if it prevents multiple registrations try conf register sc catch illegal argument exception ie return fail testregister stringbuilder stringbuilder utfutil printable_ascii utfutil printable_ascii utfutil stressed_utf utfutil stressed_utf assertnotnull subconfig tostring illegalargumentexception public void test get configs assert not null conf get configs assert false new config get configs equals conf assert equals 1 conf get configs length assert same sc conf get configs 0 testgetconfigs assertnotnull getconfigs assertfalse getconfigs assertequals getconfigs assertsame getconfigs public void test get assert same sc conf get testing testget assertsame public void testcss1 selector throws io exception for string css css1 selector assert equals css1 selector css filter css testcss1selector ioexception css1_selector assertequals css1_selector public void testcss2 selector throws io exception for string css css2 selector assert equals css2 selector css filter css testcss2selector ioexception css2_selector assertequals css2_selector public void testcss3 selector throws io exception for string css css3 selector assert equals css3 selector css filter css testcss3selector ioexception css3_selector assertequals css3_selector private string filter string css throws io exception string writer w new string writer css parser p new css parser new string reader css w false null p parse return w to string ioexception stringwriter stringwriter cssparser cssparser stringreader tostring public void test suite test throws io exception png filter filter new png filter false false true for object test test images string filename string test 0 boolean valid boolean test 1 bucket ib try ib resource to bucket filename catch io exception e system out println filename not found test skipped continue try bucket ob filter read filter ib new array bucket factory null null assert true filename should valid not be valid valid catch data filter exception dfe assert false filename should valid not be valid valid testsuitetest ioexception pngfilter pngfilter testimages resourcetobucket ioexception readfilter arraybucketfactory asserttrue datafilterexception assertfalse protected bucket resource to bucket string filename throws io exception input stream is get class get resource as stream filename if is null throw new java io file not found exception array bucket ab new array bucket bucket tools copy from ab is long max value return ab resourcetobucket ioexception inputstream getclass getresourceasstream filenotfoundexception arraybucket arraybucket buckettools copyfrom max_value public void testhtml filter throws exception general sanity checks is relativization working assert equals internal relative link html filter internal relative link assert equals internal relative link html filter internal absolute link are external links stripped out assert true html filter external link check1 starts with external link ok assert true html filter external link check2 contains generic read filter callback magichttp escape string assert true html filter external link check3 starts with external link ok regression testing bug 710 assert equals anchor test html filter anchor test assert equals anchor test empty html filter anchor test empty assert equals anchor test special html filter anchor test special assert equals anchor test special2 result html filter anchor test special2 bug 2496 assert equals anchor relative1 html filter anchor relative1 assert equals anchor relative2 html filter anchor relative2 assert equals anchor false pos1 html filter anchor false pos1 assert equals anchor false pos2 html filter anchor false pos2 evil hack test for 2496 2451 assert equals anchor mixed result html filter anchor mixed bug 2451 assert equals pount character encoding test result html filter pount character encoding test bug 2297 assert true html filter prevent fproxy access contains generic read filter callback magichttp escape string bug 2921 assert true html filter prevent external access css simple contains checked http assert false html filter prevent external access css escape contains http assert true html filter prevent external access css case contains checked http assert equals whitelist static content html filter whitelist static content testhtmlfilter assertequals internal_relative_link htmlfilter internal_relative_link assertequals internal_relative_link htmlfilter internal_absolute_link asserttrue htmlfilter external_link_check1 startswith external_link_ok asserttrue htmlfilter external_link_check2 genericreadfiltercallback magichttpescapestring asserttrue htmlfilter external_link_check3 startswith external_link_ok assertequals anchor_test htmlfilter anchor_test assertequals anchor_test_empty htmlfilter anchor_test_empty assertequals anchor_test_special htmlfilter anchor_test_special assertequals anchor_test_special2_result htmlfilter anchor_test_special2 assertequals anchor_relative1 htmlfilter anchor_relative1 assertequals anchor_relative2 htmlfilter anchor_relative2 assertequals anchor_false_pos1 htmlfilter anchor_false_pos1 assertequals anchor_false_pos2 htmlfilter anchor_false_pos2 assertequals anchor_mixed_result htmlfilter anchor_mixed assertequals pount_character_encoding_test_result htmlfilter pount_character_encoding_test asserttrue htmlfilter prevent_fproxy_access genericreadfiltercallback magichttpescapestring asserttrue htmlfilter prevent_external_access_css_simple checked_http assertfalse htmlfilter prevent_external_access_css_escape asserttrue htmlfilter prevent_external_access_css_case checked_http assertequals whitelist_static_content htmlfilter whitelist_static_content private string html filter string data throws exception string type name text html uri baseuri new uri base uri byte data to filter data get bytes utf 8 return content filter filter new array bucket data to filter bf type name baseuri null data to string htmlfilter typename base_uri datatofilter getbytes contentfilter arraybucket datatofilter typename tostring creates k packets of size sz of random data encodes them and tries to decode index contains the permutation entry private static final void encode decode fec code encode fec code decode int index byte src new byte kk packet size util rand next bytes src buffer src bufs new buffer kk for int i 0 i src bufs length i src bufs i new buffer src i packet size packet size byte repair new byte kk packet size buffer repair bufs new buffer kk for int i 0 i repair bufs length i repair bufs i new buffer repair i packet size packet size encode encode src bufs repair bufs index decode decode repair bufs index for int i 0 i src length i assert assert equals src i repair i encodedecode feccode feccode packet_size nextbytes srcbufs srcbufs srcbufs packet_size packet_size packet_size repairbufs repairbufs repairbufs packet_size packet_size srcbufs repairbufs repairbufs assertequals public void test benchmark if benchmark return int lim fec math gf size 1 fec code maybe native fec code factory get default createfec code kk lim fec code pure code new pure code kk lim int index new int kk for int i 0 i kk i index i lim i 1 byte src new byte kk packet size util rand next bytes src buffer src bufs new buffer kk for int i 0 i src bufs length i src bufs i new buffer src i packet size packet size byte repair new byte kk packet size buffer repair bufs new buffer kk for int i 0 i repair bufs length i repair bufs i new buffer repair i packet size packet size int index backup new int index length system arraycopy index 0 index backup 0 index length system out println getting ready for benchmarking encode long t1 system current time millis maybe native encode src bufs repair bufs index long t2 system current time millis pure code encode src bufs repair bufs index backup long t3 system current time millis float d native encode t2 t1 float d pure encode t3 t2 buffer repair bufs2 repair bufs clone system arraycopy repair bufs 0 repair bufs2 0 repair bufs length system out println getting ready for benchmarking decode t1 system current time millis maybe native decode repair bufs index t2 system current time millis pure code decode repair bufs2 index backup t3 system current time millis float d native decode t2 t1 float d pure decode t3 t2 system out println maybe native system out println pure code system out println native code took d native encode ms whereas java s code took d pure encode ms to encode system out println native code took d native decode ms whereas java s code took d pure decode ms to decode testbenchmark fecmath gfsize feccode maybenative feccodefactory getdefault createfeccode feccode purecode purecode packet_size nextbytes srcbufs srcbufs srcbufs packet_size packet_size packet_size repairbufs repairbufs repairbufs packet_size packet_size indexbackup indexbackup currenttimemillis maybenative srcbufs repairbufs currenttimemillis purecode srcbufs repairbufs indexbackup currenttimemillis dnativeencode dpureencode repairbufs2 repairbufs repairbufs repairbufs2 repairbufs currenttimemillis maybenative repairbufs currenttimemillis purecode repairbufs2 indexbackup currenttimemillis dnativedecode dpuredecode maybenative purecode dnativeencode dpureencode dnativedecode dpuredecode public void test simple rev int lim fec math gf size 1 fec code code fec code factory get default createfec code kk lim fec code code2 new pure code kk lim int index new int kk for int i 0 i kk i index i lim i 1 encode decode code code2 index encode decode code2 code index testsimplerev fecmath gfsize feccode feccodefactory getdefault createfeccode feccode purecode encodedecode encodedecode public void test simple int lim fec math gf size 1 fec code code fec code factory get default createfec code kk lim fec code code2 new pure code kk lim int index new int kk for int i 0 i kk i index i kk i encode decode code code2 index encode decode code2 code index testsimple fecmath gfsize feccode feccodefactory getdefault createfeccode feccode purecode encodedecode encodedecode public void test shifted int lim fec math gf size 1 fec code code fec code factory get default createfec code kk lim fec code code2 new pure code kk lim int index new int kk int max i0 kk 2 if max i0 kk lim max i0 lim kk for int s max i0 2 s max i0 s for int i 0 i kk i index i i s encode decode code code2 index encode decode code2 code index testshifted fecmath gfsize feccode feccodefactory getdefault createfeccode feccode purecode max_i0 max_i0 max_i0 max_i0 max_i0 encodedecode encodedecode return returns the filename of the database this is the name of the current test function plus db4o public string get database filename return get name db4o getdatabasefilename getname you have to call super set up if you override this method override protected void set up throws exception super set up file database file new file get database filename if database file exists database file delete assert false database file exists m wot new wot get database filename setup setup setup databasefile getdatabasefilename databasefile databasefile assertfalse databasefile mwot getdatabasefilename you have to call super tear down if you override this method override protected void tear down throws exception super tear down m wot terminate new file get database filename delete teardown teardown teardown mwot getdatabasefilename does nothing just here because j unit will complain if there are no tests public void test self junit testself return returns the filename of the database this is the name of the current test function plus db4o public string get database filename return get name db4o getdatabasefilename getname you have to call super set up if you override this method protected void set up throws exception super set up file database file new file get database filename if database file exists database file delete assert false database file exists db db4o open file get database filename ext setup setup setup databasefile getdatabasefilename databasefile databasefile assertfalse databasefile openfile getdatabasefilename you have to call super tear down if you override this method protected void tear down throws exception super tear down db close db null new file get database filename delete teardown teardown teardown getdatabasefilename does nothing just here because j unit will complain if there are no tests public void test self junit testself public void set up throws exception mssk new freeneturi ssk s zmdq gtog7v1wn3bui lo mpucyd6v5krs yr vqf uf hosg s ls rq9q9 zlrmus9 keyk2pmhej4wbtw602 uwx0o0e w0 aqacaae freetalk message list 1 muuid uuid from string d5b0dcc4 91cb 4870 8ab9 8588e895fa5d m messageid muuid base64 encode mssk get routing key m otherssk new freeneturi ssk tqaux3 nm4eh9wxtbv xx6vshv23l lpkwt bh7pe40st2o ng5 ar 2ya6r5m16b q i3o dj do linv curyd ns1b9 ew aqacaae7 freetalk message list 1 m otheruuid uuid from string 6d01e2f0 dfdd 4be9 9e93 7a35c03f3f12 mmessageid withothersskbutsameuuid muuid base64 encode m otherssk get routing key mmessageid withotheruuidbutsamessk m otheruuid base64 encode mssk get routing key mksk new freeneturi ksk test mchk new freeneturi chk 7qms7 lkly ihbz88i0 u97lxrlks2ux nwzwq oj pd xn jw ila f sjww2mp wlz wx7 fgp zbb er yd lkqie1u srcn lbm aaia 8 m invaliduuid d5b0dcc491cb48708ab98588e895fa5d m invalid messageid m invaliduuid base64 encode mssk get routing key setup szmdqgtog7v1wn3builompucyd6v5krsyrvqfufhosg slsrq9q9zlrmus9keyk2pmhej4wbtw602uwx0o0e messagelist fromstring mmessageid getroutingkey motherssk tqaux3nm4eh9wxtbvxx6vshv23llpkwtbh7pe40st2o ng5ar i3odj dolinvcurydns1b9ew messagelist motheruuid fromstring mmessageid_withothersskbutsameuuid motherssk getroutingkey mmessageid_withotheruuidbutsamessk motheruuid getroutingkey 7qms7lklyihbz88i0 u97lxrlks2uxnwzwqojpdxnjw fsjww2mpwlzwx7fgpzbberydlkqie1usrcn minvaliduuid minvalidmessageid minvaliduuid getroutingkey public void tear down throws exception teardown public void test wot messageuri freeneturi string test construction of invalid ur is try new wot messageuri null m messageid fail construction of wot messageuri with null freeneturi is possible catch illegal argument exception e try new wot messageuri mssk null fail construction of wot messageuri with null message id is possible catch illegal argument exception e try new wot messageuri mssk mmessageid withothersskbutsameuuid fail construction of wot messageuri with a message id not belonging to the author s ssk is possible catch illegal argument exception e try new wot messageuri mchk m messageid fail construction of wot messageuri with invalid key type is possible catch illegal argument exception e try new wot messageuri mksk m messageid fail construction of wot messageuri with invalid key type is possible catch illegal argument exception e try new wot messageuri mssk m invalid messageid fail construction of wot messageuri with invalid uuid is possible catch illegal argument exception e test construction of valid ur is wot messageuri uri new wot messageuri mssk m messageid assert equals mssk uri get freeneturi assert equals m messageid uri get messageid the uri should always be stored as ssk even if constructed with usk uri new wot messageuri mssk usk forssk m messageid assert true uri get freeneturi isssk assert equals mssk uri get freeneturi testwotmessageurifreeneturistring uris wotmessageuri mmessageid wotmessageuri illegalargumentexception wotmessageuri wotmessageuri illegalargumentexception wotmessageuri mmessageid_withothersskbutsameuuid wotmessageuri illegalargumentexception wotmessageuri mmessageid wotmessageuri illegalargumentexception wotmessageuri mmessageid wotmessageuri illegalargumentexception wotmessageuri minvalidmessageid wotmessageuri illegalargumentexception uris wotmessageuri wotmessageuri mmessageid assertequals getfreeneturi assertequals mmessageid getmessageid wotmessageuri uskforssk mmessageid asserttrue getfreeneturi assertequals getfreeneturi public void test wot messageuri string throws malformedurl exception test construction of invalid ur is try new wot messageuri null fail construction of wot messageuri with null uri possible catch illegal argument exception e catch malformedurl exception e fail wrong exception thrown try new wot messageuri mssk toascii string fail construction of wot messageuri without message uuid possible catch malformedurl exception e try new wot messageuri mchk toascii string muuid fail construction of wot messageuri with invalid key type is possible catch malformedurl exception e try new wot messageuri mksk toascii string muuid fail construction of wot messageuri with invalid key type is possible catch malformedurl exception e try new wot messageuri mssk toascii string m invaliduuid fail construction of wot messageuri with invalid uuid is possible catch malformedurl exception e test construction of valid ur is wot messageuri uri new wot messageuri mssk toascii string muuid assert equals mssk uri get freeneturi assert equals m messageid uri get messageid the uri should always be stored as ssk even if constructed with usk uri new wot messageuri mssk usk forssk toascii string muuid assert true uri get freeneturi isssk assert equals mssk uri get freeneturi testwotmessageuristring malformedurlexception uris wotmessageuri wotmessageuri illegalargumentexception malformedurlexception wotmessageuri toasciistring wotmessageuri malformedurlexception wotmessageuri toasciistring wotmessageuri malformedurlexception wotmessageuri toasciistring wotmessageuri malformedurlexception wotmessageuri toasciistring minvaliduuid wotmessageuri malformedurlexception uris wotmessageuri wotmessageuri toasciistring assertequals getfreeneturi assertequals mmessageid getmessageid wotmessageuri uskforssk toasciistring asserttrue getfreeneturi assertequals getfreeneturi public void test get freeneturi throws malformedurl exception wot messageuri uri new wot messageuri mssk toascii string muuid assert equals mssk uri get freeneturi testgetfreeneturi malformedurlexception wotmessageuri wotmessageuri toasciistring assertequals getfreeneturi public void test get messageid throws malformedurl exception wot messageuri uri new wot messageuri mssk toascii string muuid assert equals m messageid uri get messageid testgetmessageid malformedurlexception wotmessageuri wotmessageuri toasciistring assertequals mmessageid getmessageid public void test equals wot messageuri uri1a new wot messageuri mssk m messageid wot messageuri uri1b new wot messageuri mssk m messageid wot messageuri uri2 new wot messageuri mssk mmessageid withotheruuidbutsamessk wot messageuri uri3 new wot messageuri m otherssk mmessageid withothersskbutsameuuid assert true uri1a equals uri1a assert true uri1a equals uri1b assert true uri1b equals uri1a assert false uri1a equals uri2 assert false uri2 equals uri1a assert false uri1a equals uri3 assert false uri3 equals uri1a testequals wotmessageuri wotmessageuri mmessageid wotmessageuri wotmessageuri mmessageid wotmessageuri wotmessageuri mmessageid_withotheruuidbutsamessk wotmessageuri wotmessageuri motherssk mmessageid_withothersskbutsameuuid asserttrue asserttrue asserttrue assertfalse assertfalse assertfalse assertfalse public void test to string wot messageuri uri new wot messageuri mssk m messageid assert equals mssk to string muuid uri to string testtostring wotmessageuri wotmessageuri mmessageid assertequals tostring tostring private float icentrey public sphere filter set edge action clamp set radius 100 0f spherefilter setedgeaction setradius set the index of refaction param refraction index the index of refaction see get refraction index public void set refraction index float refraction index this refraction index refraction index refractionindex getrefractionindex setrefractionindex refractionindex refractionindex refractionindex get the index of refaction return the index of refaction see set refraction index public float get refraction index return refraction index setrefractionindex getrefractionindex refractionindex set the radius of the effect param r the radius min value 0 see get radius public void set radius float r this a r this b r getradius setradius get the radius of the effect return the radius see set radius public float get radius return a setradius getradius set the centre of the effect in the x direction as a proportion of the image size param centrex the center see get centrex public void set centrex float centrex this centrex centrex getcentrex setcentrex public float get centrex return centrex getcentrex set the centre of the effect in the y direction as a proportion of the image size param centrey the center see get centrey public void set centrey float centrey this centrey centrey getcentrey setcentrey get the centre of the effect in the y direction as a proportion of the image size return the center see set centrey public float get centrey return centrey setcentrey getcentrey set the centre of the effect as a proportion of the image size param centre the center see get centre public void set centre point2d centre this centrex float centre getx this centrey float centre gety getcentre setcentre get the centre of the effect as a proportion of the image size return the center see set centre public point2d get centre return new point2d float centrex centrey setcentre getcentre override public buffered image filter buffered image src buffered image dst int width src get width int height src get height icentrex width centrex icentrey height centrey if a 0 a width 2 if b 0 b height 2 a2 a a b2 b b return super filter src dst bufferedimage bufferedimage bufferedimage getwidth getheight override protected void transform inverse int x int y float out float dx x icentrex float dy y icentrey float x2 dx dx float y2 dy dy if y2 b2 b2 x2 a2 out 0 x out 1 y else float r refraction 1 0f refraction index float z float math sqrt 1 0f x2 a2 y2 b2 a b float z2 z z float x angle float math acos dx math sqrt x2 z2 float angle1 image math half pi x angle float angle2 float math asin math sin angle1 r refraction angle2 image math half pi x angle angle2 out 0 x float math tan angle2 z float y angle float math acos dy math sqrt y2 z2 angle1 image math half pi y angle angle2 float math asin math sin angle1 r refraction angle2 image math half pi y angle angle2 out 1 y float math tan angle2 z transforminverse rrefraction refractionindex xangle imagemath half_pi xangle rrefraction imagemath half_pi xangle yangle imagemath half_pi yangle rrefraction imagemath half_pi yangle override public string to string return distort sphere tostring public subscription request subscriptionrequest public subscription request http request http req set http req subscriptionrequest httprequest httpreq httpreq private void set service service service string event suburl service get event suburl thanks for giordano sassaroli sassarol cefriel it 05 21 03 seturi event suburl true string url base str device dev service get device if dev null url base str dev geturl base if url base str null url base str length 0 device root dev service get root device if root dev null url base str root dev geturl base thansk for markus thurner markus thurner fh hagenberg at 06 11 2004 if url base str null url base str length 0 device root dev service get root device if root dev null url base str root dev get location thanks for giordano sassaroli sassarol cefriel it 09 02 03 if url base str null url base str length 0 if http is absoluteurl event suburl url base str event suburl string req host http get host url base str int req port http get port url base str set host req host req port set request host req host set request port req port setservice eventsuburl geteventsuburl eventsuburl urlbasestr getdevice urlbasestr geturlbase urlbasestr urlbasestr rootdev getrootdevice rootdev urlbasestr rootdev geturlbase urlbasestr urlbasestr rootdev getrootdevice rootdev urlbasestr rootdev getlocation urlbasestr urlbasestr isabsoluteurl eventsuburl urlbasestr eventsuburl reqhost gethost urlbasestr reqport getport urlbasestr sethost reqhost reqport setrequesthost reqhost setrequestport reqport public void set subscribe request service service string callback long timeout set method subscription subscribe method set service service set callback callback setnt nt event set timeout timeout setsubscriberequest setmethod subscribe_method setservice setcallback settimeout public void set renew request service service string uuid long timeout set method subscription subscribe method set service service setsid uuid set timeout timeout setrenewrequest setmethod subscribe_method setservice settimeout public void set unsubscribe request service service set method subscription unsubscribe method set service service setsid service getsid setunsubscriberequest setmethod unsubscribe_method setservice public void setnt string value set header http nt value setheader public string getnt return get header value http nt getheadervalue public boolean hasnt string nt getnt return nt null 0 nt length true false private final static string callback end with public void set callback string value set string header http callback value callback start with callback end with callback_end_with setcallback setstringheader callback_start_with callback_end_with public string get callback return get string header value http callback callback start with callback end with getcallback getstringheadervalue callback_start_with callback_end_with public boolean has callback string callback get callback return callback null 0 callback length true false hascallback getcallback public void setsid string id set header http sid subscription tosid header string id setheader tosidheaderstring public string getsid thanks for grzegorz lehmann and stefano lenzi 12 06 04 string sid subscription getsid get header value http sid if sid null return return sid getheadervalue public boolean hassid string sid getsid return sid null 0 sid length true false public final void set timeout long value set header http timeout subscription to timeout header string value settimeout setheader totimeoutheaderstring public long get timeout return subscription get timeout get header value http timeout gettimeout gettimeout getheadervalue public void post subscription response sub res super post sub res subscriptionresponse subres subres public subscription response post http response http res post get request host get request port return new subscription response http res subscriptionresponse httpresponse httpres getrequesthost getrequestport subscriptionresponse httpres public class compress database this utility accepts one argument path to database file it creates new file at the same location and with the same name but with with dbz extension public static void main string args throws io exception if args length 0 args length 2 system err println usage java plugins xml spider org garret perst compress database database file path compression level return string path args 0 file input stream in new file input stream path int ext path last index of string zip path substring 0 ext dbz file output stream out new file output stream zip byte segment new byte compressed file segment length zip output stream zout new zip output stream out if args length 2 zout set level integer parse int args 1 long pos 0 int rc 1 do int offs 0 while offs segment length rc in read segment offs segment length offs 0 offs rc if offs 0 string name 000000000000 pos zip entry entry new zip entry name substring name length 12 entry set size offs zout put next entry entry zout write segment 0 offs zout close entry pos offs while rc 0 zout finish zout close system out println file zip is written compressdatabase ioexception xmlspider compressdatabase database_file_path fileinputstream fileinputstream lastindexof fileoutputstream fileoutputstream compressedfile segment_length zipoutputstream zipoutputstream setlevel parseint zipentry zipentry setsize putnextentry closeentry bootstrapping decaying running average avg public decaying keyspace average double default value int max reports simple field set fs avg new bootstrapping decaying running average default value 2 0 2 0 max reports fs bootstrappingdecayingrunningaverage decayingkeyspaceaverage defaultvalue maxreports simplefieldset bootstrappingdecayingrunningaverage defaultvalue maxreports public decaying keyspace average bootstrapping decaying running average a check the max min values ignore them avg bootstrapping decaying running average a clone decayingkeyspaceaverage bootstrappingdecayingrunningaverage bootstrappingdecayingrunningaverage override public synchronized object clone return new decaying keyspace average avg decayingkeyspaceaverage public synchronized double current value return avg current value currentvalue currentvalue public synchronized void report double d if d 0 0 d 1 0 just because we use non normalized locations doesn t mean we can accept them throw new illegal argument exception not a valid normalized key d double super value avg current value double this value location normalize super value double diff location change this value d double to average super value diff to gracefully wrap around the 1 0 0 0 threshold we average over or under it and simply normalize the result when reporting a current value example d 0 2 being reported super value 1 9 already wrapped once but at 0 9 this value 0 9 the normalized value of where we are in the keyspace diff 0 3 the diff from the normalized values location change 0 9 0 2 avg report 2 2 to successfully move the average towards the closest route to the given value avg report to average double new value avg current value if new value 0 0 new value 1 0 avg set current value location normalize new value illegalargumentexception supervalue currentvalue thisvalue supervalue thisvalue toaverage supervalue currentvalue supervalue thisvalue toaverage newvalue currentvalue newvalue newvalue setcurrentvalue newvalue public synchronized double value if reported double d if d 0 0 d 1 0 throw new illegal argument exception not a valid normalized key d double super value avg current value double this value location normalize super value double diff location change this value d return location normalize avg value if reported super value diff valueifreported illegalargumentexception supervalue currentvalue thisvalue supervalue thisvalue valueifreported supervalue public synchronized long count reports return avg count reports countreports countreports public void report long d throw new illegal argument exception keyspace average does not like longs illegalargumentexception keyspaceaverage public synchronized void change max reports int max reports avg change max reports max reports changemaxreports maxreports changemaxreports maxreports public synchronized simple field set export field set boolean short lived return avg export field set short lived simplefieldset exportfieldset shortlived exportfieldset shortlived todo make this a junit test public static void main string args decaying keyspace average a new decaying keyspace average 0 9 10 null a report 0 9 for int i 10 i 0 i a report 0 2 system out println 0 2 current a current value for int i 10 i 0 i a report 0 8 system out println 0 8 current a current value system out println positive wrap test for int wrap 3 wrap 0 wrap system out println wrap test wrap for int i 10 i 0 i a report 0 25 system out println 0 25 current a current value for int i 10 i 0 i a report 0 5 system out println 0 5 current a current value for int i 10 i 0 i a report 0 75 system out println 0 75 current a current value for int i 10 i 0 i a report 1 0 system out println 1 0 current a current value system out println negative wrap test a new decaying keyspace average 0 2 10 null a report 0 2 for int wrap 3 wrap 0 wrap system out println negwrap test wrap for int i 10 i 0 i a report 0 75 system out println 0 75 current a current value for int i 10 i 0 i a report 0 5 system out println 0 5 current a current value for int i 10 i 0 i a report 0 25 system out println 0 25 current a current value for int i 10 i 0 i a report 1 0 system out println 1 0 current a current value decayingkeyspaceaverage decayingkeyspaceaverage currentvalue currentvalue currentvalue currentvalue currentvalue currentvalue decayingkeyspaceaverage currentvalue currentvalue currentvalue currentvalue public class reference signature verification exception extends exception private static final long serial versionuid 1 public reference signature verification exception exception e super e referencesignatureverificationexception serialversionuid referencesignatureverificationexception public reference signature verification exception super referencesignatureverificationexception public reference signature verification exception string string super string referencesignatureverificationexception list page pages page status long count list page pages this count count this pages pages pagestatus main page xml spider xml spider this xml spider xml spider page maker xml spider get page maker pr xml spider get plugin respirator mainpage xmlspider xmlspider xmlspider xmlspider pagemaker xmlspider getpagemaker xmlspider getpluginrespirator public void process post request http request request html node content node create index if request is part set create index synchronized this xml spider schedule make index html node infobox page maker get infobox infobox infobox success scheduled creating index infobox add child index will start create soon content node add child infobox queue uri string adduri request get part as string adduri 512 if adduri null adduri length 0 try freeneturi uri new freeneturi adduri xml spider queueuri uri manually true html node infobox page maker get infobox infobox infobox success uri added infobox add child added uri content node add child infobox catch exception e html node infobox page maker get infobox infobox infobox error error adding uri infobox add child e get message content node add child infobox logger normal this manual added uri cause exception e xml spider start some requests processpostrequest httprequest htmlnode contentnode ispartset createindex xmlspider schedulemakeindex htmlnode pagemaker getinfobox addchild contentnode addchild getpartasstring xmlspider htmlnode pagemaker getinfobox addchild contentnode addchild htmlnode pagemaker getinfobox addchild getmessage contentnode addchild xmlspider startsomerequests public void write content http request request html node content node html node overview table content node add child table class column html node overview table row overview table add child tr page status queued status get page status status queued page status succeeded status get page status status succeeded page status failed status get page status status failed list page running fetch xml spider get running fetch config config xml spider get config column 1 html node next table cell overview table row add child td class first html node status box page maker get infobox spider status html node status content page maker get content node status box status content add child running request running fetch size config get max parallel requests status content add child br status content add child queued queued status count status content add child br status content add child succeeded succeeded status count status content add child br status content add child failed failed status count status content add child br status content add child br status content add child queued event xml spider callback executor get queue size status content add child br status content add child index writer synchronized this if xml spider is writing index status content add child span style color red font weight bold running else if xml spider is write index scheduled status content add child span style color blue font weight bold scheduled else status content add child span style color green font weight bold idle status content add child br status content add child last written xml spider get index writer t produced index 0 never new date xml spider get index writer t produced index to string next table cell add child status box column 2 next table cell overview table row add child td class second html node main box page maker get infobox main html node main content page maker get content node main box html node add form pr add form child main content plugins xml spider xml spider add form add form add child label for adduri add uri add form add child input new string name style new string adduri width 20em add form add child input type submit next table cell add child main box html node index box page maker get infobox create index html node index content page maker get content node index box html node index form pr add form child index content plugins xml spider xml spider index form index form add child input new string name type value new string create index hidden create index index form add child input new string type value new string submit create index now next table cell add child index box html node running box page maker get infobox running uri running box add attribute style right 0 html node running content page maker get content node running box if running fetch is empty running content add child no uri else html node list running content add child ol style overflow auto white space nowrap iterator page pi running fetch iterator int maxuri config get max shownur is for int i 0 i maxuri pi has next i page page pi next html node litem list add child li title page get comment litem add child a href freenet page geturi page geturi content node add child running box html node queued box page maker get infobox queued uri queued box add attribute style right 0 overflow auto html node queued content page maker get content node queued box list pages queued status queued content content node add child queued box html node succeeded box page maker get infobox succeeded uri succeeded box add attribute style right 0 html node succeeded content page maker get content node succeeded box list pages succeeded status succeeded content content node add child succeeded box html node failed box page maker get infobox failed uri failed box add attribute style right 0 html node failed content page maker get content node failed box list pages failed status failed content content node add child failed box writecontent httprequest htmlnode contentnode htmlnode overviewtable contentnode addchild htmlnode overviewtablerow overviewtable addchild pagestatus queuedstatus getpagestatus pagestatus succeededstatus getpagestatus pagestatus failedstatus getpagestatus runningfetch xmlspider getrunningfetch xmlspider getconfig htmlnode nexttablecell overviewtablerow addchild htmlnode statusbox pagemaker getinfobox htmlnode statuscontent pagemaker getcontentnode statusbox statuscontent addchild runningfetch getmaxparallelrequests statuscontent addchild statuscontent addchild queuedstatus statuscontent addchild statuscontent addchild succeededstatus statuscontent addchild statuscontent addchild failedstatus statuscontent addchild statuscontent addchild statuscontent addchild xmlspider callbackexecutor getqueue statuscontent addchild statuscontent addchild xmlspider iswritingindex statuscontent addchild xmlspider iswriteindexscheduled statuscontent addchild statuscontent addchild statuscontent addchild statuscontent addchild xmlspider getindexwriter tproducedindex xmlspider getindexwriter tproducedindex tostring nexttablecell addchild statusbox nexttablecell overviewtablerow addchild htmlnode mainbox pagemaker getinfobox htmlnode maincontent pagemaker getcontentnode mainbox htmlnode addform addformchild maincontent xmlspider xmlspider addform addform addchild addform addchild addform addchild nexttablecell addchild mainbox htmlnode indexbox pagemaker getinfobox htmlnode indexcontent pagemaker getcontentnode indexbox htmlnode indexform addformchild indexcontent xmlspider xmlspider indexform indexform addchild createindex createindex indexform addchild nexttablecell addchild indexbox htmlnode runningbox pagemaker getinfobox runningbox addattribute htmlnode runningcontent pagemaker getcontentnode runningbox runningfetch isempty runningcontent addchild htmlnode runningcontent addchild runningfetch getmaxshownuris hasnext htmlnode addchild getcomment addchild contentnode addchild runningbox htmlnode queuedbox pagemaker getinfobox queuedbox addattribute htmlnode queuedcontent pagemaker getcontentnode queuedbox listpages queuedstatus queuedcontent contentnode addchild queuedbox htmlnode succeededbox pagemaker getinfobox succeededbox addattribute htmlnode succeededcontent pagemaker getcontentnode succeededbox listpages succeededstatus succeededcontent contentnode addchild succeededbox htmlnode failedbox pagemaker getinfobox failedbox addattribute htmlnode failedcontent pagemaker getcontentnode failedbox listpages failedstatus failedcontent contentnode addchild failedbox utilities private page status get page status status status perst root root xml spider get root synchronized root int count root get page count status iterator page it root get pages status int showuri xml spider get config get max shownur is list page page new array list while page size showuri it has next page add it next return new page status count page pagestatus getpagestatus perstroot xmlspider getroot getpagecount getpages xmlspider getconfig getmaxshownuris arraylist hasnext pagestatus private void list pages page status page status html node parent if page status pages is empty parent add child no uri else html node list parent add child ol style overflow auto white space nowrap for page page page status pages html node litem list add child li title page get comment litem add child a href freenet page geturi page geturi listpages pagestatus pagestatus htmlnode pagestatus isempty addchild htmlnode addchild pagestatus htmlnode addchild getcomment addchild private boolean settimeout false private message filter timeoutfromwait true _settimeout messagefilter _timeoutfromwait public static message filter create return new message filter messagefilter messagefilter void on start waiting boolean wait for synchronized this we cannot wait on a message filter with a callback because on matched calls clear matched if we have a callback the solution would be to set a flag indicating we are wait for ing a filter here on matching a message set message call the callback immediately if not wait for ing if we are wait for ing call the callback when we exit wait for on stop waiting if wait for callback null throw new illegal state exception cannot wait on a message filter with a callback if settimeout logger error this no timeout set on filter this new exception error if initialtimeout 0 timeoutfromwait timeout system current time millis initialtimeout if or null or on start waiting wait for onstartwaiting waitfor messagefilter onmatched clearmatched waitfor setmessage waitfor waitfor waitfor onstopwaiting waitfor _callback illegalstateexception messagefilter _settimeout _initialtimeout _timeoutfromwait _timeout currenttimemillis _initialtimeout _or _or onstartwaiting waitfor set whether the timeout is relative to the creation of the filter or the start of wait for param b if true the timeout is relative to the time at which set timeout was called if false it s relative to the start of wait for public message filter set timeout relative to creation boolean b timeoutfromwait b return this waitfor settimeout waitfor messagefilter settimeoutrelativetocreation _timeoutfromwait this filter will expire after the specificed amount of time note also that where two or more filters match the same message the one with the nearer expiry time will get priority param timeout the time before this filter expires in ms return this message filter public message filter set timeout int timeout settimeout true initialtimeout timeout timeout system current time millis timeout return this messagefilter settimeout _settimeout _initialtimeout _timeout currenttimemillis public message filter set no timeout settimeout true timeout long max value initialtimeout 0 return this messagefilter setnotimeout _settimeout _timeout max_value _initialtimeout public message filter set type message type type type type return this messagefilter settype messagetype _type public message filter set source peer context source source source if source null oldbootid source get bootid return this messagefilter setsource peercontext _source _oldbootid getbootid returns the source that this filter or chain matches public peer context get source return source peercontext getsource _source public message filter set field string field name boolean value return set field field name boolean value of value messagefilter setfield fieldname setfield fieldname valueof public message filter set field string field name byte value return set field field name byte value of value messagefilter setfield fieldname setfield fieldname valueof public message filter set field string field name short value return set field field name short value of value messagefilter setfield fieldname setfield fieldname valueof public message filter set field string field name int value return set field field name integer value of value messagefilter setfield fieldname setfield fieldname valueof public message filter set field string field name long value return set field field name long value of value messagefilter setfield fieldname setfield fieldname valueof public message filter set field string field name object field value if type null type check type field name field value throw new incorrect type exception got field value get class expected type type of field name for type get name synchronized fields if fields put field name field value null fieldlist add field name return this messagefilter setfield fieldname fieldvalue _type _type checktype fieldname fieldvalue incorrecttypeexception fieldvalue getclass _type typeof fieldname _type getname _fields _fields fieldname fieldvalue _fieldlist fieldname public message filter or message filter or if or null or null or or fixme maybe throw this is almost certainly a bug and a nasty one too logger error this or replacement or or new exception error or or return this messagefilter messagefilter _or _or _or _or public message filter set async callback async message filter callback cb callback cb return this messagefilter setasynccallback asyncmessagefiltercallback _callback public boolean match message m if or null or match m return true if type null type equals m get spec return false if source null source equals m get source return false synchronized fields for string field name fieldlist if m is set field name return false if fields get field name equals m get from payload field name return false if really timed out system current time millis return false return true _or _or _type _type getspec _source _source getsource _fields fieldname _fieldlist isset fieldname _fields fieldname getfrompayload fieldname reallytimedout currenttimemillis public boolean matched return matched _matched which connection dropped or was restarted public peer context dropped connection return droppedconnection peercontext droppedconnection _droppedconnection boolean really timed out long time if callback null callback should timeout timeout 1 timeout immediately return timeout time reallytimedout _callback _callback shouldtimeout _timeout _timeout param time the current time in milliseconds return true if the filter has timed out or if it has been matched already caller will remove the filter from filters if we return true boolean timed out long time if matched logger error this impossible filter already matched in timed out this new exception error return true remove it return really timed out time _filters timedout _matched timedout reallytimedout public message get message return message getmessage _message public synchronized void set message message message logger debug this set message message on this new exception debug message message matched message null notify all setmessage setmessage _message _matched _message notifyall public int get initial timeout return initialtimeout getinitialtimeout _initialtimeout public long get timeout return timeout gettimeout _timeout override public string to string return super to string type get name tostring tostring _type getname public void clear matched if the filter matched in an or and it is re used then we need to clear all the or s message filter or synchronized this matched false message null or or if or null or clear matched clearmatched _or _or messagefilter _matched _message _or clearmatched public void clear or or null clearor _or public boolean matches dropped connection peer context ctx if source ctx return true if or null return or matches dropped connection ctx return false matchesdroppedconnection peercontext _source _or _or matchesdroppedconnection public boolean matches restarted connection peer context ctx if source ctx return true if or null return or matches restarted connection ctx return false matchesrestartedconnection peercontext _source _or _or matchesrestartedconnection notify because of a dropped connection caller must verify matchesdroppedconnection and source param ctx public void on dropped connection peer context ctx synchronized this droppedconnection ctx notify all if callback null callback on disconnect ctx _matchesdroppedconnection _source ondroppedconnection peercontext _droppedconnection notifyall _callback _callback ondisconnect notify because of a restarted connection caller must verify matchesdroppedconnection and source param ctx public void on restarted connection peer context ctx synchronized this droppedconnection ctx notify all if callback null callback on restarted ctx _matchesdroppedconnection _source onrestartedconnection peercontext _droppedconnection notifyall _callback _callback onrestarted notify waiters that we have been matched hopefully no locks will be held at this point by the caller public void on matched message msg async message filter callback cb synchronized this msg message cb callback clear matched before calling callback in case we are re added if callback null clear matched if cb null cb on matched msg onmatched asyncmessagefiltercallback _message _callback _callback clearmatched onmatched notify waiters that we have timed out public void on timed out synchronized this notify all if callback null callback on timeout ontimedout notifyall _callback _callback ontimeout returns true if a connection related to this filter has been dropped or restarted public boolean any connections dropped if matched return false if source null if source is connected return true else if source get bootid oldbootid return true counts as a disconnect if or null return or any connections dropped return false anyconnectionsdropped _matched _source _source isconnected _source getbootid _oldbootid _or _or anyconnectionsdropped public bucket read filter bucket bucket bucket factory bf string charset hash map string string other params filter callback cb throws data filter exception io exception if logger should log logger debug this logger debug this running this on bucket charset input stream strm bucket get input stream bucket temp bf make bucket 1 output stream os temp get output stream reader r null writer w null input stream reader isr null output stream writer osw null try try isr new input stream reader strm charset osw new output stream writer os charset r new buffered reader isr 32768 w new buffered writer osw 32768 catch unsupported encoding exception e closer close osw closer close os throw unknown charset exception create e charset css parser parser new css parser r w false cb parser parse r close finally do not close output related things here closer close strm closer close isr closer close r closer close w return temp readfilter bucketfactory hashmap otherparams filtercallback datafilterexception ioexception shouldlog inputstream getinputstream makebucket outputstream getoutputstream inputstreamreader outputstreamwriter inputstreamreader outputstreamwriter bufferedreader bufferedwriter unsupportedencodingexception unknowncharsetexception cssparser cssparser public bucket write filter bucket data bucket factory bf string charset hash map string string other params filter callback cb throws data filter exception io exception throw new unsupported operation exception writefilter bucketfactory hashmap otherparams filtercallback datafilterexception ioexception unsupportedoperationexception public string get charset bucket bucket string parse charset throws data filter exception io exception input stream strm bucket get input stream writer w new null writer reader r r new buffered reader new input stream reader strm parse charset 32768 css parser parser new css parser r w false new null filter callback try parser parse catch throwable t ignore all errors if logger should log logger minor this logger minor this caught t trying to detect mime type with parse charset r close return parser detected charset getcharset parsecharset datafilterexception ioexception inputstream getinputstream nullwriter bufferedreader inputstreamreader parsecharset cssparser cssparser nullfiltercallback shouldlog parsecharset detectedcharset public class virgin item exception extends runtime exception private static final long serial versionuid 1 virgin item exception doubly linked list item item super item to string virginitemexception runtimeexception serialversionuid virginitemexception doublylinkedlist tostring public wot message list inserter node my node high level simple client my client string my name wot identity manager my identity manager wot message manager my message manager super my node my client my name my identity manager my message manager m message manager my message manager m random m node fast weak random start wotmessagelistinserter mynode highlevelsimpleclient myclient myname wotidentitymanager myidentitymanager wotmessagemanager mymessagemanager mynode myclient myname myidentitymanager mymessagemanager mmessagemanager mymessagemanager mrandom mnode fastweakrandom override protected void clear being inserted flags wot message manager message manager wot message manager super m message manager synchronized message manager for wot own message list list message manager get being inserted own message lists list cancel insert clearbeinginsertedflags wotmessagemanager messagemanager wotmessagemanager mmessagemanager messagemanager wotownmessagelist messagemanager getbeinginsertedownmessagelists cancelinsert override protected collection client getter create fetch storage return null clientgetter createfetchstorage override protected collection base client putter create insert storage return new hash set base client putter max parallel messagelist insert count 2 baseclientputter createinsertstorage hashset baseclientputter max_parallel_messagelist_insert_count override public int get priority return native thread norm priority getpriority nativethread norm_priority override protected long get startup delay return startup delay 2 m random next int startup delay getstartupdelay startup_delay mrandom nextint startup_delay override protected long get sleep time return thread period 2 m random next int thread period getsleeptime thread_period mrandom nextint thread_period override protected synchronized void iterate abort all transfers synchronized m message manager for wot own message list list m message manager get not inserted own message lists try fixme ensure that after creation of a message list we wait for at least a few minutes so that if the author writes more messages they will be put in the same list insert message list list catch exception e logger error this insert of wot own message list failed e abortalltransfers mmessagemanager wotownmessagelist mmessagemanager getnotinsertedownmessagelists insertmessagelist wotownmessagelist you have to synchronize on this code wot message list inserter code when using this function private void insert message list wot own message list list throws transformer exception parser configuration exception no such message exception io exception insert exception bucket tempb mtbf make bucket 4096 todo set to a reasonable value output stream os null try os tempb get output stream list begin of insert wot message listxml encode m message manager list os os close os null tempb set read only we do not specifiy a client meta data with mimetype because that would result in the insertion of an additional chk insert block ib new insert block tempb null list get inserturi insert context ictx m client get insert context true client putter pu m client insert ib false null false ictx this pu set priority class request starter update priority class pluginmanager defaults to interactive priority add insert pu tempb null logger debug this started insert of wot own message list at request uri list geturi finally if tempb null tempb free closer close os wotmessagelistinserter insertmessagelist wotownmessagelist transformerexception parserconfigurationexception nosuchmessageexception ioexception insertexception makebucket outputstream getoutputstream beginofinsert wotmessagelistxml mmessagemanager setreadonly clientmetadata insertblock insertblock getinserturi insertcontext mclient getinsertcontext clientputter mclient setpriorityclass requeststarter update_priority_class addinsert wotownmessagelist override public synchronized void on success base client putter state object container container try logger debug this successfully inserted wot own message list at state geturi wot own message list list wot own message list m message manager get own message list message list getid fromuri state geturi list mark as inserted catch exception e logger error this wot own message list insert succeeded but on success failed e finally remove insert state onsuccess baseclientputter objectcontainer wotownmessagelist wotownmessagelist wotownmessagelist mmessagemanager getownmessagelist messagelist getidfromuri markasinserted wotownmessagelist onsuccess removeinsert override public synchronized void on failure insert exception e base client putter state object container container try if e get mode insert exception collision logger error this wot own message list insert collided trying to insert with higher index try wot own message list list wot own message list m message manager get own message list message list getid fromuri state geturi list increment insert index insert message list list catch exception ex logger error this inserting wot own message list with higher index failed ex else throw e catch exception ex logger error this wot own message list insert failed ex finally remove insert state onfailure insertexception baseclientputter objectcontainer getmode insertexception wotownmessagelist wotownmessagelist wotownmessagelist mmessagemanager getownmessagelist messagelist getidfromuri incrementinsertindex insertmessagelist wotownmessagelist wotownmessagelist removeinsert not needed functions override public void on success fetch result result client getter state object container container onsuccess fetchresult clientgetter objectcontainer public void on success fetch result result client getter state object container container override public void on failure fetch exception e client getter state object container container onsuccess fetchresult clientgetter objectcontainer onfailure fetchexception clientgetter objectcontainer public void on failure fetch exception e client getter state object container container override public void on generateduri freeneturi uri base client putter state object container container onfailure fetchexception clientgetter objectcontainer ongenerateduri baseclientputter objectcontainer public void on generateduri freeneturi uri base client putter state object container container override public void on fetchable base client putter state object container container ongenerateduri baseclientputter objectcontainer onfetchable baseclientputter objectcontainer public void on fetchable base client putter state object container container override public void on major progress object container container onfetchable baseclientputter objectcontainer onmajorprogress objectcontainer static final int max items key space 4 static int getn items page pg return bytes unpack2 pg data 0 maxitems keyspace getnitems return bytes unpack2 pg data 0 static int get size page pg return bytes unpack2 pg data 2 getsize return bytes unpack2 pg data 2 static int get key str oid page pg int index return bytes unpack4 pg data first key offs index 8 getkeystroid firstkeyoffs return bytes unpack4 pg data first key offs index 8 static int get key str size page pg int index return bytes unpack2 pg data first key offs index 8 4 firstkeyoffs getkeystrsize firstkeyoffs return bytes unpack2 pg data first key offs index 8 4 static int get key str offs page pg int index return bytes unpack2 pg data first key offs index 8 6 firstkeyoffs getkeystroffs firstkeyoffs static int get reference page pg int index return bytes unpack4 pg data first key offs index 4 getreference firstkeyoffs static void setn items page pg int n items bytes pack2 pg data 0 short n items setnitems nitems nitems bytes pack2 pg data 0 short n items static void set size page pg int size bytes pack2 pg data 2 short size nitems setsize bytes pack2 pg data 2 short size static void set key str oid page pg int index int oid bytes pack4 pg data first key offs index 8 oid setkeystroid firstkeyoffs bytes pack4 pg data first key offs index 8 oid static void set key str size page pg int index int size bytes pack2 pg data first key offs index 8 4 short size firstkeyoffs setkeystrsize firstkeyoffs bytes pack2 pg data first key offs index 8 4 short size static void set key str offs page pg int index int offs bytes pack2 pg data first key offs index 8 6 short offs firstkeyoffs setkeystroffs firstkeyoffs static void set key str chars page pg int offs char str int len str length for int i 0 i len i bytes pack2 pg data first key offs offs short str i offs 2 setkeystrchars firstkeyoffs static void set key bytes page pg int offs byte bytes system arraycopy bytes 0 pg data first key offs offs bytes length setkeybytes firstkeyoffs system arraycopy bytes 0 pg data first key offs offs bytes length static void set reference page pg int index int oid bytes pack4 pg data first key offs index 4 oid firstkeyoffs setreference firstkeyoffs final static int compare key key page pg int i long i8 int i4 float r4 double r8 switch key type case class descriptor tp boolean case class descriptor tp byte return byte key ival pg data btree page first key offs i case class descriptor tp short return short key ival bytes unpack2 pg data btree page first key offs i 2 case class descriptor tp char return char key ival char bytes unpack2 pg data btree page first key offs i 2 case class descriptor tp object case class descriptor tp int case class descriptor tp enum i4 bytes unpack4 pg data btree page first key offs i 4 return key ival i4 1 key ival i4 0 1 case class descriptor tp long case class descriptor tp date i8 bytes unpack8 pg data btree page first key offs i 8 return key lval i8 1 key lval i8 0 1 case class descriptor tp float r4 float int bits to float bytes unpack4 pg data btree page first key offs i 4 return key dval r4 1 key dval r4 0 1 case class descriptor tp double r8 double long bits to double bytes unpack8 pg data btree page first key offs i 8 return key dval r8 1 key dval r8 0 1 assert failed invalid type return 0 classdescriptor tpboolean classdescriptor tpbyte btreepage firstkeyoffs classdescriptor tpshort btreepage firstkeyoffs classdescriptor tpchar btreepage firstkeyoffs classdescriptor tpobject classdescriptor tpint classdescriptor tpenum btreepage firstkeyoffs classdescriptor tplong classdescriptor tpdate btreepage firstkeyoffs classdescriptor tpfloat intbitstofloat btreepage firstkeyoffs classdescriptor tpdouble longbitstodouble btreepage firstkeyoffs final static int compare str key key page pg int i char chars char key oval int alen chars length int blen btree page get key str size pg i int minlen alen blen alen blen int offs btree page get key str offs pg i btree page first key offs byte b pg data for int j 0 j minlen j int diff chars j char bytes unpack2 b offs if diff 0 return diff offs 2 return alen blen comparestr btreepage getkeystrsize btreepage getkeystroffs btreepage firstkeyoffs final static int compare prefix char key page pg int i int alen key length int blen btree page get key str size pg i int minlen alen blen alen blen int offs btree page get key str offs pg i btree page first key offs byte b pg data for int j 0 j minlen j int diff key j char bytes unpack2 b offs if diff 0 return diff offs 2 return minlen blen compareprefix btreepage getkeystrsize btreepage getkeystroffs btreepage firstkeyoffs static boolean find storage impl db int page id key first key key last key btree tree int height array list result page pg db get page page id int l 0 n getn items pg r n int oid height 1 try if tree type class descriptor tp string if first key null while l r int i l r 1 if compare str first key pg i first key inclusion l i 1 else r i assert that r l if last key null if height 0 while l n if compare str last key pg l last key inclusion return false oid get key str oid pg l result add db lookup object oid null l 1 else do if find db get key str oid pg l first key last key tree height result return false if l n return true while compare str last key pg l 0 return false else if height 0 while l n oid get key str oid pg l result add db lookup object oid null l 1 else do if find db get key str oid pg l first key last key tree height result return false while l n else if tree type class descriptor tp array of byte if first key null while l r int i l r 1 if tree compare byte arrays first key pg i first key inclusion l i 1 else r i assert that r l if last key null if height 0 while l n if tree compare byte arrays last key pg l last key inclusion return false oid get key str oid pg l result add db lookup object oid null l 1 else do if find db get key str oid pg l first key last key tree height result return false if l n return true while tree compare byte arrays last key pg l 0 return false else if height 0 while l n oid get key str oid pg l result add db lookup object oid null l 1 else do if find db get key str oid pg l first key last key tree height result return false while l n else if first key null while l r int i l r 1 if compare first key pg i first key inclusion l i 1 else r i assert that r l if last key null if height 0 while l n if compare last key pg l last key inclusion return false oid get reference pg max items 1 l result add db lookup object oid null l 1 return true else do if find db get reference pg max items 1 l first key last key tree height result return false if l n return true while compare last key pg l 0 return false if height 0 while l n oid get reference pg max items 1 l result add db lookup object oid null l 1 else do if find db get reference pg max items 1 l first key last key tree height result return false while l n finally db pool unfix pg return true storageimpl pageid firstkey lastkey arraylist getpage pageid getnitems classdescriptor tpstring firstkey comparestr firstkey firstkey lastkey comparestr lastkey lastkey getkeystroid lookupobject getkeystroid firstkey lastkey comparestr lastkey getkeystroid lookupobject getkeystroid firstkey lastkey classdescriptor tparrayofbyte firstkey comparebytearrays firstkey firstkey lastkey comparebytearrays lastkey lastkey getkeystroid lookupobject getkeystroid firstkey lastkey comparebytearrays lastkey getkeystroid lookupobject getkeystroid firstkey lastkey firstkey firstkey firstkey lastkey lastkey lastkey getreference maxitems lookupobject getreference maxitems firstkey lastkey lastkey getreference maxitems lookupobject getreference maxitems firstkey lastkey static boolean prefix search storage impl db int page id char key int height array list result page pg db get page page id int l 0 n getn items pg r n int oid height 1 try while l r int i l r 1 if compare prefix key pg i 0 l i 1 else r i assert that r l if height 0 while l n if compare prefix key pg l 0 return false oid get key str oid pg l result add db lookup object oid null l 1 else do if prefix search db get key str oid pg l key height result return false if l n return true while compare prefix key pg l 0 return false finally db pool unfix pg return true prefixsearch storageimpl pageid arraylist getpage pageid getnitems compareprefix compareprefix getkeystroid lookupobject prefixsearch getkeystroid compareprefix static int allocate storage impl db int root int type btree key ins int page id db allocate page page pg db put page page id setn items pg 1 if type class descriptor tp string char sval char ins key oval int len sval length set size pg len 2 set key str offs pg 0 key space len 2 set key str size pg 0 len set key str oid pg 0 ins oid set key str oid pg 1 root set key str chars pg key space len 2 sval else if type class descriptor tp array of byte byte bval byte ins key oval int len bval length set size pg len set key str offs pg 0 key space len set key str size pg 0 len set key str oid pg 0 ins oid set key str oid pg 1 root set key bytes pg key space len bval else ins pack pg 0 set reference pg max items 2 root db pool unfix pg return page id storageimpl btreekey pageid allocatepage putpage pageid setnitems classdescriptor tpstring setsize setkeystroffs keyspace setkeystrsize setkeystroid setkeystroid setkeystrchars keyspace classdescriptor tparrayofbyte setsize setkeystroffs keyspace setkeystrsize setkeystroid setkeystroid setkeybytes keyspace setreference maxitems pageid static void memcpy page dst pg int dst idx page src pg int src idx int len int item size system arraycopy src pg data first key offs src idx item size dst pg data first key offs dst idx item size len item size dst_pg dst_idx src_pg src_idx itemsize src_pg firstkeyoffs src_idx itemsize dst_pg firstkeyoffs dst_idx itemsize itemsize static int insert storage impl db int page id btree tree btree key ins int height boolean unique boolean overwrite page pg db get page page id int result int l 0 n getn items pg r n int ahead unique 1 0 try if tree type class descriptor tp string while l r int i l r 1 if compare str ins key pg i ahead l i 1 else r i assert that l r if height 0 result insert db get key str oid pg r tree ins height unique overwrite assert that result btree op not found if result btree op overflow return result else if r n compare str ins key pg r 0 if overwrite db pool unfix pg pg null pg db put page page id ins old oid get key str oid pg r set key str oid pg r ins oid return btree op overwrite else if unique return btree op duplicate db pool unfix pg pg null pg db put page page id return insert str key db pg r ins height else if tree type class descriptor tp array of byte while l r int i l r 1 if tree compare byte arrays ins key pg i ahead l i 1 else r i assert that l r if height 0 result insert db get key str oid pg r tree ins height unique overwrite assert that result btree op not found if result btree op overflow return result else if r n tree compare byte arrays ins key pg r 0 if overwrite db pool unfix pg pg null pg db put page page id ins old oid get key str oid pg r set key str oid pg r ins oid return btree op overwrite else if unique return btree op duplicate db pool unfix pg pg null pg db put page page id return insert byte array key db pg r ins height else while l r int i l r 1 if compare ins key pg i ahead l i 1 else r i assert that l r insert before e r if height 0 result insert db get reference pg max items r 1 tree ins height unique overwrite assert that result btree op not found if result btree op overflow return result n 1 else if r n compare ins key pg r 0 if overwrite db pool unfix pg pg null pg db put page page id ins old oid get reference pg max items r 1 set reference pg max items r 1 ins oid return btree op overwrite else if unique return btree op duplicate db pool unfix pg pg null pg db put page page id int item size class descriptor sizeof tree type int max key space 4 item size if n max memcpy pg r 1 pg r n r item size memcpy pg max items n 1 pg max items n n r 4 ins pack pg r setn items pg getn items pg 1 return btree op done else page is full then divide page page id db allocate page page b db put page page id assert that n max int m max 2 if r m memcpy b 0 pg 0 r item size memcpy b r 1 pg r m r 1 item size memcpy pg 0 pg m 1 max m 1 item size memcpy b max items r pg max items r r 4 ins pack b r memcpy b max items m pg max items m 1 m r 1 4 memcpy pg max items max m 1 pg max items max max m 1 4 else memcpy b 0 pg 0 m item size memcpy pg 0 pg m r m item size memcpy pg r m 1 pg r max r item size memcpy b max items m pg max items m m 4 memcpy pg max items r m pg max items r r m 4 ins pack pg r m memcpy pg max items max m 1 pg max items max max r 4 ins oid page id ins extract b first key offs m 1 item size tree type if height 0 setn items pg max m 1 setn items b m else setn items pg max m setn items b m 1 db pool unfix b return btree op overflow finally if pg null db pool unfix pg storageimpl pageid btreekey getpage pageid getnitems classdescriptor tpstring comparestr getkeystroid op_not_found op_overflow comparestr putpage pageid oldoid getkeystroid setkeystroid op_overwrite op_duplicate putpage pageid insertstrkey classdescriptor tparrayofbyte comparebytearrays getkeystroid op_not_found op_overflow comparebytearrays putpage pageid oldoid getkeystroid setkeystroid op_overwrite op_duplicate putpage pageid insertbytearraykey getreference maxitems op_not_found op_overflow putpage pageid oldoid getreference maxitems setreference maxitems op_overwrite op_duplicate putpage pageid itemsize classdescriptor keyspace itemsize itemsize maxitems maxitems setnitems getnitems op_done pageid allocatepage putpage pageid itemsize itemsize itemsize maxitems maxitems maxitems maxitems maxitems maxitems itemsize itemsize itemsize maxitems maxitems maxitems maxitems maxitems maxitems pageid firstkeyoffs itemsize setnitems setnitems setnitems setnitems op_overflow static int insert str key storage impl db page pg int r btree key ins int height int n items getn items pg int size get size pg int n height 0 n items 1 n items insert before e r char sval char ins key oval int len sval length if size len 2 n 1 str key size key space memcpy pg r 1 pg r n r str key size size len 2 set key str offs pg r key space size set key str size pg r len set key str oid pg r ins oid set key str chars pg key space size sval n items 1 else page is full then divide page int page id db allocate page page b db put page page id int moved 0 int inserted len 2 str key size int prev delta 1 31 1 for int bn 0 i 0 bn 1 int add size sub size int j n items i 1 int key len get key str size pg i if bn r key len len inserted 0 add size len if height 0 sub size 0 j 1 else sub size get key str size pg i else add size sub size key len if height 0 if i 1 r sub size get key str size pg i 1 j 1 else inserted 0 int delta moved add size 2 bn 1 str key size j str key size size sub size 2 inserted if delta prev delta if height 0 ins get str b bn 1 else assert that string fits in the b tree page moved bn 1 str key size key space if bn r ins get str pg i set key str oid b bn get key str oid pg i size key len 2 i 1 else set key str oid b bn ins oid n items compactify strings pg i if bn r bn r height 0 memcpy pg r i 1 pg r i n r str key size size len 2 n items 1 assert that string fits in the b tree page size n i 1 str key size key space set key str offs pg r i key space size set key str size pg r i len set key str oid pg r i ins oid set key str chars pg key space size sval setn items b bn set size b moved set size pg size setn items pg n items ins oid page id db pool unfix b return btree op overflow moved key len 2 prev delta delta assert that string fits in the b tree page moved bn 1 str key size key space set key str size b bn key len set key str offs b bn key space moved if bn r set key str oid b bn ins oid set key str chars b key space moved sval else set key str oid b bn get key str oid pg i memcpy b key space moved pg get key str offs pg i key len 2 1 size key len 2 i 1 setn items pg n items set size pg size return size str key size n items 1 key space 2 btree op underflow btree op done insertstrkey storageimpl btreekey nitems getnitems getsize nitems nitems strkeysize keyspace strkeysize setkeystroffs keyspace setkeystrsize setkeystroid setkeystrchars keyspace nitems pageid allocatepage putpage pageid strkeysize prevdelta addsize subsize nitems keylen getkeystrsize keylen addsize subsize subsize getkeystrsize addsize subsize keylen subsize getkeystrsize addsize strkeysize strkeysize subsize prevdelta getstr strkeysize keyspace getstr setkeystroid getkeystroid keylen setkeystroid nitems compactifystrings strkeysize nitems strkeysize keyspace setkeystroffs keyspace setkeystrsize setkeystroid setkeystrchars keyspace setnitems setsize setsize setnitems nitems pageid op_overflow keylen prevdelta strkeysize keyspace setkeystrsize keylen setkeystroffs keyspace setkeystroid setkeystrchars keyspace setkeystroid getkeystroid keyspace getkeystroffs keylen keylen setnitems nitems setsize strkeysize nitems keyspace op_underflow op_done static int insert byte array key storage impl db page pg int r btree key ins int height int n items getn items pg int size get size pg int n height 0 n items 1 n items byte bval byte ins key oval insert before e r int len bval length if size len n 1 str key size key space memcpy pg r 1 pg r n r str key size size len set key str offs pg r key space size set key str size pg r len set key str oid pg r ins oid set key bytes pg key space size bval n items 1 else page is full then divide page int page id db allocate page page b db put page page id int moved 0 int inserted len str key size int prev delta 1 31 1 for int bn 0 i 0 bn 1 int add size sub size int j n items i 1 int key len get key str size pg i if bn r key len len inserted 0 add size len if height 0 sub size 0 j 1 else sub size get key str size pg i else add size sub size key len if height 0 if i 1 r sub size get key str size pg i 1 j 1 else inserted 0 int delta moved add size bn 1 str key size j str key size size sub size inserted if delta prev delta if height 0 ins get byte array b bn 1 else assert that string fits in the b tree page moved bn 1 str key size key space if bn r ins get byte array pg i set key str oid b bn get key str oid pg i size key len i 1 else set key str oid b bn ins oid n items compactify byte arrays pg i if bn r bn r height 0 memcpy pg r i 1 pg r i n r str key size size len n items 1 assert that string fits in the b tree page size n i 1 str key size key space set key str offs pg r i key space size set key str size pg r i len set key str oid pg r i ins oid set key bytes pg key space size bval setn items b bn set size b moved set size pg size setn items pg n items ins oid page id db pool unfix b return btree op overflow moved key len prev delta delta assert that string fits in the b tree page moved bn 1 str key size key space set key str size b bn key len set key str offs b bn key space moved if bn r set key str oid b bn ins oid set key bytes b key space moved bval else set key str oid b bn get key str oid pg i memcpy b key space moved pg get key str offs pg i key len 1 size key len i 1 setn items pg n items set size pg size return size str key size n items 1 key space 2 btree op underflow btree op done insertbytearraykey storageimpl btreekey nitems getnitems getsize nitems nitems strkeysize keyspace strkeysize setkeystroffs keyspace setkeystrsize setkeystroid setkeybytes keyspace nitems pageid allocatepage putpage pageid strkeysize prevdelta addsize subsize nitems keylen getkeystrsize keylen addsize subsize subsize getkeystrsize addsize subsize keylen subsize getkeystrsize addsize strkeysize strkeysize subsize prevdelta getbytearray strkeysize keyspace getbytearray setkeystroid getkeystroid keylen setkeystroid nitems compactifybytearrays strkeysize nitems strkeysize keyspace setkeystroffs keyspace setkeystrsize setkeystroid setkeybytes keyspace setnitems setsize setsize setnitems nitems pageid op_overflow keylen prevdelta strkeysize keyspace setkeystrsize keylen setkeystroffs keyspace setkeystroid setkeybytes keyspace setkeystroid getkeystroid keyspace getkeystroffs keylen keylen setnitems nitems setsize strkeysize nitems keyspace op_underflow op_done static int compactify strings page pg int m int i j offs len n getn items pg int size new int key space 2 1 int index new int key space 2 1 if m 0 return n int n zero length strings 0 if m 0 m m for i 0 i n m i len get key str size pg i if len 0 offs get key str offs pg i 1 size offs len len index offs len i else n zero length strings 1 for i n i len get key str size pg i if len 0 offs get key str offs pg i 1 size offs len len index offs len 1 else for i 0 i m i len get key str size pg i if len 0 offs get key str offs pg i 1 size offs len len index offs len 1 for i n i len get key str size pg i if len 0 offs get key str offs pg i 1 size offs len len index offs len i m else n zero length strings 1 set key str oid pg i m get key str oid pg i set key str size pg i m len set key str oid pg i m get key str oid pg i int n items n m n n zero length strings for offs key space 2 i offs n 0 i len len size i j index i if j 0 offs len n 1 set key str offs pg j offs 2 if offs i len memcpy pg offs pg i len len 2 return n items compactifystrings getnitems keyspace keyspace nzerolengthstrings getkeystrsize getkeystroffs nzerolengthstrings getkeystrsize getkeystroffs getkeystrsize getkeystroffs getkeystrsize getkeystroffs nzerolengthstrings setkeystroid getkeystroid setkeystrsize setkeystroid getkeystroid nitems nzerolengthstrings keyspace setkeystroffs nitems static int compactify byte arrays page pg int m int i j offs len n getn items pg int size new int key space 1 int index new int key space 1 if m 0 return n int n zero length arrays 0 if m 0 m m for i 0 i n m i len get key str size pg i if len 0 offs get key str offs pg i size offs len len index offs len i else n zero length arrays 1 for i n i len get key str size pg i if len 0 offs get key str offs pg i size offs len len index offs len 1 else for i 0 i m i len get key str size pg i if len 0 offs get key str offs pg i size offs len len index offs len 1 for i n i len get key str size pg i if len 0 offs get key str offs pg i size offs len len index offs len i m else n zero length arrays 1 set key str oid pg i m get key str oid pg i set key str size pg i m len set key str oid pg i m get key str oid pg i int n items n m n n zero length arrays for offs key space i offs n 0 i len len size i j index i if j 0 offs len n 1 set key str offs pg j offs if offs i len memcpy pg offs pg i len len 1 return n items compactifybytearrays getnitems keyspace keyspace nzerolengtharrays getkeystrsize getkeystroffs nzerolengtharrays getkeystrsize getkeystroffs getkeystrsize getkeystroffs getkeystrsize getkeystroffs nzerolengtharrays setkeystroid getkeystroid setkeystrsize setkeystroid getkeystroid nitems nzerolengtharrays keyspace setkeystroffs nitems static int remove str key page pg int r int len get key str size pg r 2 int offs get key str offs pg r int size get size pg int n items getn items pg if n items 1 str key size key space memcpy pg r pg r 1 n items r 1 str key size else memcpy pg r pg r 1 n items r str key size if len 0 memcpy pg key space size len pg key space size size key space offs 1 for int i n items i 0 if get key str offs pg i offs set key str offs pg i get key str offs pg i len set size pg size len setn items pg n items 1 return size str key size n items key space 2 btree op underflow btree op done removestrkey getkeystrsize getkeystroffs getsize nitems getnitems nitems strkeysize keyspace nitems strkeysize nitems strkeysize keyspace keyspace keyspace nitems getkeystroffs setkeystroffs getkeystroffs setsize setnitems nitems strkeysize nitems keyspace op_underflow op_done static int remove byte array key page pg int r int len get key str size pg r int offs get key str offs pg r int size get size pg int n items getn items pg if n items 1 str key size key space memcpy pg r pg r 1 n items r 1 str key size else memcpy pg r pg r 1 n items r str key size if len 0 memcpy pg key space size len pg key space size size key space offs 1 for int i n items i 0 if get key str offs pg i offs set key str offs pg i get key str offs pg i len set size pg size len setn items pg n items 1 return size str key size n items key space 2 btree op underflow btree op done removebytearraykey getkeystrsize getkeystroffs getsize nitems getnitems nitems strkeysize keyspace nitems strkeysize nitems strkeysize keyspace keyspace keyspace nitems getkeystroffs setkeystroffs getkeystroffs setsize setnitems nitems strkeysize nitems keyspace op_underflow op_done static int replace str key storage impl db page pg int r btree key ins int height ins oid get key str oid pg r remove str key pg r return insert str key db pg r ins height replacestrkey storageimpl btreekey getkeystroid removestrkey insertstrkey static int replace byte array key storage impl db page pg int r btree key ins int height ins oid get key str oid pg r remove byte array key pg r return insert byte array key db pg r ins height replacebytearraykey storageimpl btreekey getkeystroid removebytearraykey insertbytearraykey static int handle page underflow storage impl db page pg int r int type btree key rem int height int n items getn items pg if type class descriptor tp string page a db put page get key str oid pg r int an getn items a if r n items exists greater page page b db get page get key str oid pg r 1 int bn getn items b int merged size an bn str key size get size a get size b if height 1 merged size get key str size pg r 2 str key size 2 if merged size key space reallocation of nodes between pages a and b int i j k db pool unfix b b db put page get key str oid pg r 1 int size a get size a int size b get size b int add size sub size if height 1 add size get key str size pg r sub size get key str size b 0 else add size sub size get key str size b 0 i 0 int prev delta an str key size size a bn str key size size b while true i 1 int delta an i str key size size a add size 2 bn i str key size size b sub size 2 if delta 0 if delta prev delta i 1 break size a add size 2 size b sub size 2 prev delta delta if height 1 add size sub size sub size get key str size b i else add size sub size get key str size b i int result btree op done if i 0 k i if height 1 int len get key str size pg r set size a get size a len 2 set key str offs a an key space get size a set key str size a an len memcpy a get key str offs a an pg get key str offs pg r len 2 1 k 1 an 1 set key str oid a an k get key str oid b k set size b get size b get key str size b k 2 for j 0 j k j int len get key str size b j set size a get size a len 2 set size b get size b len 2 set key str offs a an key space get size a set key str size a an len set key str oid a an get key str oid b j memcpy a get key str offs a an b get key str offs b j len 2 1 an 1 rem get str b i 1 result replace str key db pg r rem height setn items a an setn items b compactify strings b i db pool unfix a db pool unfix b return result else merge page b to a if height 1 int r len get key str size pg r set key str size a an r len set size a get size a r len 2 set key str offs a an key space get size a memcpy a get key str offs a an pg get key str offs pg r r len 2 1 an 1 set key str oid a an bn get key str oid b bn for int i 0 i bn i an set key str size a an get key str size b i set key str offs a an get key str offs b i get size a set key str oid a an get key str oid b i set size a get size a get size b setn items a an memcpy a key space get size a b key space get size b get size b 1 db pool unfix a db pool unfix b db free page get key str oid pg r 1 set key str oid pg r 1 get key str oid pg r return remove str key pg r else page b is before a page b db get page get key str oid pg r 1 int bn getn items b int merged size an bn str key size get size a get size b if height 1 merged size get key str size pg r 1 2 str key size 2 if merged size key space reallocation of nodes between pages a and b int i j k len db pool unfix b b db put page get key str oid pg r 1 int size a get size a int size b get size b int add size sub size if height 1 add size get key str size pg r 1 sub size get key str size b bn 1 else add size sub size get key str size b bn 1 i 0 int prev delta an str key size size a bn str key size size b while true i 1 int delta an i str key size size a add size 2 bn i str key size size b sub size 2 if delta 0 if delta prev delta i 1 break prev delta delta size a add size 2 size b sub size 2 if height 1 add size sub size sub size get key str size b bn i 1 else add size sub size get key str size b bn i 1 int result btree op done if i 0 k i assert that i bn if height 1 set size b get size b get key str size b bn k 2 memcpy a i a 0 an 1 str key size k 1 set key str oid a k get key str oid b bn len get key str size pg r 1 set key str size a k len set size a get size a len 2 set key str offs a k key space get size a memcpy a get key str offs a k pg get key str offs pg r 1 len 2 1 else memcpy a i a 0 an str key size for j 0 j k j len get key str size b bn k j set size a get size a len 2 set size b get size b len 2 set key str offs a j key space get size a set key str size a j len set key str oid a j get key str oid b bn k j memcpy a get key str offs a j b get key str offs b bn k j len 2 1 an i setn items a an rem get str b bn k 1 result replace str key db pg r 1 rem height setn items b compactify strings b i db pool unfix a db pool unfix b return result else merge page b to a if height 1 memcpy a bn 1 a 0 an 1 str key size int len get key str size pg r 1 set key str size a bn len set size a get size a len 2 set key str offs a bn key space get size a set key str oid a bn get key str oid b bn memcpy a get key str offs a bn pg get key str offs pg r 1 len 2 1 an 1 else handlepageunderflow storageimpl btreekey nitems getnitems classdescriptor tpstring putpage getkeystroid getnitems nitems getpage getkeystroid getnitems merged_size strkeysize getsize getsize merged_size getkeystrsize strkeysize merged_size keyspace putpage getkeystroid size_a getsize size_b getsize addsize subsize addsize getkeystrsize subsize getkeystrsize addsize subsize getkeystrsize prevdelta strkeysize size_a strkeysize size_b strkeysize size_a addsize strkeysize size_b subsize prevdelta size_a addsize size_b subsize prevdelta addsize subsize subsize getkeystrsize addsize subsize getkeystrsize op_done getkeystrsize setsize getsize setkeystroffs keyspace getsize setkeystrsize getkeystroffs getkeystroffs setkeystroid getkeystroid setsize getsize getkeystrsize getkeystrsize setsize getsize setsize getsize setkeystroffs keyspace getsize setkeystrsize setkeystroid getkeystroid getkeystroffs getkeystroffs getstr replacestrkey setnitems setnitems compactifystrings r_len getkeystrsize setkeystrsize r_len setsize getsize r_len setkeystroffs keyspace getsize getkeystroffs getkeystroffs r_len setkeystroid getkeystroid setkeystrsize getkeystrsize setkeystroffs getkeystroffs getsize setkeystroid getkeystroid setsize getsize getsize setnitems keyspace getsize keyspace getsize getsize freepage getkeystroid setkeystroid getkeystroid removestrkey getpage getkeystroid getnitems merged_size strkeysize getsize getsize merged_size getkeystrsize strkeysize merged_size keyspace putpage getkeystroid size_a getsize size_b getsize addsize subsize addsize getkeystrsize subsize getkeystrsize addsize subsize getkeystrsize prevdelta strkeysize size_a strkeysize size_b strkeysize size_a addsize strkeysize size_b subsize prevdelta prevdelta size_a addsize size_b subsize addsize subsize subsize getkeystrsize addsize subsize getkeystrsize op_done setsize getsize getkeystrsize strkeysize setkeystroid getkeystroid getkeystrsize setkeystrsize setsize getsize setkeystroffs keyspace getsize getkeystroffs getkeystroffs strkeysize getkeystrsize setsize getsize setsize getsize setkeystroffs keyspace getsize setkeystrsize setkeystroid getkeystroid getkeystroffs getkeystroffs setnitems getstr replacestrkey setnitems compactifystrings strkeysize getkeystrsize setkeystrsize setsize getsize setkeystroffs keyspace getsize setkeystroid getkeystroid getkeystroffs getkeystroffs static int remove storage impl db int page id btree tree btree key rem int height page pg db get page page id try int i n getn items pg l 0 r n if tree type class descriptor tp string while l r i l r 1 if compare str rem key pg i 0 l i 1 else r i if height 0 do switch remove db get key str oid pg r tree rem height case btree op underflow db pool unfix pg pg null pg db put page page id return handle page underflow db pg r tree type rem height case btree op done return btree op done case btree op overflow db pool unfix pg pg null pg db put page page id return insert str key db pg r rem height while r n else while r n if compare str rem key pg r 0 int oid get key str oid pg r if oid rem oid rem oid 0 rem old oid oid db pool unfix pg pg null pg db put page page id return remove str key pg r else break r 1 else if tree type class descriptor tp array of byte while l r i l r 1 if tree compare byte arrays rem key pg i 0 l i 1 else r i if height 0 do switch remove db get key str oid pg r tree rem height case btree op underflow db pool unfix pg pg null pg db put page page id return handle page underflow db pg r tree type rem height case btree op done return btree op done case btree op overflow db pool unfix pg pg null pg db put page page id return insert byte array key db pg r rem height while r n else while r n if tree compare byte arrays rem key pg r 0 int oid get key str oid pg r if oid rem oid rem oid 0 rem old oid oid db pool unfix pg pg null pg db put page page id return remove byte array key pg r else break r 1 else scalar types int item size class descriptor sizeof tree type while l r i l r 1 if compare rem key pg i 0 l i 1 else r i if height 0 int oid rem oid while r n if compare rem key pg r 0 if get reference pg max items r 1 oid oid 0 rem old oid get reference pg max items r 1 db pool unfix pg pg null pg db put page page id memcpy pg r pg r 1 n r 1 item size memcpy pg max items n 1 pg max items n n r 1 4 setn items pg n return n item size 4 key space 2 btree op underflow btree op done else break r 1 return btree op not found do switch remove db get reference pg max items r 1 tree rem height case btree op underflow db pool unfix pg pg null pg db put page page id return handle page underflow db pg r tree type rem height case btree op done return btree op done while r n return btree op not found finally if pg null db pool unfix pg storageimpl pageid btreekey getpage pageid getnitems classdescriptor tpstring comparestr getkeystroid op_underflow putpage pageid handlepageunderflow op_done op_done op_overflow putpage pageid insertstrkey comparestr getkeystroid oldoid putpage pageid removestrkey classdescriptor tparrayofbyte comparebytearrays getkeystroid op_underflow putpage pageid handlepageunderflow op_done op_done op_overflow putpage pageid insertbytearraykey comparebytearrays getkeystroid oldoid putpage pageid removebytearraykey itemsize classdescriptor getreference maxitems oldoid getreference maxitems putpage pageid itemsize maxitems maxitems setnitems itemsize keyspace op_underflow op_done op_not_found getreference maxitems op_underflow putpage pageid handlepageunderflow op_done op_done op_not_found static void purge storage impl db int page id int type int height if height 0 page pg db get page page id int n getn items pg 1 if type class descriptor tp string type class descriptor tp array of byte page of strings while n 0 purge db get key str oid pg n type height else while n 0 purge db get reference pg max items n 1 type height db pool unfix pg db free page page id storageimpl pageid getpage pageid getnitems classdescriptor tpstring classdescriptor tparrayofbyte getkeystroid getreference maxitems freepage pageid static int traverse forward storage impl db int page id int type int height i persistent result int pos page pg db get page page id int oid try int i n getn items pg if height 0 if type class descriptor tp string type class descriptor tp array of byte page of strings for i 0 i n i pos traverse forward db get key str oid pg i type height result pos else for i 0 i n i pos traverse forward db get reference pg max items i 1 type height result pos else if type class descriptor tp string type class descriptor tp array of byte page of strings for i 0 i n i oid get key str oid pg i result pos db lookup object oid null else page of scalars for i 0 i n i oid get reference pg max items 1 i result pos db lookup object oid null return pos finally db pool unfix pg traverseforward storageimpl pageid ipersistent getpage pageid getnitems classdescriptor tpstring classdescriptor tparrayofbyte traverseforward getkeystroid traverseforward getreference maxitems classdescriptor tpstring classdescriptor tparrayofbyte getkeystroid lookupobject getreference maxitems lookupobject static int mark page storage impl db int page id int type int height int n pages 1 page pg db getgc page page id try int i n getn items pg if height 0 if type class descriptor tp string type class descriptor tp array of byte page of strings for i 0 i n i n pages mark page db get key str oid pg i type height else for i 0 i n i n pages mark page db get reference pg max items i 1 type height else if type class descriptor tp string type class descriptor tp array of byte page of strings for i 0 i n i db mark oid get key str oid pg i else page of scalars for i 0 i n i db mark oid get reference pg max items 1 i finally db pool unfix pg return n pages markpage storageimpl pageid npages getgcpage pageid getnitems classdescriptor tpstring classdescriptor tparrayofbyte npages markpage getkeystroid npages markpage getreference maxitems classdescriptor tpstring classdescriptor tparrayofbyte markoid getkeystroid markoid getreference maxitems npages static void export page storage impl db xml exporter exporter int page id int type int height throws java io io exception page pg db get page page id try int i n getn items pg if height 0 if type class descriptor tp string type class descriptor tp array of byte page of strings for i 0 i n i export page db exporter get key str oid pg i type height else for i 0 i n i export page db exporter get reference pg max items i 1 type height else if type class descriptor tp string type class descriptor tp array of byte page of strings for i 0 i n i exporter export assoc get key str oid pg i pg data btree page first key offs btree page get key str offs pg i btree page get key str size pg i type else for i 0 i n i exporter export assoc get reference pg max items 1 i pg data btree page first key offs i class descriptor sizeof type class descriptor sizeof type type finally db pool unfix pg exportpage storageimpl xmlexporter pageid ioexception getpage pageid getnitems classdescriptor tpstring classdescriptor tparrayofbyte exportpage getkeystroid exportpage getreference maxitems classdescriptor tpstring classdescriptor tparrayofbyte exportassoc getkeystroid btreepage firstkeyoffs btreepage getkeystroffs btreepage getkeystrsize exportassoc getreference maxitems btreepage firstkeyoffs classdescriptor classdescriptor public static final sendable request item null item new null sendable request item public void dump do nothing we will be gc ed sendablerequestitem nullitem nullsendablerequestitem transient field fld btree field index btreefieldindex private final void locate field fld class descriptor locate field cls field name if fld null throw new storage error storage error indexed field not found class name field name locatefield classdescriptor locatefield fieldname storageerror storageerror indexed_field_not_found classname fieldname public class get indexed class return cls getindexedclass public field get key fields return new field fld getkeyfields public void on load cls class descriptor load class get storage class name locate field onload classdescriptor loadclass getstorage classname locatefield btree field index class cls string field name boolean unique this cls field name unique 0 btreefieldindex fieldname fieldname btree field index class cls string field name boolean unique long autoinc count this cls cls this unique unique this field name field name this class name class descriptor get class name cls this autoinc count autoinc count locate field type check type fld get type btreefieldindex fieldname autoinccount fieldname fieldname classname classdescriptor getclassname autoinccount autoinccount locatefield checktype gettype protected object unpack enum int val return fld get type get enum constants val unpackenum gettype getenumconstants private key extract key i persistent obj try field f fld key key null switch type case class descriptor tp boolean key new key f get boolean obj break case class descriptor tp byte key new key f get byte obj break case class descriptor tp short key new key f get short obj break case class descriptor tp char key new key f get char obj break case class descriptor tp int key new key f get int obj break case class descriptor tp object i persistent ptr i persistent f get obj if ptr null ptr is persistent get storage make persistent ptr key new key ptr break case class descriptor tp long key new key f get long obj break case class descriptor tp date key new key date f get obj break case class descriptor tp float key new key f get float obj break case class descriptor tp double key new key f get double obj break case class descriptor tp enum key new key enum f get obj break case class descriptor tp string key new key string f get obj break default assert failed invalid type return key catch exception x throw new storage error storage error access violation x extractkey ipersistent classdescriptor tpboolean getboolean classdescriptor tpbyte getbyte classdescriptor tpshort getshort classdescriptor tpchar getchar classdescriptor tpint getint classdescriptor tpobject ipersistent ipersistent ispersistent getstorage makepersistent classdescriptor tplong getlong classdescriptor tpdate classdescriptor tpfloat getfloat classdescriptor tpdouble getdouble classdescriptor tpenum classdescriptor tpstring storageerror storageerror access_violation public boolean add t obj return put obj public boolean put t obj return super insert extract key obj obj false 0 extractkey public t set t obj return super set extract key obj obj extractkey public void remove t obj super remove extract key obj obj extractkey public boolean contains object t obj key key extract key obj if unique return super get key null else i persistent mbrs get key key for int i 0 i mbrs length i if mbrs i obj return true return false containsobject extractkey ipersistent public boolean contains t obj key key extract key obj if unique return super get key null else i persistent mbrs get key key for int i 0 i mbrs length i if mbrs i equals obj return true return false extractkey ipersistent public synchronized void append t obj key key try switch type case class descriptor tp int key new key int autoinc count fld set int obj int autoinc count break case class descriptor tp long key new key autoinc count fld set long obj autoinc count break default throw new storage error storage error unsupported index type fld get type catch exception x throw new storage error storage error access violation x autoinc count 1 obj modify super insert key obj false classdescriptor tpint autoinccount setint autoinccount classdescriptor tplong autoinccount setlong autoinccount storageerror storageerror unsupported_index_type gettype storageerror storageerror access_violation autoinccount public t get prefix string prefix array list t list get list new key prefix true new key prefix character max value false return t list to array t array new instance cls list size getprefix arraylist getlist max_value toarray newinstance public t prefix search string key array list t list prefix search list key return t list to array t array new instance cls list size prefixsearch arraylist prefixsearchlist toarray newinstance public t get key from key till array list list new array list if root 0 btree page find storage impl get storage root check key from check key till this height list return t list to array t array new instance cls list size arraylist arraylist btreepage storageimpl getstorage checkkey checkkey toarray newinstance public t to persistent array t arr t array new instance cls n elems if root 0 btree page traverse forward storage impl get storage root type height arr 0 return arr topersistentarray newinstance nelems btreepage traverseforward storageimpl getstorage public iterable iterator t query by example t obj key key extract key obj return iterator key key ascent order iterableiterator querybyexample extractkey ascent_order public iterable iterator t select string predicate query t query new query impl t get storage return query select cls iterator predicate iterableiterator queryimpl getstorage public boolean is case insensitive return false iscaseinsensitive class btree case insensitive field index t extends i persistent extends btree field index t btree case insensitive field index btreecaseinsensitivefieldindex ipersistent btreefieldindex btreecaseinsensitivefieldindex btree case insensitive field index btree case insensitive field index class cls string field name boolean unique super cls field name unique btreecaseinsensitivefieldindex btreecaseinsensitivefieldindex fieldname fieldname btree case insensitive field index class cls string field name boolean unique long autoinc count super cls field name unique autoinc count btreecaseinsensitivefieldindex fieldname autoinccount fieldname autoinccount key check key key key if key null key oval instanceof string key new key string key oval to lower case key inclusion 0 return super check key key checkkey tolowercase checkkey public boolean is case insensitive return true iscaseinsensitive nodeip port detector node node nodeip detector ip detector node crypto crypto boolean enablear ks this node node this ip detector ip detector this crypto crypto ark putter new nodeark inserter node crypto this enablear ks ip detector add port detector this nodeipportdetector nodeipdetector ipdetector nodecrypto enablearks ipdetector ipdetector arkputter nodearkinserter enablearks ipdetector addportdetector combine the nodeip detector s output with any per port information we may have to get a definitive for that port node crypto list of ip addresses still without port numbers freenet inet address detect primaryip address freenet inet address addr crypto get bind to if addr is real internet address false true false binding to a real internet address don t want us to use the others most likely he is on a multi homed box where only one ip can be used for freenet return new freenet inet address addr return ip detector detect primaryip address crypto config include local addresses in noderefs nodeipdetector nodecrypto freenetinetaddress detectprimaryipaddress freenetinetaddress getbindto isrealinternetaddress freenetinetaddress ipdetector detectprimaryipaddress includelocaladdressesinnoderefs get our peer s this is a list of ip port s at which we might be contactable some of them will have the same port as the listen port but if we are behind a nat which rewrites our port number some of them may not if we re behind a symmetric nat which rewrites it differently for each connection we re stuffed and we tell the user peer detect primary peers boolean logminor logger should log logger minor this array list peer addresses new array list peer freenet inet address addrs detect primaryip address for int i 0 i addrs length i addresses add new peer addrs i crypto port number if logminor logger minor this adding addrs i now try to get the rewritten port number from our peers only considering those within this crypto port this time peer node peer list crypto get peer nodes if peer list null hash map peer integer counts by peer new hash map peer integer fixme use a standard mutable int object we have one somewhere for int i 0 i peer list length i peer p peer list i get remote detected peer if p null p is null continue dns requester doesn t deal with our own node if ip util is valid address p get address true false continue if logger should log logger minor this logger minor this peer peer list i get peer thinks we are p if counts by peer contains key p counts by peer put p counts by peer get p 1 else counts by peer put p 1 if counts by peer size 1 iterator peer it counts by peer key set iterator peer p it next logger minor this everyone agrees we are p if addresses contains p addresses add p else if counts by peer size 1 take two most popular addresses peer best null peer second best null int best popularity 0 int second best popularity 0 for map entry peer integer entry counts by peer entry set peer cur entry get key int cur pop entry get value logger normal this detected peer cur popularity cur pop if cur pop best popularity second best popularity best popularity best popularity cur pop second best best best cur if best null if best popularity 1 addrs length 0 if addresses contains best logger normal this adding best peer best best popularity addresses add best if second best null second best popularity 1 if addresses contains second best logger normal this adding second best peer second best second best addresses add second best if best get address equals second best get address best popularity 1 logger error this hrrrm maybe this is a symmetric nat expect trouble connecting system err println hrrrm maybe this is a symmetric nat expect trouble connecting ip detector set maybe symmetric peer p new peer best get freenet address crypto port number if addresses contains p addresses add p last peers addresses to array new peer addresses size if logminor logger minor this returning for port crypto port number arrays to string last peers return last peers listenport detectprimarypeers shouldlog arraylist arraylist freenetinetaddress detectprimaryipaddress portnumber peernode peerlist getpeernodes peerlist hashmap countsbypeer hashmap peerlist peerlist getremotedetectedpeer isnull dnsrequester iputil isvalidaddress getaddress shouldlog peerlist getpeer countsbypeer containskey countsbypeer countsbypeer countsbypeer countsbypeer countsbypeer keyset countsbypeer secondbest bestpopularity secondbestpopularity countsbypeer entryset getkey curpop getvalue curpop curpop bestpopularity secondbestpopularity bestpopularity bestpopularity curpop secondbest bestpopularity bestpopularity secondbest secondbestpopularity secondbest secondbest secondbest secondbest getaddress secondbest getaddress bestpopularity ipdetector setmaybesymmetric getfreenetaddress portnumber lastpeers toarray portnumber tostring lastpeers lastpeers void update ark putter update arkputter void startark ark putter start arkputter public peer get primary peers if last peers null return detect primary peers else return last peers getprimarypeers lastpeers detectprimarypeers lastpeers public boolean includes freenet inet address addr freenet inet address a detect primaryip address for int i 0 i a length i if a i equals addr return true return false freenetinetaddress freenetinetaddress detectprimaryipaddress public class action data extends node data public action data actiondata nodedata actiondata private action listener action listener null public action listener get action listener return action listener actionlistener actionlistener actionlistener getactionlistener actionlistener public void set action listener action listener action listener this action listener action listener setactionlistener actionlistener actionlistener actionlistener actionlistener private control response ctrl res null public control response get control response return ctrl res controlresponse ctrlres controlresponse getcontrolresponse ctrlres public void set control response control response res ctrl res res setcontrolresponse controlresponse ctrlres param jmdns impl public type resolver jmdns impl jmdns impl this jmdns impl jmdns impl jmdnsimpl typeresolver jmdnsimpl jmdnsimpl jmdnsimpl jmdnsimpl public void start timer timer timer schedule this dns constants query wait interval dns constants query wait interval dnsconstants query_wait_interval dnsconstants query_wait_interval public void run try if this jmdns impl get state dns state announced if count 3 logger finer run jmdns querying type dns outgoing out new dns outgoing dns constants flags qr query out add question new dns question services dns sd udp local dns constants type ptr dns constants class in for iterator iterator this jmdns impl get service types values iterator iterator has next out add answer new dns record pointer services dns sd udp local dns constants type ptr dns constants class in dns constants dns ttl string iterator next 0 this jmdns impl send out else after three queries we can quit this cancel else if this jmdns impl get state dns state canceled this cancel catch throwable e logger log level warning run exception e this jmdns impl recover jmdnsimpl getstate dnsstate dnsoutgoing dnsoutgoing dnsconstants flags_qr_query addquestion dnsquestion _services _dns _udp dnsconstants type_ptr dnsconstants class_in jmdnsimpl getservicetypes hasnext addanswer dnsrecord _services _dns _udp dnsconstants type_ptr dnsconstants class_in dnsconstants dns_ttl jmdnsimpl jmdnsimpl getstate dnsstate jmdnsimpl final boolean global public identifier collision message string id boolean global this identifier id this global global identifiercollisionmessage override public simple field set get field set simple field set sfs new simple field set true sfs put single identifier identifier if global sfs put single global true return sfs simplefieldset getfieldset simplefieldset simplefieldset putsingle putsingle override public string get name return identifier collision getname identifiercollision override public void run fcp connection handler handler node node throws message invalid exception throw new message invalid exception protocol error message invalid message identifier collision goes from server to client not the other way around identifier global fcpconnectionhandler messageinvalidexception messageinvalidexception protocolerrormessage invalid_message identifiercollision override public void remove from object container container container delete this removefrom objectcontainer smallest y coordinate of the rectangle public final double get top return top gettop smallest x coordinate of the rectangle public final double get left return left getleft greatest y coordinate of the rectangle public final double get bottom return bottom getbottom greatest x coordinate of the rectangle public final double get right return right getright rectangle area public final double area return bottom top right left area of covered rectangle for two sepcified rectangles public static double join area rectangler2 a rectangler2 b double left a left b left a left b left double right a right b right a right b right double top a top b top a top b top double bottom a bottom b bottom a bottom b bottom return bottom top right left joinarea clone rectangle public object clone try rectangler2 r rectangler2 super clone r top this top r left this left r bottom this bottom r right this right return r catch clone not supported exception e this shouldn t happen since we are cloneable throw new internal error clonenotsupportedexception internalerror create copy of the rectangle public rectangler2 rectangler2 r this top r top this left r left this bottom r bottom this right r right construct rectangle with specified coordinates public rectangler2 double top double left double bottom double right assert that top bottom left right this top top this left left this bottom bottom this right right default constructor for perst public rectangler2 join two rectangles this rectangle is updates to contain cover of this and specified rectangle param r rectangle to be joined with this rectangle public final void join rectangler2 r if left r left left r left if right r right right r right if top r top top r top if bottom r bottom bottom r bottom non destructive join of two rectangles param a first joined rectangle param b second joined rectangle return rectangle containing cover of these two rectangles public static rectangler2 join rectangler2 a rectangler2 b rectangler2 r new rectangler2 a r join b return r checks if this rectangle intersects with specified rectangle public final boolean intersects rectangler2 r return left r right top r bottom right r left bottom r top checks if this rectangle contains the specified rectangle public final boolean contains rectangler2 r return left r left top r top right r right bottom r bottom check if two rectangles are equal public boolean equals object o if o instanceof rectangler2 rectangler2 r rectangler2 o return left r left top r top right r right bottom r bottom return false hash code consists of all rectangle coordinates public int hash code return int double double to long bits top double double to long bits bottom 1 double double to long bits left 2 double double to long bits right 3 hashcode doubletolongbits doubletolongbits doubletolongbits doubletolongbits public string to string return top top left left bottom bottom right right tostring public http packet set version http version set content input stream null httppacket setversion setcontentinputstream public http packet http packet http packet set version http version set http packet set content input stream null httppacket httppacket httppacket setversion httppacket setcontentinputstream public http packet input stream in set version http version set in set content input stream null httppacket inputstream setversion setcontentinputstream public void init set first line clear headers set content new byte 0 false set content input stream null setfirstline clearheaders setcontent setcontentinputstream private string version public void set version string ver version ver setversion public string get version return version getversion protected boolean set input stream in boolean only headers try buffered reader reader new buffered reader new input stream reader in string first line reader read line if first line null first line length 0 return false set first line first line thanks for giordano sassaroli sassarol cefriel it 09 03 03 http status http status new http status first line int stat code http status get status code if stat code http status continue ad hoc code for managing iis non standard behaviour iis sends 100 code response and a 200 code response in the same stream so the code should check the presence of the actual response in the stream skip all header lines string header line reader read line while header line null 0 header line length http header header new http header header line if header has name true set header header header line reader read line look forward another first line string actual first line reader read line if actual first line null 0 actual first line length this is the actual first line set first line actual first line else return true string header line reader read line while header line null 0 header line length http header header new http header header line if header has name true set header header header line reader read line if only headers true set content false return true boolean is chunked request is chunked long content len 0 if is chunked request true try string chunk size line reader read line content len long parse long new string chunk size line get bytes 0 chunk size line length 2 catch exception e else content len get content length string builder content buf new string builder while 0 content len int chunk size http get chunk size char read buf new char chunk size long read cnt 0 while read cnt content len try thanks for mark retallack 02 02 05 long buf read len content len read cnt if chunk size buf read len buf read len chunk size int read len reader read read buf 0 int buf read len if read len 0 break content buf append new string read buf 0 read len read cnt read len catch exception e debug warning e break if is chunked request true skip crlf long skip len 0 do long skip cnt reader skip http crlf length skip len if skip cnt 0 break skip len skip cnt while skip len http crlf length read next chunk size try string chunk size line reader read line content len long parse long new string chunk size line get bytes 0 chunk size line length 2 catch exception e content len 0 else content len 0 thanks for ralf g r bergs 02 09 04 string content str content buf to string set content content str get bytes false catch exception e debug warning e return false return true inputstream onlyheaders bufferedreader bufferedreader inputstreamreader firstline readline firstline firstline setfirstline firstline httpstatus httpstatus httpstatus firstline statcode httpstatus getstatuscode statcode httpstatus headerline readline headerline headerline httpheader httpheader headerline hasname setheader headerline readline actualfirstline readline actualfirstline actualfirstline setfirstline actualfirstline headerline readline headerline headerline httpheader httpheader headerline hasname setheader headerline readline onlyheaders setcontent ischunkedrequest ischunked contentlen ischunkedrequest chunksizeline readline contentlen parselong chunksizeline getbytes chunksizeline contentlen getcontentlength stringbuilder contentbuf stringbuilder contentlen chunksize getchunksize readbuf chunksize readcnt readcnt contentlen bufreadlen contentlen readcnt chunksize bufreadlen bufreadlen chunksize readlen readbuf bufreadlen readlen contentbuf readbuf readlen readcnt readlen ischunkedrequest skiplen skipcnt skiplen skipcnt skiplen skipcnt skiplen chunksizeline readline contentlen parselong chunksizeline getbytes chunksizeline contentlen contentlen contentstr contentbuf tostring setcontent contentstr getbytes protected boolean set input stream in return set in false inputstream protected boolean set http socket http sock return set http sock get input stream httpsocket httpsock httpsock getinputstream protected void set http packet http packet set first line http packet get first line clear headers int n headers http packet getn headers for int n 0 n n headers n http header header http packet get header n add header header set content http packet get content httppacket httppacket setfirstline httppacket getfirstline clearheaders nheaders httppacket getnheaders nheaders httpheader httppacket getheader addheader setcontent httppacket getcontent public boolean read http socket http sock init return set http sock httpsocket httpsock httpsock private string first line private void set first line string value first line value firstline setfirstline firstline protected string get first line return first line getfirstline firstline protected string get first line token int num string tokenizer st new string tokenizer first line http reqest line delim string last token for int n 0 n num n if st has more tokens false return last token st next token return last token getfirstlinetoken stringtokenizer stringtokenizer firstline reqest_line_delim lasttoken hasmoretokens lasttoken nexttoken lasttoken public boolean has first line return 0 first line length true false hasfirstline firstline private vector http header list new vector public int getn headers return http header list size httpheaderlist getnheaders httpheaderlist public void add header http header header http header list add header addheader httpheader httpheaderlist public void add header string name string value http header header new http header name value http header list add header addheader httpheader httpheader httpheaderlist public http header get header int n return http header http header list get n httpheader getheader httpheader httpheaderlist public http header get header string name int n headers getn headers for int n 0 n n headers n http header header get header n string header name header get name if header name equals ignore case name true return header return null httpheader getheader nheaders getnheaders nheaders httpheader getheader headername getname headername equalsignorecase public void clear headers http header list clear http header list new vector clearheaders httpheaderlist httpheaderlist public boolean has header string name return get header name null true false hasheader getheader public void set header string name string value http header header get header name if header null header set value value return add header name value setheader httpheader getheader setvalue addheader public void set header string name int value set header name integer to string value setheader setheader tostring public void set header string name long value set header name long to string value setheader setheader tostring public void set header http header header set header header get name header get value setheader httpheader setheader getname getvalue public string get header value string name http header header get header name if header null return return header get value getheadervalue httpheader getheader getvalue public void set string header string name string value string start width string end width string header value value if header value starts with start width false header value start width header value if header value ends with end width false header value header value end width set header name header value setstringheader startwidth endwidth headervalue headervalue startswith startwidth headervalue startwidth headervalue headervalue endswith endwidth headervalue headervalue endwidth setheader headervalue public void set string header string name string value set string header name value setstringheader setstringheader public string get string header value string name string start width string end width string header value get header value name if header value starts with start width true header value header value substring 1 header value length if header value ends with end width true header value header value substring 0 header value length 1 return header value getstringheadervalue startwidth endwidth headervalue getheadervalue headervalue startswith startwidth headervalue headervalue headervalue headervalue endswith endwidth headervalue headervalue headervalue headervalue public string get string header value string name return get string header value name getstringheadervalue getstringheadervalue public void set integer header string name int value set header name integer to string value setintegerheader setheader tostring public void set long header string name long value set header name long to string value setlongheader setheader tostring public int get integer header value string name http header header get header name if header null return 0 return string util to integer header get value getintegerheadervalue httpheader getheader stringutil tointeger getvalue public long get long header value string name http header header get header name if header null return 0 return string util to long header get value getlongheadervalue httpheader getheader stringutil tolong getvalue public string get header string string builder str new string builder int n headers getn headers for int n 0 n n headers n http header header get header n str append header get name header get value http crlf return str to string getheaderstring stringbuilder stringbuilder nheaders getnheaders nheaders httpheader getheader getname getvalue tostring public void set content byte data boolean update with content length content data if update with content length true set content length data length setcontent updatewithcontentlength updatewithcontentlength setcontentlength public void set content byte data set content data true setcontent setcontent public void set content string data boolean update with content length set content data get bytes update with content length setcontent updatewithcontentlength setcontent getbytes updatewithcontentlength public void set content string data set content data true setcontent setcontent public byte get content return content getcontent public string get content string return new string content getcontentstring public boolean has content return content length 0 true false hascontent private input stream content input null public void set content input stream input stream in content input in inputstream contentinput setcontentinputstream inputstream contentinput public input stream get content input stream return content input inputstream getcontentinputstream contentinput public boolean has content input stream return content input null true false hascontentinputstream contentinput public void set content type string type set header http content type type setcontenttype setheader content_type public string get content type return get header value http content type getcontenttype getheadervalue content_type public void set content length long len set long header http content length len setcontentlength setlongheader content_length public long get content length return get long header value http content length getcontentlength getlongheadervalue content_length public boolean has connection return has header http connection hasconnection hasheader public void set connection string value set header http connection value setconnection setheader public string get connection return get header value http connection getconnection getheadervalue public boolean is close connection if has connection false return false string connection get connection if connection null return false return connection equals ignore case http close iscloseconnection hasconnection getconnection equalsignorecase public boolean is keep alive connection if has connection false return false string connection get connection if connection null return false return connection equals ignore case http keep alive iskeepaliveconnection hasconnection getconnection equalsignorecase keep_alive public boolean has content range return has header http content range has header http range hascontentrange hasheader content_range hasheader public void set content range long first pos long last pos long length string range str range str http content range bytes range str long to string first pos range str long to string last pos range str 0 length long to string length set header http content range range str setcontentrange firstpos lastpos rangestr rangestr content_range_bytes rangestr tostring firstpos rangestr tostring lastpos rangestr tostring setheader content_range rangestr public long get content range long range new long 3 range 0 range 1 range 2 0 if has content range false return range string range line get header value http content range thanks for brent hills 10 20 04 if range line length 0 range line get header value http range if range line length 0 return range thanks for brent hills 10 20 04 string tokenizer str token new string tokenizer range line skip bytes if str token has more tokens false return range str token next token get first byte pos if str token has more tokens false return range string first pos str str token next token try range 0 long parse long first pos str catch number format exception e if str token has more tokens false return range string last pos str str token next token try range 1 long parse long last pos str catch number format exception e if str token has more tokens false return range string length str str token next token try range 2 long parse long length str catch number format exception e return range getcontentrange hascontentrange rangeline getheadervalue content_range rangeline rangeline getheadervalue rangeline stringtokenizer strtoken stringtokenizer rangeline strtoken hasmoretokens strtoken nexttoken strtoken hasmoretokens firstposstr strtoken nexttoken parselong firstposstr numberformatexception strtoken hasmoretokens lastposstr strtoken nexttoken parselong lastposstr numberformatexception strtoken hasmoretokens lengthstr strtoken nexttoken parselong lengthstr numberformatexception public long get content range first position long range get content range return range 0 getcontentrangefirstposition getcontentrange public long get content range last position long range get content range return range 1 getcontentrangelastposition getcontentrange public long get content range instance length long range get content range return range 2 getcontentrangeinstancelength getcontentrange public void set cache control string directive set header http cache control directive setcachecontrol setheader cache_control public void set cache control string directive int value string str val directive integer to string value set header http cache control str val setcachecontrol strval tostring setheader cache_control strval public void set cache control int value set cache control http max age value setcachecontrol setcachecontrol max_age public string get cache control return get header value http cache control getcachecontrol getheadervalue cache_control public void set server string name set header http server name setserver setheader public string get server return get header value http server getserver getheadervalue public void set host string host int port string host addr host if host interface isi pv6 address host true host addr host set header http host host addr integer to string port sethost hostaddr hostinterface isipv6address hostaddr setheader hostaddr tostring public string get host return get header value http host gethost getheadervalue public void set date calendar cal date date new date cal set header http date date get date string setdate setheader getdatestring public string get date return get header value http date getdate getheadervalue public boolean has transfer encoding return has header http transfer encoding hastransferencoding hasheader transfer_encoding public void set transfer encoding string value set header http transfer encoding value settransferencoding setheader transfer_encoding public string get transfer encoding return get header value http transfer encoding gettransferencoding getheadervalue transfer_encoding public boolean is chunked if has transfer encoding false return false string trans enc get transfer encoding if trans enc null return false return trans enc equals ignore case http chunked ischunked hastransferencoding transenc gettransferencoding transenc transenc equalsignorecase static logger register log threshold callback new log threshold callback override public void should update logminor logger should log logger minor this registerlogthresholdcallback logthresholdcallback shouldupdate shouldlog private static final boolean local requests compete fairly true public static boolean is valid priority class int prio return prio maximum priority class prio minimum priority class local_requests_compete_fairly isvalidpriorityclass maximum_priority_class minimum_priority_class public request starter node client core node base request throttle throttle string name token bucket output bucket token bucket input bucket running average average output bytes per request running average average input bytes per request boolean is insert boolean isssk this core node this stats core node stats this throttle throttle this name name this output bucket output bucket this input bucket input bucket this average output bytes per request average output bytes per request this average input bytes per request average input bytes per request this is insert is insert this isssk isssk requeststarter nodeclientcore baserequestthrottle tokenbucket outputbucket tokenbucket inputbucket runningaverage averageoutputbytesperrequest runningaverage averageinputbytesperrequest isinsert nodestats outputbucket outputbucket inputbucket inputbucket averageoutputbytesperrequest averageoutputbytesperrequest averageinputbytesperrequest averageinputbytesperrequest isinsert isinsert void set scheduler request scheduler sched this sched sched setscheduler requestscheduler void start sched start core core get executor execute this name sched queue fill request starter queue getexecutor queuefillrequeststarterqueue final string name override public string to string return name tostring void real run chosen block req null sent request time system current time millis the last time at which we sent a request or decided not to long cycle time sent request time while true allow 5 minutes before we start killing requests due to not connecting opennet manager om if core node peers count connected peers 3 om core node get opennet null system current time millis om get creation time 5 60 1000 try synchronized this wait 1000 catch interrupted exception e todo auto generated catch block e print stack trace continue if req null req sched grab request if req null if logminor logger minor this running req priority req get priority wait long delay throttle get delay if logminor logger minor this delay delay from throttle long sleep until cycle time delay if local requests compete fairly input bucket blocking grab int math max 0 average input bytes per request current value output bucket blocking grab int math max 0 average output bytes per request current value long now do now system current time millis if now sleep until try thread sleep sleep until now if logminor logger minor this slept sleep until now ms catch interrupted exception e ignore while now sleep until string reason if local requests compete fairly if reason stats should reject request true is insert isssk true false null null if logminor logger minor this not sending local request reason wait one throttle delay before trying again cycle time system current time millis continue let local requests compete with all the others else stats wait until not overloaded is insert else if logminor logger minor this waiting always take the lock on request starter first afaics we don t synchronize on request starter anywhere else nested locks here prevent extra latency when there is a race and therefore allow us to sleep indefinitely synchronized this req sched grab request if req null try wait 100 1000 as close to indefinite as i m comfortable with toad catch interrupted exception e ignore if req null continue if start request req logminor don t log if it s a cancelled transient request if req is persistent req is cancelled logger normal this no requests to start on req req null cycle time sent request time system current time millis realrun chosenblock sentrequesttime currenttimemillis cycletime sentrequesttime opennetmanager countconnectedpeers getopennet currenttimemillis getcreationtime interruptedexception printstacktrace grabrequest getpriority getdelay sleepuntil cycletime local_requests_compete_fairly inputbucket blockinggrab averageinputbytesperrequest currentvalue outputbucket blockinggrab averageoutputbytesperrequest currentvalue currenttimemillis sleepuntil sleepuntil sleepuntil interruptedexception sleepuntil local_requests_compete_fairly shouldrejectrequest isinsert cycletime currenttimemillis waituntilnotoverloaded isinsert requeststarter requeststarter grabrequest interruptedexception startrequest ispersistent iscancelled cycletime sentrequesttime currenttimemillis private boolean start request chosen block req boolean logminor if req is persistent req is cancelled req on dumped return false if req key null if sched add to fetching req key req on dumped return false else if req is persistent transient chosen block req request instanceof sendable insert if sched add transient insert fetching sendable insert transient chosen block req request req token req on dumped return false if logminor logger minor this running request req priority req get priority core get executor execute new sender thread req req key request starter sender thread for req return true startrequest chosenblock ispersistent iscancelled ondumped addtofetching ondumped ispersistent transientchosenblock sendableinsert addtransientinsertfetching sendableinsert transientchosenblock ondumped getpriority getexecutor senderthread requeststarter senderthread public void run freenet support logger os thread logpid this while true try real run catch out of memory error e oom handler handleoom e catch throwable t logger error this caught t t osthread realrun outofmemoryerror oomhandler private final key key public sender thread chosen block req key key this req req this key key senderthread chosenblock public void run try freenet support logger os thread logpid this fixme key is not known for inserts here if key null stats report outgoing local request location key to normalized double if req send core sched if req is persistent req is cancelled logger error this run not able to send a request on req else logger normal this run not able to send a request on req request was cancelled if logminor logger minor this finished req finally if key null sched remove fetching key key else if req is persistent transient chosen block req request instanceof sendable insert sched remove transient insert fetching sendable insert transient chosen block req request req token osthread reportoutgoinglocalrequestlocation tonormalizeddouble ispersistent iscancelled removefetchingkey ispersistent transientchosenblock sendableinsert removetransientinsertfetching sendableinsert transientchosenblock public void wake up synchronized this notify all wakeup notifyall public boolean exclude random grab array item item object container container client context context if sched is running or queued persistent request sendable request item logger normal this excluding already running request item new exception debug return true if is insert return false if item instanceof base sendable get logger error this on a request scheduler exclude called with item new exception error return false base sendable get get base sendable get item if get has valid keys sched fetching keys container context return false logger normal this excluding no valid keys get return true randomgrabarrayitem objectcontainer clientcontext isrunningorqueuedpersistentrequest sendablerequest isinsert basesendableget basesendableget basesendableget hasvalidkeys fetchingkeys applies distortion by adding fish eye effect and horizontal vertical lines param base image the base image return the distorted image public buffered image get distorted image buffered image base image graphics2d graph graphics2d base image get graphics int image height base image get height int image width base image get width want lines put them in a variable so we might configure these later int horizontal lines image height 7 int vertical lines image width 7 calculate space between lines int horizontal gaps image height horizontal lines 1 int vertical gaps image width vertical lines 1 draw the horizontal stripes for int i horizontal gaps i image height i i horizontal gaps graph set color color blue graph draw line 0 i image width i draw the vertical stripes for int i vertical gaps i image width i i vertical gaps graph set color color red graph draw line i 0 i image height create a pixel array of the original image we need this later to do the operations on int pix new int image height image width int j 0 for int j1 0 j1 image width j1 for int k1 0 k1 image height k1 pix j base image getrgb j1 k1 j double distance ran int image width 4 image width 3 put the distortion in the dead middle int width middle base image get width 2 int height middle base image get height 2 again iterate over all pixels for int x 0 x base image get width x for int y 0 y base image get height y int relx x width middle int rely y height middle double d1 math sqrt relx relx rely rely if d1 distance int j2 width middle int fish eye formula d1 distance distance d1 double x width middle int k2 height middle int fish eye formula d1 distance distance d1 double y height middle base image setrgb x y pix j2 image height k2 return base image baseimage bufferedimage getdistortedimage bufferedimage baseimage baseimage getgraphics imageheight baseimage getheight imagewidth baseimage getwidth horizontallines imageheight verticallines imagewidth horizontalgaps imageheight horizontallines verticalgaps imagewidth verticallines horizontalgaps imageheight horizontalgaps setcolor drawline imagewidth verticalgaps imagewidth verticalgaps setcolor drawline imageheight imageheight imagewidth imagewidth imageheight baseimage ranint imagewidth imagewidth widthmiddle baseimage getwidth heightmiddle baseimage getheight baseimage getwidth baseimage getheight widthmiddle heightmiddle widthmiddle fisheyeformula widthmiddle heightmiddle fisheyeformula heightmiddle baseimage imageheight baseimage param i param j return private int ran int int i int j double d math random return int double i double j i 1 d ranint implementation of g s 3 4 s3 3 2 s2 1 4 s with s from 0 to 1 param s return private double fish eye formula double s if s 0 0d return 0 0d if s 1 0d return s else return 0 75d s s s 1 5d s s 0 25d s fisheyeformula private config config null public config get config return this config getconfig public void set config config config this config config setconfig public class seed client peer node extends peer node public seed client peer node simple field set fs node node2 node crypto crypto peer manager peers boolean from local boolean no sig outgoing packet mangler mangler throws fs parse exception peer parse exception reference signature verification exception super fs node2 crypto peers from local no sig mangler true seedclientpeernode peernode seedclientpeernode simplefieldset nodecrypto peermanager fromlocal nosig outgoingpacketmangler fsparseexception peerparseexception referencesignatureverificationexception fromlocal nosig override public peer node status get status boolean no heavy return new peer node status this no heavy peernodestatus getstatus noheavy peernodestatus noheavy override public boolean is darknet return false isdarknet override public boolean is opennet return false not exactly isopennet override public boolean is seed return true isseed override public boolean is real connection return false we may be connected to the same node as a seed and as a regular connection isrealconnection override public boolean equals object o if o this return true only equal to seednode of its own type different to an opennet peer node with the same identity if o instanceof seed client peer node return super equals o else return false opennetpeernode seedclientpeernode override public void on success boolean insert boolean ssk ignore onsuccess override public boolean is routing compatible return false isroutingcompatible override public boolean can accept announcements return true canacceptannouncements override public boolean record status return false recordstatus override public boolean handshake unknown initiator return true handshakeunknowninitiator override public int handshake setup type return fnp packet mangler setup opennet seednode handshakesetuptype fnppacketmangler setup_opennet_seednode override public boolean should send handshake return false shouldsendhandshake override public boolean disconnected boolean dump message queue boolean dump trackers boolean ret super disconnected dump message queue dump trackers node peers disconnect this false false false return ret dumpmessagequeue dumptrackers dumpmessagequeue dumptrackers override protected boolean generate identity from pubkey return true generateidentityfrompubkey override protected boolean ignore last good version return true ignorelastgoodversion override void startark fetcher do not start an ark fetcher startarkfetcher override public boolean should disconnect and remove now if is connected seed client peer node s always start off unverified if it doesn t manage to connect in 60 seconds dump it however we don t want to be dumped before we connect so we need to check that first synchronize to avoid messy races synchronized this if time last connection completed 0 system current time millis last received packet time 60 1000 return true else disconnect after an hour in any event if system current time millis time last connection completed 60 60 1000 return true return false shoulddisconnectandremovenow isconnected seedclientpeernode timelastconnectioncompleted currenttimemillis lastreceivedpackettime currenttimemillis timelastconnectioncompleted plugin respirator pr private static final string plug name test gallery public void terminate goon false pluginrespirator plugname testgallery private string get array element string array int element try return array element catch exception e e print stack trace return getarrayelement printstacktrace public string handlehttp post http request request throws pluginhttp exception return null handlehttppost httprequest pluginhttpexception private string mk default page string builder out new string builder out append html head title plug name title head body n out append center h1 plug name h1 br br br n out append load gallery from the following key br out append form method get out append input type text name uri value default gallery uri size 80 out append input type submit value go form n out append center body html return out to string mkdefaultpage stringbuilder stringbuilder plugname plugname default_gallery_uri tostring public string handlehttp get http request request throws pluginhttp exception string builder out new string builder int page request get int param page 1 string uri request get param uri request get path if uri equals return mk default page try int i 0 cache later high level simple client hlsc pr gethl simple client string imglist new string hlsc fetch new freeneturi uri as byte array trim imglist imglist replace all r n imglist imglist replace all n n n imglist imglist replace all n n n imglist imglist replace all n n n imglist imglist replace all n n n imglist imglist replace all n n n cache string imgarr imglist split n string title imgarr 0 trim replace all freenet index of 3 untitled imgarr i imgarr 0 title out append html head title append title append title head body n out append center h1 append title append h1 br page append page append br br n mk page index out imgarr length page uri out append table tr n int images 0 int flush page 1 6 4 for i 1 i imgarr length images 6 4 i url name size if imgarr i trim length 5 continue if flush 0 flush continue images string imginfo imgarr i split string iname get array element imginfo 1 trim string isname iname if iname length 15 isname iname substring 0 11 iname substring iname last index of f2 echo f rev cut d f2 rev cut c 13 echo f rev cut d f1 rev string isize get array element imginfo 2 trim string iurl get array element imginfo 0 trim iurl iurl replace all uri iurl iurl replace all freenet if iurl starts with iurl iurl out append td align center valign top width 102px n out append a title append iname append href append iurl append img src append iurl append border 0 width 100 br n if imginfo length 1 out append font size 2 append isname append font n out append a n for int j 2 j imginfo length j out append br font size 2 append imginfo j trim append font n out append td n new row if i 6 0 out append tr tr n out append tr table n mk page index out imgarr length page uri out append center body html return out to string catch exception e todo auto generated catch block return e to string e print stack trace handlehttpget httprequest pluginhttpexception stringbuilder stringbuilder getintparam getparam getpath mkdefaultpage highlevelsimpleclient gethlsimpleclient asbytearray replaceall replaceall replaceall replaceall replaceall replaceall replaceall indexof mkpageindex getarrayelement lastindexof getarrayelement getarrayelement replaceall replaceall startswith mkpageindex tostring tostring printstacktrace private void mk page index string builder out int imgarrlength int page string uri for int pg 1 pg int math ceil imgarrlength 1 6 4 pg out append nbsp if pg page out append a href append uri append page append pg append append pg append a else out append append pg append out append nbsp n mkpageindex stringbuilder public void run plugin plugin respirator pr this pr pr while goon try thread sleep 300000 catch interrupted exception e runplugin pluginrespirator interruptedexception private static final long serial versionuid 4071292828166415028l public ssdp search socket list serialversionuid ssdpsearchsocketlist public ssdp search socket getssdp search socket int n return ssdp search socket get n ssdpsearchsocket getssdpsearchsocket ssdpsearchsocket public void add search listener search listener listener int n servers size for int n 0 n n servers n ssdp search socket sock getssdp search socket n sock add search listener listener addsearchlistener searchlistener nservers nservers ssdpsearchsocket getssdpsearchsocket addsearchlistener public boolean open int n host addrs host interface getn host addresses for int n 0 n n host addrs n string bind addr host interface get host address n ssdp search socket ssdp search socket new ssdp search socket bind addr add ssdp search socket return true nhostaddrs hostinterface getnhostaddresses nhostaddrs bindaddr hostinterface gethostaddress ssdpsearchsocket ssdpsearchsocket ssdpsearchsocket bindaddr ssdpsearchsocket public void close int n sockets size for int n 0 n n sockets n ssdp search socket sock getssdp search socket n sock close clear nsockets nsockets ssdpsearchsocket getssdpsearchsocket public void start int n sockets size for int n 0 n n sockets n ssdp search socket sock getssdp search socket n sock start nsockets nsockets ssdpsearchsocket getssdpsearchsocket public void stop int n sockets size for int n 0 n n sockets n ssdp search socket sock getssdp search socket n sock stop nsockets nsockets ssdpsearchsocket getssdpsearchsocket public article parser author name null author domain null title null date null boards null reply to board null parentid null text null articleparser authorname authordomain replytoboard public string get author name return author name getauthorname authorname public string get author domain return author domain getauthordomain authordomain public string get title return title gettitle public list string get boards return boards getboards public string get reply to board return reply to board getreplytoboard replytoboard public string get parentid throws no such field exception if parentid null throw new no such field exception fixme also throw this in the other getter functions return parentid getparentid nosuchfieldexception nosuchfieldexception public string get text return text gettext public content type string type string subtype string charset string boundary this type type this subtype subtype this charset charset this boundary boundary contenttype parse a content type header public static content type parse header string hdr header tokenizer tokenizer new header tokenizer hdr true true content type result new content type null null us ascii null if tokenizer get token 0 return null result type tokenizer get token text if tokenizer get token return null if tokenizer get token 0 return null result subtype tokenizer get token text while tokenizer get token if tokenizer get token 0 break string param tokenizer get token text if tokenizer get token break if tokenizer get token 0 break string value tokenizer get token text if param equals ignore case charset result charset value else if param equals ignore case boundary result boundary value return result contenttype parseheader headertokenizer headertokenizer contenttype contenttype gettoken gettokentext gettoken gettoken gettokentext gettoken gettoken gettokentext gettoken gettoken gettokentext equalsignorecase equalsignorecase public mailbox string name string local string domain this name name this local local this domain domain parse a from header and extract the first address this does not fully parse the header so it will accept strings that are not actually valid mailing addresses public static mailbox parse header string hdr header tokenizer tokenizer new header tokenizer hdr string name null local null domain null string builder current new string builder boolean in domain false in angles false while tokenizer tokens remaining int c tokenizer get token if c if in domain return null local current to string in domain true current new string builder else if c current append else if c 0 string word tokenizer get token text current append word else if c if in angles in domain return null name current to string in angles true current new string builder else if in domain c in angles false break else if in domain c c break else name local domain null in domain in angles false current new string builder if in domain in angles domain current to string return new mailbox name local domain else return null parseheader headertokenizer headertokenizer stringbuilder stringbuilder indomain inangles tokensremaining gettoken indomain tostring indomain stringbuilder gettokentext inangles indomain tostring inangles stringbuilder indomain inangles indomain indomain inangles stringbuilder indomain inangles tostring parse a newsgroups or follow to header and return a list of newsgroup names private static array list string parse newsgroups string hdr header tokenizer tokenizer new header tokenizer hdr false false array list string result new array list string while tokenizer tokens remaining int c tokenizer get token if c 0 string name tokenizer get token text string board name freetalknntp group group to board name name if board is name valid board name result add board name return result arraylist parsenewsgroups headertokenizer headertokenizer arraylist arraylist tokensremaining gettoken gettokentext boardname freetalknntpgroup grouptoboardname isnamevalid boardname boardname parse a references header and return a list of message i ds private static array list string parse references string hdr header tokenizer tokenizer new header tokenizer hdr string builder current null array list string result new array list string while tokenizer tokens remaining int c tokenizer get token if c current new string builder else if c if current null result add current to string current null else if c 0 if current null current append tokenizer get token text else if c 0 if current null current append char c return result ids arraylist parsereferences headertokenizer headertokenizer stringbuilder arraylist arraylist tokensremaining gettoken stringbuilder tostring gettokentext decode any encoded words in the header as per rfc 2047 private static string decodemime header string str string builder result new string builder matcher matcher encoded word pattern matcher str int pos 0 while matcher find string charset name matcher group 1 string encoding name matcher group 2 string data matcher group 3 result append str substring pos matcher start try charset charset charset for name charset name transfer encoding encoding transfer encoding header word encoding encoding name byte encoded bytes data get bytes us ascii byte buffer decoded bytes encoding decode byte buffer wrap encoded bytes result append charset decode decoded bytes catch exception e result append matcher group pos matcher end result append str substring pos return result to string decodemimeheader stringbuilder stringbuilder encodedwordpattern charsetname encodingname forname charsetname transferencoding transferencoding headerwordencoding encodingname encodedbytes getbytes bytebuffer decodedbytes bytebuffer encodedbytes decodedbytes tostring get the named header contents private static string get header string head lines string name int i j for i 0 i head lines length i for j 0 j name length j head lines i length j if name char at j character to lower case head lines i char at j break if j name length continue while j head lines i length head lines i char at j head lines i char at j t j if j head lines i length head lines i char at j continue j skip initial whitespace while j head lines i length head lines i char at j head lines i char at j t j string builder result new string builder decodemime header head lines i substring j find continuation lines i while i head lines length head lines i length 0 head lines i char at 0 head lines i char at 0 t result append n result append decodemime header head lines i i return result to string return null getheader headlines headlines headlines charat tolowercase headlines charat headlines headlines charat headlines charat headlines headlines charat headlines headlines charat headlines charat stringbuilder stringbuilder decodemimeheader headlines headlines headlines headlines charat headlines charat decodemimeheader headlines tostring parse the message body private void parse body byte buffer bytes content type type string encoding name fixme handle multi part content upload non text parts as attachments etc charset body charset try body charset charset for name type charset catch illegal argument exception e body charset charset for name utf 8 try transfer encoding encoding transfer encoding body encoding encoding name byte buffer decoded bytes encoding decode bytes text body charset decode decoded bytes to string catch exception e text body charset decode bytes to string parsebody bytebuffer contenttype encodingname bodycharset bodycharset forname illegalargumentexception bodycharset forname transferencoding transferencoding bodyencoding encodingname bytebuffer decodedbytes bodycharset decodedbytes tostring bodycharset tostring parse a complete message the input is given as a byte buffer since we do not know what encoding has been used until we parse the header return true if the message was parsed successfully public boolean parse message byte buffer bytes split up message into head body byte buffer head bytes body bytes boolean linestart true find the blank line separating head from body while bytes has remaining byte b bytes get if bytes has remaining b r b bytes get if b n if linestart break else linestart true else linestart false if bytes has remaining logger debug this unable to find start of message body return false save remaining unread bytes in body bytes body bytes bytes slice and previous bytes in head bytes bytes flip head bytes bytes slice first try decoding headers as utf 8 charset utf8 charset for name utf 8 string headutf8 utf8 decode head bytes to string string head lines headutf8 split r n read newsgroups followup to and references headers string newsgroups header get header head lines newsgroups string followup to header get header head lines followup to string references header get header head lines references string in reply to header get header head lines in reply to string transfer encoding header get header head lines content transfer encoding if newsgroups header null logger debug this unable to find newsgroups header return false read content type header string type header get header head lines content type content type body type null if type header null body type content type parse header type header if body type null body type new content type text plain utf 8 null and then try decoding the headers again using the body charset charset body charset try body charset charset for name body type charset catch illegal argument exception e body charset charset for name utf 8 head bytes rewind string head body charset decode head bytes to string head lines head split r n read from and subject headers using the body charset string from header get header head lines from string subject header get header head lines subject if from header null logger debug this unable to find from header return false if subject header null logger debug this unable to find subject header return false try using the body charset for newsgroups and followup to if utf 8 didn t work if newsgroups header index of 0xfffd 1 followup to header null followup to header index of 0xfffd 1 newsgroups header get header head lines newsgroups followup to header get header head lines followup to mailbox addr mailbox parse header from header if addr null logger debug this unable to parse from header return false author name addr local author domain addr domain title message make title valid subject header boards parse newsgroups newsgroups header if followup to header null array list string followups parse newsgroups followup to header if followups is empty reply to board followups get 0 if in reply to header null array list string refs parse references in reply to header if refs is empty parentid refs get refs size 1 else if references header null array list string refs parse references references header if refs is empty parentid refs get refs size 1 if transfer encoding header null parse body body bytes body type transfer encoding header else parse body body bytes body type 8bit return true parsemessage bytebuffer bytebuffer headbytes bodybytes hasremaining hasremaining hasremaining bodybytes bodybytes headbytes headbytes forname headbytes tostring headlines newsgroupsheader getheader headlines followuptoheader getheader headlines referencesheader getheader headlines inreplytoheader getheader headlines transferencodingheader getheader headlines newsgroupsheader typeheader getheader headlines contenttype bodytype typeheader bodytype contenttype parseheader typeheader bodytype bodytype contenttype bodycharset bodycharset forname bodytype illegalargumentexception bodycharset forname headbytes bodycharset headbytes tostring headlines fromheader getheader headlines subjectheader getheader headlines fromheader subjectheader newsgroupsheader indexof followuptoheader followuptoheader indexof newsgroupsheader getheader headlines followuptoheader getheader headlines parseheader fromheader authorname authordomain maketitlevalid subjectheader parsenewsgroups newsgroupsheader followuptoheader arraylist parsenewsgroups followuptoheader isempty replytoboard inreplytoheader arraylist parsereferences inreplytoheader isempty referencesheader arraylist parsereferences referencesheader isempty transferencodingheader parsebody bodybytes bodytype transferencodingheader parsebody bodybytes bodytype static void make kleinberg network node nodes boolean ideal locations int degree boolean force neighbour connections if ideal locations first set the locations up so we don t spend a long time swapping just to stabilise each network double div 1 0 nodes length double loc 0 0 for int i 0 i nodes length i nodes i set location loc loc div if force neighbour connections for int i 0 i nodes length i int next i 1 nodes length connect nodes i nodes next for int i 0 i nodes length i node a nodes i normalise the probabilities double norm 0 0 for int j 0 j nodes length j node b nodes j if a get location b get location continue norm 1 0 distance a b create degree 2 outgoing connections for int k 0 k nodes length k node b nodes k if a get location b get location continue double p 1 0 distance a b norm for int n 0 n degree 2 n if math random p connect a b break makekleinbergnetwork ideallocations forceneighbourconnections ideallocations setlocation forceneighbourconnections getlocation getlocation getlocation getlocation static void connect node a node b try a connect b b connect a catch fs parse exception e logger error real node secret ping test class cannot connect e catch peer parse exception e logger error real node secret ping test class cannot connect 2 e catch freenet io comm reference signature verification exception e logger error real node secret ping test class cannot connect 3 e fsparseexception realnodesecretpingtest peerparseexception realnodesecretpingtest referencesignatureverificationexception realnodesecretpingtest static double distance node a node b double al a get location double bl b get location return location distance al bl getlocation getlocation static string get port number peer node p if p null p get peer null return null return integer to string p get peer get port getportnumber peernode getpeer tostring getpeer getport static string get port number node n if n null return null return integer to string n get darknet port number getportnumber tostring getdarknetportnumber static void wait for all connected node nodes throws interrupted exception long t start system current time millis while true int count fully connected 0 int count really connected 0 int total peers 0 int total connections 0 int total partial connections 0 int total compatible connections 0 int total backed off 0 double total ping time 0 0 double max ping time 0 0 double min ping time double max value for int i 0 i nodes length i int count connected nodes i peers count connected darknet peers int count almost connected nodes i peers count almost connected darknet peers int count total nodes i peers count valid peers int count backed off nodes i peers count backed off peers int count compatible nodes i peers count compatible darknet peers total peers count total total connections count connected total partial connections count almost connected total compatible connections count compatible total backed off count backed off double ping time nodes i node stats get node average ping time total ping time ping time if ping time max ping time max ping time ping time if ping time min ping time min ping time ping time if count connected count total count fully connected if count backed off 0 count really connected else if logger should log logger minor real node test class logger minor real node test class connection count for nodes i count connected partial count almost connected if count backed off 0 if logger should log logger minor real node test class logger minor real node test class backed off nodes i count backed off double avg ping time total ping time nodes length if count fully connected nodes length count really connected nodes length min ping time node stats sub max ping time max ping time node stats sub max ping time avg ping time node stats sub max ping time system err println all nodes fully connected logger normal real node test class all nodes fully connected system err println return else long t delta system current time millis t start 1000 system err println waiting for nodes to be fully connected count fully connected nodes length total connections total peers connections total partial total partial connections compatible total compatible connections backed off total backed off ping min avg max int min ping time int avg ping time int max ping time at t delta s logger normal real node test class waiting for nodes to be fully connected count fully connected nodes length total connections total peers connections total partial total partial connections compatible total compatible connections backed off total backed off ping min avg max int min ping time int avg ping time int max ping time at t delta s thread sleep 1000 waitforallconnected interruptedexception tstart currenttimemillis countfullyconnected countreallyconnected totalpeers totalconnections totalpartialconnections totalcompatibleconnections totalbackedoff totalpingtime maxpingtime minpingtime max_value countconnected countconnecteddarknetpeers countalmostconnected countalmostconnecteddarknetpeers counttotal countvalidpeers countbackedoff countbackedoffpeers countcompatible countcompatibledarknetpeers totalpeers counttotal totalconnections countconnected totalpartialconnections countalmostconnected totalcompatibleconnections countcompatible totalbackedoff countbackedoff pingtime nodestats getnodeaveragepingtime totalpingtime pingtime pingtime maxpingtime maxpingtime pingtime pingtime minpingtime minpingtime pingtime countconnected counttotal countfullyconnected countbackedoff countreallyconnected shouldlog realnodetest realnodetest countconnected countalmostconnected countbackedoff shouldlog realnodetest realnodetest countbackedoff avgpingtime totalpingtime countfullyconnected countreallyconnected minpingtime nodestats sub_max_ping_time maxpingtime nodestats sub_max_ping_time avgpingtime nodestats sub_max_ping_time realnodetest tdelta currenttimemillis tstart countfullyconnected totalconnections totalpeers totalpartialconnections totalcompatibleconnections totalbackedoff minpingtime avgpingtime maxpingtime tdelta realnodetest countfullyconnected totalconnections totalpeers totalpartialconnections totalcompatibleconnections totalbackedoff minpingtime avgpingtime maxpingtime tdelta public get request status message simple field set fs this identifier fs get identifier this global fields string to bool fs get global false this only data fields string to bool fs get only data false getrequeststatusmessage simplefieldset stringtobool onlydata stringtobool onlydata override public simple field set get field set simple field set fs new simple field set true fs put single identifier identifier return fs simplefieldset getfieldset simplefieldset simplefieldset putsingle override public string get name return name getname override public void run final fcp connection handler handler node node throws message invalid exception client request req handler get reboot request global handler identifier if req null node client core client context job runner queue new db job public void run object container container client context context client request req handler get forever request global handler identifier container container activate req 1 if req null protocol error message msg new protocol error message protocol error message no such identifier false null identifier global handler output handler queue msg else req send pending messages handler output handler true true only data container container deactivate req 1 native thread norm priority false else req send pending messages handler output handler true true only data null fcpconnectionhandler messageinvalidexception clientrequest getrebootrequest clientcore clientcontext jobrunner dbjob objectcontainer clientcontext clientrequest getforeverrequest protocolerrormessage protocolerrormessage protocolerrormessage no_such_identifier outputhandler sendpendingmessages outputhandler onlydata nativethread norm_priority sendpendingmessages outputhandler onlydata public void run object container container client context context client request req handler get forever request global handler identifier container container activate req 1 if req null protocol error message msg new protocol error message protocol error message no such identifier false null identifier global handler output handler queue msg else req send pending messages handler output handler true true only data container container deactivate req 1 objectcontainer clientcontext clientrequest getforeverrequest protocolerrormessage protocolerrormessage protocolerrormessage no_such_identifier outputhandler sendpendingmessages outputhandler onlydata override public void remove from object container container container delete this removefrom objectcontainer private static final long serial versionuid 1 node init exception int exit code string msg super msg exit code this exit code exit code serialversionuid nodeinitexception exitcode exitcode exitcode exitcode private static final long serial versionuid 1 public ssk decode exception string string super string serialversionuid sskdecodeexception node crypto config sub config config int sort order boolean is opennet security levels security levels throws node init exception config register listen port 1 means random sort order true true node port node port long new int callback override public integer get synchronized node crypto config class if crypto null port number crypto port number return port number override public void set integer val throws invalid config value exception if port number 1 port number 0 port number 65535 throw new invalid config value exception invalid port number synchronized node crypto config class if port number val return fixme implement on the fly listen port changing note that this sort of thing should be the exception rather than the rule if crypto null throw new invalid config value exception switching listen port on the fly not yet supported port number val override public boolean is read only return true false try port number config get int listen port catch exception e fixme is this really necessary logger error this caught e e system err println e e print stack trace port number 1 config register bind to 0 0 0 0 sort order true true node bind to node bind to long new node bindto callback try bind to new freenet inet address config get string bind to false catch unknown host exception e throw new node init exception node init exception exit could not bind usm invalid bind to config get string bind to config register testing drop packets every 0 sort order true false node drop packet every node drop packet every long new int callback override public integer get synchronized node crypto config this return drop probability override public void set integer val throws invalid config value exception if val 0 throw new invalid config value exception testing drop packets every must not be negative synchronized node crypto config this if val drop probability return drop probability val if crypto null return crypto on set drop probability val false drop probability config get int testing drop packets every config register one connection perip is opennet sort order true false node one connection perip node one connection perip long new boolean callback override public boolean get synchronized node crypto config this return one connection per address override public void set boolean val throws invalid config value exception synchronized node crypto config this one connection per address val one connection per address config get boolean one connection perip if is opennet security levels add network threat level listener new security level listener network threat level public void on change network threat level old level network threat level new level might be useful for nodes on the same nat etc so turn it off for low otherwise is sensible it s always off on darknet since we can reasonably expect to know our peers even if we are paranoid about them if new level network threat level low one connection per address false if old level network threat level low one connection per address true config register always allow local addresses is opennet sort order true false node always allow local addresses node always allow local addresses long new boolean callback override public boolean get synchronized node crypto config this return always allow local addresses override public void set boolean val throws invalid config value exception synchronized node crypto config this always allow local addresses val always allow local addresses config get boolean always allow local addresses if is opennet security levels add friends threat level listener new security level listener friends threat level public void on change friends threat level old level friends threat level new level if new level friends threat level high always allow local addresses false if old level friends threat level high always allow local addresses false config register assumena ted true sort order true true node assumena ted node assumena ted long new boolean callback override public boolean get return assumena ted override public void set boolean val throws invalid config value exception assumena ted val assumena ted config get boolean assumena ted include local i ps in noderef file config register include local addresses in noderefs is opennet sort order true false nodeip dectector incl local address nodeip dectector incl local address long new boolean callback override public boolean get return include local addresses in noderefs override public void set boolean val throws invalid config value exception include local addresses in noderefs val include local addresses in noderefs config get boolean include local addresses in noderefs enable disable padding of outgoing packets won t affect auth packets config register padd data packets true sort order true false node padd data packets node padd data packets long new boolean callback override public boolean get return padd data packets override public void set boolean val throws invalid config value exception node need restart exception if val equals get return padd data packets val padd data packets config get boolean padd data packets security levels add network threat level listener new security level listener network threat level public void on change network threat level old level network threat level new level might be useful for nodes which are running with a tight bandwidth quota to minimize the overhead so turn it off for low otherwise is sensible if new level network threat level low padd data packets false if old level network threat level low padd data packets true nodecryptoconfig subconfig sortorder isopennet securitylevels securitylevels nodeinitexception listenport sortorder portlong intcallback nodecryptoconfig portnumber portnumber portnumber invalidconfigvalueexception portnumber portnumber portnumber invalidconfigvalueexception nodecryptoconfig portnumber listenport invalidconfigvalueexception listenport portnumber isreadonly portnumber getint listenport printstacktrace portnumber bindto sortorder bindto bindtolong nodebindtocallback bindto freenetinetaddress getstring bindto unknownhostexception nodeinitexception nodeinitexception exit_could_not_bind_usm bindto getstring bindto testingdroppacketsevery sortorder droppacketevery droppacketeverylong intcallback nodecryptoconfig dropprobability invalidconfigvalueexception invalidconfigvalueexception testingdroppacketsevery nodecryptoconfig dropprobability dropprobability onsetdropprobability dropprobability getint testingdroppacketsevery oneconnectionperip isopennet sortorder oneconnectionperip oneconnectionperiplong booleancallback nodecryptoconfig oneconnectionperaddress invalidconfigvalueexception nodecryptoconfig oneconnectionperaddress oneconnectionperaddress getboolean oneconnectionperip isopennet securitylevels addnetworkthreatlevellistener securitylevellistener network_threat_level onchange network_threat_level oldlevel network_threat_level newlevel newlevel network_threat_level oneconnectionperaddress oldlevel network_threat_level oneconnectionperaddress alwaysallowlocaladdresses isopennet sortorder alwaysallowlocaladdresses alwaysallowlocaladdresseslong booleancallback nodecryptoconfig alwaysallowlocaladdresses invalidconfigvalueexception nodecryptoconfig alwaysallowlocaladdresses alwaysallowlocaladdresses getboolean alwaysallowlocaladdresses isopennet securitylevels addfriendsthreatlevellistener securitylevellistener friends_threat_level onchange friends_threat_level oldlevel friends_threat_level newlevel newlevel friends_threat_level alwaysallowlocaladdresses oldlevel friends_threat_level alwaysallowlocaladdresses assumenated sortorder assumenated assumenatedlong booleancallback assumenated invalidconfigvalueexception assumenated assumenated getboolean assumenated ips includelocaladdressesinnoderefs isopennet sortorder nodeipdectector incllocaladdress nodeipdectector incllocaladdresslong booleancallback includelocaladdressesinnoderefs invalidconfigvalueexception includelocaladdressesinnoderefs includelocaladdressesinnoderefs getboolean includelocaladdressesinnoderefs padddatapackets sortorder padddatapackets padddatapacketslong booleancallback padddatapackets invalidconfigvalueexception nodeneedrestartexception padddatapackets padddatapackets getboolean padddatapackets securitylevels addnetworkthreatlevellistener securitylevellistener network_threat_level onchange network_threat_level oldlevel network_threat_level newlevel newlevel network_threat_level padddatapackets oldlevel network_threat_level padddatapackets config register listen port 1 means random sort order true true node port node port long new int callback override public integer get synchronized node crypto config class if crypto null port number crypto port number return port number listenport sortorder portlong intcallback nodecryptoconfig portnumber portnumber portnumber override public void set integer val throws invalid config value exception if port number 1 port number 0 port number 65535 throw new invalid config value exception invalid port number synchronized node crypto config class if port number val return fixme implement on the fly listen port changing note that this sort of thing should be the exception rather than the rule if crypto null throw new invalid config value exception switching listen port on the fly not yet supported port number val invalidconfigvalueexception portnumber portnumber portnumber invalidconfigvalueexception nodecryptoconfig portnumber listenport invalidconfigvalueexception listenport portnumber override public boolean is read only return true isreadonly override public integer get synchronized node crypto config this return drop probability nodecryptoconfig dropprobability override public void set integer val throws invalid config value exception if val 0 throw new invalid config value exception testing drop packets every must not be negative synchronized node crypto config this if val drop probability return drop probability val if crypto null return crypto on set drop probability val invalidconfigvalueexception invalidconfigvalueexception testingdroppacketsevery nodecryptoconfig dropprobability dropprobability onsetdropprobability override public boolean get synchronized node crypto config this return one connection per address nodecryptoconfig oneconnectionperaddress override public void set boolean val throws invalid config value exception synchronized node crypto config this one connection per address val invalidconfigvalueexception nodecryptoconfig oneconnectionperaddress public void on change network threat level old level network threat level new level might be useful for nodes on the same nat etc so turn it off for low otherwise is sensible it s always off on darknet since we can reasonably expect to know our peers even if we are paranoid about them if new level network threat level low one connection per address false if old level network threat level low one connection per address true onchange network_threat_level oldlevel network_threat_level newlevel newlevel network_threat_level oneconnectionperaddress oldlevel network_threat_level oneconnectionperaddress override public boolean get synchronized node crypto config this return always allow local addresses nodecryptoconfig alwaysallowlocaladdresses override public void set boolean val throws invalid config value exception synchronized node crypto config this always allow local addresses val invalidconfigvalueexception nodecryptoconfig alwaysallowlocaladdresses public void on change friends threat level old level friends threat level new level if new level friends threat level high always allow local addresses false if old level friends threat level high always allow local addresses false onchange friends_threat_level oldlevel friends_threat_level newlevel newlevel friends_threat_level alwaysallowlocaladdresses oldlevel friends_threat_level alwaysallowlocaladdresses config register assumena ted true sort order true true node assumena ted node assumena ted long new boolean callback override public boolean get return assumena ted assumenated sortorder assumenated assumenatedlong booleancallback assumenated override public void set boolean val throws invalid config value exception assumena ted val invalidconfigvalueexception assumenated config register include local addresses in noderefs is opennet sort order true false nodeip dectector incl local address nodeip dectector incl local address long new boolean callback override public boolean get return include local addresses in noderefs includelocaladdressesinnoderefs isopennet sortorder nodeipdectector incllocaladdress nodeipdectector incllocaladdresslong booleancallback includelocaladdressesinnoderefs override public void set boolean val throws invalid config value exception include local addresses in noderefs val invalidconfigvalueexception includelocaladdressesinnoderefs config register padd data packets true sort order true false node padd data packets node padd data packets long new boolean callback override public boolean get return padd data packets padddatapackets sortorder padddatapackets padddatapacketslong booleancallback padddatapackets override public void set boolean val throws invalid config value exception node need restart exception if val equals get return padd data packets val invalidconfigvalueexception nodeneedrestartexception padddatapackets public void on change network threat level old level network threat level new level might be useful for nodes which are running with a tight bandwidth quota to minimize the overhead so turn it off for low otherwise is sensible if new level network threat level low padd data packets false if old level network threat level low padd data packets true onchange network_threat_level oldlevel network_threat_level newlevel newlevel network_threat_level padddatapackets oldlevel network_threat_level padddatapackets public static final int option count 3 synchronized void starting node crypto crypto2 if crypto null throw new illegal state exception replacing existing node crypto crypto with crypto2 crypto crypto2 option_count nodecrypto illegalstateexception nodecrypto synchronized void started node crypto crypto2 if crypto null throw new illegal state exception replacing existing node crypto crypto with crypto2 nodecrypto illegalstateexception nodecrypto synchronized void maybe started node crypto crypto2 maybestarted nodecrypto synchronized void stopping node crypto crypto2 crypto null nodecrypto public synchronized int get port return port number getport portnumber class node bindto callback extends string callback override public string get return bind to to string nodebindtocallback stringcallback bindto tostring override public void set string val throws invalid config value exception if val equals get return fixme why not can t we use freenet io network interface like everywhere else just adapt it for udp throw new invalid config value exception cannot be updated on the fly invalidconfigvalueexception networkinterface invalidconfigvalueexception throw new invalid config value exception cannot be updated on the fly override public boolean is read only return true invalidconfigvalueexception isreadonly public synchronized freenet inet address get bind to return bind to freenetinetaddress getbindto bindto public synchronized void set port int port port number port setport portnumber public synchronized int get drop probability return drop probability getdropprobability dropprobability public synchronized boolean one connection per address return one connection per address oneconnectionperaddress oneconnectionperaddress public synchronized boolean always allow local addresses return always allow local addresses alwaysallowlocaladdresses alwaysallowlocaladdresses public boolean always handshake aggressively return assumena ted alwayshandshakeaggressively assumenated public boolean include local addresses in noderefs return include local addresses in noderefs includelocaladdressesinnoderefs includelocaladdressesinnoderefs public boolean padd data packets return padd data packets padddatapackets padddatapackets protected string name public string get name return name getname protected void set name string s name s length 0 s l10n get string bookmark no name setname getstring noname override public boolean equals object o if o this return true if o instanceof bookmark bookmark b bookmark o if b name equals name return false return true else return false override public int hash code return name hash code hashcode hashcode public abstract simple field set get simple field set simplefieldset getsimplefieldset private static final long serial versionuid 1l public no such identity exception super serialversionuid nosuchidentityexception public no such identity exception string id super unknown identity id id nosuchidentityexception override public boolean equals object o if o instanceof ssk block return false ssk block block ssk block o if block pub key equals pub key return false if block node key equals node key return false if block headers offset headers offset return false if block hash identifier hash identifier return false if block sym cipher identifier sym cipher identifier return false only compare some of the headers see top for int i 0 i header compare to i if block headers i headers i return false if arrays equals block headers headers return false if arrays equals block data data return false return true sskblock sskblock sskblock pubkey pubkey nodekey nodekey headersoffset headersoffset hashidentifier hashidentifier symcipheridentifier symcipheridentifier header_compare_to override public int hash code return hash code hashcode hashcode initialize and verify data headers against key provided key must have a pubkey or we throw public ssk block byte data byte headers nodessk node key boolean dont verify throws ssk verify exception if headers length total headers length throw new illegal argument exception headers length headers length should be total headers length this data data this headers headers this node key node key if data length data length throw new ssk verify exception data length wrong data length should be data length this pub key node key get pub key if pub key null throw new ssk verify exception pub key was null from node key message digest md sha256 get message digest now verify it hash identifier short headers 0 0xff 8 headers 1 0xff if hash identifier hash sha256 throw new ssk verify exception hash not sha 256 int x 2 sym cipher identifier short headers x 0xff 8 headers x 1 0xff x 2 then e h docname byte eh docname new byte e h docname length system arraycopy headers x eh docname 0 eh docname length x e h docname length headers offset x is index to start of encrypted headers x encrypted headers length extract the signature byte bufr new byte sig r length byte bufs new byte sig s length if x sig r length sig s length headers length throw new ssk verify exception headers too short headers length should be at least x sig r length sig s length if dont verify system arraycopy headers x bufr 0 sig r length x sig r length if dont verify system arraycopy headers x bufs 0 sig s length x sig s length compute the hash on the data if dont verify md update data byte data hash md digest all headers up to and not including the signature md update headers 0 headers offset encrypted headers length then the implicit data hash md update data hash makes the implicit overall hash byte overall hash md digest now verify it native big integer r new native big integer 1 bufr native big integer s new native big integer 1 bufs if dsa verify pub key new dsa signature r s new native big integer 1 overall hash false dsa verify pub key new dsa signature r s new native big integer 1 overall hash true throw new ssk verify exception signature verification failed for node level ssk if arrays equals eh docname node key encrypted hashed docname throw new ssk verify exception e h docname wrong wrong key nfrom headers hex util bytes to hex eh docname nfrom key hex util bytes to hex node key encrypted hashed docname sha256 return message digest md hash code fields hash code data fields hash code headers node key hash code pub key hash code hash identifier sskblock nodekey dontverify sskverifyexception total_headers_length illegalargumentexception total_headers_length nodekey nodekey data_length sskverifyexception data_length pubkey nodekey getpubkey pubkey sskverifyexception pubkey nodekey messagedigest getmessagedigest hashidentifier hashidentifier hash_sha256 sskverifyexception symcipheridentifier ehdocname e_h_docname_length ehdocname ehdocname e_h_docname_length headersoffset encrypted_headers_length sig_r_length sig_s_length sig_r_length sig_s_length sskverifyexception sig_r_length sig_s_length dontverify sig_r_length sig_r_length dontverify sig_s_length sig_s_length dontverify datahash headersoffset encrypted_headers_length datahash overallhash nativebiginteger nativebiginteger nativebiginteger nativebiginteger pubkey dsasignature nativebiginteger overallhash pubkey dsasignature nativebiginteger overallhash sskverifyexception ehdocname nodekey encryptedhasheddocname sskverifyexception hexutil bytestohex ehdocname hexutil bytestohex nodekey encryptedhasheddocname returnmessagedigest hashcode hashcode hashcode nodekey hashcode pubkey hashcode hashidentifier public key get key return node key getkey nodekey public byte get raw headers return headers getrawheaders public byte get raw data return data getrawdata public dsa public key get pub key return pub key dsapublickey getpubkey pubkey public byte get pubkey bytes return pub key as bytes getpubkeybytes pubkey asbytes public byte get full key return get key get full key getfullkey getkey getfullkey public byte get routing key return get key get routing key getroutingkey getkey getroutingkey public boolean object can new object container container storing an ssk block is not supported there are some complications so lets not implement this since we don t actually use the functionality atm the major problems are in both chk block and ssk block who is responsible for deleting the node keys we have to have them in the objects in ssk block who is responsible for deleting the dsa public key and the dsa group a group might be unique or might be shared between very many ss ks especially in the second case we don t want to just copy every time even for transient uses the best solution may be to copy in object can new but even then callers to the relevant getter methods may be a worry throw new unsupported operation exception block set storage in database not supported objectcannew objectcontainer sskblock chkblock sskblock sskblock dsapublickey dsagroup ssks objectcannew unsupportedoperationexception public plugin talker fred plugin talker fpt node node2 string pluginname2 string connection identifier throws plugin not found exception node node2 plugin name pluginname2 plugin find plugin pluginname2 access fred pluginfcp access direct replysender new plugin reply sender direct node2 fpt pluginname2 connection identifier plugintalker fredplugintalker connectionidentifier pluginnotfoundexception pluginname findplugin fredpluginfcp access_direct pluginreplysenderdirect connectionidentifier public plugin talker node node2 fcp connection handler handler string pluginname2 string connection identifier boolean access2 throws plugin not found exception node node2 plugin name pluginname2 plugin find plugin pluginname2 access access2 fred pluginfcp access fcp full fred pluginfcp access fcp restricted replysender new plugin reply senderfcp handler pluginname2 connection identifier plugintalker fcpconnectionhandler connectionidentifier pluginnotfoundexception pluginname findplugin fredpluginfcp access_fcp_full fredpluginfcp access_fcp_restricted pluginreplysenderfcp connectionidentifier protected fred pluginfcp find plugin string pluginname2 throws plugin not found exception logger normal this searching fcp plugin pluginname2 fred pluginfcp plug node plugin manager getfcp plugin pluginname2 if plug null logger error this could not find fcp plugin pluginname2 throw new plugin not found exception logger normal this found fcp plugin pluginname2 return plug fredpluginfcp findplugin pluginnotfoundexception fredpluginfcp pluginmanager getfcpplugin pluginnotfoundexception public void send final simple field set plugparams final bucket data2 node executor execute new runnable public void run try plugin handle replysender plugparams data2 access catch thread death td throw td fatal thread is stop ed catch virtual machine error vme throw vme oom is included here catch throwable t logger error this cought error while execute fcp plugin handler for plugin name report it to the plugin author t get message t fcp plugin talk runner for this simplefieldset threaddeath virtualmachineerror pluginname getmessage fcpplugin public void run try plugin handle replysender plugparams data2 access catch thread death td throw td fatal thread is stop ed catch virtual machine error vme throw vme oom is included here catch throwable t logger error this cought error while execute fcp plugin handler for plugin name report it to the plugin author t get message t threaddeath virtualmachineerror pluginname getmessage override public void should update logminor logger should log logger minor this logdebug logger should log logger debug this shouldupdate shouldlog shouldlog create a single block inserter param parent param data param compression codec the compression codec param uri param ctx param cb param is metadata param source length the length of the original uncompressed data param token param getchk only param add to parent param dont send encoded param token object param container param context param persistent param free data public single block inserter base client putter parent bucket data short compression codec freeneturi uri insert context ctx put completion callback cb boolean is metadata int source length int token boolean getchk only boolean add to parent boolean dont send encoded object token object object container container client context context boolean persistent boolean free data super persistent assert persistent parent persistent this consecutivern fs 0 this token object token object this token token this parent parent this dont send encoded dont send encoded this retries 0 this finished false this ctx ctx this free data free data errors new failure code tracker true this cb cb this uri uri this compression codec compression codec this source data data if source data null throw new null pointer exception this is metadata is metadata this source length source length this getchk only getchk only isssk uri get key type to upper case equals ssk if add to parent parent add block container parent add must succeed blocks 1 container parent notify clients container context singleblockinserter compressioncodec ismetadata sourcelength getchkonly addtoparent dontsendencoded tokenobject freedata singleblockinserter baseclientputter compressioncodec insertcontext putcompletioncallback ismetadata sourcelength getchkonly addtoparent dontsendencoded tokenobject objectcontainer clientcontext freedata consecutivernfs tokenobject tokenobject dontsendencoded dontsendencoded freedata freedata failurecodetracker compressioncodec compressioncodec sourcedata sourcedata nullpointerexception ismetadata ismetadata sourcelength sourcelength getchkonly getchkonly getkeytype touppercase addtoparent addblock addmustsucceedblocks notifyclients protected client key block inner encode random source random object container container throws insert exception if persistent container activate uri 1 container activate source data 1 try return inner encode random uri source data is metadata compression codec source length catch key encode exception e logger error single block inserter class caught e e throw new insert exception insert exception internal error e null catch malformedurl exception e throw new insert exception insert exception invalid uri e null catch io exception e logger error single block inserter class caught e encoding data source data e throw new insert exception insert exception bucket error e null clientkeyblock innerencode randomsource objectcontainer insertexception sourcedata innerencode sourcedata ismetadata compressioncodec sourcelength keyencodeexception singleblockinserter insertexception insertexception internal_error malformedurlexception insertexception insertexception invalid_uri ioexception singleblockinserter sourcedata insertexception insertexception bucket_error protected static client key block inner encode random source random freeneturi uri bucket source data boolean is metadata short compression codec int source length throws insert exception chk encode exception io exception ssk encode exception malformedurl exception string uri type uri get key type if uri type equals chk return clientchk block encode source data is metadata compression codec 1 compression codec source length else if uri type equals ssk uri type equals ksk insertable clientssk ik insertable clientssk create uri return ik encode source data is metadata compression codec 1 compression codec source length random else throw new insert exception insert exception invalid uri unknown keytype uri type null clientkeyblock innerencode randomsource sourcedata ismetadata compressioncodec sourcelength insertexception chkencodeexception ioexception sskencodeexception malformedurlexception uritype getkeytype uritype clientchkblock sourcedata ismetadata compressioncodec compressioncodec sourcelength uritype uritype insertableclientssk insertableclientssk sourcedata ismetadata compressioncodec compressioncodec sourcelength insertexception insertexception invalid_uri uritype protected void on encode client key key object container container client context context synchronized this if finished return if resultinguri null return resultinguri key geturi if persistent container store this container activate cb 1 cb on encode key this container context if persistent container deactivate cb 1 onencode clientkey objectcontainer clientcontext onencode protected client key block encode object container container client context context boolean called bycb throws insert exception if persistent container activate source data 1 container activate cb 1 client key block block boolean should send synchronized this if finished return null if source data null logger error this source data is null on this but not finished return null block inner encode context random container should send resultinguri null resultinguri block get client key geturi if logminor logger minor this encoded resultinguri for this should send should send dont send encoded dont send encoded if should send dont send encoded cb on encode block get client key this container context if should send persistent container store this if persistent called bycb container deactivate cb 1 return block clientkeyblock objectcontainer clientcontext calledbycb insertexception sourcedata clientkeyblock shouldsend sourcedata innerencode shouldsend getclientkey shouldsend shouldsend dontsendencoded dontsendencoded shouldsend dontsendencoded onencode getclientkey shouldsend calledbycb override public short get priority class object container container if persistent container activate parent 1 return parent get priority class not much point deactivating getpriorityclass objectcontainer getpriorityclass override public int get retry count return retries getretrycount override public void on failure low level put exception e object key num object container container client context context synchronized this if finished return if persistent container activate errors 1 if parent is cancelled fail new insert exception insert exception cancelled container context return if logminor logger minor this on failure on e for this switch e code case low level put exception collision fail new insert exception insert exception collision container context return case low level put exception internal error fail new insert exception insert exception internal error container context return case low level put exception rejected overload errors inc insert exception rejected overload break case low level put exception route not found errors inc insert exception route not found break case low level put exception route really not found errors inc insert exception route really not found break default logger error this unknown low level put exception code e code errors inc insert exception internal error if persistent container activate ctx 1 if e code low level put exception route not found e code low level put exception route really not found consecutivern fs if logminor logger minor this consecutive rn fs consecutivern fs ctx consecutivern fs count as success if consecutivern fs ctx consecutivern fs count as success if logminor logger minor this consecutive rn fs consecutivern fs counting as success on success key num container context return else consecutivern fs 0 if logminor logger minor this failed e retries if retries ctx max insert retries ctx max insert retries 1 fail insert exception construct persistent errors clone errors container context if persistent container deactivate ctx 1 return if persistent container store this container deactivate ctx 1 get scheduler context register insert this persistent false true container onfailure lowlevelputexception keynum objectcontainer clientcontext iscancelled insertexception insertexception onfailure lowlevelputexception insertexception insertexception lowlevelputexception internal_error insertexception insertexception internal_error lowlevelputexception rejected_overload insertexception rejected_overload lowlevelputexception route_not_found insertexception route_not_found lowlevelputexception route_really_not_found insertexception route_really_not_found lowlevelputexception insertexception internal_error lowlevelputexception route_not_found lowlevelputexception route_really_not_found consecutivernfs rnfs consecutivernfs consecutivernfscountassuccess consecutivernfs consecutivernfscountassuccess rnfs consecutivernfs onsuccess keynum consecutivernfs maxinsertretries maxinsertretries insertexception getscheduler registerinsert private void fail insert exception e object container container client context context fail e false container context insertexception objectcontainer clientcontext private void fail insert exception e boolean force fatal object container container client context context synchronized this if finished return finished true if persistent container store this if e is fatal force fatal parent fatally failed block container context else parent failed block container context unregister container context if free data if persistent container activate source data 1 source data free if persistent source data remove from container source data null if persistent container store this if persistent container activate cb 1 cb on failure e this container context insertexception forcefatal objectcontainer clientcontext isfatal forcefatal fatallyfailedblock failedblock freedata sourcedata sourcedata sourcedata removefrom sourcedata onfailure public client key block get block object container container client context context boolean called bycb try synchronized this if finished return null if persistent container store this return encode container context called bycb catch insert exception e if persistent container activate cb 1 cb on failure e this container context if persistent called bycb container deactivate cb 1 return null catch throwable t if persistent container activate cb 1 logger error this caught t t cb on failure new insert exception insert exception internal error t null this container context if persistent called bycb container deactivate cb 1 return null clientkeyblock getblock objectcontainer clientcontext calledbycb calledbycb insertexception onfailure calledbycb onfailure insertexception insertexception internal_error calledbycb public void schedule object container container client context context throws insert exception synchronized this if finished if logminor logger minor this finished already this return if getchk only boolean deactivatecb false if persistent deactivatecb container ext is active cb if deactivatecb container activate cb 1 container activate parent 1 client key block block encode container context true cb on encode block get client key this container context parent completed block false container context cb on success this container context finished true if persistent container store this if deactivatecb container deactivate cb 1 else get scheduler context register insert this persistent true true container objectcontainer clientcontext insertexception getchkonly isactive clientkeyblock onencode getclientkey completedblock onsuccess getscheduler registerinsert override public boolean isssk return isssk public freeneturi geturi object container container client context context synchronized this if resultinguri null if persistent container activate resultinguri 5 return persistent resultinguri clone resultinguri get block container context true synchronized this fixme not really necessary resultinguri is never dropped only set if persistent container activate resultinguri 5 return persistent resultinguri clone resultinguri objectcontainer clientcontext getblock public synchronized freeneturi geturi no encode return resultinguri geturinoencode override public void on success object key num object container container client context context if logminor logger minor this succeeded this token if persistent container activate parent 1 if parent is cancelled fail new insert exception insert exception cancelled container context return synchronized this if finished normal with persistence logger normal this block already completed this return finished true if persistent container store this container activate source data 1 if free data source data free if persistent source data remove from container source data null if persistent container store this parent completed block false container context unregister container context if persistent container activate cb 1 if logminor logger minor this calling on success for cb cb on success this container context if persistent container deactivate cb 1 onsuccess keynum objectcontainer clientcontext iscancelled insertexception insertexception sourcedata freedata sourcedata sourcedata removefrom sourcedata completedblock onsuccess onsuccess public base client putter get parent return parent baseclientputter getparent public void cancel object container container client context context synchronized this if finished return finished true boolean was active true if persistent container store this was active container ext is active cb if was active container activate cb 1 container activate source data 1 if free data source data free if persistent source data remove from container source data null if persistent container store this super unregister container context cb on failure new insert exception insert exception cancelled this container context if was active container deactivate cb 1 objectcontainer clientcontext wasactive wasactive isactive wasactive sourcedata freedata sourcedata sourcedata removefrom sourcedata onfailure insertexception insertexception wasactive public synchronized boolean is empty object container container return finished isempty objectcontainer override public synchronized boolean is cancelled object container container return finished iscancelled objectcontainer override public sendable request sender get sender object container container client context context return new sendable request sender public boolean send node client core core request scheduler sched final client context context chosen block req ignore key num key since we re only sending one block client key block b client key key null if logminor logger minor this starting request single block inserter this block item block block item req token try try b inner encode context random block uri block copy bucket block is metadata block compression codec block source length catch chk encode exception e throw new low level put exception low level put exception internal error e to string e get message e catch ssk encode exception e throw new low level put exception low level put exception internal error e to string e get message e catch malformedurl exception e throw new low level put exception low level put exception internal error e to string e get message e catch insert exception e throw new low level put exception low level put exception internal error e to string e get message e catch io exception e throw new low level put exception low level put exception internal error e to string e get message e if b null logger error this asked to send empty block on single block inserter this new exception error return false key b get client key final client key k key if block persistent context job runner queue new db job public void run object container container client context context if container ext is stored single block inserter this return container activate single block inserter this 1 on encode k container context container deactivate single block inserter this 1 native thread norm priority 1 false else context main executor execute new runnable public void run on encode k null context got uri core real put b req cache local requests catch low level put exception e if e code low level put exception collision collision try clientssk block collided clientssk block core node fetch clientssk key true byte data collided memory decode true byte inserting bucket tools to byte array block copy bucket if collided is metadata block is metadata collided get compression codec block compression codec arrays equals data inserting if logminor logger minor this collided with identical data single block inserter this req on insert success context return true catch key verify exception e1 logger error this caught e1 when checking collision e1 catch key decode exception e1 logger error this caught e1 when checking collision e1 catch io exception e1 logger error this caught e1 when checking collision e1 req on failure e context if logminor logger minor this request failed single block inserter this for e return true finally block copy bucket free if logminor logger minor this request succeeded single block inserter this req on insert success context return true sendablerequestsender getsender objectcontainer clientcontext sendablerequestsender nodeclientcore requestscheduler clientcontext chosenblock keynum clientkeyblock clientkey singleblockinserter blockitem blockitem innerencode copybucket ismetadata compressioncodec sourcelength chkencodeexception lowlevelputexception lowlevelputexception internal_error tostring getmessage sskencodeexception lowlevelputexception lowlevelputexception internal_error tostring getmessage malformedurlexception lowlevelputexception lowlevelputexception internal_error tostring getmessage insertexception lowlevelputexception lowlevelputexception internal_error tostring getmessage ioexception lowlevelputexception lowlevelputexception internal_error tostring getmessage singleblockinserter getclientkey clientkey jobrunner dbjob objectcontainer clientcontext isstored singleblockinserter singleblockinserter onencode singleblockinserter nativethread norm_priority mainexecutor onencode realput cachelocalrequests lowlevelputexception lowlevelputexception clientsskblock clientsskblock memorydecode buckettools tobytearray copybucket ismetadata ismetadata getcompressioncodec compressioncodec singleblockinserter oninsertsuccess keyverifyexception keydecodeexception ioexception onfailure singleblockinserter copybucket singleblockinserter oninsertsuccess public boolean send node client core core request scheduler sched final client context context chosen block req ignore key num key since we re only sending one block client key block b client key key null if logminor logger minor this starting request single block inserter this block item block block item req token try try b inner encode context random block uri block copy bucket block is metadata block compression codec block source length catch chk encode exception e throw new low level put exception low level put exception internal error e to string e get message e catch ssk encode exception e throw new low level put exception low level put exception internal error e to string e get message e catch malformedurl exception e throw new low level put exception low level put exception internal error e to string e get message e catch insert exception e throw new low level put exception low level put exception internal error e to string e get message e catch io exception e throw new low level put exception low level put exception internal error e to string e get message e if b null logger error this asked to send empty block on single block inserter this new exception error return false key b get client key final client key k key if block persistent context job runner queue new db job public void run object container container client context context if container ext is stored single block inserter this return container activate single block inserter this 1 on encode k container context container deactivate single block inserter this 1 native thread norm priority 1 false else context main executor execute new runnable public void run on encode k null context got uri core real put b req cache local requests catch low level put exception e if e code low level put exception collision collision try clientssk block collided clientssk block core node fetch clientssk key true byte data collided memory decode true byte inserting bucket tools to byte array block copy bucket if collided is metadata block is metadata collided get compression codec block compression codec arrays equals data inserting if logminor logger minor this collided with identical data single block inserter this req on insert success context return true catch key verify exception e1 logger error this caught e1 when checking collision e1 catch key decode exception e1 logger error this caught e1 when checking collision e1 catch io exception e1 logger error this caught e1 when checking collision e1 req on failure e context if logminor logger minor this request failed single block inserter this for e return true finally block copy bucket free if logminor logger minor this request succeeded single block inserter this req on insert success context return true nodeclientcore requestscheduler clientcontext chosenblock keynum clientkeyblock clientkey singleblockinserter blockitem blockitem innerencode copybucket ismetadata compressioncodec sourcelength chkencodeexception lowlevelputexception lowlevelputexception internal_error tostring getmessage sskencodeexception lowlevelputexception lowlevelputexception internal_error tostring getmessage malformedurlexception lowlevelputexception lowlevelputexception internal_error tostring getmessage insertexception lowlevelputexception lowlevelputexception internal_error tostring getmessage ioexception lowlevelputexception lowlevelputexception internal_error tostring getmessage singleblockinserter getclientkey clientkey jobrunner dbjob objectcontainer clientcontext isstored singleblockinserter singleblockinserter onencode singleblockinserter nativethread norm_priority mainexecutor onencode realput cachelocalrequests lowlevelputexception lowlevelputexception clientsskblock clientsskblock memorydecode buckettools tobytearray copybucket ismetadata ismetadata getcompressioncodec compressioncodec singleblockinserter oninsertsuccess keyverifyexception keydecodeexception ioexception onfailure singleblockinserter copybucket singleblockinserter oninsertsuccess public void run object container container client context context if container ext is stored single block inserter this return container activate single block inserter this 1 on encode k container context container deactivate single block inserter this 1 objectcontainer clientcontext isstored singleblockinserter singleblockinserter onencode singleblockinserter context main executor execute new runnable public void run on encode k null context mainexecutor onencode override public request client get client object container container if persistent container activate parent 1 return parent get client requestclient getclient objectcontainer getclient override public client requester get client request return parent clientrequester getclientrequest public object get token return token object gettoken tokenobject attempt to encode the block if necessary public void try encode object container container client context context synchronized this if resultinguri null return if finished return try encode container context false catch insert exception e fail e container context catch throwable t logger error this caught t t don t requeue on background block encoder not necessary to do so we ll ask again when we need it and it ll probably just break again tryencode objectcontainer clientcontext insertexception backgroundblockencoder override public synchronized long count sendable keys object container container client context context if finished return 0 else return 1 countsendablekeys objectcontainer clientcontext override public synchronized long count all keys object container container client context context return count sendable keys container context countallkeys objectcontainer clientcontext countsendablekeys override public synchronized sendable request item choose key keys fetching locally ignored object container container client context context if finished return null if persistent if ignored has transient insert this new fake block item return null return get block item container context sendablerequestitem choosekey keysfetchinglocally objectcontainer clientcontext hastransientinsert fakeblockitem getblockitem private block item get block item object container container client context context try synchronized this if finished return null if persistent if source data null logger error this get block item source data null but active container ext is active this return null boolean deactivate bucket false if persistent container activate uri 1 deactivate bucket container ext is active source data if deactivate bucket container activate source data 1 bucket data source data create shadow freeneturi u uri if u get key type equals chk persistent u freeneturi empty chk uri else u u clone if data null data context temp bucket factory make bucket source data size bucket tools copy source data data if persistent if deactivate bucket container deactivate source data 1 container deactivate uri 1 return new block item this data is metadata compression codec source length u hash code persistent catch io exception e fail new insert exception insert exception bucket error e null container context return null blockitem getblockitem objectcontainer clientcontext sourcedata getblockitem sourcedata isactive deactivatebucket deactivatebucket isactive sourcedata deactivatebucket sourcedata sourcedata createshadow getkeytype empty_chk_uri tempbucketfactory makebucket sourcedata buckettools sourcedata deactivatebucket sourcedata blockitem ismetadata compressioncodec sourcelength hashcode ioexception insertexception insertexception bucket_error override public list persistent chosen block make blocks persistent chosen request request request scheduler sched object container container client context context block item item get block item container context if item null return null persistent chosen block block new persistent chosen block true request item null null sched return collections singleton list block persistentchosenblock makeblocks persistentchosenrequest requestscheduler objectcontainer clientcontext blockitem getblockitem persistentchosenblock persistentchosenblock singletonlist block item single block inserter parent bucket bucket boolean meta short codec int srclen freeneturi u int hash code boolean persistent throws io exception this parent parent this copy bucket bucket this is metadata meta this compression codec codec this source length srclen this uri u this hash code hash code this persistent persistent blockitem singleblockinserter hashcode ioexception copybucket ismetadata compressioncodec sourcelength hashcode hashcode public void dump copy bucket free copybucket override public int hash code return hash code hashcode hashcode override public boolean equals object o if o instanceof block item if block item o parent parent return true else if o instanceof fake block item if fake block item o get parent parent return true return false blockitem blockitem fakeblockitem fakeblockitem getparent private class fake block item implements sendable request item public void dump do nothing fakeblockitem sendablerequestitem public single block inserter get parent return single block inserter this singleblockinserter getparent singleblockinserter override public int hash code return single block inserter this hash code hashcode singleblockinserter hashcode override public boolean equals object o if o instanceof block item if block item o parent single block inserter this return true else if o instanceof fake block item if fake block item o get parent single block inserter this return true return false blockitem blockitem singleblockinserter fakeblockitem fakeblockitem getparent singleblockinserter public void remove from object container container client context context if logminor logger minor this remove from on this container activate uri 5 uri remove from container if resultinguri null container activate resultinguri 5 resultinguri remove from container cb parent are responsible for removing themselves ctx is passed in and unmodified usually the client putter removes it container activate errors 5 errors remove from container if free data source data null container ext is stored source data logger error this data not removed container activate source data 1 source data remove from container container delete this removefrom objectcontainer clientcontext removefrom removefrom removefrom clientputter removefrom freedata sourcedata isstored sourcedata sourcedata sourcedata removefrom override public boolean cache inserts object container container boolean deactivate false if persistent deactivate container ext is active ctx if deactivate container activate ctx 1 boolean retval ctx cache local requests if deactivate container deactivate ctx 1 return retval cacheinserts objectcontainer isactive cachelocalrequests public boolean object can new object container container if finished logger error this object can new when already finished on this return false if logdebug logger debug this object can new on this new exception debug return true objectcannew objectcontainer objectcannew objectcannew private insert exception error public void on success fetch result result client getter state object container container ignore insertexception onsuccess fetchresult clientgetter objectcontainer public void on failure fetch exception e client getter state object container container ignore onfailure fetchexception clientgetter objectcontainer public synchronized void on success base client putter state object container container succeeded true finished true notify all onsuccess baseclientputter objectcontainer notifyall public synchronized void on failure insert exception e base client putter state object container container error e finished true notify all onfailure insertexception baseclientputter objectcontainer notifyall public synchronized void on generateduri freeneturi uri base client putter state object container container if logger should log logger minor this logger minor this uri uri if this uri null this uri uri if uri equals this uri return logger error this uri already set this uri but new uri uri new exception error ongenerateduri baseclientputter objectcontainer shouldlog public synchronized freeneturi wait for completion throws insert exception while finished try wait catch interrupted exception e ignore if error null error uri uri throw error if succeeded return uri logger error this did not succeed but no error throw new insert exception insert exception internal error did not succeed but no error uri waitforcompletion insertexception interruptedexception insertexception insertexception internal_error public void on major progress object container container ignore onmajorprogress objectcontainer public void on fetchable base client putter state object container container ignore onfetchable baseclientputter objectcontainer public client context node client core core fec queue fec queue executor main executor background block encoder block encoder archive manager archive manager persistent temp bucket factory ptbf bucket factory tbf healing queue hq usk manager usk manager random source strong random random fast weak random ticker ticker filename generator fg filename generator persistentfg real compressor rc this bootid core node bootid this fec queue fec queue job runner core this main executor main executor this nodedb handle core node nodedb handle this background block encoder block encoder this random strong random this archive manager archive manager this persistent bucket factory ptbf if persistent bucket factory null throw new null pointer exception this temp bucket factory tbf if temp bucket factory null throw new null pointer exception this healing queue hq this usk manager usk manager this fast weak random fast weak random this ticker ticker this fg fg this persistentfg persistentfg this rc rc clientcontext nodeclientcore fecqueue fecqueue mainexecutor backgroundblockencoder blockencoder archivemanager archivemanager persistenttempbucketfactory bucketfactory healingqueue uskmanager uskmanager randomsource strongrandom fastweakrandom filenamegenerator filenamegenerator realcompressor fecqueue fecqueue jobrunner mainexecutor mainexecutor nodedbhandle nodedbhandle backgroundblockencoder blockencoder strongrandom archivemanager archivemanager persistentbucketfactory persistentbucketfactory nullpointerexception tempbucketfactory tempbucketfactory nullpointerexception healingqueue uskmanager uskmanager fastweakrandom fastweakrandom public void init request starter group starters this ssk fetch scheduler starters ssk fetch scheduler this chk fetch scheduler starters chk fetch scheduler this ssk insert scheduler starters ssk put scheduler this chk insert scheduler starters chk put scheduler requeststartergroup sskfetchscheduler sskfetchscheduler chkfetchscheduler chkfetchscheduler sskinsertscheduler sskputscheduler chkinsertscheduler chkputscheduler public client request scheduler get ssk fetch scheduler return ssk fetch scheduler clientrequestscheduler getsskfetchscheduler sskfetchscheduler public client request scheduler get chk fetch scheduler return chk fetch scheduler clientrequestscheduler getchkfetchscheduler chkfetchscheduler public client request scheduler get ssk insert scheduler return ssk insert scheduler clientrequestscheduler getsskinsertscheduler sskinsertscheduler public client request scheduler get chk insert scheduler return chk insert scheduler clientrequestscheduler getchkinsertscheduler chkinsertscheduler public void start final client putter inserter final boolean early encode throws insert exception if inserter persistent job runner queue new db job public void run object container container client context context container activate inserter 1 try inserter start early encode false container context catch insert exception e inserter client on failure e inserter container container deactivate inserter 1 native thread norm priority false else inserter start early encode false null this clientputter earlyencode insertexception jobrunner dbjob objectcontainer clientcontext earlyencode insertexception onfailure nativethread norm_priority earlyencode public void run object container container client context context container activate inserter 1 try inserter start early encode false container context catch insert exception e inserter client on failure e inserter container container deactivate inserter 1 objectcontainer clientcontext earlyencode insertexception onfailure public void start final client getter getter throws fetch exception if getter persistent job runner queue new db job public void run object container container client context context container activate getter 1 try getter start container context catch fetch exception e getter client callback on failure e getter container container deactivate getter 1 native thread norm priority false else getter start null this clientgetter fetchexception jobrunner dbjob objectcontainer clientcontext fetchexception clientcallback onfailure nativethread norm_priority public void run object container container client context context container activate getter 1 try getter start container context catch fetch exception e getter client callback on failure e getter container container deactivate getter 1 objectcontainer clientcontext fetchexception clientcallback onfailure public void start final simple manifest putter inserter throws insert exception if inserter persistent job runner queue new db job public void run object container container client context context container activate inserter 1 try inserter start container context catch insert exception e inserter cb on failure e inserter container container deactivate inserter 1 native thread norm priority false else inserter start null this simplemanifestputter insertexception jobrunner dbjob objectcontainer clientcontext insertexception onfailure nativethread norm_priority public void run object container container client context context container activate inserter 1 try inserter start container context catch insert exception e inserter cb on failure e inserter container container deactivate inserter 1 objectcontainer clientcontext insertexception onfailure public void start final base manifest putter inserter throws insert exception if inserter persistent job runner queue new db job public void run object container container client context context container activate inserter 1 try inserter start container context catch insert exception e inserter cb on failure e inserter container container deactivate inserter 1 native thread norm priority false else inserter start null this basemanifestputter insertexception jobrunner dbjob objectcontainer clientcontext insertexception onfailure nativethread norm_priority public void run object container container client context context container activate inserter 1 try inserter start container context catch insert exception e inserter cb on failure e inserter container container deactivate inserter 1 objectcontainer clientcontext insertexception onfailure public bucket factory get bucket factory boolean persistent if persistent return persistent bucket factory else return temp bucket factory bucketfactory getbucketfactory persistentbucketfactory tempbucketfactory public request scheduler get fetch scheduler boolean ssk if ssk return ssk fetch scheduler return chk fetch scheduler requestscheduler getfetchscheduler sskfetchscheduler chkfetchscheduler public boolean object can new object container container logger error this not storing client context in database new exception error return false objectcannew objectcontainer clientcontext public string arr option sub config conf string option name string default value int sort order boolean expert boolean force write string short desc string long desc string arr callback cb super conf option name cb sort order expert force write short desc long desc option data type string array this default value default value null new string 0 default value this current value default value null new string 0 default value stringarroption subconfig optionname defaultvalue sortorder forcewrite shortdesc longdesc stringarrcallback optionname sortorder forcewrite shortdesc longdesc datatype string_array defaultvalue defaultvalue defaultvalue currentvalue defaultvalue defaultvalue override public string parse string string val throws invalid config value exception if val length 0 return new string 0 string out val split delimiter try for int i 0 i out length i if out i equals out i else out i url decoder decode out i true fixme false catch url encoded format exception e throw new invalid config value exception l10n parse error error e get localized message return out parsestring invalidconfigvalueexception urldecoder urlencodedformatexception invalidconfigvalueexception parseerror getlocalizedmessage public void set initial value string val throws invalid config value exception this current value val setinitialvalue invalidconfigvalueexception currentvalue private string l10n string key string pattern string value return l10n get string string arr option key pattern value getstring stringarroption override public string to string string arr if arr null return null string builder sb new string builder for int i 0 i arr length i string val arr i if val length 0 sb append append delimiter else sb append url encoder encode arr i false append delimiter if sb length 0 sb set length sb length 1 drop surplus delimiter return sb to string tostring stringbuilder stringbuilder urlencoder setlength tostring public static string decode string s try return url decoder decode s false catch url encoded format exception e return null urldecoder urlencodedformatexception override public boolean is default get value return current value null false arrays equals current value default value isdefault getvalue currentvalue currentvalue defaultvalue private int levels 256 public oil filter oilfilter set the range of the effect in pixels param range the range see get range public void set range int range this range range getrange setrange get the range of the effect in pixels return the range see set range public int get range return range setrange getrange set the number of levels for the effect param levels the number of levels see get levels public void set levels int levels this levels levels getlevels setlevels get the number of levels for the effect return the number of levels see set levels public int get levels return levels setlevels getlevels override protected int filter pixels int width int height int in pixels rectangle transformed space int index 0 int r histogram new int levels int g histogram new int levels int b histogram new int levels int r total new int levels int g total new int levels int b total new int levels int out pixels new int width height for int y 0 y height y for int x 0 x width x for int i 0 i levels i r histogram i g histogram i b histogram i r total i g total i b total i 0 for int row range row range row int iy y row int ioffset if 0 iy iy height ioffset iy width for int col range col range col int ix x col if 0 ix ix width int rgb in pixels ioffset ix int r rgb 16 0xff int g rgb 8 0xff int b rgb 0xff int ri r levels 256 int gi g levels 256 int bi b levels 256 r total ri r g total gi g b total bi b r histogram ri g histogram gi b histogram bi int r 0 g 0 b 0 for int i 1 i levels i if r histogram i r histogram r r i if g histogram i g histogram g g i if b histogram i b histogram b b i r r total r r histogram r g g total g g histogram g b b total b b histogram b out pixels index 0xff000000 r 16 g 8 b return out pixels filterpixels inpixels transformedspace rhistogram ghistogram bhistogram rtotal gtotal btotal outpixels rhistogram ghistogram bhistogram rtotal gtotal btotal inpixels rtotal gtotal btotal rhistogram ghistogram bhistogram rhistogram rhistogram ghistogram ghistogram bhistogram bhistogram rtotal rhistogram gtotal ghistogram btotal bhistogram outpixels outpixels override public string to string return stylize oil tostring public class key decode exception extends exception private static final long serial versionuid 1 public key decode exception string message super message keydecodeexception serialversionuid keydecodeexception public key decode exception super keydecodeexception public key decode exception string message throwable cause super message cause keydecodeexception public key decode exception throwable cause super cause keydecodeexception public simple progress message string identifier boolean global splitfile progress event event this ident identifier this event event this global global simpleprogressmessage splitfileprogressevent override public simple field set get field set simple field set fs new simple field set true fs put total event total blocks fs put required event min successful blocks fs put failed event failed blocks fs put fatally failed event fatally failed blocks fs put succeeded event succeed blocks fs put finalized total event finalized total fs put single identifier ident if global fs put single global true return fs simplefieldset getfieldset simplefieldset simplefieldset totalblocks minsuccessfulblocks failedblocks fatallyfailed fatallyfailedblocks succeedblocks finalizedtotal finalizedtotal putsingle putsingle override public string get name return simple progress getname simpleprogress override public void run fcp connection handler handler node node throws message invalid exception throw new message invalid exception protocol error message invalid message simple progress goes from server to client not the other way around ident global fcpconnectionhandler messageinvalidexception messageinvalidexception protocolerrormessage invalid_message simpleprogress public double get fraction return double event succeed blocks double event total blocks getfraction succeedblocks totalblocks public double get min blocks return event min successful blocks getminblocks minsuccessfulblocks public double get total blocks return event total blocks gettotalblocks totalblocks public double get fetched blocks return event succeed blocks getfetchedblocks succeedblocks public double get failed blocks return event failed blocks getfailedblocks failedblocks public double get fataly failed blocks return event fatally failed blocks getfatalyfailedblocks fatallyfailedblocks public boolean is total finalized return event finalized total istotalfinalized finalizedtotal override public void remove from object container container container activate event 1 event remove from container container delete this removefrom objectcontainer removefrom public class vector3f extends tuple3f public vector3f this 0 0 0 public vector3f float x this x x 0 this y x 1 this z x 2 public vector3f float x float y float z this x x this y y this z z public vector3f vector3f t this x t x this y t y this z t z public vector3f tuple3f t this x t x this y t y this z t z public float angle vector3f v return float math acos dot v length v length public float dot vector3f v return v x x v y y v z z public void cross vector3f v1 vector3f v2 x v1 y v2 z v1 z v2 y y v1 z v2 x v1 x v2 z z v1 x v2 y v1 y v2 x public float length return float math sqrt x x y y z z public void normalize float d 1 0f float math sqrt x x y y z z x d y d z d bookmark editor toadlet high level simple client client node client core core bookmark manager bookmarks super client this core core this bookmark manager bookmarks this cuted path null bookmarkeditortoadlet highlevelsimpleclient nodeclientcore bookmarkmanager bookmarkmanager cutedpath get all bookmark as a tree of lt li gt lt li gt s private void add category to list bookmark category cat string path html node list list bookmark item items cat get items final string edit l10n get string bookmark editor toadlet edit final string delete l10n get string bookmark editor toadlet delete final string cut l10n get string bookmark editor toadlet cut final string move up l10n get string bookmark editor toadlet move up final string move down l10n get string bookmark editor toadlet move down final string paste l10n get string bookmark editor toadlet paste final string add bookmark l10n get string bookmark editor toadlet add bookmark final string add category l10n get string bookmark editor toadlet add category for int i 0 i items size i bookmark item item items get i string item path url encoder encode path item get name false html node li new html node li class item item get name html node actions new html node span class actions actions add child a href action edit bookmark item path add child img new string src alt title new string static icon edit png edit edit actions add child a href action del bookmark item path add child img new string src alt title new string static icon delete png delete delete if cuted path null actions add child a href action cut bookmark item path add child img new string src alt title new string static icon cut png cut cut if i 0 actions add child a href action up bookmark item path add child img new string src alt title new string static icon go up png move up move up if i items size 1 actions add child a href action down bookmark item path add child img new string src alt title new string static icon go down png move down move down li add child actions list add child li list bookmark category cats cat get sub categories for int i 0 i cats size i string cat path path cats get i get name string cat path encoded url encoder encode cat path false html node sub cat list add child li class cat cats get i get name html node actions new html node span class actions actions add child a href action edit bookmark cat path encoded add child img new string src alt title new string static icon edit png edit edit actions add child a href action del bookmark cat path encoded add child img new string src alt title new string static icon delete png delete delete actions add child a href action add item bookmark cat path encoded add child img new string src alt title new string static icon bookmark new png add bookmark add bookmark actions add child a href action add cat bookmark cat path encoded add child img new string src alt title new string static icon folder new png add category add category if cuted path null actions add child a href action cut bookmark cat path encoded add child img new string src alt title new string static icon cut png cut cut if i 0 actions add child a href action up bookmark cat path encoded add child img new string src alt title new string static icon go up png move up move up if i cats size 1 actions add child a href action down bookmark cat path encoded add child img new string src alt title new string static icon go down png move down move down if cuted path null cat path encoded starts with cuted path cat path encoded equals bookmark manager parent path cuted path actions add child a href action paste bookmark cat path encoded add child img new string src alt title new string static icon paste png paste paste sub cat add child actions if cats get i size 0 add category to list cats get i cat path list add child li add child ul addcategorytolist bookmarkcategory htmlnode bookmarkitem getitems getstring bookmarkeditortoadlet getstring bookmarkeditortoadlet getstring bookmarkeditortoadlet moveup getstring bookmarkeditortoadlet moveup movedown getstring bookmarkeditortoadlet movedown getstring bookmarkeditortoadlet addbookmark getstring bookmarkeditortoadlet addbookmark addcategory getstring bookmarkeditortoadlet addcategory bookmarkitem itempath urlencoder getname htmlnode htmlnode getname htmlnode htmlnode addchild itempath addchild addchild itempath addchild cutedpath addchild itempath addchild addchild itempath addchild moveup moveup addchild itempath addchild movedown movedown addchild addchild bookmarkcategory getsubcategories catpath getname catpathencoded urlencoder catpath htmlnode subcat addchild getname htmlnode htmlnode addchild catpathencoded addchild addchild catpathencoded addchild addchild additem catpathencoded addchild addbookmark addbookmark addchild addcat catpathencoded addchild addcategory addcategory cutedpath addchild catpathencoded addchild addchild catpathencoded addchild moveup moveup addchild catpathencoded addchild movedown movedown cutedpath catpathencoded startswith cutedpath catpathencoded bookmarkmanager parentpath cutedpath addchild catpathencoded addchild subcat addchild addcategorytolist catpath addchild addchild public html node get bookmarks list html node bookmarks new html node ul id bookmarks html node root bookmarks add child li class cat root html node actions new html node span class actions string add bookmark l10n get string bookmark editor toadlet add bookmark string add category l10n get string bookmark editor toadlet add category string paste l10n get string bookmark editor toadlet paste actions add child a href action add item bookmark add child img new string src alt title new string static icon bookmark new png add bookmark add bookmark actions add child a href action add cat bookmark add child img new string src alt title new string static icon folder new png add category add category if cuted path null equals bookmark manager parent path cuted path actions add child a href action paste bookmark add child img new string src alt title new string static icon paste png paste paste root add child actions add category to list bookmark manager main category root add child ul return bookmarks htmlnode getbookmarkslist htmlnode htmlnode htmlnode addchild htmlnode htmlnode addbookmark getstring bookmarkeditortoadlet addbookmark addcategory getstring bookmarkeditortoadlet addcategory getstring bookmarkeditortoadlet addchild additem addchild addbookmark addbookmark addchild addcat addchild addcategory addcategory cutedpath bookmarkmanager parentpath cutedpath addchild addchild addchild addcategorytolist bookmarkmanager main_category addchild override public void handle get uri uri http request req toadlet context ctx throws toadlet context closed exception io exception page maker page maker ctx get page maker string editor title l10n get string bookmark editor toadlet title string error l10n get string bookmark editor toadlet error html node page node page maker get page node editor title ctx html node content page maker get content node page node string original bookmark req get param bookmark if req get param action length 0 original bookmark length 0 string action req get param action string bookmark path try bookmark path url decoder decode original bookmark false catch url encoded format exception e html node error box content add child page maker get infobox infobox error error page maker get content node error box add child l10n get string bookmark editor toadlet url decode error writehtml reply ctx 200 ok page node generate return bookmark bookmark if bookmark path ends with bookmark bookmark manager get category by path bookmark path else bookmark bookmark manager get item by path bookmark path if bookmark null html node error box content add child page maker get infobox infobox error error page maker get content node error box add child l10n get string bookmark editor toadlet bookmark does not exist new string bookmark new string bookmark path this writehtml reply ctx 200 ok page node generate return else if del equals action string bm new string bookmark string path new string bookmark path string query title l10n get string bookmark editor toadlet bookmark instanceof bookmark item delete bookmark delete category html node info box content add child page maker get infobox infobox query query title html node info box content page maker get content node info box string query l10n get string bookmark editor toadlet bookmark instanceof bookmark item delete bookmark confirm delete category confirm bm path info box content add child p add child query html node confirm form ctx add form child info box content confirm delete form confirm form add child input new string type name value new string hidden bookmark bookmark path confirm form add child input new string type name value new string submit cancel l10n get string toadlet cancel confirm form add child input new string type name value new string submit confirmdelete l10n get string bookmark editor toadlet confirm delete else if cut equals action cuted path bookmark path else if paste equals action cuted path null bookmark manager move bookmark cuted path bookmark path bookmark manager store bookmarks cuted path null else if edit equals action add item equals action add cat equals action string header if edit equals action header l10n get string bookmark editor toadlet edit bookmark instanceof bookmark item bookmark category title else if add item equals action header l10n get string bookmark editor toadlet add new bookmark else header l10n get string bookmark editor toadlet add new category html node action box content add child page maker get infobox infobox query header html node form ctx add form child page maker get content node action box edit bookmark form form add child label for name l10n get string bookmark editor toadlet name label form add child input new string type id name size value new string text name name 20 edit equals action bookmark get name form add child br boolean is new false if edit equals action bookmark instanceof bookmark item is new add item equals action bookmark item item is new null bookmark item bookmark string key action equals edit item get key form add child label for key l10n get string bookmark editor toadlet key label form add child input new string type id name size value new string text key key 50 key form add child br form add child label for descb l10n get string bookmark editor toadlet desc label form add child br form add child textarea new string id name row cols new string descb descb 3 70 item null item get description form add child br form add child label for has an activelink l10n get string bookmark editor toadlet has an activelink label if item null item has an activelink form add child input new string type id name checked new string checkbox has an activelink has an activelink string value of item has an activelink else form add child input new string type id name new string checkbox has an activelink has an activelink form add child input new string type name value new string hidden bookmark bookmark path form add child input new string type name value new string hidden action req get param action form add child br form add child input new string type value new string submit l10n get string bookmark editor toadlet save else if up equals action bookmark manager move bookmark up bookmark path true else if down equals action bookmark manager move bookmark down bookmark path true if cuted path null html node info box content add child page maker get infobox infobox normal l10n get string bookmark editor toadlet paste title html node info box content page maker get content node info box info box content add child l10n get string bookmark editor toadlet paste or cancel html node cancel form ctx add form child info box content bookmark editor cancel cut form cancel form add child input new string type name value new string submit cancel cut l10n get string bookmark editor toadlet cancel cut cancel form add child input new string type name value new string hidden action cancel cut html node bookmarks box content add child page maker get infobox infobox normal l10n get string bookmark editor toadlet my bookmarks title page maker get content node bookmarks box add child get bookmarks list html node add default bookmarks form ctx add form child content add default bookmarks add default bookmarks form add child input new string type name value new string submit add default bookmarks l10n get string bookmark editor toadlet add default bookmarks if logger should log logger debug this logger debug this returning n page node generate this writehtml reply ctx 200 ok page node generate handleget httprequest toadletcontext toadletcontextclosedexception ioexception pagemaker pagemaker getpagemaker editortitle getstring bookmarkeditortoadlet getstring bookmarkeditortoadlet htmlnode pagenode pagemaker getpagenode editortitle htmlnode pagemaker getcontentnode pagenode originalbookmark getparam getparam originalbookmark getparam bookmarkpath bookmarkpath urldecoder originalbookmark urlencodedformatexception htmlnode errorbox addchild pagemaker getinfobox pagemaker getcontentnode errorbox addchild getstring bookmarkeditortoadlet urldecodeerror writehtmlreply pagenode bookmarkpath endswith bookmarkmanager getcategorybypath bookmarkpath bookmarkmanager getitembypath bookmarkpath htmlnode errorbox addchild pagemaker getinfobox pagemaker getcontentnode errorbox addchild getstring bookmarkeditortoadlet bookmarkdoesnotexist bookmarkpath writehtmlreply pagenode bookmarkpath querytitle getstring bookmarkeditortoadlet bookmarkitem deletebookmark deletecategory htmlnode infobox addchild pagemaker getinfobox querytitle htmlnode infoboxcontent pagemaker getcontentnode infobox getstring bookmarkeditortoadlet bookmarkitem deletebookmarkconfirm deletecategoryconfirm infoboxcontent addchild addchild htmlnode confirmform addformchild infoboxcontent confirmdeleteform confirmform addchild bookmarkpath confirmform addchild getstring confirmform addchild getstring bookmarkeditortoadlet confirmdelete cutedpath bookmarkpath cutedpath bookmarkmanager movebookmark cutedpath bookmarkpath bookmarkmanager storebookmarks cutedpath additem addcat getstring bookmarkeditortoadlet bookmarkitem additem getstring bookmarkeditortoadlet addnewbookmark getstring bookmarkeditortoadlet addnewcategory htmlnode actionbox addchild pagemaker getinfobox htmlnode addformchild pagemaker getcontentnode actionbox editbookmarkform addchild getstring bookmarkeditortoadlet namelabel addchild getname addchild isnew bookmarkitem isnew additem bookmarkitem isnew bookmarkitem getkey addchild getstring bookmarkeditortoadlet keylabel addchild addchild addchild getstring bookmarkeditortoadlet desclabel addchild addchild getdescription addchild addchild hasanactivelink getstring bookmarkeditortoadlet hasanactivelinklabel hasanactivelink addchild hasanactivelink hasanactivelink valueof hasanactivelink addchild hasanactivelink hasanactivelink addchild bookmarkpath addchild getparam addchild addchild getstring bookmarkeditortoadlet bookmarkmanager movebookmarkup bookmarkpath bookmarkmanager movebookmarkdown bookmarkpath cutedpath htmlnode infobox addchild pagemaker getinfobox getstring bookmarkeditortoadlet pastetitle htmlnode infoboxcontent pagemaker getcontentnode infobox infoboxcontent addchild getstring bookmarkeditortoadlet pasteorcancel htmlnode cancelform addformchild infoboxcontent bookmarkeditor cancelcutform cancelform addchild cancelcut getstring bookmarkeditortoadlet cancelcut cancelform addchild cancelcut htmlnode bookmarksbox addchild pagemaker getinfobox getstring bookmarkeditortoadlet mybookmarkstitle pagemaker getcontentnode bookmarksbox addchild getbookmarkslist htmlnode adddefaultbookmarksform addformchild adddefaultbookmarks adddefaultbookmarksform addchild adddefaultbookmarks getstring bookmarkeditortoadlet adddefaultbookmarks shouldlog pagenode writehtmlreply pagenode override public void handle post uri uri http request req toadlet context ctx throws toadlet context closed exception io exception page maker page maker ctx get page maker html node page node page maker get page node l10n get string bookmark editor toadlet title ctx html node content page maker get content node page node string passwd req get part as string form password 32 boolean no password passwd null passwd equals core form password if no password write permanent redirect ctx invalid return if req is part set add default bookmarks bookmark manager re add default bookmarks this write temporary redirect ctx ok return string bookmark path req get part as string bookmark max bookmark path length try bookmark bookmark if bookmark path ends with bookmark bookmark manager get category by path bookmark path else bookmark bookmark manager get item by path bookmark path if bookmark null req is part set cancel cut html node error box content add child page maker get infobox infobox error l10n get string bookmark editor toadlet error page maker get content node error box add child l10n get string bookmark editor toadlet bookmark does not exist new string bookmark new string bookmark path this writehtml reply ctx 200 ok page node generate return string action req get part as string action max action length if req is part set confirmdelete bookmark manager remove bookmark bookmark path bookmark manager store bookmarks html node success box content add child page maker get infobox infobox success l10n get string bookmark editor toadlet delete succeeded title page maker get content node success box add child p l10n get string bookmark editor toadlet delete succeeded else if req is part set cancel cut cuted path null else if edit equals action add item equals action add cat equals action string name unnamed if req is part set name name req get part as string name max name length if edit equals action bookmark manager rename bookmark bookmark path name boolean has an activelink req is part set has an activelink if bookmark instanceof bookmark item bookmark item bookmark update new freeneturi req get part as string key max key length has an activelink req get part as string descb max key length bookmark manager store bookmarks html node success box content add child page maker get infobox infobox success l10n get string bookmark editor toadlet changes saved title page maker get content node success box add child p l10n get string bookmark editor toadlet changes saved else if add item equals action add cat equals action bookmark new bookmark null if add item equals action freeneturi key new freeneturi req get part as string key max key length todo nextgens i suggest you implement a http request get boolean string name using fields stringtobool nextgens http request get boolean string name boolean default even values as on true yes should be accepted boolean has an activelink req is part set has an activelink if name contains html node error box content add child page maker get infobox infobox error l10n get string bookmark editor toadlet invalid name title page maker get content node error box add child l10n get string bookmark editor toadlet invalid name else new bookmark new bookmark item key name req get part as string descb max key length has an activelink core alerts else if name contains html node error box content add child page maker get infobox infobox error l10n get string bookmark editor toadlet invalid name title page maker get content node error box add child l10n get string bookmark editor toadlet invalid name else new bookmark new bookmark category name if new bookmark null bookmark manager add bookmark bookmark path new bookmark bookmark manager store bookmarks html node success box content add child page maker get infobox infobox success l10n get string bookmark editor toadlet added new bookmark title page maker get content node success box add child p l10n get string bookmark editor toadlet added new bookmark catch malformedurl exception mue html node error box content add child page maker get infobox infobox error l10n get string bookmark editor toadlet invalid key title page maker get content node error box add child l10n get string bookmark editor toadlet invalid key html node bookmarks box content add child page maker get infobox infobox normal l10n get string bookmark editor toadlet my bookmarks title page maker get content node bookmarks box add child get bookmarks list html node add default bookmarks form ctx add form child content add default bookmarks add default bookmarks form add child input new string type name value new string submit add default bookmarks l10n get string bookmark editor toadlet add default bookmarks this writehtml reply ctx 200 ok page node generate handlepost httprequest toadletcontext toadletcontextclosedexception ioexception pagemaker pagemaker getpagemaker htmlnode pagenode pagemaker getpagenode getstring bookmarkeditortoadlet htmlnode pagemaker getcontentnode pagenode getpartasstring formpassword nopassword formpassword nopassword writepermanentredirect ispartset adddefaultbookmarks bookmarkmanager readddefaultbookmarks writetemporaryredirect bookmarkpath getpartasstring max_bookmark_path_length bookmarkpath endswith bookmarkmanager getcategorybypath bookmarkpath bookmarkmanager getitembypath bookmarkpath ispartset cancelcut htmlnode errorbox addchild pagemaker getinfobox getstring bookmarkeditortoadlet pagemaker getcontentnode errorbox addchild getstring bookmarkeditortoadlet bookmarkdoesnotexist bookmarkpath writehtmlreply pagenode getpartasstring max_action_length ispartset bookmarkmanager removebookmark bookmarkpath bookmarkmanager storebookmarks htmlnode successbox addchild pagemaker getinfobox getstring bookmarkeditortoadlet deletesucceededtitle pagemaker getcontentnode successbox addchild getstring bookmarkeditortoadlet deletesucceeded ispartset cancelcut cutedpath additem addcat ispartset getpartasstring max_name_length bookmarkmanager renamebookmark bookmarkpath hasanactivelink ispartset hasanactivelink bookmarkitem bookmarkitem getpartasstring max_key_length hasanactivelink getpartasstring max_key_length bookmarkmanager storebookmarks htmlnode successbox addchild pagemaker getinfobox getstring bookmarkeditortoadlet changessavedtitle pagemaker getcontentnode successbox addchild getstring bookmarkeditortoadlet changessaved additem addcat newbookmark additem getpartasstring max_key_length httprequest getboolean httprequest getboolean hasanactivelink ispartset hasanactivelink htmlnode errorbox addchild pagemaker getinfobox getstring bookmarkeditortoadlet invalidnametitle pagemaker getcontentnode errorbox addchild getstring bookmarkeditortoadlet invalidname newbookmark bookmarkitem getpartasstring max_key_length hasanactivelink htmlnode errorbox addchild pagemaker getinfobox getstring bookmarkeditortoadlet invalidnametitle pagemaker getcontentnode errorbox addchild getstring bookmarkeditortoadlet invalidname newbookmark bookmarkcategory newbookmark bookmarkmanager addbookmark bookmarkpath newbookmark bookmarkmanager storebookmarks htmlnode successbox addchild pagemaker getinfobox getstring bookmarkeditortoadlet addednewbookmarktitle pagemaker getcontentnode successbox addchild getstring bookmarkeditortoadlet addednewbookmark malformedurlexception htmlnode errorbox addchild pagemaker getinfobox getstring bookmarkeditortoadlet invalidkeytitle pagemaker getcontentnode errorbox addchild getstring bookmarkeditortoadlet invalidkey htmlnode bookmarksbox addchild pagemaker getinfobox getstring bookmarkeditortoadlet mybookmarkstitle pagemaker getcontentnode bookmarksbox addchild getbookmarkslist htmlnode adddefaultbookmarksform addformchild adddefaultbookmarks adddefaultbookmarksform addchild adddefaultbookmarks getstring bookmarkeditortoadlet adddefaultbookmarks writehtmlreply pagenode override public string supported methods return get post supportedmethods static final string name list persistent requests public list persistent requests message simple field set fs do nothing listpersistentrequests listpersistentrequestsmessage simplefieldset override public simple field set get field set return new simple field set true simplefieldset getfieldset simplefieldset override public string get name return name getname override public void run final fcp connection handler handler node node throws message invalid exception fcp client reboot client handler get reboot client reboot client queue pending messages on connection restart handler output handler null reboot client queue pending messages from running requests handler output handler null if handler get reboot client watch global fcp client global reboot client handler server global reboot client global reboot client queue pending messages on connection restart handler output handler null global reboot client queue pending messages from running requests handler output handler null node client core client context job runner queue new db job public void run object container container client context context fcp client forever client handler get forever client container container activate forever client 1 forever client queue pending messages on connection restart handler output handler container forever client queue pending messages from running requests handler output handler container if handler get reboot client watch global fcp client global forever client handler server global forever client global forever client queue pending messages on connection restart handler output handler container global forever client queue pending messages from running requests handler output handler container handler output handler queue new end list persistent requests message container deactivate forever client 1 native thread high priority 1 false fcpconnectionhandler messageinvalidexception fcpclient rebootclient getrebootclient rebootclient queuependingmessagesonconnectionrestart outputhandler rebootclient queuependingmessagesfromrunningrequests outputhandler getrebootclient watchglobal fcpclient globalrebootclient globalrebootclient globalrebootclient queuependingmessagesonconnectionrestart outputhandler globalrebootclient queuependingmessagesfromrunningrequests outputhandler clientcore clientcontext jobrunner dbjob objectcontainer clientcontext fcpclient foreverclient getforeverclient foreverclient foreverclient queuependingmessagesonconnectionrestart outputhandler foreverclient queuependingmessagesfromrunningrequests outputhandler getrebootclient watchglobal fcpclient globalforeverclient globalforeverclient globalforeverclient queuependingmessagesonconnectionrestart outputhandler globalforeverclient queuependingmessagesfromrunningrequests outputhandler outputhandler endlistpersistentrequestsmessage foreverclient nativethread high_priority public void run object container container client context context fcp client forever client handler get forever client container container activate forever client 1 forever client queue pending messages on connection restart handler output handler container forever client queue pending messages from running requests handler output handler container if handler get reboot client watch global fcp client global forever client handler server global forever client global forever client queue pending messages on connection restart handler output handler container global forever client queue pending messages from running requests handler output handler container handler output handler queue new end list persistent requests message container deactivate forever client 1 objectcontainer clientcontext fcpclient foreverclient getforeverclient foreverclient foreverclient queuependingmessagesonconnectionrestart outputhandler foreverclient queuependingmessagesfromrunningrequests outputhandler getrebootclient watchglobal fcpclient globalforeverclient globalforeverclient globalforeverclient queuependingmessagesonconnectionrestart outputhandler globalforeverclient queuependingmessagesfromrunningrequests outputhandler outputhandler endlistpersistentrequestsmessage foreverclient override public void remove from object container container container delete this removefrom objectcontainer persistent map impl storage storage class key type int initial size super storage type get type code key type keys new comparable initial size values storage v create link initial size persistentmapimpl keytype initialsize gettypecode keytype initialsize createlink initialsize v value public k get key return key getkey public v get value return value getvalue public v set value v value modify v prev value this value this value value return prev value setvalue prevvalue prevvalue persistent map entry k key v value this key key this value value persistentmapentry this value value persistent map entry persistentmapentry static class persistent map comparator k extends comparable v extends i persistent extends persistent comparator persistent map entry k v public int compare members persistent map entry k v m1 persistent map entry k v m2 return m1 key compare to m2 key persistentmapcomparator ipersistent persistentcomparator persistentmapentry comparemembers persistentmapentry persistentmapentry compareto public int compare member with key persistent map entry k v mbr object key return mbr key compare to key comparememberwithkey persistentmapentry compareto persistent map impl persistentmapimpl protected int get type code class c if c equals byte class c equals byte class return class descriptor tp byte else if c equals short class c equals short class return class descriptor tp short else if c equals char class c equals character class return class descriptor tp char else if c equals int class c equals integer class return class descriptor tp int else if c equals long class c equals long class return class descriptor tp long else if c equals float class c equals float class return class descriptor tp float else if c equals double class c equals double class return class descriptor tp double else if c equals string class return class descriptor tp string else if c equals boolean class c equals boolean class return class descriptor tp boolean else if c is enum return class descriptor tp enum else if c equals java util date class return class descriptor tp date else if comparable class is assignable from c return class descriptor tp raw else throw new storage error storage error unsupported type c gettypecode classdescriptor tpbyte classdescriptor tpshort classdescriptor tpchar classdescriptor tpint classdescriptor tplong classdescriptor tpfloat classdescriptor tpdouble classdescriptor tpstring classdescriptor tpboolean isenum classdescriptor tpenum classdescriptor tpdate isassignablefrom classdescriptor tpraw storageerror storageerror unsupported_type public int size return index null collection index size values size public boolean is empty return size 0 isempty public boolean contains value object value iterator entry k v i entry set iterator if value null while i has next entry k v e i next if e get value null return true else while i has next entry k v e i next if value equals e get value return true return false containsvalue entryset hasnext getvalue hasnext getvalue private int binary search object key comparable keys comparable this keys int l 0 r values size while l r int i l r 1 if keys i compare to key 0 l i 1 else r i return r binarysearch compareto public boolean contains key object key if index null if type class descriptor tp raw return sorted collection index contains key key else key k generate key key return index index entry iterator k k index ascent order has next else int i binary search key return i values size comparable keys i equals key containskey classdescriptor tpraw sortedcollection containskey generatekey entryiterator ascent_order hasnext binarysearch public v get object key if index null if type class descriptor tp raw persistent map entry k v entry sorted collection persistent map entry k v index get key return entry null entry value null else return index v index get generate key key else int i binary search key if i values size comparable keys i equals key return values get i return null classdescriptor tpraw persistentmapentry sortedcollection persistentmapentry generatekey binarysearch public entry k v get entry object key if index null if type class descriptor tp raw return sorted collection persistent map entry k v index get key else v value index v index get generate key key return value null new persistent map entry k key value null else int i binary search key if i values size comparable keys i equals key v value values get i return value null new persistent map entry k key value null return null getentry classdescriptor tpraw sortedcollection persistentmapentry generatekey persistentmapentry binarysearch persistentmapentry public v put k key v value v prev null if index null int size values size int i binary search key if i size key equals comparable keys i prev values set i value else if size btree treshold comparable keys comparable this keys if type class descriptor tp raw sorted collection persistent map entry k v col get storage persistent map entry k v create sorted collection new persistent map comparator k v true index col for i 0 i size i col add new persistent map entry k keys i values get i prev insert in sorted collection key value else index v idx get storage v create index btree map key type type true index idx for i 0 i size i idx set generate key keys i values get i prev idx set generate key key value this keys null this values null modify else object old keys object keys if size old keys length comparable new keys new comparable size 1 old keys length 2 size 1 old keys length 2 system arraycopy old keys 0 new keys 0 i system arraycopy old keys i new keys i 1 size i keys new keys new keys i key else system arraycopy old keys i old keys i 1 size i old keys i key values insert i value else if type class descriptor tp raw prev insert in sorted collection key value else prev index v index set generate key key value return prev binarysearch btree_treshold classdescriptor tpraw sortedcollection persistentmapentry getstorage persistentmapentry createsortedcollection persistentmapcomparator persistentmapentry insertinsortedcollection getstorage createindex mapkeytype generatekey generatekey oldkeys oldkeys newkeys oldkeys oldkeys oldkeys newkeys oldkeys newkeys newkeys newkeys oldkeys oldkeys oldkeys classdescriptor tpraw insertinsortedcollection generatekey private v insert in sorted collection k key v value sorted collection persistent map entry k v col sorted collection persistent map entry k v index persistent map entry k v entry col get key v prev null get storage make persistent value if entry null col add new persistent map entry key value else prev entry set value value return prev insertinsortedcollection sortedcollection persistentmapentry sortedcollection persistentmapentry persistentmapentry getstorage makepersistent persistentmapentry setvalue public v remove object key if index null int size values size int i binary search key if i size comparable keys i equals key system arraycopy keys i 1 keys i size i 1 comparable keys size 1 null return values remove i return null else if type class descriptor tp raw sorted collection persistent map entry k v col sorted collection persistent map entry k v index persistent map entry k v entry col get key if entry null return null col remove entry return entry value else try return index v index remove generate key key catch storage error x if x get error code storage error key not found return null throw x binarysearch classdescriptor tpraw sortedcollection persistentmapentry sortedcollection persistentmapentry persistentmapentry generatekey storageerror geterrorcode storageerror key_not_found public void put all map extends k extends v t iterator extends entry extends k extends v i t entry set iterator while i has next entry extends k extends v e i next put e get key e get value putall entryset hasnext getkey getvalue public void clear if index null collection index clear else values clear keys new comparable comparable keys length public set k key set if key set null key set new abstract set k public iterator k iterator return new iterator k private iterator entry k v i entry set iterator public boolean has next return i has next public k next return i next get key public void remove i remove public int size return persistent map impl this size public boolean contains object k return persistent map impl this contains key k return key set keyset keyset keyset abstractset entryset hasnext hasnext getkey persistentmapimpl persistentmapimpl containskey keyset key set new abstract set k public iterator k iterator return new iterator k private iterator entry k v i entry set iterator public boolean has next return i has next public k next return i next get key public void remove i remove keyset abstractset entryset hasnext hasnext getkey private iterator entry k v i entry set iterator public boolean has next return i has next entryset hasnext hasnext public k next return i next get key getkey public void remove i remove public int size return persistent map impl this size persistentmapimpl public boolean contains object k return persistent map impl this contains key k persistentmapimpl containskey public collection v values if values col null values col new abstract collection v public iterator v iterator return new iterator v private iterator entry k v i entry set iterator public boolean has next return i has next public v next return i next get value public void remove i remove public int size return persistent map impl this size public boolean contains object v return persistent map impl this contains value v return values col valuescol valuescol abstractcollection entryset hasnext hasnext getvalue persistentmapimpl persistentmapimpl containsvalue valuescol values col new abstract collection v public iterator v iterator return new iterator v private iterator entry k v i entry set iterator public boolean has next return i has next public v next return i next get value public void remove i remove valuescol abstractcollection entryset hasnext hasnext getvalue private iterator entry k v i entry set iterator public boolean has next return i has next entryset hasnext hasnext public v next return i next get value getvalue public void remove i remove public int size return persistent map impl this size persistentmapimpl public boolean contains object v return persistent map impl this contains value v persistentmapimpl containsvalue protected iterator entry k v entry iterator if index null if type class descriptor tp raw return new iterator entry k v private iterator persistent map entry k v i sorted collection persistent map entry k v index iterator public boolean has next return i has next public entry k v next return i next public void remove i remove else return new iterator entry k v private iterator entry object v i index v index entry iterator public boolean has next return i has next public entry k v next final entry object v e i next return new entry k v public k get key return k e get key public v get value return e get value public v set value v value throw new unsupported operation exception entry map set value public void remove i remove else return new iterator entry k v private int i 1 public boolean has next return i 1 values size public entry k v next if has next throw new no such element exception i 1 return new entry k v public k get key return k comparable keys i public v get value return values get i public v set value v value throw new unsupported operation exception entry map set value public void remove if i 0 throw new illegal state exception int size values size system arraycopy keys i 1 keys i size i 1 comparable keys size 1 null values remove object i i 1 entryiterator classdescriptor tpraw persistentmapentry sortedcollection persistentmapentry hasnext hasnext entryiterator hasnext hasnext getkey getkey getvalue getvalue setvalue unsupportedoperationexception setvalue hasnext hasnext nosuchelementexception getkey getvalue setvalue unsupportedoperationexception setvalue illegalstateexception removeobject private iterator persistent map entry k v i sorted collection persistent map entry k v index iterator public boolean has next return i has next persistentmapentry sortedcollection persistentmapentry hasnext hasnext public entry k v next return i next public void remove i remove private iterator entry object v i index v index entry iterator public boolean has next return i has next entryiterator hasnext hasnext public entry k v next final entry object v e i next return new entry k v public k get key return k e get key public v get value return e get value public v set value v value throw new unsupported operation exception entry map set value getkey getkey getvalue getvalue setvalue unsupportedoperationexception setvalue final entry object v e i next return new entry k v public k get key return k e get key getkey getkey return k e get key public v get value return e get value getkey getvalue getvalue return e get value public v set value v value throw new unsupported operation exception entry map set value getvalue setvalue unsupportedoperationexception setvalue public void remove i remove private int i 1 public boolean has next return i 1 values size hasnext public entry k v next if has next throw new no such element exception i 1 return new entry k v public k get key return k comparable keys i public v get value return values get i public v set value v value throw new unsupported operation exception entry map set value hasnext nosuchelementexception getkey getvalue setvalue unsupportedoperationexception setvalue i 1 return new entry k v public k get key return k comparable keys i getkey return k comparable keys i public v get value return values get i getvalue return values get i public v set value v value throw new unsupported operation exception entry map set value setvalue unsupportedoperationexception setvalue public void remove if i 0 throw new illegal state exception int size values size system arraycopy keys i 1 keys i size i 1 comparable keys size 1 null values remove object i i 1 illegalstateexception removeobject public set entry k v entry set if entry set null entry set new abstract set entry k v public iterator entry k v iterator return entry iterator public int size return persistent map impl this size public boolean remove object o if o instanceof map entry return false map entry k v entry map entry k v o k key entry get key v value entry get value if value null v v persistent map impl this get key if value equals v persistent map impl this remove key return true else if persistent map impl this contains key key persistent map impl this get key null persistent map impl this remove key return true return false public boolean contains object k entry k v e entry k v k if e get value null return e get value equals persistent map impl this get e get key else return persistent map impl this contains key e get key persistent map impl this get e get key null return entry set entryset entryset entryset abstractset entryiterator persistentmapimpl getkey getvalue persistentmapimpl persistentmapimpl persistentmapimpl containskey persistentmapimpl persistentmapimpl getvalue getvalue persistentmapimpl getkey persistentmapimpl containskey getkey persistentmapimpl getkey entryset if entry set null entry set new abstract set entry k v public iterator entry k v iterator return entry iterator entryset entryset abstractset entryiterator public int size return persistent map impl this size persistentmapimpl public boolean remove object o if o instanceof map entry return false map entry k v entry map entry k v o k key entry get key v value entry get value if value null v v persistent map impl this get key if value equals v persistent map impl this remove key return true else if persistent map impl this contains key key persistent map impl this get key null persistent map impl this remove key return true return false getkey getvalue persistentmapimpl persistentmapimpl persistentmapimpl containskey persistentmapimpl persistentmapimpl public boolean contains object k entry k v e entry k v k if e get value null return e get value equals persistent map impl this get e get key else return persistent map impl this contains key e get key persistent map impl this get e get key null getvalue getvalue persistentmapimpl getkey persistentmapimpl containskey getkey persistentmapimpl getkey public boolean equals object o if o this return true if o instanceof map return false map k v t map k v o if t size size return false try iterator entry k v i entry set iterator while i has next entry k v e i next k key e get key v value e get value if value null if t get key null t contains key key return false else if value equals t get key return false catch class cast exception unused return false catch null pointer exception unused return false return true entryset hasnext getkey getvalue containskey classcastexception nullpointerexception public int hash code int h 0 iterator entry k v i entry set iterator while i has next h i next hash code return h hashcode entryset hasnext hashcode public string to string string buffer buf new string buffer buf append iterator entry k v i entry set iterator boolean has next i has next while has next entry k v e i next k key e get key v value e get value if key this buf append this map else buf append key buf append if value this buf append this map else buf append value has next i has next if has next buf append buf append return buf to string tostring stringbuffer stringbuffer entryset hasnext hasnext hasnext getkey getvalue hasnext hasnext hasnext tostring final key generate key object key return generate key key true generatekey generatekey final key generate key object key boolean inclusive if key instanceof integer return new key integer key int value inclusive else if key instanceof byte return new key byte key byte value inclusive else if key instanceof character return new key character key char value inclusive else if key instanceof short return new key short key short value inclusive else if key instanceof long return new key long key long value inclusive else if key instanceof float return new key float key float value inclusive else if key instanceof double return new key double key double value inclusive else if key instanceof string return new key string key inclusive else if key instanceof enum return new key enum key inclusive else if key instanceof java util date return new key java util date key inclusive else throw new storage error storage error unsupported index type key get class generatekey intvalue bytevalue charvalue shortvalue longvalue floatvalue doublevalue storageerror storageerror unsupported_index_type getclass public comparator super k comparator return null public sorted map k v sub map k from k to if from compare to to 0 throw new illegal argument exception from to return new sub map from to sortedmap submap compareto illegalargumentexception submap public sorted map k v head map k to return new sub map null to sortedmap headmap submap public sorted map k v tail map k from return new sub map from null sortedmap tailmap submap sub map k from k to this from from this to to this from key from null generate key from true null this to key to null generate key to false null submap fromkey generatekey tokey generatekey public boolean is empty return entry set is empty isempty entryset isempty public boolean contains key object key return in range k key persistent map impl this contains key key containskey inrange persistentmapimpl containskey public v get object key if in range k key return null return persistent map impl this get key inrange persistentmapimpl public v put k key v value if in range key throw new illegal argument exception key out of range return persistent map impl this put key value inrange illegalargumentexception persistentmapimpl public comparator super k comparator return null public k first key return entry iterator index ascent order next get key firstkey entryiterator ascent_order getkey public k last key return entry iterator index descent order next get key lastkey entryiterator descent_order getkey protected iterator entry k v entry iterator final int order if index null if type class descriptor tp raw if order index ascent order return new iterator entry k v private iterator persistent map entry k v i sorted collection persistent map entry k v index iterator from key to key public boolean has next return i has next public entry k v next return i next public void remove i remove else return new iterator entry k v private array list persistent map entry k v entries sorted collection persistent map entry k v index get list from key to key private int i entries size public boolean has next return i 0 public entry k v next if has next throw new no such element exception return entries get i public void remove if i entries size entries get i null throw new illegal state exception sorted collection persistent map entry k v index remove entries get i entries set i null else return new iterator entry k v private iterator entry object v i index v index entry iterator from key to key order public boolean has next return i has next public entry k v next final entry object v e i next return new entry k v public k get key return k e get key public v get value return e get value public v set value v value throw new unsupported operation exception entry map set value public void remove i remove else if order index ascent order final int beg from null binary search from 0 1 final int end values size return new iterator entry k v private int i beg public boolean has next return i 1 end to null comparable keys i 1 compare to to 0 public entry k v next if has next throw new no such element exception i 1 return new entry k v public k get key return k comparable keys i public v get value return values get i public v set value v value throw new unsupported operation exception entry map set value public void remove if i 0 throw new illegal state exception int size values size system arraycopy keys i 1 keys i size i 1 comparable keys size 1 null values remove object i i 1 else final int beg to null binary search to 0 1 return new iterator entry k v private int i beg public boolean has next return i 0 from null comparable keys i 1 compare to from 0 public entry k v next if has next throw new no such element exception i 1 return new entry k v public k get key return k comparable keys i public v get value return values get i public v set value v value throw new unsupported operation exception entry map set value public void remove if i 0 throw new illegal state exception int size values size system arraycopy keys i 1 keys i size i 1 comparable keys size 1 null values remove object i entryiterator classdescriptor tpraw ascent_order persistentmapentry sortedcollection persistentmapentry fromkey tokey hasnext hasnext arraylist persistentmapentry sortedcollection persistentmapentry getlist fromkey tokey hasnext hasnext nosuchelementexception illegalstateexception sortedcollection persistentmapentry entryiterator fromkey tokey hasnext hasnext getkey getkey getvalue getvalue setvalue unsupportedoperationexception setvalue ascent_order binarysearch hasnext compareto hasnext nosuchelementexception getkey getvalue setvalue unsupportedoperationexception setvalue illegalstateexception removeobject binarysearch hasnext compareto hasnext nosuchelementexception getkey getvalue setvalue unsupportedoperationexception setvalue illegalstateexception removeobject private iterator persistent map entry k v i sorted collection persistent map entry k v index iterator from key to key public boolean has next return i has next persistentmapentry sortedcollection persistentmapentry fromkey tokey hasnext hasnext return i has next public entry k v next return i next hasnext return i next public void remove i remove private int i entries size public boolean has next return i 0 hasnext public entry k v next if has next throw new no such element exception return entries get i hasnext nosuchelementexception public void remove if i entries size entries get i null throw new illegal state exception sorted collection persistent map entry k v index remove entries get i entries set i null illegalstateexception sortedcollection persistentmapentry private iterator entry object v i index v index entry iterator from key to key order public boolean has next return i has next entryiterator fromkey tokey hasnext hasnext public entry k v next final entry object v e i next return new entry k v public k get key return k e get key public v get value return e get value public v set value v value throw new unsupported operation exception entry map set value getkey getkey getvalue getvalue setvalue unsupportedoperationexception setvalue final entry object v e i next return new entry k v public k get key return k e get key getkey getkey return k e get key public v get value return e get value getkey getvalue getvalue return e get value public v set value v value throw new unsupported operation exception entry map set value getvalue setvalue unsupportedoperationexception setvalue public void remove i remove private int i beg public boolean has next return i 1 end to null comparable keys i 1 compare to to 0 hasnext compareto public entry k v next if has next throw new no such element exception i 1 return new entry k v public k get key return k comparable keys i public v get value return values get i public v set value v value throw new unsupported operation exception entry map set value hasnext nosuchelementexception getkey getvalue setvalue unsupportedoperationexception setvalue i 1 return new entry k v public k get key return k comparable keys i getkey return k comparable keys i public v get value return values get i getvalue return values get i public v set value v value throw new unsupported operation exception entry map set value setvalue unsupportedoperationexception setvalue public void remove if i 0 throw new illegal state exception int size values size system arraycopy keys i 1 keys i size i 1 comparable keys size 1 null values remove object i i 1 illegalstateexception removeobject private int i beg public boolean has next return i 0 from null comparable keys i 1 compare to from 0 hasnext compareto public entry k v next if has next throw new no such element exception i 1 return new entry k v public k get key return k comparable keys i public v get value return values get i public v set value v value throw new unsupported operation exception entry map set value hasnext nosuchelementexception getkey getvalue setvalue unsupportedoperationexception setvalue i 1 return new entry k v public k get key return k comparable keys i getkey return k comparable keys i public v get value return values get i getvalue return values get i public v set value v value throw new unsupported operation exception entry map set value setvalue unsupportedoperationexception setvalue public void remove if i 0 throw new illegal state exception int size values size system arraycopy keys i 1 keys i size i 1 comparable keys size 1 null values remove object i illegalstateexception removeobject public set entry k v entry set if entry set null entry set new abstract set entry k v public iterator entry k v iterator return entry iterator index ascent order public int size iterator entry k v i iterator int n for n 0 i has next i next n 1 return n public boolean is empty return iterator has next public boolean remove object o if o instanceof map entry return false map entry k v entry map entry k v o k key entry get key if in range key return false v value entry get value if value null v v persistent map impl this get key if value equals v persistent map impl this remove key return true else if persistent map impl this contains key key persistent map impl this get key null persistent map impl this remove key return true return false public boolean contains object k entry k v e entry k v k if in range e get key return false if e get value null return e get value equals persistent map impl this get e get key else return persistent map impl this contains key e get key persistent map impl this get e get key null return entry set entryset entryset entryset abstractset entryiterator ascent_order hasnext isempty hasnext getkey inrange getvalue persistentmapimpl persistentmapimpl persistentmapimpl containskey persistentmapimpl persistentmapimpl inrange getkey getvalue getvalue persistentmapimpl getkey persistentmapimpl containskey getkey persistentmapimpl getkey entryset if entry set null entry set new abstract set entry k v public iterator entry k v iterator return entry iterator index ascent order entryset entryset abstractset entryiterator ascent_order public int size iterator entry k v i iterator int n for n 0 i has next i next n 1 return n hasnext public boolean is empty return iterator has next isempty hasnext public boolean remove object o if o instanceof map entry return false map entry k v entry map entry k v o k key entry get key if in range key return false v value entry get value if value null v v persistent map impl this get key if value equals v persistent map impl this remove key return true else if persistent map impl this contains key key persistent map impl this get key null persistent map impl this remove key return true return false getkey inrange getvalue persistentmapimpl persistentmapimpl persistentmapimpl containskey persistentmapimpl persistentmapimpl public boolean contains object k entry k v e entry k v k if in range e get key return false if e get value null return e get value equals persistent map impl this get e get key else return persistent map impl this contains key e get key persistent map impl this get e get key null inrange getkey getvalue getvalue persistentmapimpl getkey persistentmapimpl containskey getkey persistentmapimpl getkey public sorted map k v sub map k from k to if in range2 from throw new illegal argument exception from out of range if in range2 to throw new illegal argument exception to out of range return new sub map from to sortedmap submap inrange2 illegalargumentexception inrange2 illegalargumentexception submap public sorted map k v head map k to if in range2 to throw new illegal argument exception to out of range return new sub map this from to sortedmap headmap inrange2 illegalargumentexception submap public sorted map k v tail map k from if in range2 from throw new illegal argument exception from out of range return new sub map from this to sortedmap tailmap inrange2 illegalargumentexception submap private boolean in range k key return from null key compare to from 0 to null key compare to to 0 inrange compareto compareto this form allows the high endpoint as well as all legit keys private boolean in range2 k key return from null key compare to from 0 to null key compare to to 0 inrange2 compareto compareto public k first key if index null if type class descriptor tp raw return sorted collection persistent map entry k v index iterator next key else return k index v index entry iterator next get key else comparable keys comparable this keys if values size 0 throw new no such element exception return k comparable keys 0 firstkey classdescriptor tpraw sortedcollection persistentmapentry entryiterator getkey nosuchelementexception public k last key if index null if type class descriptor tp raw array list persistent map entry k v entries sorted collection persistent map entry k v index get list null null return entries get entries size 1 key else return k index v index entry iterator null null index descent order next get key else int size values size if size 0 throw new no such element exception return k comparable keys size 1 lastkey classdescriptor tpraw arraylist persistentmapentry sortedcollection persistentmapentry getlist entryiterator descent_order getkey nosuchelementexception public iterator v select class cls string predicate query v query new query impl v get storage return query select cls values iterator predicate queryimpl getstorage int types btree compound index btreecompoundindex btree compound index class key types boolean unique this unique unique type class descriptor tp array of byte types new int key types length for int i 0 i key types length i types i get compound key component type key types i btreecompoundindex keytypes classdescriptor tparrayofbyte keytypes keytypes getcompoundkeycomponenttype keytypes btree compound index int types boolean unique this types types this unique unique btreecompoundindex static int get compound key component type class c if c equals boolean class return class descriptor tp boolean else if c equals byte class return class descriptor tp byte else if c equals character class return class descriptor tp char else if c equals short class return class descriptor tp short else if c equals integer class return class descriptor tp int else if c equals long class return class descriptor tp long else if c equals float class return class descriptor tp float else if c equals double class return class descriptor tp double else if c equals string class return class descriptor tp string else if c equals date class return class descriptor tp date else if c equals byte class return class descriptor tp array of byte else if i persistent class is assignable from c return class descriptor tp object else throw new storage error storage error unsupported index type c getcompoundkeycomponenttype classdescriptor tpboolean classdescriptor tpbyte classdescriptor tpchar classdescriptor tpshort classdescriptor tpint classdescriptor tplong classdescriptor tpfloat classdescriptor tpdouble classdescriptor tpstring classdescriptor tpdate classdescriptor tparrayofbyte ipersistent isassignablefrom classdescriptor tpobject storageerror storageerror unsupported_index_type public class get key types class key types new class types length for int i 0 i key types length i key types i map key type types i return key types getkeytypes keytypes keytypes keytypes mapkeytype keytypes int compare byte arrays byte key byte item int offs int lengtn int o1 0 int o2 offs byte a1 key byte a2 item for int i 0 i types length o1 key length i int diff 0 switch types i case class descriptor tp boolean case class descriptor tp byte diff a1 o1 a2 o2 break case class descriptor tp short diff bytes unpack2 a1 o1 bytes unpack2 a2 o2 o1 2 o2 2 break case class descriptor tp char diff char bytes unpack2 a1 o1 char bytes unpack2 a2 o2 o1 2 o2 2 break case class descriptor tp int case class descriptor tp object case class descriptor tp enum int i1 bytes unpack4 a1 o1 int i2 bytes unpack4 a2 o2 diff i1 i2 1 i1 i2 0 1 o1 4 o2 4 break case class descriptor tp long case class descriptor tp date long l1 bytes unpack8 a1 o1 long l2 bytes unpack8 a2 o2 diff l1 l2 1 l1 l2 0 1 o1 8 o2 8 break case class descriptor tp float float f1 float int bits to float bytes unpack4 a1 o1 float f2 float int bits to float bytes unpack4 a2 o2 diff f1 f2 1 f1 f2 0 1 o1 4 o2 4 break case class descriptor tp double double d1 double long bits to double bytes unpack8 a1 o1 double d2 double long bits to double bytes unpack8 a2 o2 diff d1 d2 1 d1 d2 0 1 o1 8 o2 8 break case class descriptor tp string int len1 bytes unpack4 a1 o1 int len2 bytes unpack4 a2 o2 o1 4 o2 4 int len len1 len2 len1 len2 while len 0 diff char bytes unpack2 a1 o1 char bytes unpack2 a2 o2 if diff 0 return diff o1 2 o2 2 diff len1 len2 break case class descriptor tp array of byte int len1 bytes unpack4 a1 o1 int len2 bytes unpack4 a2 o2 o1 4 o2 4 int len len1 len2 len1 len2 while len 0 diff a1 o1 a2 o2 if diff 0 return diff diff len1 len2 break default assert failed invalid type if diff 0 return diff return 0 comparebytearrays classdescriptor tpboolean classdescriptor tpbyte classdescriptor tpshort classdescriptor tpchar classdescriptor tpint classdescriptor tpobject classdescriptor tpenum classdescriptor tplong classdescriptor tpdate classdescriptor tpfloat intbitstofloat intbitstofloat classdescriptor tpdouble longbitstodouble longbitstodouble classdescriptor tpstring classdescriptor tparrayofbyte object unpack byte array key page pg int pos int offs btree page first key offs btree page get key str offs pg pos byte data pg data object values new object types length for int i 0 i types length i object v null switch types i case class descriptor tp boolean v boolean value of data offs 0 break case class descriptor tp byte v new byte data offs break case class descriptor tp short v short value of bytes unpack2 data offs offs 2 break case class descriptor tp char v new character char bytes unpack2 data offs offs 2 break case class descriptor tp int v new integer bytes unpack4 data offs offs 4 break case class descriptor tp object int oid bytes unpack4 data offs v oid 0 null storage impl get storage lookup object oid null offs 4 break case class descriptor tp long v new long bytes unpack8 data offs offs 8 break case class descriptor tp date long msec bytes unpack8 data offs v msec 1 null new date msec offs 8 break case class descriptor tp float v new float float int bits to float bytes unpack4 data offs offs 4 break case class descriptor tp double v new double double long bits to double bytes unpack8 data offs offs 8 break case class descriptor tp string int len bytes unpack4 data offs offs 4 char sval new char len for int j 0 j len j sval j char bytes unpack2 data offs offs 2 v new string sval break case class descriptor tp array of byte int len bytes unpack4 data offs offs 4 byte bval new byte len system arraycopy data offs bval 0 len offs len break default assert failed invalid type values i v return values unpackbytearraykey btreepage firstkeyoffs btreepage getkeystroffs classdescriptor tpboolean valueof classdescriptor tpbyte classdescriptor tpshort valueof classdescriptor tpchar classdescriptor tpint classdescriptor tpobject storageimpl getstorage lookupobject classdescriptor tplong classdescriptor tpdate classdescriptor tpfloat intbitstofloat classdescriptor tpdouble longbitstodouble classdescriptor tpstring classdescriptor tparrayofbyte private key convert key key key if key null return null if key type class descriptor tp array of object throw new storage error storage error incompatible key type object values object key oval byte buffer buf new byte buffer int dst 0 for int i 0 i values length i object v values i switch types i case class descriptor tp boolean buf extend dst 1 buf arr dst byte boolean v boolean value 1 0 break case class descriptor tp byte buf extend dst 1 buf arr dst number v byte value break case class descriptor tp short buf extend dst 2 bytes pack2 buf arr dst number v short value dst 2 break case class descriptor tp char buf extend dst 2 bytes pack2 buf arr dst v instanceof number number v short value short character v char value dst 2 break case class descriptor tp int buf extend dst 4 bytes pack4 buf arr dst number v int value dst 4 break case class descriptor tp object buf extend dst 4 bytes pack4 buf arr dst v null 0 i persistent v get oid dst 4 break case class descriptor tp long buf extend dst 8 bytes pack8 buf arr dst number v long value dst 8 break case class descriptor tp date buf extend dst 8 bytes pack8 buf arr dst v null 1 date v get time dst 8 break case class descriptor tp float buf extend dst 4 bytes pack4 buf arr dst float float to int bits number v float value dst 4 break case class descriptor tp double buf extend dst 8 bytes pack8 buf arr dst double double to long bits number v double value dst 8 break case class descriptor tp enum buf extend dst 4 bytes pack4 buf arr dst enum v ordinal dst 4 break case class descriptor tp string buf extend dst 4 if v null string str string v int len str length bytes pack4 buf arr dst len dst 4 buf extend dst len 2 for int j 0 j len j bytes pack2 buf arr dst short str char at j dst 2 else bytes pack4 buf arr dst 0 dst 4 break case class descriptor tp array of byte buf extend dst 4 if v null byte arr byte v int len arr length bytes pack4 buf arr dst len dst 4 buf extend dst len system arraycopy arr 0 buf arr dst len dst len else bytes pack4 buf arr dst 0 dst 4 break default assert failed invalid type return new key buf to array key inclusion 0 convertkey classdescriptor tparrayofobject storageerror storageerror incompatible_key_type bytebuffer bytebuffer classdescriptor tpboolean booleanvalue classdescriptor tpbyte bytevalue classdescriptor tpshort shortvalue classdescriptor tpchar shortvalue charvalue classdescriptor tpint intvalue classdescriptor tpobject ipersistent getoid classdescriptor tplong longvalue classdescriptor tpdate gettime classdescriptor tpfloat floattointbits floatvalue classdescriptor tpdouble doubletolongbits doublevalue classdescriptor tpenum classdescriptor tpstring charat classdescriptor tparrayofbyte toarray public array list t get list key from key till return super get list convert key from convert key till arraylist getlist getlist convertkey convertkey public t get key key return super get convert key key convertkey public t remove key key return super remove convert key key convertkey public void remove key key t obj super remove convert key key obj convertkey public t set key key t obj return super set convert key key obj convertkey public boolean put key key t obj return super put convert key key obj convertkey public iterable iterator t iterator key from key till int order return super iterator convert key from convert key till order iterableiterator convertkey convertkey public iterable iterator map entry object t entry iterator key from key till int order return super entry iterator convert key from convert key till order iterableiterator entryiterator entryiterator convertkey convertkey public static string encode string s int n s length string builder sb new string builder n encode to buffer n s sb return sb to string stringbuilder stringbuilder encodetobuffer tostring public static void encode to buffer string s string builder sb encode to buffer s length s sb encodetobuffer stringbuilder encodetobuffer private static void encode to buffer int n string s string builder sb for int i 0 i n i char c s char at i if character is letter or digit c only special characters need checking sb append c else if char table contains key c sb append sb append char table get c sb append else sb append c encodetobuffer stringbuilder charat isletterordigit chartable containskey chartable encode string so it is safe to be used in xml attribute value and text html encode encode use some html specific entities e g amp hence not suitable for generic xml public static string encodexml string s extensible markup language xml 1 0 fifth edition 10 att value reference reference 14 char data s s replace 38 s s replace 34 s s replace 39 s s replace 60 s s replace 62 char data can t contain return s htmlencode attvalue chardata chardata public char table hash map character string map int keys new int map size int key index 0 int max 0 for character key map key set int val key char value keys key index val if val max max val modulo map size int collision table new int max 1 using integers instead of booleans no cleanup boolean ok false while ok modulo try a higher modulo ok true for int i 0 ok i keys length i key index keys i modulo try this modulo if collision table key index modulo is this value already used ok false else collision table key index modulo system out println the modulo is modulo was the modulo is 1474 chars new char modulo strings new string modulo for character character map key set key index character char value modulo chars key index character char value strings key index map get character if chars 0 0 strings 0 null chars 0 1 chartable hashmap keyindex keyset charvalue keyindex collisiontable keyindex collisiontable keyindex collisiontable keyindex keyset keyindex charvalue keyindex charvalue keyindex public boolean contains key char key return chars key modulo key containskey public string get char key return chars key modulo key strings key modulo null public request tag boolean isssk start start super this start start this isssk isssk requesttag public void set request sender finished int status request sender finished code status setrequestsenderfinished requestsenderfinishedcode public void set sender request sender rs sender new weak reference request sender rs setsender requestsender weakreference requestsender public void handler threw throwable t this handler threw t handlerthrew handlerthrew public void set served from datastore served from datastore true setservedfromdatastore servedfromdatastore public void set rejected rejected true setrejected override public void log still present long uid string buffer sb new string buffer sb append still present after append time util format time age sb append append uid append start append start sb append ssk append isssk append from store append served from datastore if sender null sb append sender hasn t been set else request sender s sender get if s null sb append sender null else sb append sender append s sb append status sb append s get status string sb append finished code append request sender finished code sb append rejected append rejected sb append thrown append handler threw if aborted downstream transfer sb append aborted downstream transfer reason sb append aborted downstream reason sb append desc sb append aborted downstream desc if handler disconnected sb append handler disconnected true if handler threw null logger error this sb to string handler threw else logger error this sb to string logstillpresent stringbuffer stringbuffer timeutil formattime servedfromdatastore requestsender getstatusstring finishedcode requestsenderfinishedcode handlerthrew aborteddownstreamtransfer aborteddownstreamtransfer aborteddownstreamreason aborteddownstreamdesc handlerdisconnected handlerdisconnected handlerthrew tostring handlerthrew tostring public void on abort downstream transfers int reason string desc aborted downstream transfer true aborted downstream reason reason aborted downstream desc desc onabortdownstreamtransfers aborteddownstreamtransfer aborteddownstreamreason aborteddownstreamdesc public void handler disconnected handler disconnected true handlerdisconnected handlerdisconnected public static double get location string init try if init null return 1 double d double parse double init if d 0 0 d 1 0 return 1 return d catch number format exception e return 1 getlocation parsedouble numberformatexception static double distance peer node p double loc double d distance p get location loc return d return d p get bias peernode getlocation getbias distance between two locations both parameters must be in 0 0 1 0 public static double distance double a double b return distance a b false public static double distance double a double b boolean allow crazy circular keyspace if allow crazy if a 0 0 a 1 0 b 0 0 b 1 0 logger error peer manager class invalid location a a b b please report this bug new exception error throw new null pointer exception return simple distance a b else if a 0 0 a 1 0 a 2 0 if b 0 0 b 1 0 b 2 0 if a 1 0 b 2 0 return 0 0 both are out of range so both are equal if a 1 0 return a b if b 1 0 return b a return simple distance a b allowcrazy allowcrazy peermanager nullpointerexception simpledistance simpledistance private static double simple distance double a double b if a b return math min a b 1 0 a b else return math min b a 1 0 b a simpledistance patterned after distance double double but also retuns the direction of the change positive negative when given two values on opposite ends of the keyspace it will return 0 5 public static double change double from double to if to from double direct difference to from double opposite difference 1 0 to from if direct difference opposite difference return direct difference else return opposite difference else it s going the other way return 1 change to from except the edge case of 0 5 double direct difference from to double opposite difference 1 0 from to if direct difference opposite difference return direct difference else return opposite difference directdifference oppositedifference directdifference oppositedifference directdifference oppositedifference directdifference oppositedifference directdifference oppositedifference directdifference oppositedifference given an arbitrary double not bound to 0 0 1 0 return the normalized double 0 0 1 0 which would result in simple wrapping overflowing e g normalize 1 0 0 5 0 5 normalize 0 5 1 0 0 5 normalize 0 0 1 0 0 0 1 0 bug if given double has wrapped too many times the return value may be not be precise public static double normalize double rough int int part int rough double maybe negative rough int part note maybe negative is bound between 1 0 1 0 if maybe negative 0 return 1 0 maybe negative return maybe negative intpart maybenegative intpart maybenegative maybenegative maybenegative maybenegative public static boolean equals double new loc double current location return math abs new loc current location double min value 2 newloc currentlocation newloc currentlocation min_value int types alt btree compound index altbtreecompoundindex alt btree compound index class key types boolean unique this unique unique type class descriptor tp raw types new int key types length for int i 0 i key types length i types i get compound key component type key types i altbtreecompoundindex keytypes classdescriptor tpraw keytypes keytypes getcompoundkeycomponenttype keytypes static int get compound key component type class c if c equals boolean class return class descriptor tp boolean else if c equals byte class return class descriptor tp byte else if c equals character class return class descriptor tp char else if c equals short class return class descriptor tp short else if c equals integer class return class descriptor tp int else if c equals long class return class descriptor tp long else if c equals float class return class descriptor tp float else if c equals double class return class descriptor tp double else if c equals string class return class descriptor tp string else if c equals date class return class descriptor tp date else if i persistent class is assignable from c return class descriptor tp object else if comparable class is assignable from c return class descriptor tp raw else throw new storage error storage error unsupported index type c getcompoundkeycomponenttype classdescriptor tpboolean classdescriptor tpbyte classdescriptor tpchar classdescriptor tpshort classdescriptor tpint classdescriptor tplong classdescriptor tpfloat classdescriptor tpdouble classdescriptor tpstring classdescriptor tpdate ipersistent isassignablefrom classdescriptor tpobject isassignablefrom classdescriptor tpraw storageerror storageerror unsupported_index_type public class get key types class key types new class types length for int i 0 i key types length i key types i map key type types i return key types getkeytypes keytypes keytypes keytypes mapkeytype keytypes public int compare to object o compound key c compound key o int n keys length c keys length keys length c keys length for int i 0 i n i int diff comparable keys i compare to c keys i if diff 0 return diff return 0 allow to compare part of the compound key compareto compoundkey compoundkey compareto compound key object keys this keys keys compoundkey private key convert key key key if key null return null if key type class descriptor tp array of object throw new storage error storage error incompatible key type object key components object key oval if key components length types length throw new storage error storage error incompatible key type boolean is copy false for int i 0 i key components length i int type types i if type class descriptor tp object type class descriptor tp boolean if is copy object new key components new object key components length system arraycopy key components 0 new key components 0 key components length key components new key components is copy true key components i type class descriptor tp object object new integer key components i null 0 i persistent key components i get oid object new byte byte boolean key components i boolean value 1 0 return new key new compound key key components key inclusion 0 convertkey classdescriptor tparrayofobject storageerror storageerror incompatible_key_type keycomponents keycomponents storageerror storageerror incompatible_key_type iscopy keycomponents classdescriptor tpobject classdescriptor tpboolean iscopy newkeycomponents keycomponents keycomponents newkeycomponents keycomponents keycomponents newkeycomponents iscopy keycomponents classdescriptor tpobject keycomponents ipersistent keycomponents getoid keycomponents booleanvalue compoundkey keycomponents public array list t get list key from key till return super get list convert key from convert key till arraylist getlist getlist convertkey convertkey public t get key key return super get convert key key convertkey public t remove key key return super remove convert key key convertkey public void remove key key t obj super remove convert key key obj convertkey public t set key key t obj return super set convert key key obj convertkey public boolean put key key t obj return super put convert key key obj convertkey public iterable iterator t iterator key from key till int order return super iterator convert key from convert key till order iterableiterator convertkey convertkey public iterable iterator map entry object t entry iterator key from key till int order return super entry iterator convert key from convert key till order iterableiterator entryiterator entryiterator convertkey convertkey public native thread string name int priority boolean dont check renice super name this current priority priority this dont check renice dont check renice nativethread dontcheckrenice currentpriority dontcheckrenice dontcheckrenice public native thread runnable r string name int priority boolean dont check renice super r name this current priority priority this dont check renice dont check renice nativethread dontcheckrenice currentpriority dontcheckrenice dontcheckrenice public native thread thread group g runnable r string name int priority boolean dont check renice super g r name this current priority priority this dont check renice dont check renice nativethread threadgroup dontcheckrenice currentpriority dontcheckrenice dontcheckrenice set linux priority jni call return true if successful false otherwise private static native boolean set linux priority int prio get linux priority jni call private static native int get linux priority setlinuxpriority getlinuxpriority override public void run if set native priority current priority system err println set native priority current priority has failed super run setnativepriority currentpriority setnativepriority currentpriority rescale java priority and set linux priority private boolean set native priority int prio logger minor this set native priority prio set priority prio if loadnative logger minor this loadnative is false return true int real prio get linux priority if disabled logger normal this not setting native priority as disabled due to renicing return false if native priority base real prio dont check renice the user has reniced freenet or we didn t use the packet sender to create the thread either ways it s bad for us let s disable the renicing as we can t rely on it anymore disabled true logger error this freenet has detected it has been reniced that s bad don t do it nice level detected statically native priority base actual nice level real prio on this system err println freenet has detected it has been reniced that s bad don t do it nice level detected statically native priority base actual nice level real prio on this new null pointer exception print stack trace return false final int linux priority native priority base native priority range native priority range prio min priority java priority range if linux priority real prio return true ok that s an obvious coding mistake if prio current priority throw new illegal state exception you re trying to set a thread priority above the current value it s not possible if you aren t root and shouldn t ever occur in our code asked prio linux priority current max current priority native priority base shoudln t happen please report logger minor this setting native priority to linux priority base native priority base for this return set linux priority linux priority setnativepriority setnativepriority setpriority _loadnative _loadnative realprio getlinuxpriority _disabled native_priority_base realprio dontcheckrenice packetsender _disabled native_priority_base realprio native_priority_base realprio nullpointerexception printstacktrace linuxpriority native_priority_base native_priority_range native_priority_range min_priority java_priority_range linuxpriority realprio currentpriority illegalstateexception linuxpriority currentmax currentpriority native_priority_base linuxpriority native_priority_base setlinuxpriority linuxpriority public int get native priority return current priority getnativepriority currentpriority public static boolean using native code return loadnative disabled usingnativecode _loadnative _disabled public static final string code2 string int code switch code case invalid action return invalid action case invalid args return invalid args case out of sync return out of sync case invalid var return invalid var case precondition failed return precondition failed case action failed return action failed return code2string invalid_action invalid_args out_of_sync invalid_var precondition_failed action_failed public u pnp status set code 0 set description upnpstatus setcode setdescription public u pnp status int code string desc set code code set description desc upnpstatus setcode setdescription public int get code return code getcode public void set code int code this code code setcode public string get description return description getdescription public void set description string description this description description setdescription override protected bucket make bucket long size throws io exception filename generator filename generator new filename generator weakprng false null junit temp file bucket file bucket new temp file bucket filename generator make random filename filename generator return new padded ephemerally encrypted bucket file bucket 1024 strongprng weakprng makebucket ioexception filenamegenerator filenamegenerator filenamegenerator tempfilebucket filebucket tempfilebucket filenamegenerator makerandomfilename filenamegenerator paddedephemerallyencryptedbucket filebucket override protected void free bucket bucket bucket throws io exception bucket free freebucket ioexception private int count public int size return count public array list t elements array list t list new array list t count fill list root zero fill list root one return list arraylist arraylist arraylist rootzero rootone public object to array return elements to array toarray toarray public e e to array e arr return elements to array arr toarray toarray public iterator t iterator return elements iterator private static e extends i persistent void fill array list e list p trie node e node if node null list add node obj fill list node child zero fill list node child one ipersistent arraylist ptrienode childzero childone private static int first bit long key int key length return int key key length 1 1 firstbit keylength keylength private static int get common part length long keya int key lengtha long keyb int key lengthb if key lengtha key lengthb keya key lengtha key lengthb key lengtha key lengthb else keyb key lengthb key lengtha key lengthb key lengtha long diff keya keyb int count 0 while diff 0 diff 1 count 1 return key lengtha count getcommonpartlength keylengtha keylengthb keylengtha keylengthb keylengtha keylengthb keylengtha keylengthb keylengthb keylengtha keylengthb keylengtha keylengtha public t add patricia trie key key t obj modify count 1 if first bit key mask key length 1 if root one null return root one add key mask key length obj else root one new p trie node t key mask key length obj return null else if root zero null return root zero add key mask key length obj else root zero new p trie node t key mask key length obj return null patriciatriekey firstbit rootone rootone rootone ptrienode rootzero rootzero rootzero ptrienode public t find best match patricia trie key key if first bit key mask key length 1 if root one null return root one find best match key mask key length else if root zero null return root zero find best match key mask key length return null findbestmatch patriciatriekey firstbit rootone rootone findbestmatch rootzero rootzero findbestmatch public t find exact match patricia trie key key if first bit key mask key length 1 if root one null return root one find exact match key mask key length else if root zero null return root zero find exact match key mask key length return null findexactmatch patriciatriekey firstbit rootone rootone findexactmatch rootzero rootzero findexactmatch public t remove patricia trie key key if first bit key mask key length 1 if root one null t obj root one remove key mask key length if obj null modify count 1 if root one is not used root one deallocate root one null return obj else if root zero null t obj root zero remove key mask key length if obj null modify count 1 if root zero is not used root zero deallocate root zero null return obj return null patriciatriekey firstbit rootone rootone rootone isnotused rootone rootone rootzero rootzero rootzero isnotused rootzero rootzero public void clear if root one null root one deallocate root one null if root zero null root zero deallocate root zero null count 0 rootone rootone rootone rootzero rootzero rootzero p trie node long key int key length t obj this obj obj this key key this key length key length ptrienode keylength keylength keylength p trie node ptrienode t add long key int key length t obj if key this key key length this key length modify t prev obj this obj this obj obj return prev obj int key length common get common part length key key length this key this key length int key length diff this key length key length common long key common key key length key length common long key diff this key key common key length diff if key length diff 0 modify p trie node t new node new p trie node t key diff key length diff this obj new node child zero child zero new node child one child one this key key common this key length key length common this obj null if first bit key diff key length diff 1 child zero null child one new node else child zero new node child one null if key length key length common key length diff key length key length common key diff key key common key length diff if first bit key diff key length diff 1 if child one null return child one add key diff key length diff obj else modify child one new p trie node t key diff key length diff obj return null else if child zero null return child zero add key diff key length diff obj else modify child zero new p trie node t key diff key length diff obj return null else t prev obj this obj this obj obj return prev obj keylength keylength keylength prevobj prevobj keylengthcommon getcommonpartlength keylength keylength keylengthdiff keylength keylengthcommon keycommon keylength keylengthcommon keydiff keycommon keylengthdiff keylengthdiff ptrienode newnode ptrienode keydiff keylengthdiff newnode childzero childzero newnode childone childone keycommon keylength keylengthcommon firstbit keydiff keylengthdiff childzero childone newnode childzero newnode childone keylength keylengthcommon keylengthdiff keylength keylengthcommon keydiff keycommon keylengthdiff firstbit keydiff keylengthdiff childone childone keydiff keylengthdiff childone ptrienode keydiff keylengthdiff childzero childzero keydiff keylengthdiff childzero ptrienode keydiff keylengthdiff prevobj prevobj t find best match long key int key length if key length this key length int key length common get common part length key key length this key this key length int key length diff key length key length common long key common key key length diff long key diff key key common key length diff if first bit key diff key length diff 1 if child one null return child one find best match key diff key length diff else if child zero null return child zero find best match key diff key length diff return obj findbestmatch keylength keylength keylength keylengthcommon getcommonpartlength keylength keylength keylengthdiff keylength keylengthcommon keycommon keylengthdiff keydiff keycommon keylengthdiff firstbit keydiff keylengthdiff childone childone findbestmatch keydiff keylengthdiff childzero childzero findbestmatch keydiff keylengthdiff t find exact match long key int key length if key length this key length if key this key key length this key length return obj else int key length common get common part length key key length this key this key length if key length common this key length int key length diff key length key length common long key common key key length diff long key diff key key common key length diff if first bit key diff key length diff 1 if child one null return child one find best match key diff key length diff else if child zero null return child zero find best match key diff key length diff return null findexactmatch keylength keylength keylength keylength keylength keylengthcommon getcommonpartlength keylength keylength keylengthcommon keylength keylengthdiff keylength keylengthcommon keycommon keylengthdiff keydiff keycommon keylengthdiff firstbit keydiff keylengthdiff childone childone findbestmatch keydiff keylengthdiff childzero childzero findbestmatch keydiff keylengthdiff boolean is not used return obj null child one null child zero null isnotused childone childzero t remove long key int key length if key length this key length if key this key key length this key length t obj this obj this obj null return obj else int key length common get common part length key key length this key this key length int key length diff key length key length common long key common key key length diff long key diff key key common key length diff if first bit key diff key length diff 1 if child one null t obj child one find best match key diff key length diff if obj null if child one is not used modify child one deallocate child one null return obj else if child zero null t obj child zero find best match key diff key length diff if obj null if child zero is not used modify child zero deallocate child zero null return obj return null keylength keylength keylength keylength keylength keylengthcommon getcommonpartlength keylength keylength keylengthdiff keylength keylengthcommon keycommon keylengthdiff keydiff keycommon keylengthdiff firstbit keydiff keylengthdiff childone childone findbestmatch keydiff keylengthdiff childone isnotused childone childone childzero childzero findbestmatch keydiff keylengthdiff childzero isnotused childzero childzero public void deallocate if child one null child one deallocate if child zero null child zero deallocate super deallocate childone childone childzero childzero construct a curl filter with no distortion public curl filter set edge action zero curlfilter curlfilter setedgeaction public void set transition float transition this transition transition settransition public float get transition return transition gettransition public void set angle float angle this angle angle setangle public float get angle return angle getangle public void set radius float radius this radius radius setradius public float get radius return radius getradius public sampler buffered image image int width image get width int height image get height int type image get type in pixels image utils getrgb image 0 0 width height null bufferedimage getwidth getheight gettype inpixels imageutils public int sample float x float y int srcx int math floor x int srcy int math floor y float x weight x srcx float y weight y srcy int nw ne sw se if srcx 0 srcx width 1 srcy 0 srcy height 1 easy case all corners are in the image int i width srcy srcx nw in pixels i ne in pixels i 1 sw in pixels i width se in pixels i width 1 else some of the corners are off the image nw get pixel in pixels srcx srcy width height ne get pixel in pixels srcx 1 srcy width height sw get pixel in pixels srcx srcy 1 width height se get pixel in pixels srcx 1 srcy 1 width height return image math bilinear interpolate x weight y weight nw ne sw se xweight yweight inpixels inpixels inpixels inpixels getpixel inpixels getpixel inpixels getpixel inpixels getpixel inpixels imagemath bilinearinterpolate xweight yweight final private int get pixel int pixels int x int y int width int height if x 0 x width y 0 y height switch edge action case zero default return 0 case wrap return pixels image math mod y height width image math mod x width case clamp return pixels image math clamp y 0 height 1 width image math clamp x 0 width 1 return pixels y width x getpixel edgeaction imagemath imagemath imagemath imagemath override public buffered image filter buffered image src buffered image dst int width src get width int height src get height this width src get width this height src get height int type src get type original space new rectangle 0 0 width height transformed space new rectangle 0 0 width height transform space transformed space if dst null color model dstcm src get color model dst new buffered image dstcm dstcm create compatible writable raster transformed space width transformed space height dstcm is alpha premultiplied null writable raster dst raster dst get raster int in pixels getrgb src 0 0 width height null if interpolation nearest neighbour return filter pixelsnn dst width height in pixels transformed space int src width width int src height height int src width1 width 1 int src height1 height 1 int out width transformed space width int out height transformed space height int outx outy int index 0 int out pixels new int out width outx transformed space x outy transformed space y float out new float 4 for int y 0 y out height y for int x 0 x out width x transform inverse outx x outy y out int srcx int math floor out 0 int srcy int math floor out 1 float x weight out 0 srcx float y weight out 1 srcy int nw ne sw se if srcx 0 srcx src width1 srcy 0 srcy src height1 easy case all corners are in the image int i src width srcy srcx nw in pixels i ne in pixels i 1 sw in pixels i src width se in pixels i src width 1 else some of the corners are off the image nw get pixel in pixels srcx srcy src width src height ne get pixel in pixels srcx 1 srcy src width src height sw get pixel in pixels srcx srcy 1 src width src height se get pixel in pixels srcx 1 srcy 1 src width src height int rgb image math bilinear interpolate x weight y weight nw ne sw se int r rgb 16 0xff int g rgb 8 0xff int b rgb 0xff float shade out 2 r int r shade g int g shade b int b shade rgb rgb 0xff000000 r 16 g 8 b if out 3 0 out pixels x pixel utils combine pixels rgb in pixels src width y x pixel utils normal else out pixels x rgb setrgb dst 0 y transformed space width 1 out pixels return dst bufferedimage bufferedimage bufferedimage getwidth getheight getwidth getheight gettype originalspace transformedspace transformspace transformedspace colormodel getcolormodel bufferedimage createcompatiblewritableraster transformedspace transformedspace isalphapremultiplied writableraster dstraster getraster inpixels nearest_neighbour filterpixelsnn inpixels transformedspace srcwidth srcheight srcwidth1 srcheight1 outwidth transformedspace outheight transformedspace outpixels outwidth transformedspace transformedspace outheight outwidth transforminverse xweight yweight srcwidth1 srcheight1 srcwidth inpixels inpixels inpixels srcwidth inpixels srcwidth getpixel inpixels srcwidth srcheight getpixel inpixels srcwidth srcheight getpixel inpixels srcwidth srcheight getpixel inpixels srcwidth srcheight imagemath bilinearinterpolate xweight yweight outpixels pixelutils combinepixels inpixels srcwidth pixelutils outpixels transformedspace outpixels final private int get pixel int pixels int x int y int width int height if x 0 x width y 0 y height switch edge action case zero default return 0 case wrap return pixels image math mod y height width image math mod x width case clamp return pixels image math clamp y 0 height 1 width image math clamp x 0 width 1 return pixels y width x getpixel edgeaction imagemath imagemath imagemath imagemath override protected void transform inverse int x int y float out fisheye float mirror distance width centrex float mirror radius width centrey float cx width 5f float cy height 5f float dx x cx float dy y cy float r2 dx dx dy dy float r float math sqrt r2 float phi float math pi 5 math asin math sqrt mirror radius mirror radius r2 mirror radius r r mirror radius width mirror distance float math tan phi phi float math atan2 dy dx out 0 cx r float math cos phi out 1 cy r float math sin phi float t transition float px x py y float s float math sin angle float c float math cos angle float tx t width tx t float math sqrt width width height height start from the correct corner according to the angle float xoffset c 0 width 0 float yoffset s 0 height 0 transform into unrotated coordinates px xoffset py yoffset float qx px c py s float qy px s py c boolean outside qx tx boolean unfolded qx tx 2 boolean oncurl outside unfolded qx qx tx 2 qx 2 tx qx transform back into rotated coordinates px qx c qy s py qx s qy c px xoffset py yoffset see if we re off the edge of the page boolean offpage px 0 py 0 px width py height if we re off the edge but in the curl if offpage oncurl px x py y shade the curl float shade offpage oncurl 1 9f 1 0f float math cos math exp qx tx radius 0 out 2 1 shade if outside out 0 out 1 1 else out 0 px out 1 py out 3 offpage oncurl 1 0 transforminverse mirrordistance mirrorradius mirrorradius mirrorradius mirrorradius mirrorradius mirrordistance override public string to string return distort curl tostring private static final long serial versionuid 2379889735659369065l public http server list serialversionuid httpserverlist public void add request listener http request listener listener int n servers size for int n 0 n n servers n http server server gethttp server n server add request listener listener addrequestlistener httprequestlistener nservers nservers httpserver gethttpserver addrequestlistener public http server gethttp server int n return http server get n httpserver gethttpserver httpserver public void close int n servers size for int n 0 n n servers n http server server gethttp server n server close nservers nservers httpserver gethttpserver public boolean open int port int n host addrs host interface getn host addresses for int n 0 n n host addrs n string bind addr host interface get host address n http server http server new http server if http server open bind addr port false close clear return false add http server return true nhostaddrs hostinterface getnhostaddresses nhostaddrs bindaddr hostinterface gethostaddress httpserver httpserver httpserver httpserver bindaddr httpserver public void start int n servers size for int n 0 n n servers n http server server gethttp server n server start nservers nservers httpserver gethttpserver public void stop int n servers size for int n 0 n n servers n http server server gethttp server n server stop nservers nservers httpserver gethttpserver private final string id public node hello message final node node string id this node node this id id nodehellomessage override public simple field set get field set simple field set sfs new simple field set true fixme sfs put single fcp version 2 0 sfs put single node fred sfs put single version version get version string sfs put build version build number sfs put single revision version cvs revision sfs put ext build node starter ext build number sfs put single ext revision node starter ext revision number sfs put single testnet boolean to string node null false node is testnet enabled sfs put single compression codecs integer to string compressor compressor type values length sfs put single connection identifier id sfs put single node language l10n get selected language to string return sfs simplefieldset getfieldset simplefieldset simplefieldset putsingle fcpversion putsingle putsingle getversionstring buildnumber putsingle cvsrevision extbuild nodestarter extbuildnumber putsingle extrevision nodestarter extrevisionnumber putsingle tostring istestnetenabled putsingle compressioncodecs tostring compressor_type putsingle connectionidentifier putsingle nodelanguage getselectedlanguage tostring override public string get name return node hello message name getname nodehellomessage override public void run fcp connection handler handler node node throws message invalid exception throw new message invalid exception protocol error message invalid message node hello goes from server to client not the other way around null false fcpconnectionhandler messageinvalidexception messageinvalidexception protocolerrormessage invalid_message nodehello override public void remove from object container container container delete this removefrom objectcontainer public buffered image filter buffered image src buffered image dst int width src get width int height src get height if dst null dst create compatible dest image src null int in pixels new int width height int out pixels new int width height getrgb src 0 0 width height in pixels kernel kernel gaussian filter make kernel h radius threshold blur kernel in pixels out pixels width height true threshold blur kernel out pixels in pixels height width true setrgb dst 0 0 width height in pixels return dst bufferedimage bufferedimage bufferedimage getwidth getheight createcompatibledestimage inpixels outpixels inpixels gaussianfilter makekernel hradius thresholdblur inpixels outpixels thresholdblur outpixels inpixels inpixels convolve with a kernel consisting of one row private void threshold blur kernel kernel int in pixels int out pixels int width int height boolean alpha int index 0 float matrix kernel get kernel data null int cols kernel get width int cols2 cols 2 for int y 0 y height y int ioffset y width int out index y for int x 0 x width x float r 0 g 0 b 0 a 0 int moffset cols2 int rgb1 in pixels ioffset x int a1 rgb1 24 0xff int r1 rgb1 16 0xff int g1 rgb1 8 0xff int b1 rgb1 0xff float af 0 rf 0 gf 0 bf 0 for int col cols2 col cols2 col float f matrix moffset col if f 0 int ix x col if 0 ix ix width ix x int rgb2 in pixels ioffset ix int a2 rgb2 24 0xff int r2 rgb2 16 0xff int g2 rgb2 8 0xff int b2 rgb2 0xff int d d a1 a2 if d threshold d threshold a f a2 af f d r1 r2 if d threshold d threshold r f r2 rf f d g1 g2 if d threshold d threshold g f g2 gf f d b1 b2 if d threshold d threshold b f b2 bf f a af 0 a1 a af r rf 0 r1 r rf g gf 0 g1 g gf b bf 0 b1 b bf int ia alpha pixel utils clamp int a 0 5 0xff int ir pixel utils clamp int r 0 5 int ig pixel utils clamp int g 0 5 int ib pixel utils clamp int b 0 5 out pixels out index ia 24 ir 16 ig 8 ib out index height thresholdblur inpixels outpixels getkerneldata getwidth outindex inpixels inpixels pixelutils pixelutils pixelutils pixelutils outpixels outindex outindex set the horizontal size of the blur param h radius the radius of the blur in the horizontal direction min value 0 see geth radius public void seth radius int h radius this h radius h radius hradius gethradius sethradius hradius hradius hradius get the horizontal size of the blur return the radius of the blur in the horizontal direction see seth radius public int geth radius return h radius sethradius gethradius hradius set the vertical size of the blur param v radius the radius of the blur in the vertical direction min value 0 see getv radius public void setv radius int v radius this v radius v radius vradius getvradius setvradius vradius vradius vradius get the vertical size of the blur return the radius of the blur in the vertical direction see setv radius public int getv radius return v radius setvradius getvradius vradius set the radius of the effect param radius the radius min value 0 see get radius public void set radius int radius this h radius this v radius radius getradius setradius hradius vradius get the radius of the effect return the radius see set radius public int get radius return h radius setradius getradius hradius set the threshold value param threshold the threshold value see get threshold public void set threshold int threshold this threshold threshold getthreshold setthreshold get the threshold value return the threshold value see set threshold public int get threshold return threshold setthreshold getthreshold override public string to string return blur smart blur tostring public peer message peer node pn boolean with metadata boolean with volatile string identifier this pn pn this with metadata with metadata this with volatile with volatile this identifier identifier peermessage peernode withmetadata withvolatile withmetadata withmetadata withvolatile withvolatile override public simple field set get field set simple field set fs pn export field set if with metadata simple field set meta pn export metadata field set if meta is empty fs put metadata meta if with volatile simple field set vol pn export volatile field set if vol is empty fs put volatile vol if identifier null fs put single identifier identifier return fs simplefieldset getfieldset simplefieldset exportfieldset withmetadata simplefieldset exportmetadatafieldset isempty withvolatile simplefieldset exportvolatilefieldset isempty putsingle override public string get name return name getname override public void run fcp connection handler handler node node throws message invalid exception throw new message invalid exception protocol error message invalid message peer goes from server to client not the other way around null false fcpconnectionhandler messageinvalidexception messageinvalidexception protocolerrormessage invalid_message override public void remove from object container container container delete this removefrom objectcontainer public class node data public node data set node null nodedata nodedata setnode private node node public void set node node node this node node setnode public node get node return node getnode private usk fetcher tag usk origusk usk fetcher callback callback long nodedb handle boolean persistent object container container fetch context ctx boolean keep last data long token boolean has own fetch context this nodedb handle nodedb handle this callback callback this origusk origusk this edition origusk suggested edition this persistent persistent this ctx ctx this keep last data keep last data this token token this own fetch context has own fetch context polling priority normal callback get polling priority normal polling priority progress callback get polling priority progress priority polling priority normal uskfetchertag uskfetchercallback nodedbhandle objectcontainer fetchcontext keeplastdata hasownfetchcontext nodedbhandle nodedbhandle suggestededition keeplastdata keeplastdata ownfetchcontext hasownfetchcontext pollingprioritynormal getpollingprioritynormal pollingpriorityprogress getpollingpriorityprogress pollingprioritynormal for a persistent request the caller must call remove from database when finished note that the caller is responsible for deleting the usk fetcher callback and the fetch context param usk param callback param nodedb handle param persistent param container param ctx param keep last param token return public static usk fetcher tag create usk usk usk fetcher callback callback long nodedb handle boolean persistent object container container fetch context ctx boolean keep last int token boolean has own fetch context usk fetcher tag tag new usk fetcher tag usk callback nodedb handle persistent container ctx keep last token has own fetch context if persistent container store tag return tag removefromdatabase uskfetchercallback fetchcontext nodedbhandle keeplast uskfetchertag uskfetchercallback nodedbhandle objectcontainer fetchcontext keeplast hasownfetchcontext uskfetchertag uskfetchertag nodedbhandle keeplast hasownfetchcontext synchronized void updated edition long ed object container container if edition ed edition ed if persistent container store this update updatededition objectcontainer private static final request client client new request client public boolean persistent the actual usk fetch is non persistent only the tags survive a restart return false requestclient requestclient public void remove from object container container throw new unsupported operation exception removefrom objectcontainer unsupportedoperationexception public void start usk manager manager client context context object container container usk usk origusk if persistent container activate origusk 5 if usk suggested edition edition usk usk copy edition else if persistent copy it to avoid deactivation issues usk usk clone fetcher manager get fetcher usk ctx new usk fetcher wrapper usk priority client keep last data fetcher add callback this fetcher schedule null context non persistent uskmanager clientcontext objectcontainer suggestededition getfetcher uskfetcherwrapper keeplastdata addcallback public void cancel object container container client context context if fetcher null fetcher cancel null context synchronized this finished true on cancelled will remove from so we do not want to store this objectcontainer clientcontext oncancelled removefrom public long get token return token gettoken public void schedule object container container client context context start context usk manager context container objectcontainer clientcontext uskmanager public void on cancelled object container container client context context synchronized this finished true if persistent if cancelled externally and this function is called from usk fetcher container may be null even though we are running on the database thread resulting in a database leak context job runner run blocking new db job public void run object container container client context context container activate callback 1 callback on cancelled container context remove from container context container deactivate callback 1 native thread high priority else callback on cancelled container context oncancelled objectcontainer clientcontext uskfetcher jobrunner runblocking dbjob objectcontainer clientcontext oncancelled removefrom nativethread high_priority oncancelled public void run object container container client context context container activate callback 1 callback on cancelled container context remove from container context container deactivate callback 1 objectcontainer clientcontext oncancelled removefrom public void on failure object container container client context context synchronized this finished true if persistent if container null container activate callback 1 callback on failure container context container deactivate callback 1 remove from container context else context job runner queue new db job public void run object container container client context context container activate callback 1 callback on failure container context container deactivate callback 1 remove from container context native thread high priority false else callback on failure container context onfailure objectcontainer clientcontext onfailure removefrom jobrunner dbjob objectcontainer clientcontext onfailure removefrom nativethread high_priority onfailure public void run object container container client context context container activate callback 1 callback on failure container context container deactivate callback 1 remove from container context objectcontainer clientcontext onfailure removefrom public short get polling priority normal return polling priority normal getpollingprioritynormal pollingprioritynormal public short get polling priority progress return polling priority progress getpollingpriorityprogress pollingpriorityprogress public void on found edition final long l final usk key object container container client context context final boolean metadata final short codec final byte data final boolean new known good final boolean new slot too synchronized this if fetcher null logger error this on found edition but fetcher is null isn t on found edition terminal for usk fetcher callback s new exception debug finished true fetcher null if persistent if container null container activate callback 1 callback on found edition l key container context metadata codec data new known good new slot too container deactivate callback 1 remove from container context else context job runner queue new db job public void run object container container client context context container activate callback 1 callback on found edition l key container context metadata codec data new known good new slot too container deactivate callback 1 remove from container context native thread high priority false else callback on found edition l key container context metadata codec data new known good new slot too onfoundedition objectcontainer clientcontext newknowngood newslottoo onfoundedition onfoundedition uskfetchercallback onfoundedition newknowngood newslottoo removefrom jobrunner dbjob objectcontainer clientcontext onfoundedition newknowngood newslottoo removefrom nativethread high_priority onfoundedition newknowngood newslottoo public void run object container container client context context container activate callback 1 callback on found edition l key container context metadata codec data new known good new slot too container deactivate callback 1 remove from container context objectcontainer clientcontext onfoundedition newknowngood newslottoo removefrom public final boolean is finished return finished isfinished override public void should update logminor logger should log logger minor this logdebug logger should log logger minor this shouldupdate shouldlog shouldlog public void remove from object container container client context context if logminor logger minor this removing this container activate origusk 5 origusk remove from container if own fetch context container activate ctx 1 ctx remove from container container delete this removefrom objectcontainer clientcontext removefrom ownfetchcontext removefrom public boolean object can deactivate object container container return false objectcandeactivate objectcontainer private string value new string public parameter public parameter string name string value set name name set value value setname setvalue public void set name string name this name name setname public string get name return name getname public void set value string value this value value setvalue public string get value return value getvalue binary blob inserter bucket blob client putter parent request client client context boolean tolerant short prio class insert context ctx client context context object container container throws io exception binary blob format exception logminor logger should log logger minor this this ctx ctx this max retries ctx max insert retries this consecutivern fs count as success ctx consecutivern fs count as success this parent parent this client context client context this errors new failure code tracker true data input stream dis new data input stream blob get input stream block set blocks new simple block set binary blob read binary blob dis blocks tolerant dis close vector my inserters new vector iterator i blocks keys iterator int x 0 while i has next key key key i next key block block blocks get key my sendable insert inserter new my sendable insert x block prio class get scheduler block context client context my inserters add inserter inserters my sendable insert my inserters to array new my sendable insert my inserters size parent add must succeed blocks inserters length container parent notify clients container context binaryblobinserter clientputter requestclient clientcontext prioclass insertcontext clientcontext objectcontainer ioexception binaryblobformatexception shouldlog maxretries maxinsertretries consecutivernfscountassuccess consecutivernfscountassuccess clientcontext clientcontext failurecodetracker datainputstream datainputstream getinputstream blockset simpleblockset binaryblob readbinaryblob myinserters hasnext keyblock mysendableinsert mysendableinsert prioclass getscheduler clientcontext myinserters mysendableinsert myinserters toarray mysendableinsert myinserters addmustsucceedblocks notifyclients private client request scheduler get scheduler key block block client context context if block instanceof chk block return context get chk insert scheduler else if block instanceof ssk block return context get ssk insert scheduler else throw new illegal argument exception unknown block type block get class block clientrequestscheduler getscheduler keyblock clientcontext chkblock getchkinsertscheduler sskblock getsskinsertscheduler illegalargumentexception getclass public void cancel object container container client context context for int i 0 i inserters length i if inserters i null inserters i cancel container context parent on failure new insert exception insert exception cancelled this container context objectcontainer clientcontext onfailure insertexception insertexception public base client putter get parent return parent baseclientputter getparent public object get token return client context gettoken clientcontext public void schedule object container container client context context throws insert exception for int i 0 i inserters length i inserters i schedule objectcontainer clientcontext insertexception private int retries public my sendable insert int i key block block short prio class client request scheduler scheduler request client client super block prio class client scheduler this block num i mysendableinsert keyblock prioclass clientrequestscheduler requestclient prioclass blocknum public void on success object container container client context context synchronized this if inserters block num null return inserters block num null completed blocks succeeded blocks parent completed block false container context maybe finish container context onsuccess objectcontainer clientcontext blocknum blocknum completedblocks succeededblocks completedblock maybefinish fixme combine it somehow override public void on failure low level put exception e object key num object container container client context context synchronized binary blob inserter this if inserters block num null return if parent is cancelled fail new insert exception insert exception cancelled true container context return logminor logger should log logger minor binary blob inserter this switch e code case low level put exception collision fail new insert exception insert exception collision false container context break case low level put exception internal error errors inc insert exception internal error break case low level put exception rejected overload errors inc insert exception rejected overload break case low level put exception route not found errors inc insert exception route not found break case low level put exception route really not found errors inc insert exception route really not found break default logger error this unknown low level put exception code e code errors inc insert exception internal error if e code low level put exception route not found consecutivern fs if logminor logger minor this consecutive rn fs consecutivern fs consecutivern fs count as success if consecutivern fs consecutivern fs count as success if logminor logger minor this consecutive rn fs consecutivern fs counting as success on success container context return else consecutivern fs 0 if logminor logger minor this failed e retries if retries max retries max retries 1 fail insert exception construct errors false container context return retry this block this schedule onfailure lowlevelputexception keynum objectcontainer clientcontext binaryblobinserter blocknum iscancelled insertexception insertexception shouldlog binaryblobinserter lowlevelputexception insertexception insertexception lowlevelputexception internal_error insertexception internal_error lowlevelputexception rejected_overload insertexception rejected_overload lowlevelputexception route_not_found insertexception route_not_found lowlevelputexception route_really_not_found insertexception route_really_not_found lowlevelputexception insertexception internal_error lowlevelputexception route_not_found consecutivernfs rnfs consecutivernfs consecutivernfscountassuccess consecutivernfs consecutivernfscountassuccess rnfs consecutivernfs onsuccess consecutivernfs maxretries maxretries insertexception private void fail insert exception e boolean fatal object container container client context context synchronized binary blob inserter this if inserters block num null return inserters block num null completed blocks if fatal binary blob inserter this fatal true if fatal parent fatally failed block container context else parent failed block container context maybe finish container context insertexception objectcontainer clientcontext binaryblobinserter blocknum blocknum completedblocks binaryblobinserter fatallyfailedblock failedblock maybefinish override public boolean should cache return ctx cache local requests shouldcache cachelocalrequests public void maybe finish object container container client context context boolean success boolean was fatal synchronized this if completed blocks inserters length return success completed blocks succeeded blocks was fatal fatal if success parent on success this container context else if was fatal parent on failure new insert exception insert exception fatal errors in blocks errors null this container context else parent on failure new insert exception insert exception too many retries in blocks errors null this container context maybefinish objectcontainer clientcontext wasfatal completedblocks completedblocks succeededblocks wasfatal onsuccess wasfatal onfailure insertexception insertexception fatal_errors_in_blocks onfailure insertexception insertexception too_many_retries_in_blocks public void remove from object container container client context context fixme persistent blob inserts are not supported throw new unsupported operation exception removefrom objectcontainer clientcontext unsupportedoperationexception it converts a given time interval into a week day hour second milliseconds string param time interval interval to convert param max terms the terms number to display e g 2 means h and m if the time could be expressed in hour 3 means h m s in the same example the maximum terms number available is 6 param with second fractions if true it displays seconds milliseconds return the formatted string public static string format time long time interval int max terms boolean with second fractions if max terms 6 throw new illegal argument exception string builder sb new string builder 64 long l time interval int term count 0 if l 0 sb append l l 1 if with second fractions l 1000 return 0 if term count max terms return sb to string long weeks l 7l 24 60 60 1000 if weeks 0 sb append weeks append w term count l l weeks 7l 24 60 60 1000 if term count max terms return sb to string long days l 24l 60 60 1000 if days 0 sb append days append d term count l l days 24l 60 60 1000 if term count max terms return sb to string long hours l 60l 60 1000 if hours 0 sb append hours append h term count l l hours 60l 60 1000 if term count max terms return sb to string long minutes l 60l 1000 if minutes 0 sb append minutes append m term count l l minutes 60l 1000 if term count max terms return sb to string if with second fractions max terms term count 2 if l 0 double fractional seconds l 1000 0d decimal format fix3 new decimal format 0 000 sb append fix3 format fractional seconds append s term count l l long fractional seconds long 1000 else long seconds l 1000l if seconds 0 sb append seconds append s term count l l long seconds long 1000 return sb to string timeinterval maxterms withsecondfractions formattime timeinterval maxterms withsecondfractions maxterms illegalargumentexception stringbuilder stringbuilder timeinterval termcount withsecondfractions termcount maxterms tostring termcount termcount maxterms tostring termcount termcount maxterms tostring termcount termcount maxterms tostring termcount termcount maxterms tostring withsecondfractions maxterms termcount fractionalseconds decimalformat decimalformat fractionalseconds termcount fractionalseconds termcount tostring public static string format time long time interval return format time time interval 2 false formattime timeinterval formattime timeinterval public static string format time long time interval int max terms return format time time interval max terms false formattime timeinterval maxterms formattime timeinterval maxterms public class chk store extends store callback override public boolean collision possible return false chkstore storecallback collisionpossible override public storable block construct byte data byte headers byte routing key byte full key throws key verify exception if data null headers null throw new chk verify exception need either data and headers return chk block construct data headers storableblock routingkey fullkey keyverifyexception chkverifyexception chkblock public chk block fetch nodechk chk boolean dont promote throws io exception return chk block store fetch chk get routing key null dont promote chkblock dontpromote ioexception chkblock getroutingkey dontpromote public void put chk block b throws io exception nodechk key nodechk b get key try store put b key get routing key key get full key b get raw data b get raw headers false catch key collision exception e logger error this impossible for chk store e e chkblock ioexception getkey getroutingkey getfullkey getrawdata getrawheaders keycollisionexception chkstore override public int data length return chk block data length datalength chkblock data_length override public int full key length return nodechk full key length fullkeylength full_key_length override public int header length return chk block total headers length headerlength chkblock total_headers_length override public int routing key length return nodechk key length routingkeylength key_length override public boolean store full keys worth the extra two file descriptors because if we have the keys we can do lazy reconstruction i e don t construct each block just transcode from the keys file straight into the database return true storefullkeys override public boolean construct needs key return false constructneedskey override public byte routing key from full key byte key buf return nodechk routing key from full key key buf routingkeyfromfullkey keybuf routingkeyfromfullkey keybuf private static final long serial versionuid 7670838856130773012l public archive restart exception string msg super msg serialversionuid archiverestartexception public ssdp search response socket set control point null ssdpsearchresponsesocket setcontrolpoint public ssdp search response socket string bind addr int port super bind addr port set control point null ssdpsearchresponsesocket bindaddr bindaddr setcontrolpoint private control point control point null public void set control point control point ctrlp this control point ctrlp controlpoint controlpoint setcontrolpoint controlpoint controlpoint public control point get control point return control point controlpoint getcontrolpoint controlpoint public void run thread this thread thread current thread control point ctrl point get control point while device search response thread this thread thread yield ssdp packet packet receive if packet null break if ctrl point null ctrl point search response received packet thisthread currentthread controlpoint ctrlpoint getcontrolpoint devicesearchresponsethread thisthread ssdppacket ctrlpoint ctrlpoint searchresponsereceived public void start device search response thread new thread this u pnp ssdp search response socket device search response thread set daemon true device search response thread start devicesearchresponsethread upnp ssdpsearchresponsesocket devicesearchresponsethread setdaemon devicesearchresponsethread public void stop device search response thread null devicesearchresponsethread public boolean post string addr int port ssdp search response res return post addr port res get header ssdpsearchresponse getheader public boolean post string addr int port ssdp search request req return post addr port req to string ssdpsearchrequest tostring private float m11 1 0f public swim filter swimfilter set the amount of swim param amount the amount of swim min value 0 max value 100 see get amount public void set amount float amount this amount amount getamount setamount get the amount of swim return the amount swim see set amount public float get amount return amount setamount getamount specifies the scale of the distortion param scale the scale of the distortion min value 1 max value 300 see get scale public void set scale float scale this scale scale getscale setscale returns the scale of the distortion return the scale of the distortion see set scale public float get scale return scale setscale getscale specifies the stretch factor of the distortion param stretch the stretch factor of the distortion min value 1 max value 50 see get stretch public void set stretch float stretch this stretch stretch getstretch setstretch returns the stretch factor of the distortion return the stretch factor of the distortion see set stretch public float get stretch return stretch setstretch getstretch specifies the angle of the effect param angle the angle of the effect angle see get angle public void set angle float angle this angle angle float cos float math cos angle float sin float math sin angle m00 cos m01 sin m10 sin m11 cos getangle setangle returns the angle of the effect return the angle of the effect see set angle public float get angle return angle setangle getangle specifies the turbulence of the texture param turbulence the turbulence of the texture min value 0 max value 1 see get turbulence public void set turbulence float turbulence this turbulence turbulence getturbulence setturbulence returns the turbulence of the effect return the turbulence of the effect see set turbulence public float get turbulence return turbulence setturbulence getturbulence specifies the time use this to animate the effect param time the time angle see get time public void set time float time this time time gettime settime returns the time return the time see set time public float get time return time settime gettime override protected void transform inverse int x int y float out float nx m00 x m01 y float ny m10 x m11 y nx scale ny scale stretch if turbulence 1 0f out 0 x amount noise noise3 nx 0 5f ny time out 1 y amount noise noise3 nx ny 0 5f time else out 0 x amount noise turbulence3 nx 0 5f ny turbulence time out 1 y amount noise turbulence3 nx ny 0 5f turbulence time transforminverse override public string to string return distort swim tostring param args throws io exception public static void main string args throws io exception file f1 new file args 0 file f2 new file args 1 simple field set fs1 simple field set read from f1 false true simple field set fs2 simple field set read from f2 false true fs1 put all overwrite fs2 print writer pw new print writer system out fs1 write to ordered pw pw flush ioexception ioexception simplefieldset simplefieldset readfrom simplefieldset simplefieldset readfrom putalloverwrite printwriter printwriter writetoordered transient field fld rnd btree multi field index rndbtreemultifieldindex rnd btree multi field index class cls string field name boolean unique this cls cls this unique unique this field name field name this class name class descriptor get class name cls locate fields type class descriptor tp raw rndbtreemultifieldindex fieldname fieldname fieldname classname classdescriptor getclassname locatefields classdescriptor tpraw private final void locate fields class scope cls fld new field field name length for int i 0 i field name length i fld i class descriptor locate field cls field name i if fld i null throw new storage error storage error indexed field not found class name field name i locatefields fieldname fieldname classdescriptor locatefield fieldname storageerror storageerror indexed_field_not_found classname fieldname public class get indexed class return cls getindexedclass public field get key fields return fld getkeyfields public void on load cls class descriptor load class get storage class name locate fields onload classdescriptor loadclass getstorage classname locatefields public int compare to object o compound key c compound key o int n keys length c keys length keys length c keys length for int i 0 i n i int diff comparable keys i compare to c keys i if diff 0 return diff return 0 allow to compare part of the compound key compareto compoundkey compoundkey compareto compound key object keys this keys keys compoundkey private key convert key key key if key null return null if key type class descriptor tp array of object throw new storage error storage error incompatible key type return new key new compound key object key oval key inclusion 0 convertkey classdescriptor tparrayofobject storageerror storageerror incompatible_key_type compoundkey private key extract key i persistent obj object keys new object fld length try for int i 0 i keys length i keys i fld i get obj if keys i instanceof i persistent i persistent p i persistent keys i if p is persistent get storage make persistent p catch exception x throw new storage error storage error access violation x return new key new compound key keys extractkey ipersistent ipersistent ipersistent ipersistent ispersistent getstorage makepersistent storageerror storageerror access_violation compoundkey public boolean put t obj return super put extract key obj obj extractkey public t set t obj return super set extract key obj obj extractkey public void remove t obj super remove extract key obj obj extractkey public t remove key key return super remove convert key key convertkey public boolean contains object t obj key key extract key obj if unique return super get key null else i persistent mbrs get key key for int i 0 i mbrs length i if mbrs i obj return true return false containsobject extractkey ipersistent public boolean contains t obj key key extract key obj if unique return super get key null else i persistent mbrs get key key for int i 0 i mbrs length i if mbrs i equals obj return true return false extractkey ipersistent public void append t obj throw new storage error storage error unsupported index type storageerror storageerror unsupported_index_type public t get key from key till array list list new array list if root null root find convert key from convert key till height list return t list to array t array new instance cls list size arraylist arraylist convertkey convertkey toarray newinstance public t get prefix string prefix throw new storage error storage error incompatible key type getprefix storageerror storageerror incompatible_key_type public t prefix search string key throw new storage error storage error incompatible key type prefixsearch storageerror storageerror incompatible_key_type public t to persistent array t arr t array new instance cls n elems if root null root traverse forward height arr 0 return arr topersistentarray newinstance nelems traverseforward public t get key key return super get convert key key convertkey public iterable iterator t iterator key from key till int order return super iterator convert key from convert key till order iterableiterator convertkey convertkey public iterable iterator map entry object t entry iterator key from key till int order return super entry iterator convert key from convert key till order iterableiterator entryiterator entryiterator convertkey convertkey public iterable iterator t query by example t obj key key extract key obj return iterator key key ascent order iterableiterator querybyexample extractkey ascent_order public iterable iterator t select string predicate query t query new query impl t get storage return query select cls iterator predicate iterableiterator queryimpl getstorage public boolean is case insensitive return false iscaseinsensitive class rnd btree case insensitive multi field index t extends i persistent extends rnd btree multi field index t rnd btree case insensitive multi field index rndbtreecaseinsensitivemultifieldindex ipersistent rndbtreemultifieldindex rndbtreecaseinsensitivemultifieldindex rnd btree case insensitive multi field index rnd btree case insensitive multi field index class cls string field names boolean unique super cls field names unique rndbtreecaseinsensitivemultifieldindex rndbtreecaseinsensitivemultifieldindex fieldnames fieldnames key check key key key if key null compound key ck compound key key oval for int i 0 i ck keys length i if ck keys i instanceof string ck keys i string ck keys i to lower case return super check key key checkkey compoundkey compoundkey tolowercase checkkey public boolean is case insensitive return true iscaseinsensitive public class snmp port number callback extends int callback public snmp port number callback snmpportnumbercallback intcallback snmpportnumbercallback public integer get return snmp agent getsnmp agent getsnm port snmpagent getsnmpagent getsnmport public void set integer val throws invalid config value exception if val equals get snmp agent setsnmp port val invalidconfigvalueexception snmpagent setsnmpport create an entry dns entry string name int type int clazz this key name to lower case this name name this type type this clazz clazz dns constants class mask this unique clazz dns constants class unique 0 dnsentry tolowercase dnsconstants class_mask dnsconstants class_unique check if two entries have exactly the same name type and class public boolean equals object obj if obj instanceof dns entry dns entry other dns entry obj return name equals other name type other type clazz other clazz return false dnsentry dnsentry dnsentry public string get name return name getname public int get type return type gettype overriden to return a value which is consistent with the value returned by equals object public int hash code return name hash code type clazz hashcode hashcode get a string given a clazz static string get clazz int clazz switch clazz dns constants class mask case dns constants class in return in case dns constants class cs return cs case dns constants class ch return ch case dns constants class hs return hs case dns constants class none return none case dns constants class any return any default return getclazz dnsconstants class_mask dnsconstants class_in dnsconstants class_cs dnsconstants class_ch dnsconstants class_hs dnsconstants class_none dnsconstants class_any get a string given a type static string get type int type switch type case dns constants type a return a case dns constants type aaaa return aaaa case dns constants type ns return ns case dns constants type md return md case dns constants type mf return mf case dns constants type cname return cname case dns constants type soa return soa case dns constants type mb return mb case dns constants type mg return mg case dns constants type mr return mr case dns constants type null return null case dns constants type wks return wks case dns constants type ptr return ptr case dns constants type hinfo return hinfo case dns constants type minfo return minfo case dns constants type mx return mx case dns constants type txt return txt case dns constants type srv return srv case dns constants type any return any default return gettype dnsconstants type_a dnsconstants type_aaaa dnsconstants type_ns dnsconstants type_md dnsconstants type_mf dnsconstants type_cname dnsconstants type_soa dnsconstants type_mb dnsconstants type_mg dnsconstants type_mr dnsconstants type_null dnsconstants type_wks dnsconstants type_ptr dnsconstants type_hinfo dnsconstants type_minfo dnsconstants type_mx dnsconstants type_txt dnsconstants type_srv dnsconstants type_any public string to string string hdr string other return hdr get type type get clazz clazz unique unique name other null other tostring gettype getclazz tries to resolve the best type of cpu that we have an optimized jbigi dll so for return a string containing the cpu type or null if cpu type is unknown private static string resolvecpu type try if system get property os arch to lower case matches i x0 9 86 64 amd64 return jbigi optimization x86 64 else if system get property os arch to lower case matches ppc system out println detected powerpc return jbigi optimization ppc else cpu info c cpuid get info if c instanceof amdcpu info amdcpu info amdcpu amdcpu info c if amdcpu is athlon64 compatible return jbigi optimization x86 64 32 if amdcpu is athlon compatible return jbigi optimization athlon if amdcpu isk6 3 compatible return jbigi optimization k6 3 if amdcpu isk6 2 compatible return jbigi optimization k6 2 if amdcpu isk6 compatible return jbigi optimization k6 else if c instanceof intelcpu info intelcpu info intelcpu intelcpu info c if intelcpu is pentium4 compatible return jbigi optimization pentium4 if intelcpu is pentium3 compatible return jbigi optimization pentium3 if intelcpu is pentium2 compatible return jbigi optimization pentium2 if intelcpu is pentiummmx compatible return jbigi optimization pentiummmx if intelcpu is pentium compatible return jbigi optimization pentium return null catch unknowncpu exception e return null todo log something here maybe resolvecputype getproperty tolowercase 86_64 jbigi_optimization_x86_64 getproperty tolowercase jbigi_optimization_ppc cpuinfo getinfo amdcpuinfo amdcpuinfo amdcpuinfo isathlon64compatible jbigi_optimization_x86_64_32 isathloncompatible jbigi_optimization_athlon isk6_3_compatible jbigi_optimization_k6_3 isk6_2_compatible jbigi_optimization_k6_2 isk6compatible jbigi_optimization_k6 intelcpuinfo intelcpuinfo intelcpuinfo ispentium4compatible jbigi_optimization_pentium4 ispentium3compatible jbigi_optimization_pentium3 ispentium2compatible jbigi_optimization_pentium2 ispentiummmxcompatible jbigi_optimization_pentiummmx ispentiumcompatible jbigi_optimization_pentium unknowncpuexception calculate base exponent modulus param base big endian twos complement representation of the base but it must be positive param exponent big endian twos complement representation of the exponent param modulus big endian twos complement representation of the modulus return big endian twos complement representation of base exponent modulus converts a big integer byte array to a double param ba big endian twos complement representation of the big integer to convert to a double return the plain double value represented by ba biginteger biginteger public native big integer byte val super val takes up too much ram int target length bit length 8 1 if val length target length cached ba val nativebiginteger targetlength bitlength targetlength cachedba public native big integer int signum byte magnitude super signum magnitude nativebiginteger public native big integer int bitlen int certainty random rnd super bitlen certainty rnd nativebiginteger public native big integer int numbits random rnd super numbits rnd nativebiginteger public native big integer string val super val nativebiginteger public native big integer string val int radix super val radix nativebiginteger creates a new native big integer with the same value as the supplied big integer warning not very efficent public native big integer big integer integer now why doesn t sun provide a constructor like this one in big integer this integer to byte array nativebiginteger biginteger nativebiginteger biginteger biginteger tobytearray override public big integer mod pow big integer exponent big integer m if nativeok return new native big integer native mod pow to byte array exponent to byte array m to byte array else return new native big integer super mod pow exponent m biginteger modpow biginteger biginteger _nativeok nativebiginteger nativemodpow tobytearray tobytearray tobytearray nativebiginteger modpow override public byte to byte array if cached ba null since we are immutable it is safe to never update the cached ba after it has initially been generated cached ba super to byte array return cached ba tobytearray cachedba cachedba tobytearray cachedba override public string to string int radix if radix 16 return to hex string return super to string radix tostring tohexstring tostring public string to hex string byte buf to byte array return hex util bytes to hex buf tohexstring tobytearray hexutil bytestohex override public double double value if nativeok return native double value to byte array else return super double value doublevalue _nativeok nativedoublevalue tobytearray doublevalue return true iff native methods will be used by this class public static boolean is native return nativeok isnative _nativeok p do whatever we can to load up the native library backing this big integer s native methods if it can find a custom built jbigi dll libjbigi so it ll use that otherwise it ll try to look in the classpath for the correct library see load from resource if the user specifies djbigi enable false it ll skip all of this p private static final void load native try string wanted prop system get property jbigi enable true boolean want native true equals ignore case wanted prop if want native boolean loaded load from resource true if loaded nativeok true if dolog system err println info optimized native big integer library get resource name true loaded from resource else loaded load generic true if loaded nativeok true if dolog system err println info optimized native big integer library get middle name true loaded from somewhere in the path else loaded load from resource false if loaded nativeok true if dolog system err println info non optimized native big integer library get resource name false loaded from resource else loaded load generic false if loaded nativeok true if dolog system err println info non optimized native big integer library get middle name false loaded from somewhere in the path else nativeok false if dolog nativeok system err println info native big integer library jbigi not loaded using pure java catch throwable e if dolog system err println info native big integer library jbigi not loaded reason e get message using pure java biginteger loadfromresource loadnative wantedprop getproperty wantnative equalsignorecase wantedprop wantnative loadfromresource _nativeok _dolog biginteger getresourcename loadgeneric _nativeok _dolog biginteger getmiddlename loadfromresource _nativeok _dolog biginteger getresourcename loadgeneric _nativeok _dolog biginteger getmiddlename _nativeok _dolog _nativeok biginteger _dolog biginteger getmessage p try loading it from an explictly build jbigi dll libjbigi so first before looking into a jbigi jar for any other libraries p return true if it was loaded successfully else false private static final boolean load generic boolean optimized try string name get middle name optimized if name null return false system load library name return true catch unsatisfied link error ule return false loadgeneric getmiddlename loadlibrary unsatisfiedlinkerror a helper function to make loading the native library easier param f the file to which to write the library param url the url of the resource return true is the library was loaded false on error throws file not found exception if the library could not be read from the reference throws unsatisfied link error if and only if the library is incompatible with this system private static final boolean try load resource file f url resource throws file not found exception unsatisfied link error input stream is try is resource open stream catch io exception e f delete throw new file not found exception file output stream fos null try f delete on exit fos new file output stream f byte buf new byte 4096 1024 int read while read is read buf 0 fos write buf 0 read fos close fos null system load f get absolute path return true catch io exception e catch unsatisfied link error ule likely to be noexec if ule to string to lower case index of not permitted 1 throw ule finally closer close fos f delete return false filenotfoundexception unsatisfiedlinkerror tryloadresource filenotfoundexception unsatisfiedlinkerror inputstream openstream ioexception filenotfoundexception fileoutputstream deleteonexit fileoutputstream getabsolutepath ioexception unsatisfiedlinkerror tostring tolowercase indexof p check all of the jars in the classpath for the file specified by the environmental property jbigi impl and load it as the native library implementation for instance a windows user on a p4 would define djbigi impl win 686 if there is a jbigi jar in the classpath containing the files win 686 win athlon freebsd p4 linux p3 where each of those files contain the correct binary file for a native library e g windows dll or a nix so p p this is a pretty ugly hack using the general technique illustrated by the onion fec libraries it works by pulling the resource writing out the byte stream to a temporary file loading the native library from that file then deleting the file p return true if it was loaded successfully else false private static final boolean load from resource boolean optimized string resource name get resource name optimized if resource name null return false url resource native big integer class get class loader get resource resource name if resource null if dolog system err println notice resource name get resource name true was not found return false file temp null try try temp file create temp file jbigi lib tmp if try load resource temp resource return true catch io exception e finally if temp null temp delete logger error native big integer class can t load from system get property java io tmpdir system err println can t load from system get property java io tmpdir temp new file jbigi lib tmp if try load resource temp resource return true catch exception fnf logger error native big integer class error reading jbigi resource fnf system err println error reading jbigi resource catch unsatisfied link error ule logger error native big integer class library resource name is not appropriate for this system system err println library resource name is not appropriate for this system finally if temp null temp delete return false loadfromresource resourcename getresourcename resourcename nativebiginteger getclassloader getresource resourcename _dolog getresourcename createtempfile tryloadresource ioexception nativebiginteger getproperty getproperty tryloadresource nativebiginteger unsatisfiedlinkerror nativebiginteger resourcename resourcename private static final string get resource name boolean optimized string pname native big integer class get package get name replace string pref get library prefix string middle get middle name optimized string suff get library suffix if pref null middle null suff null return null return pname pref middle suff getresourcename nativebiginteger getpackage getname getlibraryprefix getmiddlename getlibrarysuffix private static final string get middle name boolean optimized string s append if optimized if scpu type null return null else s append scpu type else s append none boolean is windows system get property os name to lower case index of windows 1 boolean is linux system get property os name to lower case index of linux 1 boolean is freebsd system get property os name to lower case index of freebsd 1 boolean is macos system get property os name to lower case index of mac os x 1 if is windows return jbigi windows s append the convention on windows if is linux return jbigi linux s append the convention on linux if is freebsd return jbigi freebsd s append the convention on freebsd if is macos return jbigi osx s append the convention on mac os x throw new runtime exception dont know jbigi library name for os type system get property os name getmiddlename sappend scputype sappend scputype sappend iswindows getproperty tolowercase indexof islinux getproperty tolowercase indexof isfreebsd getproperty tolowercase indexof ismacos getproperty tolowercase indexof iswindows sappend islinux sappend isfreebsd sappend ismacos sappend runtimeexception getproperty private static final string get library suffix boolean is windows system get property os name to lower case index of windows 1 boolean is macos system get property os name to lower case index of mac os x 1 if is windows return dll else if is macos return jnilib else return so getlibrarysuffix iswindows getproperty tolowercase indexof ismacos getproperty tolowercase indexof iswindows ismacos private static final string get library prefix boolean is windows system get property os name to lower case index of windows 1 if is windows return else return lib getlibraryprefix iswindows getproperty tolowercase indexof iswindows public lru object cache int size int initial capacity size 0 default init size size threshold int initial capacity load factor table new entry initial capacity pin list new entry 0 null null pin limit size pin list lru pin list mru pin list lruobjectcache initialcapacity defaultinitsize initialcapacity loadfactor initialcapacity pinlist pinlimit pinlist pinlist pinlist public synchronized boolean remove int oid entry tab table int index oid 0x7fffffff tab length for entry e tab index prev null e null prev e e e next if e oid oid if prev null prev next e next else tab index e next e clear unpin object e count 1 return true return false unpinobject protected reference create reference object obj return new weak reference obj createreference weakreference private final void unpin object entry e if e pin null e unpin n pinned 1 unpinobject npinned private final void pin object entry e i persistent obj if pin limit 0 if e pin null e unlink else if n pinned pin limit pin list lru unpin else n pinned 1 e link after pin list obj pinobject ipersistent pinlimit npinned pinlimit pinlist npinned linkafter pinlist public synchronized void put int oid i persistent obj reference ref create reference obj entry tab table int index oid 0x7fffffff tab length for entry e tab index e null e e next if e oid oid e ref ref pin object e obj return if count threshold flushing rehash the table if the threshold is exceeded rehash tab table index oid 0x7fffffff tab length creates the new entry tab index new entry oid ref tab index pin object tab index obj count ipersistent createreference pinobject pinobject public i persistent get int oid while true cs synchronized this entry tab table int index oid 0x7fffffff tab length for entry e tab index e null e e next if e oid oid i persistent obj i persistent e ref get if obj null if e dirty 0 break cs else if obj is deleted e ref clear unpin object e return null pin object e obj return obj return null runtime run finalization ipersistent ipersistent ipersistent isdeleted unpinobject pinobject runfinalization public void flush while true cs synchronized this flushing true for int i 0 i table length i entry e next prev for e table i prev null e null e next i persistent obj i persistent e ref get next e next if obj null if obj is modified obj store prev e else if e dirty 0 break cs else count 1 e clear if prev null table i next else prev next next flushing false if count threshold rehash the table if the threshold is exceeded rehash return runtime run finalization ipersistent ipersistent ismodified runfinalization public void invalidate while true cs synchronized this for int i 0 i table length i for entry e table i e null e e next i persistent obj i persistent e ref get if obj null if obj is modified e dirty 0 unpin object e obj invalidate else if e dirty 0 break cs table i null count 0 n pinned 0 pin list lru pin list mru pin list return runtime run finalization ipersistent ipersistent ismodified unpinobject npinned pinlist pinlist pinlist runfinalization public synchronized void clear entry tab table for int i 0 i tab length i tab i null count 0 n pinned 0 pin list lru pin list mru pin list npinned pinlist pinlist pinlist void rehash int old capacity table length entry old map table int i for i old capacity i 0 entry e next prev for prev null e old map i e null e next next e next i persistent obj i persistent e ref get if obj null obj is deleted e dirty 0 count 1 e clear if prev null old map i next else prev next next else prev e if count threshold 1 return int new capacity old capacity 2 1 entry new map new entry new capacity threshold int new capacity load factor table new map for i old capacity i 0 for entry old old map i old null entry e old old old next int index e oid 0x7fffffff new capacity e next new map index new map index e oldcapacity oldmap oldcapacity oldmap ipersistent ipersistent isdeleted oldmap newcapacity oldcapacity newmap newcapacity newcapacity loadfactor newmap oldcapacity oldmap newcapacity newmap newmap public synchronized void set dirty i persistent obj int oid obj get oid entry tab table int index oid 0x7fffffff tab length for entry e tab index e null e e next if e oid oid e dirty 1 return setdirty ipersistent getoid public synchronized void clear dirty i persistent obj int oid obj get oid entry tab table int index oid 0x7fffffff tab length for entry e tab index e null e e next if e oid oid if e dirty 0 e dirty 1 return cleardirty ipersistent getoid public int size return count i persistent pin void unlink lru mru mru mru lru lru ipersistent void unpin unlink lru mru null pin null void link after entry head i persistent obj mru head mru mru lru this head mru this lru head pin obj linkafter ipersistent void clear ref clear ref null dirty 0 next null entry int oid reference ref entry chain next chain this oid oid this ref ref protected void set up throws exception super set up m identity manager new wot identity manager db m message manager new wot message manager db m identity manager construct identities setup setup midentitymanager wotidentitymanager mmessagemanager wotmessagemanager midentitymanager constructidentities private void construct identities throws malformedurl exception string requestss ks new string ssk ly n0 nk5n qpt6br ggtckfhpy11 gzgk dn4v dszl6fw pg gd ql sg9ncbbf8xis cx yb lm9 jxe3 oi sydy oa zgcs4k aqacaae wot ssk wc oy byjh hpye gea4f0q tm8 wxim leu tehh0 ovo iysli m2xhpkg lhq1yqpqd yp0 yvbs qdnju4pd0 nm wga1cwre aqacaae wot ssk oh iaam npk igdbkwpc ob9phc qoa015n aoia0ud 9a4tm 5 jp16w6 ys ai qwe fljj g jck0a yxzu nfs6 bjkx psk aqacaae wot ssk vm fi2tyuli54 kgl nmm hz4k xh kl nhldvgoc fdll5vru 00v jvrvf8p5xrd3kuiawxhn7rp dxb5kjp9z8x uqe a aqacaae wot ssk hh v2 xm cb zp 738qte67j ug1m5l5fl vv qfc2b ype1o4 c8h39jkp08cao ejvtv ris hlc mnl tlpnfi czl4gmz4 aqacaae wot string insertss ks new string ssk egaz bi trp gsilvbjgt91mox5jtc6pfidf dyjt3 fcsri gd ql sg9ncbbf8xis cx yb lm9 jxe3 oi sydy oa zgcs4k aqecaae wot ssk ze0 i5n rq60j549pck sb2zsyf98kn kcz psa ggt1lue m2xhpkg lhq1yqpqd yp0 yvbs qdnju4pd0 nm wga1cwre aqecaae wot ssk rgnz2 lrmns3 djx5 dfp uf dpaq wn mmalbvh9x8ub9 cg rc 5 jp16w6 ys ai qwe fljj g jck0a yxzu nfs6 bjkx psk aqecaae wot ssk xj het73nz3vikr hc km8 gtwce muzo6aem iw16 pft6ha 00v jvrvf8p5xrd3kuiawxhn7rp dxb5kjp9z8x uqe a aqecaae wot ssk req uma bjh dr rd8z8kog mw9d vd5q3 rhhe asyjqr luxgy c8h39jkp08cao ejvtv ris hlc mnl tlpnfi czl4gmz4 aqecaae wot m own identities new wot own identity requestss ks length for int i 0 i requestss ks length i freeneturi requesturi new freeneturi requestss ks i freeneturi inserturi new freeneturi insertss ks i m own identities i new wot own identity wot own identity getuid fromuri requesturi requesturi inserturi nickname i m own identities i initialize transient db m identity manager m own identities i store constructidentities malformedurlexception requestssks n0nk5nqpt6brggtckfhpy11gzgkdn4vdszl6fwpg gdqlsg9ncbbf8xis cxyb lm9jxe3oisydyoazgcs4k wcoybyjhhpye gea4f0qtm8wximleutehh0ovoiysli m2xhpkglhq1yqpqdyp0yvbs qdnju4pd0nmwga1cwre ohiaamnpkigdbkwpcob9phcqoa015naoia0ud 5jp16w6 aiqwefljj gjck0ayxzu nfs6bjkxpsk vmfi2tyuli54kglnmmhz4k xhklnhldvgocfdll5vru jvrvf8p5xrd3kuiawxhn7rpdxb5kjp9z8xuqe v2xmcbzp 738qte67jug1m5l5flvvqfc2bype1o4 rishlcmnltlpnficzl4gmz4 insertssks egazbitrpgsilvbjgt91mox5jtc6pfidfdyjt3fcsri gdqlsg9ncbbf8xis cxyb lm9jxe3oisydyoazgcs4k i5nrq60j549pck sb2zsyf98knkczpsaggt1lue m2xhpkglhq1yqpqdyp0yvbs qdnju4pd0nmwga1cwre rgnz2lrmns3djx5dfpufdpaqwnmmalbvh9x8ub9cgrc 5jp16w6 aiqwefljj gjck0ayxzu nfs6bjkxpsk xjhet73nz3vikrhc km8gtwcemuzo6aemiw16pft6ha jvrvf8p5xrd3kuiawxhn7rpdxb5kjp9z8xuqe requmabjhdrrd8z8kogmw9dvd5q3rhheasyjqrluxgy rishlcmnltlpnficzl4gmz4 mownidentities wotownidentity requestssks requestssks requestssks insertssks mownidentities wotownidentity wotownidentity getuidfromuri mownidentities initializetransient midentitymanager mownidentities constructor when we are returning the data f proxy fetch result f proxy fetch in progress parent bucket data string mime type long time started boolean gone to network long eta boolean has waited this data data this mime type mime type this size data size this time started time started this gone to network gone to network total blocks required blocks fetched blocks failed blocks fatally failed blocks 0 finalized blocks true failed null this progress parent this eta eta this has waited has waited fproxyfetchresult fproxyfetchinprogress mimetype timestarted gonetonetwork haswaited mimetype mimetype timestarted timestarted gonetonetwork gonetonetwork totalblocks requiredblocks fetchedblocks failedblocks fatallyfailedblocks finalizedblocks haswaited haswaited constructor when we are not returning the data because it is still running or it failed f proxy fetch result f proxy fetch in progress parent string mime type long size long time started boolean gone to network int total blocks int required blocks int fetched blocks int failed blocks int fatally failed blocks boolean finalized blocks fetch exception failed long eta boolean has waited this data null this mime type mime type this size size this time started time started this gone to network gone to network this total blocks total blocks this required blocks required blocks this fetched blocks fetched blocks this failed blocks failed blocks this fatally failed blocks fatally failed blocks this finalized blocks finalized blocks this failed failed this progress parent this eta eta this has waited has waited fproxyfetchresult fproxyfetchinprogress mimetype timestarted gonetonetwork totalblocks requiredblocks fetchedblocks failedblocks fatallyfailedblocks finalizedblocks fetchexception haswaited mimetype mimetype timestarted timestarted gonetonetwork gonetonetwork totalblocks totalblocks requiredblocks requiredblocks fetchedblocks fetchedblocks failedblocks failedblocks fatallyfailedblocks fatallyfailedblocks finalizedblocks finalizedblocks haswaited haswaited must be called when fproxy has finished with the data public void close progress close this public boolean has data return data null hasdata public boolean has waited return has waited haswaited haswaited public ssdp search response set status code http status ok set cache control device default lease time set header http server u pnp get server name set header http ext ssdpsearchresponse setstatuscode httpstatus setcachecontrol default_lease_time setheader upnp getservername setheader public void on load cls class descriptor load class get storage class name locate fields onload classdescriptor loadclass getstorage classname locatefields private final void locate fields if field names null fields cls get declared fields else fields new field field names length for int i 0 i fields length i fields i class descriptor locate field cls field names i if fields i null throw new storage error storage error indexed field not found class name field names i locatefields fieldnames getdeclaredfields fieldnames classdescriptor locatefield fieldnames storageerror storageerror indexed_field_not_found classname fieldnames public reflection multidimensional comparator storage storage class cls string field names boolean treate zero as undefined value super storage this cls cls this field names field names this treate zero as undefined value treate zero as undefined value class name class descriptor get class name cls locate fields reflectionmultidimensionalcomparator fieldnames treatezeroasundefinedvalue fieldnames fieldnames treatezeroasundefinedvalue treatezeroasundefinedvalue classname classdescriptor getclassname locatefields reflection multidimensional comparator reflectionmultidimensionalcomparator private static boolean is zero object val return val instanceof double val instanceof float number val double value 0 0 val instanceof number number val long value 0 false iszero doublevalue longvalue public int compare t m1 t m2 int i try comparable c1 comparable fields i get m1 comparable c2 comparable fields i get m2 if c1 null c2 null return eq else if c1 null treate zero as undefined value is zero c1 return left undefined else if c2 null treate zero as undefined value is zero c2 return right undefined else int diff c1 compare to c2 return diff 0 lt diff 0 eq gt catch illegal access exception x throw new illegal access error treatezeroasundefinedvalue iszero left_undefined treatezeroasundefinedvalue iszero right_undefined compareto illegalaccessexception illegalaccesserror public int get number of dimensions return fields length getnumberofdimensions public t clone field t obj int i if desc null desc storage impl get storage find class descriptor cls t clone t desc new instance try fields i set clone fields i get obj return clone catch illegal access exception x throw new illegal access error clonefield storageimpl getstorage findclassdescriptor newinstance illegalaccessexception illegalaccesserror set the action to perform for pixels off the edge of the image param edge action one of zero clamp or wrap see get edge action public void set edge action int edge action this edge action edge action edgeaction getedgeaction setedgeaction edgeaction edgeaction edgeaction get the action to perform for pixels off the edge of the image return one of zero clamp or wrap see set edge action public int get edge action return edge action setedgeaction getedgeaction edgeaction set the type of interpolation to perform param interpolation one of nearest neighbour or bilinear see get interpolation public void set interpolation int interpolation this interpolation interpolation nearest_neighbour getinterpolation setinterpolation get the type of interpolation to perform return one of nearest neighbour or bilinear see set interpolation public int get interpolation return interpolation nearest_neighbour setinterpolation getinterpolation inverse transform a point this method needs to be overriden by all subclasses param x the x position of the pixel in the output image param y the y position of the pixel in the output image param out the position of the pixel in the input image forward transform a rectangle used to determine the size of the output image param rect the rectangle to transform protected void transform space rectangle rect transformspace public buffered image filter buffered image src buffered image dst int width src get width int height src get height int type src get type writable raster src raster src get raster original space new rectangle 0 0 width height transformed space new rectangle 0 0 width height transform space transformed space if dst null color model dstcm src get color model dst new buffered image dstcm dstcm create compatible writable raster transformed space width transformed space height dstcm is alpha premultiplied null writable raster dst raster dst get raster int in pixels getrgb src 0 0 width height null if interpolation nearest neighbour return filter pixelsnn dst width height in pixels transformed space int src width width int src height height int src width1 width 1 int src height1 height 1 int out width transformed space width int out height transformed space height int outx outy int index 0 int out pixels new int out width outx transformed space x outy transformed space y float out new float 2 for int y 0 y out height y for int x 0 x out width x transform inverse outx x outy y out int srcx int math floor out 0 int srcy int math floor out 1 float x weight out 0 srcx float y weight out 1 srcy int nw ne sw se if srcx 0 srcx src width1 srcy 0 srcy src height1 easy case all corners are in the image int i src width srcy srcx nw in pixels i ne in pixels i 1 sw in pixels i src width se in pixels i src width 1 else some of the corners are off the image nw get pixel in pixels srcx srcy src width src height ne get pixel in pixels srcx 1 srcy src width src height sw get pixel in pixels srcx srcy 1 src width src height se get pixel in pixels srcx 1 srcy 1 src width src height out pixels x image math bilinear interpolate x weight y weight nw ne sw se setrgb dst 0 y transformed space width 1 out pixels return dst bufferedimage bufferedimage bufferedimage getwidth getheight gettype writableraster srcraster getraster originalspace transformedspace transformspace transformedspace colormodel getcolormodel bufferedimage createcompatiblewritableraster transformedspace transformedspace isalphapremultiplied writableraster dstraster getraster inpixels nearest_neighbour filterpixelsnn inpixels transformedspace srcwidth srcheight srcwidth1 srcheight1 outwidth transformedspace outheight transformedspace outpixels outwidth transformedspace transformedspace outheight outwidth transforminverse xweight yweight srcwidth1 srcheight1 srcwidth inpixels inpixels inpixels srcwidth inpixels srcwidth getpixel inpixels srcwidth srcheight getpixel inpixels srcwidth srcheight getpixel inpixels srcwidth srcheight getpixel inpixels srcwidth srcheight outpixels imagemath bilinearinterpolate xweight yweight transformedspace outpixels final private int get pixel int pixels int x int y int width int height if x 0 x width y 0 y height switch edge action case zero default return 0 case wrap return pixels image math mod y height width image math mod x width case clamp return pixels image math clamp y 0 height 1 width image math clamp x 0 width 1 return pixels y width x getpixel edgeaction imagemath imagemath imagemath imagemath protected buffered image filter pixelsnn buffered image dst int width int height int in pixels rectangle transformed space int src width width int src height height int out width transformed space width int out height transformed space height int outx outy srcx srcy int out pixels new int out width outx transformed space x outy transformed space y int rgb new int 4 float out new float 2 for int y 0 y out height y for int x 0 x out width x transform inverse outx x outy y out srcx int out 0 srcy int out 1 int casting rounds towards zero so we check out 0 0 not srcx 0 if out 0 0 srcx src width out 1 0 srcy src height int p switch edge action case zero default p 0 break case wrap p in pixels image math mod srcy src height src width image math mod srcx src width break case clamp p in pixels image math clamp srcy 0 src height 1 src width image math clamp srcx 0 src width 1 break out pixels x p else int i src width srcy srcx rgb 0 in pixels i out pixels x in pixels i setrgb dst 0 y transformed space width 1 out pixels return dst bufferedimage filterpixelsnn bufferedimage inpixels transformedspace srcwidth srcheight outwidth transformedspace outheight transformedspace outpixels outwidth transformedspace transformedspace outheight outwidth transforminverse srcwidth srcheight edgeaction inpixels imagemath srcheight srcwidth imagemath srcwidth inpixels imagemath srcheight srcwidth imagemath srcwidth outpixels srcwidth inpixels outpixels inpixels transformedspace outpixels bucket data public minimal splitfile block int n this number n minimalsplitfileblock public int get number return number getnumber public boolean has data return data null hasdata public bucket get data return data getdata public void set data bucket data this data data setdata public void store to object container container if logger should log logger minor this logger minor this storing this with data data if data null data store to container container store this storeto objectcontainer shouldlog storeto public void remove from object container container if data null container activate data 1 data remove from container container delete this removefrom objectcontainer removefrom public persistent chosen block boolean is insert persistent chosen request parent sendable request item token key key client key ckey request scheduler sched super token key ckey parent local request only parent cache local requests parent ignore store sched this is insert is insert this parent parent if logger should log logger minor this logger minor this created this for parent ckey ckey persistentchosenblock isinsert persistentchosenrequest sendablerequestitem clientkey requestscheduler localrequestonly cachelocalrequests ignorestore isinsert isinsert shouldlog override public void on fetch success client context context assert is insert synchronized this if finished logger error this already finished in on success on this new exception debug return finished true fetch succeeded true parent on finished this context parent scheduler succeeded sendable get parent request true onfetchsuccess clientcontext isinsert onsuccess fetchsucceeded onfinished sendableget override public void on failure low level get exception e client context context assert is insert synchronized this if finished logger error this already finished in on failure on this new exception debug return if e null throw new null pointer exception failed get e finished true parent on finished this context onfailure lowlevelgetexception clientcontext isinsert onfailure nullpointerexception failedget onfinished override public void on insert success client context context assert is insert synchronized this if finished logger error this already finished in on success on this new exception debug return insert succeeded true finished true parent on finished this context oninsertsuccess clientcontext isinsert onsuccess insertsucceeded onfinished override public void on failure low level put exception e client context context assert is insert synchronized this if finished logger error this already finished in on failure on this new exception debug return if e null throw new null pointer exception failed put e finished true parent on finished this context onfailure lowlevelputexception clientcontext isinsert onfailure nullpointerexception failedput onfinished low level get exception failed get return failed get lowlevelgetexception failedget failedget boolean insert succeeded return insert succeeded insertsucceeded insertsucceeded boolean fetch succeeded return fetch succeeded fetchsucceeded fetchsucceeded low level put exception failed put return failed put lowlevelputexception failedput failedput override public boolean is persistent return true ispersistent override public boolean is cancelled we can t tell without accesing the database and we can t access the database on the request starter thread return false iscancelled override public boolean send node client core core request scheduler sched try return super send core sched finally boolean was finished synchronized this was finished finished if finished finished true if parent request instanceof sendable get logger error this sendable get parent request didn t call a callback on this if was finished parent on finished this sched get context nodeclientcore requestscheduler wasfinished wasfinished sendableget sendableget wasfinished onfinished getcontext override public short get priority return parent prio getpriority override public sendable request sender get sender client context context return parent sender sendablerequestsender getsender clientcontext logger register log threshold callback new log threshold callback override public void should update logminor logger should log logger minor this registerlogthresholdcallback logthresholdcallback shouldupdate shouldlog archive handler impl freeneturi key archive type archive type compressor type ctype boolean force refetch archive this key key this archive type archive type this compressor type ctype this force refetch archive force refetch archive archivehandlerimpl archive_type archivetype compressor_type forcerefetcharchive archivetype archivetype compressortype forcerefetcharchive forcerefetcharchive public bucket get string internal name archive context archive context archive manager manager throws archive failure exception archive restart exception metadata parse exception fetch exception do loop detection on the archive that we are about to fetch archive context do loop detection key if force refetch archive return null bucket data fetch from cache if logminor logger minor this checking cache key internal name if data manager get cached key internal name null return data return null internalname archivecontext archivecontext archivemanager archivefailureexception archiverestartexception metadataparseexception fetchexception archivecontext doloopdetection forcerefetcharchive internalname getcached internalname public bucket get metadata archive context archive context archive manager manager throws archive failure exception archive restart exception metadata parse exception fetch exception return get metadata archive context manager getmetadata archivecontext archivecontext archivemanager archivefailureexception archiverestartexception metadataparseexception fetchexception archivecontext public void extract to cache bucket bucket archive context actx string element archive extract callback callback archive manager manager object container container client context context throws archive failure exception archive restart exception force refetch archive false now we don t need to force refetch any more archive store context ctx manager make context key archive type compressor type false manager extract to cache key archive type compressor type bucket actx ctx element callback container context extracttocache archivecontext archiveextractcallback archivemanager objectcontainer clientcontext archivefailureexception archiverestartexception forcerefetcharchive archivestorecontext makecontext archivetype compressortype extracttocache archivetype compressortype public archive type get archive type return archive type archive_type getarchivetype archivetype public compressor type get compressor type return compressor type compressor_type getcompressortype compressortype public freeneturi get key return key getkey unpack a fetched archive on a separate thread for a persistent caller this involves add a tag to the database so that it will be restarted on a crash run the actual unpack on a separate thread copy the data to a persistent bucket schedule a database job call the callback param bucket param actx param element param callback param container param context public void extract persistent off thread bucket bucket boolean free bucket archive context actx string element archive extract callback callback object container container final client context context assert element null no callback would be called final archive manager manager context archive manager final archive extract tag tag new archive extract tag this bucket free bucket actx element callback context nodedb handle container store tag run persistent off thread tag context manager context persistent bucket factory extractpersistentoffthread freebucket archivecontext archiveextractcallback objectcontainer clientcontext archivemanager archivemanager archiveextracttag archiveextracttag freebucket nodedbhandle runpersistentoffthread persistentbucketfactory private static void run persistent off thread final archive extract tag tag final client context context final archive manager manager final bucket factory bf final proxy callback proxy callback new proxy callback if logminor logger minor archive handler impl class scheduling off thread extraction tag data for tag handler key element tag element for tag callback new exception debug context main executor execute new runnable public void run try if logminor logger minor this extracting off thread tag data for tag handler key element tag element for tag callback tag handler extract to cache tag data tag actx tag element proxy callback manager null context if logminor logger minor this extracted final bucket data if proxy callback data null data null else try if logminor logger minor this copying data data bf make bucket proxy callback data size bucket tools copy proxy callback data data proxy callback data free if logminor logger minor this copied and freed original catch io exception e throw new archive failure exception failure copying data to persistent storage e context job runner queue new db job public void run object container container client context context if logminor logger minor this calling callback for tag data for tag handler key element tag element for tag callback container activate tag callback 1 if proxy callback data null tag callback not in archive container context else tag callback got bucket data container context tag callback remove from container if tag free bucket tag data free tag data remove from container container deactivate tag callback 1 container delete tag native thread norm priority false catch final archive failure exception e context job runner queue new db job public void run object container container client context context container activate tag callback 1 tag callback on failed e container context tag callback remove from container if tag free bucket tag data free tag data remove from container container delete tag native thread norm priority false catch final archive restart exception e context job runner queue new db job public void run object container container client context context container activate tag callback 1 tag callback on failed e container context tag callback remove from container if tag free bucket tag data free tag data remove from container container delete tag native thread norm priority false off thread extract runpersistentoffthread archiveextracttag clientcontext archivemanager bucketfactory proxycallback proxycallback proxycallback archivehandlerimpl mainexecutor extracttocache proxycallback proxycallback makebucket proxycallback buckettools proxycallback proxycallback ioexception archivefailureexception jobrunner dbjob objectcontainer clientcontext proxycallback notinarchive gotbucket removefrom freebucket removefrom nativethread norm_priority archivefailureexception jobrunner dbjob objectcontainer clientcontext onfailed removefrom freebucket removefrom nativethread norm_priority archiverestartexception jobrunner dbjob objectcontainer clientcontext onfailed removefrom freebucket removefrom nativethread norm_priority public void run try if logminor logger minor this extracting off thread tag data for tag handler key element tag element for tag callback tag handler extract to cache tag data tag actx tag element proxy callback manager null context if logminor logger minor this extracted final bucket data if proxy callback data null data null else try if logminor logger minor this copying data data bf make bucket proxy callback data size bucket tools copy proxy callback data data proxy callback data free if logminor logger minor this copied and freed original catch io exception e throw new archive failure exception failure copying data to persistent storage e context job runner queue new db job public void run object container container client context context if logminor logger minor this calling callback for tag data for tag handler key element tag element for tag callback container activate tag callback 1 if proxy callback data null tag callback not in archive container context else tag callback got bucket data container context tag callback remove from container if tag free bucket tag data free tag data remove from container container deactivate tag callback 1 container delete tag native thread norm priority false catch final archive failure exception e context job runner queue new db job public void run object container container client context context container activate tag callback 1 tag callback on failed e container context tag callback remove from container if tag free bucket tag data free tag data remove from container container delete tag native thread norm priority false catch final archive restart exception e context job runner queue new db job public void run object container container client context context container activate tag callback 1 tag callback on failed e container context tag callback remove from container if tag free bucket tag data free tag data remove from container container delete tag native thread norm priority false extracttocache proxycallback proxycallback makebucket proxycallback buckettools proxycallback proxycallback ioexception archivefailureexception jobrunner dbjob objectcontainer clientcontext proxycallback notinarchive gotbucket removefrom freebucket removefrom nativethread norm_priority archivefailureexception jobrunner dbjob objectcontainer clientcontext onfailed removefrom freebucket removefrom nativethread norm_priority archiverestartexception jobrunner dbjob objectcontainer clientcontext onfailed removefrom freebucket removefrom nativethread norm_priority public void run object container container client context context if logminor logger minor this calling callback for tag data for tag handler key element tag element for tag callback container activate tag callback 1 if proxy callback data null tag callback not in archive container context else tag callback got bucket data container context tag callback remove from container if tag free bucket tag data free tag data remove from container container deactivate tag callback 1 container delete tag objectcontainer clientcontext proxycallback notinarchive gotbucket removefrom freebucket removefrom public void run object container container client context context container activate tag callback 1 tag callback on failed e container context tag callback remove from container if tag free bucket tag data free tag data remove from container container delete tag objectcontainer clientcontext onfailed removefrom freebucket removefrom public void run object container container client context context container activate tag callback 1 tag callback on failed e container context tag callback remove from container if tag free bucket tag data free tag data remove from container container delete tag objectcontainer clientcontext onfailed removefrom freebucket removefrom called from archive manager init static void init object container container client context context final long nodedb handle object set archive extract tag set container query new predicate archive extract tag override public boolean match archive extract tag tag return tag nodedb handle nodedb handle while set has next archive extract tag tag set next tag activate for execution container run persistent off thread tag context context archive manager context persistent bucket factory archivemanager objectcontainer clientcontext nodedbhandle objectset archiveextracttag archiveextracttag archiveextracttag nodedbhandle nodedbhandle hasnext archiveextracttag activateforexecution runpersistentoffthread archivemanager persistentbucketfactory static void init object container container client context context final long nodedb handle object set archive extract tag set container query new predicate archive extract tag override public boolean match archive extract tag tag return tag nodedb handle nodedb handle objectcontainer clientcontext nodedbhandle objectset archiveextracttag archiveextracttag archiveextracttag nodedbhandle nodedbhandle bucket data public void got bucket bucket data object container container client context context this data data gotbucket objectcontainer clientcontext public void not in archive object container container client context context this data null notinarchive objectcontainer clientcontext public void on failed archive restart exception e object container container client context context must not be called throw new unsupported operation exception onfailed archiverestartexception objectcontainer clientcontext unsupportedoperationexception public void on failed archive failure exception e object container container client context context must not be called throw new unsupported operation exception onfailed archivefailureexception objectcontainer clientcontext unsupportedoperationexception public void remove from object container container container delete this removefrom objectcontainer public void activate for execution object container container container activate this 1 container activate key 5 activateforexecution objectcontainer public archive handler clone handler return new archive handler impl key clone archive type compressor type force refetch archive archivehandler clonehandler archivehandlerimpl archivetype compressortype forcerefetcharchive public void remove from object container container if key null logger error this remove from key null for this i exist container ext is stored this i am active container ext is active this new exception error else key remove from container container delete this removefrom objectcontainer removefrom isstored isactive removefrom archive extract tag archive handler impl handler bucket data boolean free bucket archive context actx string element archive extract callback callback long nodedb handle this handler handler this data data this free bucket free bucket this actx actx this element element this callback callback this nodedb handle nodedb handle archiveextracttag archivehandlerimpl freebucket archivecontext archiveextractcallback nodedbhandle freebucket freebucket nodedbhandle nodedbhandle public void activate for execution object container container container activate this 1 container activate data 5 handler activate for execution container container activate actx 5 container activate callback 1 activateforexecution objectcontainer activateforexecution public static void main string args throws fs parse exception peer parse exception invalid threshold exception node init exception reference signature verification exception logger setup stdout logging logger normal freenet node cpu adjusting swap request interval minor freenet node location manager debug freenet node fnp packet manager normal freenet io comm message core debug system out println secret ping network coloring test using real nodes system out println string wd real node network color test new file wd mkdir note global test init returns in ignored random source node starter global test init wd false logger error freenet node location normal freenet node simulator real node network coloring test normal freenet node networkid manager normal true dummy random source random new dummy random source diffie hellman init random node subneta new node number of nodes node subnetb new node number of nodes node bridges new node bridges int total nodes number of nodes 2 bridges node all nodes new node total nodes cheat and use total nodes as a counter for a moment total nodes 0 logger normal real node routing test class creating nodes executor executor new pooled executor allow secret pings and send them automatically must be done before creating the nodes freenet node networkid manager disable secret pings false freenet node networkid manager disable secret pinger false freenet node networkid manager disable swap segregation false for int i 0 i number of nodes i all nodes total nodes subneta i node starter create test node 5001 total nodes 0 wd false true true max htl 0 no dropped packets random executor 500 number of nodes store size true true false false false false true 0 enable foaf false null total nodes logger normal real node routing test class created a node total nodes for int i 0 i number of nodes i all nodes total nodes subnetb i node starter create test node 5001 total nodes 0 wd false true true max htl 0 no dropped packets random executor 500 number of nodes store size true true false false false false true 0 enable foaf false null total nodes logger normal real node routing test class created b node total nodes for int i 0 i bridges i all nodes total nodes bridges i node starter create test node 5001 total nodes 0 wd false true true max htl 0 no dropped packets random executor 500 number of nodes store size true true false false false false true 0 enable foaf false null total nodes logger normal real node routing test class created bridge node total nodes logger normal real node routing test class created total nodes nodes now link them up make kleinberg network subneta true make it easy we re not testing swapping here degree false make kleinberg network subnetb true make it easy we re not testing swapping here degree false int a target count leafs subneta 1 int b target count leafs subnetb 1 int general target a target b target bridges logger normal real node routing test class added small world links weakly connect the subnets if bridges 0 for int i 0 i bridge links i connect a random node from a to a random node from b node a subneta random next int number of nodes node b subnetb random next int number of nodes connect a b else for int b 0 b bridges b node bridge bridges b make bridge links into a for int i 0 i bridge links i node nodea subneta random next int number of nodes connect bridge nodea make bridge links into b for int i 0 i bridge links i node nodeb subnetb random next int number of nodes connect bridge nodeb for int i 0 i total nodes i all nodes i start false now sit back and watch the fireworks int cycle number 0 running average general new bootstrapping decaying running average 0 0 0 0 1 0 2000 null running average a rate new bootstrapping decaying running average 0 0 0 0 1 0 500 null running average b rate new bootstrapping decaying running average 0 0 0 0 1 0 500 null running average bridge rate new bootstrapping decaying running average 0 0 0 0 1 0 500 null hash set integer general ids new hash set integer hash set integer a ids new hash set integer hash set integer b ids new hash set integer hash set integer bridge ids new hash set integer while true cycle number try thread sleep 5000 catch interrupted exception e ignore running average a loc new trivial running average running average b loc new trivial running average long total successes 0 long total total pings 0 general ids clear a ids clear b ids clear bridge ids clear for int i 0 i number of nodes i long good subneta i netid secret ping successes long total subneta i netid total secret ping attempts int id subneta i netid our network id a loc report subneta i get location total successes good total total pings total eh not really but i guess it s close reset this nodes good total double rate 0 0 if total 0 rate 1 0 good total general report rate a rate report rate general ids add integer value of id a ids add integer value of id for int i 0 i number of nodes i long good subnetb i netid secret ping successes long total subnetb i netid total secret ping attempts int id subnetb i netid our network id b loc report subnetb i get location total successes good total total pings total eh not really but i guess it s close reset this nodes good total double rate 0 0 if total 0 rate 1 0 good total general report rate b rate report rate general ids add integer value of id b ids add integer value of id for int i 0 i bridges i long good bridges i netid secret ping successes long total bridges i netid total secret ping attempts int id bridges i netid our network id total successes good total total pings total eh not really but i guess it s close reset this nodes good total double rate 0 0 if total 0 rate 1 0 good total general report rate bridge rate report rate general ids add integer value of id bridge ids add integer value of id logger error log cycle cycle number logger error log total secret pings total total pings logger error log total successful total successes logger error log p success all general current value logger error log p success a a rate current value logger error log p success b b rate current value if bridges 0 logger error log p success brg bridge rate current value id report all general ids general target id report a a ids a target id report b b ids b target if bridges 0 id report brg bridge ids bridges this is really rough but can generally give an indication of keyspace skew statistically they should remain 0 5 but if one keyspace starts to get absorbed into the other the balance will shift does not work if the aborbtion point is 0 5 logger error log a loc a loc current value logger error log b loc b loc current value fsparseexception peerparseexception invalidthresholdexception nodeinitexception referencesignatureverificationexception setupstdoutlogging cpuadjustingswaprequestinterval locationmanager fnppacketmanager messagecore secretping networkcoloring realnodenetworkcolortest globaltestinit nodestarter globaltestinit realnodenetworkcoloringtest networkidmanager dummyrandomsource dummyrandomsource diffiehellman number_of_nodes number_of_nodes totalnodes number_of_nodes allnodes totalnodes totalnodes totalnodes realnoderoutingtest pooledexecutor networkidmanager disablesecretpings networkidmanager disablesecretpinger networkidmanager disableswapsegregation number_of_nodes allnodes totalnodes nodestarter createtestnode totalnodes max_htl number_of_nodes storesize enable_foaf totalnodes realnoderoutingtest totalnodes number_of_nodes allnodes totalnodes nodestarter createtestnode totalnodes max_htl number_of_nodes storesize enable_foaf totalnodes realnoderoutingtest totalnodes allnodes totalnodes nodestarter createtestnode totalnodes max_htl number_of_nodes storesize enable_foaf totalnodes realnoderoutingtest totalnodes realnoderoutingtest totalnodes makekleinbergnetwork makekleinbergnetwork atarget countleafs btarget countleafs generaltarget atarget btarget realnoderoutingtest bridge_links nextint number_of_nodes nextint number_of_nodes bridge_links bridge_links nextint number_of_nodes bridge_links bridge_links nextint number_of_nodes totalnodes allnodes cyclenumber runningaverage bootstrappingdecayingrunningaverage runningaverage arate bootstrappingdecayingrunningaverage runningaverage brate bootstrappingdecayingrunningaverage runningaverage bridgerate bootstrappingdecayingrunningaverage hashset generalids hashset hashset aids hashset hashset bids hashset hashset bridgeids hashset cyclenumber interruptedexception runningaverage aloc trivialrunningaverage runningaverage bloc trivialrunningaverage totalsuccesses totaltotalpings generalids aids bids bridgeids number_of_nodes secretpingsuccesses totalsecretpingattempts ournetworkid aloc getlocation totalsuccesses totaltotalpings arate generalids valueof aids valueof number_of_nodes secretpingsuccesses totalsecretpingattempts ournetworkid bloc getlocation totalsuccesses totaltotalpings brate generalids valueof bids valueof secretpingsuccesses totalsecretpingattempts ournetworkid totalsuccesses totaltotalpings bridgerate generalids valueof bridgeids valueof cyclenumber secretpings totaltotalpings totalsuccesses psuccess currentvalue psuccess arate currentvalue psuccess brate currentvalue psuccess bridgerate currentvalue idreport generalids generaltarget idreport aids atarget idreport bids btarget idreport bridgeids aloc aloc currentvalue bloc bloc currentvalue private static void id report string group hash set integer ids int target num print out the number which are non zero display the distinct ones if a few int size ids size int max 6 string builder sb new string builder integer to string size append append integer to string target num sb append ids append group append iterator integer iter ids iterator for int i 0 i max i size i string this id iter next to string if i 0 sb append this id else sb append append this id if size max sb append logger error log sb to string idreport hashset targetnum stringbuilder stringbuilder tostring tostring targetnum thisid tostring thisid thisid tostring private static int count leafs node network int retval 0 for int i 0 i network length i int peers network i peers count valid peers if peers 1 retval return retval countleafs countvalidpeers public boolean has next if curr obj null return true while iterator has next object obj iterator next if query cls is instance obj curr obj t obj if condition null return true try if condition evaluate bool this return true catch jsql runtime exception x query report runtime error x curr obj null return false hasnext currobj hasnext isinstance currobj evaluatebool jsqlruntimeexception reportruntimeerror currobj public t next if has next throw new no such element exception t obj curr obj curr obj null return obj hasnext nosuchelementexception currobj currobj public void remove throw new unsupported operation exception unsupportedoperationexception filter iterator query impl query iterator t iterator node condition this query query this iterator iterator this condition condition index var new int max index vars filteriterator queryimpl indexvar maxindexvars final static int op date const 154 static string wrap null string object val return val null string val opdateconst wrapnullstring public boolean equals object o return o instanceof node node o tag tag node o type type static final boolean equal objects object a object b return a b a null a equals b equalobjects static final int get field type class type if type equals byte class type equals short class type equals int class type equals long class return tp int else if type equals boolean class return tp bool else if type equals double class type equals float class return tp real else if type equals string class return tp str else if type equals date class return tp date else if type equals boolean class return tp array bool else if type equals byte class return tp array int1 else if type equals short class return tp array int2 else if type equals char class return tp array char else if type equals int class return tp array int4 else if type equals long class return tp array int8 else if type equals float class return tp array real4 else if type equals double class return tp array real8 else if type equals string class return tp array str else if collection class is assignable from type return tp collection else if type is array return tp array obj else if type equals object class return tp any else return tp obj getfieldtype tpint tpbool tpreal tpstr tpdate tparraybool tparrayint1 tparrayint2 tparraychar tparrayint4 tparrayint8 tparrayreal4 tparrayreal8 tparraystr isassignablefrom tpcollection isarray tparrayobj tpany tpobj string get field name return null getfieldname boolean evaluate bool filter iterator t throw new abstract method error evaluatebool filteriterator abstractmethoderror throw new abstract method error long evaluate int filter iterator t throw new abstract method error abstractmethoderror evaluateint filteriterator abstractmethoderror throw new abstract method error double evaluate real filter iterator t throw new abstract method error abstractmethoderror evaluatereal filteriterator abstractmethoderror throw new abstract method error string evaluate str filter iterator t return wrap null string evaluate obj t abstractmethoderror evaluatestr filteriterator wrapnullstring evaluateobj return wrap null string evaluate obj t date evaluate date filter iterator t return date evaluate obj t wrapnullstring evaluateobj evaluatedate filteriterator evaluateobj object evaluate obj filter iterator t switch type case tp str return evaluate str t case tp date return evaluate date t case tp int return new long evaluate int t case tp real return new double evaluate real t case tp bool return evaluate bool t boolean true boolean false default throw new abstract method error evaluateobj filteriterator tpstr evaluatestr tpdate evaluatedate tpint evaluateint tpreal evaluatereal tpbool evaluatebool abstractmethoderror class get type return null gettype public string to string return node tag tag type type tostring node int type int tag this type type this tag tag class empty node extends node boolean evaluate bool filter iterator t return true emptynode evaluatebool filteriterator empty node super tp bool op true emptynode tpbool optrue abstract class literal node extends node abstract object get value literalnode getvalue abstract object get value object evaluate obj filter iterator t return get value getvalue evaluateobj filteriterator getvalue literal node int type int tag super type tag literalnode long value public boolean equals object o return o instanceof int literal node int literal node o value value intliteralnode intliteralnode object get value return new long value getvalue long evaluate int filter iterator t return value evaluateint filteriterator int literal node long value super tp int op int const this value value intliteralnode tpint opintconst double value public boolean equals object o return o instanceof real literal node real literal node o value value realliteralnode realliteralnode object get value return new double value getvalue double evaluate real filter iterator t return value evaluatereal filteriterator real literal node double value super tp real op real const this value value realliteralnode tpreal oprealconst string value public boolean equals object o return o instanceof str literal node str literal node o value equals value strliteralnode strliteralnode object get value return value getvalue string evaluate str filter iterator t return value evaluatestr filteriterator str literal node string value super tp str op str const this value value strliteralnode tpstr opstrconst class current node extends node class get type return cls currentnode gettype object evaluate obj filter iterator t return t curr obj evaluateobj filteriterator currobj current node class cls super tp obj op current this cls cls currentnode tpobj opcurrent date value public boolean equals object o return o instanceof date literal node date literal node o value equals value dateliteralnode dateliteralnode object get value return value getvalue date evaluate date filter iterator t return value evaluatedate filteriterator date literal node date value super tp date op date const this value value dateliteralnode tpdate opdateconst class constant node extends literal node object get value switch tag case op null return null case op false return boolean false case op true return boolean true default throw new error invalid tag tag constantnode literalnode getvalue opnull opfalse optrue boolean evaluate bool filter iterator t return tag op false evaluatebool filteriterator opfalse constant node int type int tag super type tag constantnode int loop id index out of range error int loop loop id loop loopid indexoutofrangeerror loopid int loop id public boolean equals object o return o instanceof exists node exists node o expr equals expr exists node o loop id loop id loopid existsnode existsnode existsnode loopid loopid boolean evaluate bool filter iterator t t index var loop id 0 try while expr evaluate bool t t index var loop id 1 return true catch index out of range error x if x loop id loop id throw x return false evaluatebool filteriterator indexvar loopid evaluatebool indexvar loopid indexoutofrangeerror loopid loopid exists node node expr int loop id super tp bool op exists this expr expr this loop id loop id existsnode loopid tpbool opexists loopid loopid int loop id public boolean equals object o return o instanceof index node index node o loop id loop id loopid indexnode indexnode loopid loopid long evaluate int filter iterator t return t index var loop id evaluateint filteriterator indexvar loopid index node int loop super tp int op index var loop id loop indexnode tpint opindexvar loopid node right public boolean equals object o return o instanceof get at node get at node o left equals left get at node o right equals right getatnode getatnode getatnode long evaluate int filter iterator t object arr left evaluate obj t long idx right evaluate int t if right tag op index var try if idx array get length arr throw new index out of range error index node right loop id catch illegal argument exception x throw new error argument is not array int index int idx switch tag case op get at int1 return byte arr index case op get at int2 return short arr index case op get at int4 return int arr index case op get at int8 return long arr index case op get at char return char arr index case op str get at return string arr char at index default throw new error invalid tag tag evaluateint filteriterator evaluateobj evaluateint opindexvar getlength indexoutofrangeerror indexnode loopid illegalargumentexception opgetatint1 opgetatint2 opgetatint4 opgetatint8 opgetatchar opstrgetat charat double evaluate real filter iterator t object arr left evaluate obj t long index right evaluate int t if right tag op index var try if index array get length arr throw new index out of range error index node right loop id catch illegal argument exception x throw new error argument is not array switch tag case op get at real4 return float arr int index case op get at real8 return double arr int index default throw new error invalid tag tag evaluatereal filteriterator evaluateobj evaluateint opindexvar getlength indexoutofrangeerror indexnode loopid illegalargumentexception opgetatreal4 opgetatreal8 boolean evaluate bool filter iterator t boolean arr boolean left evaluate obj t long index right evaluate int t if right tag op index var try if index arr length throw new index out of range error index node right loop id catch illegal argument exception x throw new error argument is not array return arr int index evaluatebool filteriterator evaluateobj evaluateint opindexvar indexoutofrangeerror indexnode loopid illegalargumentexception string evaluate str filter iterator t string arr string left evaluate obj t long index right evaluate int t if right tag op index var try if index arr length throw new index out of range error index node right loop id catch illegal argument exception x throw new error argument is not array return wrap null string arr int index evaluatestr filteriterator evaluateobj evaluateint opindexvar indexoutofrangeerror indexnode loopid illegalargumentexception wrapnullstring object evaluate obj filter iterator t object arr left evaluate obj t long index right evaluate int t try if right tag node op index var if index array get length arr throw new index out of range error index node right loop id return array get arr int index catch illegal argument exception x throw new error argument is not array evaluateobj filteriterator evaluateobj evaluateint opindexvar getlength indexoutofrangeerror indexnode loopid illegalargumentexception get at node int type int tag node base node index super type tag left base right index getatnode public boolean equals object o return o instanceof invoke node equal objects invoke node o target target arrays equals invoke node o arguments arguments equal objects invoke node o mth mth invokenode equalobjects invokenode invokenode equalobjects invokenode class get type return mth get return type gettype getreturntype string get field name if target null target tag op current string base name target get field name return base name null base name mth get name null else return mth get name getfieldname opcurrent basename getfieldname basename basename getname getname object get target filter iterator t if target null return t curr obj object obj target evaluate obj t if obj null throw new jsql null pointer exception target get type mth to string return obj gettarget filteriterator currobj evaluateobj jsqlnullpointerexception gettype tostring object evaluate arguments filter iterator t object parameters null int n arguments length if n 0 parameters new object n for int i 0 i n i node arg arguments i object value switch arg type case node tp int value new long arg evaluate int t break case node tp real value new double arg evaluate real t break case node tp str value arg evaluate str t break case node tp date value arg evaluate date t break case node tp bool value new boolean arg evaluate bool t break default value arg evaluate obj t parameters i value return parameters evaluatearguments filteriterator tpint evaluateint tpreal evaluatereal tpstr evaluatestr tpdate evaluatedate tpbool evaluatebool evaluateobj long evaluate int filter iterator t object obj get target t object parameters evaluate arguments t try return number mth invoke obj parameters long value catch exception x x print stack trace throw new error method invocation error evaluateint filteriterator gettarget evaluatearguments longvalue printstacktrace double evaluate real filter iterator t object obj get target t object parameters evaluate arguments t try return number mth invoke obj parameters double value catch exception x x print stack trace throw new error method invocation error evaluatereal filteriterator gettarget evaluatearguments doublevalue printstacktrace boolean evaluate bool filter iterator t object obj get target t object parameters evaluate arguments t try return boolean mth invoke obj parameters boolean value catch exception x x print stack trace throw new error method invocation error evaluatebool filteriterator gettarget evaluatearguments booleanvalue printstacktrace string evaluate str filter iterator t object obj get target t object parameters evaluate arguments t try return wrap null string mth invoke obj parameters catch exception x x print stack trace throw new error method invocation error evaluatestr filteriterator gettarget evaluatearguments wrapnullstring printstacktrace object evaluate obj filter iterator t object obj get target t object parameters evaluate arguments t try return mth invoke obj parameters catch exception x x print stack trace throw new error method invocation error evaluateobj filteriterator gettarget evaluatearguments printstacktrace invoke node node target method mth node arguments super get field type mth get return type op invoke this target target this arguments arguments this mth mth invokenode getfieldtype getreturntype opinvoke public boolean equals object o if o instanceof invoke any node return false invoke any node node invoke any node o return equal objects node target target arrays equals node arguments arguments arrays equals node profile profile equal objects node method name method name equal objects node contains field name contains field name invokeanynode invokeanynode invokeanynode equalobjects equalobjects methodname methodname equalobjects containsfieldname containsfieldname class get type return object class gettype string get field name if target null if target tag op current string base name target get field name return base name null base name method name null else return method name else return contains field name null contains field name method name method name getfieldname opcurrent basename getfieldname basename basename methodname methodname containsfieldname containsfieldname methodname methodname invoke any node node target string name node arguments string contains field name super tp any op invoke any this target target this contains field name contains field name method name name this arguments arguments profile new class arguments length invokeanynode containsfieldname tpany opinvokeany containsfieldname containsfieldname methodname object evaluate obj filter iterator t class cls method m object obj t curr obj if target null obj target evaluate obj t if obj null throw new jsql null pointer exception null method name object parameters null int n arguments length if n 0 parameters new object n for int i 0 i n i node arg arguments i object value class type switch arg type case node tp int value new long arg evaluate int t type long class break case node tp real value new double arg evaluate real t type double class break case node tp str value arg evaluate str t type string class break case node tp date value arg evaluate date t type date class break case node tp bool value new boolean arg evaluate bool t type boolean class break default value arg evaluate obj t if value null type value get class if type equals long class type equals integer class type equals byte class type equals character class type equals short class type long class else if type equals float class type equals double class type double class else if type equals boolean class type boolean class else type object class parameters i value profile i type try if target null t contains elem null if m query impl lookup method t contains elem get class method name profile null return t query resolve m invoke t contains elem parameters cls obj get class if m query impl lookup method cls method name profile null return t query resolve m invoke t contains elem parameters catch invocation target exception x x print stack trace throw new illegal access error catch illegal access exception x x print stack trace throw new illegal access error throw new jsql no such field exception cls method name evaluateobj filteriterator currobj evaluateobj jsqlnullpointerexception methodname tpint evaluateint tpreal evaluatereal tpstr evaluatestr tpdate evaluatedate tpbool evaluatebool evaluateobj getclass containselem queryimpl lookupmethod containselem getclass methodname containselem getclass queryimpl lookupmethod methodname containselem invocationtargetexception printstacktrace illegalaccesserror illegalaccessexception printstacktrace illegalaccesserror jsqlnosuchfieldexception methodname class convert any node extends node public boolean equals object o return o instanceof convert any node super equals o convert any node o expr equals expr convertanynode convertanynode convertanynode boolean evaluate bool filter iterator t return boolean evaluate obj t boolean value evaluatebool filteriterator evaluateobj booleanvalue long evaluate int filter iterator t return number evaluate obj t long value evaluateint filteriterator evaluateobj longvalue double evaluate real filter iterator t return number evaluate obj t double value evaluatereal filteriterator evaluateobj doublevalue object evaluate obj filter iterator t return expr evaluate obj t evaluateobj filteriterator evaluateobj convert any node int type node expr super type op convert any this expr expr convertanynode opconvertany public boolean equals object o return o instanceof bin op node super equals o bin op node o left equals left bin op node o right equals right binopnode binopnode binopnode long evaluate int filter iterator t long lval left evaluate int t long rval right evaluate int t long res switch tag case op int add return lval rval case op int sub return lval rval case op int mul return lval rval case op int div if rval 0 throw new jsql arithmetic exception divided by zero return lval rval case op int and return lval rval case op int or return lval rval case op int pow res 1 if rval 0 lval 1 lval rval rval while rval 0 if rval 1 0 res lval lval lval rval 1 return res default throw new error invalid tag evaluateint filteriterator evaluateint evaluateint opintadd opintsub opintmul opintdiv jsqlarithmeticexception opintand opintor opintpow double evaluate real filter iterator t double lval left evaluate real t double rval right evaluate real t switch tag case op real add return lval rval case op real sub return lval rval case op real mul return lval rval case op real div return lval rval case op real pow return math pow lval rval default throw new error invalid tag evaluatereal filteriterator evaluatereal evaluatereal oprealadd oprealsub oprealmul oprealdiv oprealpow string evaluate str filter iterator t string lval left evaluate str t string rval right evaluate str t return lval rval evaluatestr filteriterator evaluatestr evaluatestr object evaluate obj filter iterator t object lval rval try lval left evaluate obj t catch jsql runtime exception x t query report runtime error x rval right evaluate obj t if rval instanceof boolean return boolean rval boolean value boolean true boolean false throw x if lval instanceof boolean switch tag case op any and return boolean lval boolean value boolean right evaluate obj t boolean value boolean true boolean false case op any or return boolean lval boolean value boolean right evaluate obj t boolean value boolean true boolean false default throw new error operation is not applicable to operands of boolean type rval right evaluate obj t if lval instanceof double lval instanceof float rval instanceof double rval instanceof float double r1 number lval double value double r2 number rval double value switch tag case op any add return new double r1 r2 case op any sub return new double r1 r2 case op any mul return new double r1 r2 case op any div return new double r1 r2 case op any pow return new double math pow r1 r2 default throw new error operation is not applicable to operands of real type else if lval instanceof string rval instanceof string return string lval string rval else long i1 number lval long value long i2 number rval long value long res switch tag case op any add return new long i1 i2 case op any sub return new long i1 i2 case op any mul return new long i1 i2 case op any div if i2 0 throw new jsql arithmetic exception divided by zero return new long i1 i2 case op any and return new long i1 i2 case op any or return new long i1 i2 case op any pow res 1 if i1 0 i2 1 i2 i1 i1 while i1 0 if i1 1 0 res i2 i2 i2 i1 1 return new long res default throw new error operation is not applicable to operands of integer type evaluateobj filteriterator evaluateobj jsqlruntimeexception reportruntimeerror evaluateobj booleanvalue opanyand booleanvalue evaluateobj booleanvalue opanyor booleanvalue evaluateobj booleanvalue evaluateobj doublevalue doublevalue opanyadd opanysub opanymul opanydiv opanypow longvalue longvalue opanyadd opanysub opanymul opanydiv jsqlarithmeticexception opanyand opanyor opanypow static boolean are equal object a object b if a b return true if a instanceof double a instanceof float b instanceof double b instanceof float return number a double value number b double value else if a instanceof number b instanceof number return number a long value number b long value else if a null return a equals b return false areequal doublevalue doublevalue longvalue longvalue static int compare object a object b if a null return b null 0 1 else if b null return 1 else if a instanceof double a instanceof float b instanceof double b instanceof float double r1 number a double value double r2 number b double value return r1 r2 1 r1 r2 0 1 else if a instanceof number b instanceof number long i1 number a long value long i2 number b long value return i1 i2 1 i1 i2 0 1 else return comparable a compare to b doublevalue doublevalue longvalue longvalue compareto boolean evaluate bool filter iterator t switch tag case op any eq return are equal left evaluate obj t right evaluate obj t case op any ne return are equal left evaluate obj t right evaluate obj t case op any lt return compare left evaluate obj t right evaluate obj t 0 case op any le return compare left evaluate obj t right evaluate obj t 0 case op any gt return compare left evaluate obj t right evaluate obj t 0 case op any ge return compare left evaluate obj t right evaluate obj t 0 case op in any object elem left evaluate obj t object set right evaluate obj t if set instanceof string return string set index of string elem 0 else object arr object set for int i arr length i 0 if elem equals arr i return true return false case op bool and try if left evaluate bool t return false catch jsql runtime exception x t query report runtime error x return right evaluate bool t case op bool or try if left evaluate bool t return true catch jsql runtime exception x t query report runtime error x return right evaluate bool t case op int eq return left evaluate int t right evaluate int t case op int ne return left evaluate int t right evaluate int t case op int lt return left evaluate int t right evaluate int t case op int le return left evaluate int t right evaluate int t case op int gt return left evaluate int t right evaluate int t case op int ge return left evaluate int t right evaluate int t case op real eq return left evaluate real t right evaluate real t case op real ne return left evaluate real t right evaluate real t case op real lt return left evaluate real t right evaluate real t case op real le return left evaluate real t right evaluate real t case op real gt return left evaluate real t right evaluate real t case op real ge return left evaluate real t right evaluate real t case op str eq return left evaluate str t equals right evaluate str t case op str ne return left evaluate str t equals right evaluate str t case op str lt return left evaluate str t compare to right evaluate str t 0 case op str le return left evaluate str t compare to right evaluate str t 0 case op str gt return left evaluate str t compare to right evaluate str t 0 case op str ge return left evaluate str t compare to right evaluate str t 0 case op date eq return left evaluate date t equals right evaluate date t case op date ne return left evaluate date t equals right evaluate date t case op date lt return left evaluate date t compare to right evaluate date t 0 case op date le return left evaluate date t compare to right evaluate date t 0 case op date gt return left evaluate date t compare to right evaluate date t 0 case op date ge return left evaluate date t compare to right evaluate date t 0 case op bool eq return left evaluate bool t right evaluate bool t case op bool ne return left evaluate bool t right evaluate bool t case op obj eq return are equal left evaluate obj t right evaluate obj t case op obj ne return are equal left evaluate obj t right evaluate obj t case op scan collection return collection right evaluate obj t contains left evaluate obj t case op scan array bool boolean val left evaluate bool t boolean arr boolean right evaluate obj t for int i arr length i 0 if arr i val return true return false case op scan array int1 long val left evaluate int t byte arr byte right evaluate obj t for int i arr length i 0 if arr i val return true return false case op scan array char long val left evaluate int t char arr char right evaluate obj t for int i arr length i 0 if arr i val return true return false case op scan array int2 long val left evaluate int t short arr short right evaluate obj t for int i arr length i 0 if arr i val return true return false case op scan array int4 long val left evaluate int t int arr int right evaluate obj t for int i arr length i 0 if arr i val return true return false case op scan array int8 long val left evaluate int t long arr long right evaluate obj t for int i arr length i 0 if arr i val return true return false case op scan array real4 double val left evaluate real t float arr float right evaluate obj t for int i arr length i 0 if arr i val return true return false case op scan array real8 double val left evaluate real t double arr double right evaluate obj t for int i arr length i 0 if arr i val return true return false case op scan array str string val left evaluate str t string arr string right evaluate obj t for int i arr length i 0 if val equals arr i return true return false case op scan array obj object val left evaluate obj t object arr object right evaluate obj t for int i arr length i 0 if are equal val arr i return true return false case op in string string substr left evaluate str t string str right evaluate str t return str index of substr 0 default throw new error invalid tag tag evaluatebool filteriterator opanyeq areequal evaluateobj evaluateobj opanyne areequal evaluateobj evaluateobj opanylt evaluateobj evaluateobj opanyle evaluateobj evaluateobj opanygt evaluateobj evaluateobj opanyge evaluateobj evaluateobj opinany evaluateobj evaluateobj indexof opbooland evaluatebool jsqlruntimeexception reportruntimeerror evaluatebool opboolor evaluatebool jsqlruntimeexception reportruntimeerror evaluatebool opinteq evaluateint evaluateint opintne evaluateint evaluateint opintlt evaluateint evaluateint opintle evaluateint evaluateint opintgt evaluateint evaluateint opintge evaluateint evaluateint oprealeq evaluatereal evaluatereal oprealne evaluatereal evaluatereal opreallt evaluatereal evaluatereal oprealle evaluatereal evaluatereal oprealgt evaluatereal evaluatereal oprealge evaluatereal evaluatereal opstreq evaluatestr evaluatestr opstrne evaluatestr evaluatestr opstrlt evaluatestr compareto evaluatestr opstrle evaluatestr compareto evaluatestr opstrgt evaluatestr compareto evaluatestr opstrge evaluatestr compareto evaluatestr opdateeq evaluatedate evaluatedate opdatene evaluatedate evaluatedate opdatelt evaluatedate compareto evaluatedate opdatele evaluatedate compareto evaluatedate opdategt evaluatedate compareto evaluatedate opdatege evaluatedate compareto evaluatedate opbooleq evaluatebool evaluatebool opboolne evaluatebool evaluatebool opobjeq areequal evaluateobj evaluateobj opobjne areequal evaluateobj evaluateobj opscancollection evaluateobj evaluateobj opscanarraybool evaluatebool evaluateobj opscanarrayint1 evaluateint evaluateobj opscanarraychar evaluateint evaluateobj opscanarrayint2 evaluateint evaluateobj opscanarrayint4 evaluateint evaluateobj opscanarrayint8 evaluateint evaluateobj opscanarrayreal4 evaluatereal evaluateobj opscanarrayreal8 evaluatereal evaluateobj opscanarraystr evaluatestr evaluateobj opscanarrayobj evaluateobj evaluateobj areequal opinstring evaluatestr evaluatestr indexof bin op node int type int tag node left node right super type tag this left left this right right binopnode public boolean equals object o return o instanceof compare node super equals o compare node o o1 equals o1 compare node o o2 equals o2 equal objects compare node o o3 o3 comparenode comparenode comparenode equalobjects comparenode boolean evaluate bool filter iterator t switch tag case op any between object val o1 evaluate obj t return bin op node compare val o2 evaluate obj t 0 bin op node compare val o3 evaluate obj t 0 case op int between long val o1 evaluate int t return val o2 evaluate int t val o3 evaluate int t case op real between double val o1 evaluate real t return val o2 evaluate real t val o3 evaluate real t case op str between string val o1 evaluate str t return val compare to o2 evaluate str t 0 val compare to o3 evaluate str t 0 case op date between date val o1 evaluate date t return val compare to o2 evaluate date t 0 val compare to o3 evaluate date t 0 case op str like string str o1 evaluate str t string pat o2 evaluate str t int pi 0 si 0 pn pat length sn str length int wildcard 1 strpos 1 while true if pi pn pat char at pi wildcard pi strpos si else if si sn return pi pn else if pi pn str char at si pat char at pi pat char at pi si 1 pi 1 else if wildcard 0 si strpos pi wildcard else return false case op str like esc string str o1 evaluate str t string pat o2 evaluate str t char escape o3 evaluate str t char at 0 int pi 0 si 0 pn pat length sn str length int wildcard 1 strpos 1 while true if pi pn pat char at pi wildcard pi strpos si else if si sn return pi pn else if pi 1 pn pat char at pi escape pat char at pi 1 str char at si si 1 pi 2 else if pi pn pat char at pi escape str char at si pat char at pi pat char at pi si 1 pi 1 else if wildcard 0 si strpos pi wildcard else return false default throw new error invalid tag tag evaluatebool filteriterator opanybetween evaluateobj binopnode evaluateobj binopnode evaluateobj opintbetween evaluateint evaluateint evaluateint oprealbetween evaluatereal evaluatereal evaluatereal opstrbetween evaluatestr compareto evaluatestr compareto evaluatestr opdatebetween evaluatedate compareto evaluatedate compareto evaluatedate opstrlike evaluatestr evaluatestr charat charat charat charat _ opstrlikeesc evaluatestr evaluatestr evaluatestr charat charat charat charat charat charat charat charat charat _ compare node int tag node a node b node c super tp bool tag o1 a o2 b o3 c comparenode tpbool node opd public boolean equals object o return o instanceof unary op node super equals o unary op node o opd equals opd unaryopnode unaryopnode object evaluate obj filter iterator t object val opd evaluate obj t switch tag case op any neg return val instanceof double val instanceof float object new double number val double value object new long number val long value case op any abs if val instanceof double val instanceof float double rval number val double value return new double rval 0 rval rval else long ival number val long value return new long ival 0 ival ival case op any not return val instanceof boolean boolean val boolean value boolean false boolean true object new long number val long value default throw new error invalid tag tag evaluateobj filteriterator evaluateobj opanyneg doublevalue longvalue opanyabs doublevalue longvalue opanynot booleanvalue longvalue long evaluate int filter iterator t long val switch tag case op int not return opd evaluate int t case op int neg return opd evaluate int t case op int abs val opd evaluate int t return val 0 val val case op real to int return long opd evaluate real t case op any length object obj opd evaluate obj t if obj instanceof string return string obj length else try return array get length obj catch illegal argument exception x throw new error argument is not array case op length try return array get length opd evaluate obj t catch illegal argument exception x throw new error argument is not array case op str length return opd evaluate str t length default throw new error invalid tag tag evaluateint filteriterator opintnot evaluateint opintneg evaluateint opintabs evaluateint oprealtoint evaluatereal opanylength evaluateobj getlength illegalargumentexception oplength getlength evaluateobj illegalargumentexception opstrlength evaluatestr double evaluate real filter iterator t double val switch tag case op real neg return opd evaluate real t case op real abs val opd evaluate real t return val 0 val val case op real sin return math sin opd evaluate real t case op real cos return math cos opd evaluate real t case op real tan return math tan opd evaluate real t case op real asin return math asin opd evaluate real t case op real acos return math acos opd evaluate real t case op real atan return math atan opd evaluate real t case op real exp return math exp opd evaluate real t case op real log return math log opd evaluate real t case op real sqrt return math sqrt opd evaluate real t case op real ceil return math ceil opd evaluate real t case op real floor return math floor opd evaluate real t case op int to real return double opd evaluate int t default throw new error invalid tag tag evaluatereal filteriterator oprealneg evaluatereal oprealabs evaluatereal oprealsin evaluatereal oprealcos evaluatereal oprealtan evaluatereal oprealasin evaluatereal oprealacos evaluatereal oprealatan evaluatereal oprealexp evaluatereal opreallog evaluatereal oprealsqrt evaluatereal oprealceil evaluatereal oprealfloor evaluatereal opinttoreal evaluateint date evaluate date filter iterator t switch tag case op str to date return query impl parse date opd evaluate str t default throw new error invalid tag tag evaluatedate filteriterator opstrtodate queryimpl parsedate evaluatestr string evaluate str filter iterator t switch tag case op str upper return opd evaluate str t to upper case case op str lower return opd evaluate str t to lower case case op int to str return long to string opd evaluate int t 10 case op real to str return double to string opd evaluate real t case op date to str return opd evaluate date t to string case op any to str return opd evaluate obj t to string default throw new error invalid tag tag evaluatestr filteriterator opstrupper evaluatestr touppercase opstrlower evaluatestr tolowercase opinttostr tostring evaluateint oprealtostr tostring evaluatereal opdatetostr evaluatedate tostring opanytostr evaluateobj tostring boolean evaluate bool filter iterator t switch tag case op bool not return opd evaluate bool t case op is null return opd evaluate obj t null default throw new error invalid tag tag evaluatebool filteriterator opboolnot evaluatebool opisnull evaluateobj unary op node int type int tag node node super type tag opd node unaryopnode public boolean equals object o if o instanceof load any node return false load any node node load any node o return equal objects node base base equal objects node field name field name equal objects node f f equal objects node m m loadanynode loadanynode loadanynode equalobjects equalobjects fieldname fieldname equalobjects equalobjects class get type return object class gettype string get field name if base null if base tag op current string base name base get field name return base name null base name field name null else return field name else return contains field name null contains field name field name field name getfieldname opcurrent basename getfieldname basename basename fieldname fieldname containsfieldname containsfieldname fieldname fieldname load any node node base string name string contains field name super tp any op load any field name name this contains field name contains field name this base base loadanynode containsfieldname tpany oploadany fieldname containsfieldname containsfieldname public string to string return load any node field name field name contains field name contains field name base base f f m m tostring loadanynode fieldname fieldname containsfieldname containsfieldname object evaluate obj filter iterator t object obj class cls field f this f method m this m try if base null if t contains elem null obj t contains elem cls obj get class if f null f get declaring class equals cls return t query resolve f get obj if m null m get declaring class equals cls return t query resolve m invoke obj if f class descriptor locate field cls field name null this f f return t query resolve f get obj if m query impl lookup method cls field name query impl default profile null this m m return t query resolve m invoke obj obj t curr obj else obj base evaluate obj t if obj null throw new jsql null pointer exception null field name cls obj get class if f null f get declaring class equals cls return t query resolve f get obj if m null m get declaring class equals cls return t query resolve m invoke obj if f class descriptor locate field cls field name null this f f return t query resolve f get obj if m query impl lookup method cls field name query impl default profile null this m m return t query resolve m invoke obj catch illegal access exception x x print stack trace throw new illegal access error catch invocation target exception x x print stack trace throw new illegal access error throw new jsql no such field exception cls field name evaluateobj filteriterator containselem containselem getclass getdeclaringclass getdeclaringclass classdescriptor locatefield fieldname queryimpl lookupmethod fieldname queryimpl defaultprofile currobj evaluateobj jsqlnullpointerexception fieldname getclass getdeclaringclass getdeclaringclass classdescriptor locatefield fieldname queryimpl lookupmethod fieldname queryimpl defaultprofile illegalaccessexception printstacktrace illegalaccesserror invocationtargetexception printstacktrace illegalaccesserror jsqlnosuchfieldexception fieldname public boolean equals object o return o instanceof resolve node resolve node o expr equals expr resolve node o resolver equals resolver resolve node o resolved class equals resolved class resolvenode resolvenode resolvenode resolvenode resolvedclass resolvedclass class get type return resolved class gettype resolvedclass object evaluate obj filter iterator t return resolver resolve expr evaluate obj t evaluateobj filteriterator evaluateobj string get field name if expr null return expr get field name else return null getfieldname getfieldname resolve node node expr resolver resolver class resolved class super tp obj op resolve this expr expr this resolver resolver this resolved class resolved class resolvenode resolvedclass tpobj opresolve resolvedclass resolvedclass public boolean equals object o return o instanceof load node super equals o load node o field equals field equal objects load node o base base loadnode loadnode equalobjects loadnode class get type return field get type gettype gettype string get field name if base null base tag op current string base name base get field name return base name null base name field get name null else return field get name getfieldname opcurrent basename getfieldname basename basename getname getname final object get base filter iterator t if base null return t curr obj object obj base evaluate obj t if obj null throw new jsql null pointer exception base get type field get name return obj getbase filteriterator currobj evaluateobj jsqlnullpointerexception gettype getname long evaluate int filter iterator t try return field get long get base t catch illegal access exception x throw new illegal access error evaluateint filteriterator getlong getbase illegalaccessexception illegalaccesserror double evaluate real filter iterator t try return field get double get base t catch illegal access exception x throw new illegal access error evaluatereal filteriterator getdouble getbase illegalaccessexception illegalaccesserror boolean evaluate bool filter iterator t try return field get boolean get base t catch illegal access exception x throw new illegal access error evaluatebool filteriterator getboolean getbase illegalaccessexception illegalaccesserror string evaluate str filter iterator t try return wrap null string field get get base t catch illegal access exception x throw new illegal access error evaluatestr filteriterator wrapnullstring getbase illegalaccessexception illegalaccesserror object evaluate obj filter iterator t try return field get get base t catch illegal access exception x throw new illegal access error evaluateobj filteriterator getbase illegalaccessexception illegalaccesserror load node node base field f super get field type f get type op load field f this base base loadnode getfieldtype gettype opload class aggregate function node extends node public boolean equals object o return o instanceof aggregate function node super equals o equal objects aggregate function node o argument argument aggregate function node o index index aggregatefunctionnode aggregatefunctionnode equalobjects aggregatefunctionnode aggregatefunctionnode long evaluate int filter iterator t return t int aggragate func value index evaluateint filteriterator intaggragatefuncvalue double evaluate real filter iterator t return t real aggragate func value index evaluatereal filteriterator realaggragatefuncvalue aggregate function node int type int tag node arg super type tag argument arg aggregatefunctionnode string contains array name invoke element node method mth node arguments string array name super null mth arguments contains array name array name containsarrayname invokeelementnode arrayname containsarrayname arrayname public boolean equals object o return o instanceof invoke element node super equals o invokeelementnode object get target filter iterator t return t contains elem gettarget filteriterator containselem string get field name if contains array name null return contains array name mth get name else return null getfieldname containsarrayname containsarrayname getname public boolean equals object o return o instanceof element node equal objects element node o array name array name equal objects element node o field field equal objects element node o type type elementnode equalobjects elementnode arrayname arrayname equalobjects elementnode equalobjects elementnode element node string array field f super get field type f get type op element array name array type f get type field f elementnode getfieldtype gettype opelement arrayname gettype string get field name return array name null array name field get name null getfieldname arrayname arrayname getname boolean evaluate bool filter iterator t try return field get boolean t contains elem catch illegal access exception x throw new illegal access error evaluatebool filteriterator getboolean containselem illegalaccessexception illegalaccesserror long evaluate int filter iterator t try return field get long t contains elem catch illegal access exception x throw new illegal access error evaluateint filteriterator getlong containselem illegalaccessexception illegalaccesserror double evaluate real filter iterator t try return field get double t contains elem catch illegal access exception x throw new illegal access error evaluatereal filteriterator getdouble containselem illegalaccessexception illegalaccesserror string evaluate str filter iterator t try return wrap null string field get t contains elem catch illegal access exception x throw new illegal access error evaluatestr filteriterator wrapnullstring containselem illegalaccessexception illegalaccesserror object evaluate obj filter iterator t try return field get t contains elem catch illegal access exception x throw new illegal access error evaluateobj filteriterator containselem illegalaccessexception illegalaccesserror class get type return type gettype public boolean equals object o if o instanceof contains node return false contains node node contains node o return node contains expr equals contains expr equal objects node group by field group by field equal objects node group by method group by method equal objects node group by field name group by field name equal objects node contains field class contains field class node group by type group by type equal objects node having expr having expr equal objects node with expr with expr equal objects node aggregate functions aggregate functions containsnode containsnode containsnode containsexpr containsexpr equalobjects groupbyfield groupbyfield equalobjects groupbymethod groupbymethod equalobjects groupbyfieldname groupbyfieldname equalobjects containsfieldclass containsfieldclass groupbytype groupbytype equalobjects havingexpr havingexpr equalobjects withexpr withexpr equalobjects aggregatefunctions aggregatefunctions public int compare object o1 object o2 if o1 o2 return 0 try if group by method null return comparable group by method invoke o1 compare to group by method invoke o2 switch group by type case tp int long v1 group by field get long o1 long v2 group by field get long o2 return v1 v2 1 v1 v2 0 1 case tp real double v1 group by field get double o1 double v2 group by field get double o2 return v1 v2 1 v1 v2 0 1 case tp bool boolean v1 group by field get boolean o1 boolean v2 group by field get boolean o2 return v1 v2 0 1 v2 1 0 default return comparable group by field get o1 compare to group by field get o2 catch invocation target exception x x print stack trace throw new illegal access error catch illegal access exception x x print stack trace throw new illegal access error groupbymethod groupbymethod compareto groupbymethod groupbytype tpint groupbyfield getlong groupbyfield getlong tpreal groupbyfield getdouble groupbyfield getdouble tpbool groupbyfield getboolean groupbyfield getboolean groupbyfield compareto groupbyfield invocationtargetexception printstacktrace illegalaccesserror illegalaccessexception printstacktrace illegalaccesserror boolean evaluate bool filter iterator t int i j k l n 0 len 0 object collection collection contains expr evaluate obj t if collection null return false object sorted array null if having expr null with expr null collection instanceof collection n collection instanceof collection collection collection size object collection length if t contains array null t contains array length n t contains array new object n sorted array t contains array t contains array null prevent reuse of the same array by nexted contains in with expression object save contains elem t contains elem if collection instanceof collection if with expr null object elem iterator iterator collection collection iterator while iterator has next elem iterator next if elem null if resolver null elem resolver resolve elem else elem t query resolve elem t contains elem elem try if with expr evaluate bool t if having expr null t contains elem save contains elem return true sorted array len elem catch jsql runtime exception x t query report runtime error x else sorted array collection collection to array n sorted array length if t query resolve map null for i 0 i n i sorted array i t query resolve sorted array i len n else object a object collection n a length if with expr null for i 0 i n i object elem a i if elem null if resolver null elem resolver resolve elem else elem t query resolve elem t contains elem elem try if with expr evaluate bool t if having expr null t contains elem save contains elem return true sorted array len elem catch jsql runtime exception x t query report runtime error x else system arraycopy a 0 sorted array 0 n if t query resolve map null for i 0 i n i sorted array i t query resolve sorted array i len n t contains elem save contains elem if sorted array null t contains array sorted array if len 0 return false if group by field name null len 0 class type sorted array 0 get class group by field class descriptor locate field type group by field name if group by field null group by method query impl lookup method type group by field name query impl default profile if group by method null throw new jsql no such field exception type group by field name else group by type node get field type group by field get type arrays sort sorted array 0 len this n aggregate functions size if t int aggragate func value null t int aggragate func value length n t int aggragate func value new long n t real aggragate func value new double n for i 0 i len i j for j i 1 j len compare sorted array i sorted array j 0 j for k 0 k n k aggregate function node agr aggregate function node aggregate functions get k node argument agr argument if agr type tp int long ival 0 switch agr tag case op sum for l i l j l t contains elem sorted array l ival argument evaluate int t break case op avg for l i l j l t contains elem sorted array l ival argument evaluate int t ival j i break case op min ival long max value for l i l j l t contains elem sorted array l long v argument evaluate int t if v ival ival v break case op max ival long min value for l i l j l t contains elem sorted array l long v argument evaluate int t if v ival ival v break case op count ival j i t int aggragate func value k ival else double rval 0 0 switch agr tag case op sum for l i l j l t contains elem sorted array l rval argument evaluate real t break case op avg for l i l j l t contains elem sorted array l rval argument evaluate real t rval j i break case op min rval double positive infinity for l i l j l t contains elem sorted array l double v argument evaluate real t if v rval rval v break case op max rval double negative infinity for l i l j l t contains elem sorted array l double v argument evaluate real t if v rval rval v t real aggragate func value k rval t contains elem save contains elem try if having expr evaluate bool t return true catch jsql runtime exception x t query report runtime error x return false evaluatebool filteriterator containsexpr evaluateobj sortedarray havingexpr withexpr containsarray containsarray containsarray sortedarray containsarray containsarray savecontainselem containselem withexpr hasnext containselem withexpr evaluatebool havingexpr containselem savecontainselem sortedarray jsqlruntimeexception reportruntimeerror sortedarray toarray sortedarray resolvemap sortedarray sortedarray withexpr containselem withexpr evaluatebool havingexpr containselem savecontainselem sortedarray jsqlruntimeexception reportruntimeerror sortedarray resolvemap sortedarray sortedarray containselem savecontainselem sortedarray containsarray sortedarray groupbyfieldname sortedarray getclass groupbyfield classdescriptor locatefield groupbyfieldname groupbyfield groupbymethod queryimpl lookupmethod groupbyfieldname queryimpl defaultprofile groupbymethod jsqlnosuchfieldexception groupbyfieldname groupbytype getfieldtype groupbyfield gettype sortedarray aggregatefunctions intaggragatefuncvalue intaggragatefuncvalue intaggragatefuncvalue realaggragatefuncvalue sortedarray sortedarray aggregatefunctionnode aggregatefunctionnode aggregatefunctions tpint opsum containselem sortedarray evaluateint opavg containselem sortedarray evaluateint opmin max_value containselem sortedarray evaluateint opmax min_value containselem sortedarray evaluateint opcount intaggragatefuncvalue opsum containselem sortedarray evaluatereal opavg containselem sortedarray evaluatereal opmin positive_infinity containselem sortedarray evaluatereal opmax negative_infinity containselem sortedarray evaluatereal realaggragatefuncvalue containselem savecontainselem havingexpr evaluatebool jsqlruntimeexception reportruntimeerror contains node node contains expr class contains field class super tp bool op contains this contains expr contains expr this contains field class contains field class aggregate functions new array list containsnode containsexpr containsfieldclass tpbool opcontains containsexpr containsexpr containsfieldclass containsfieldclass aggregatefunctions arraylist final int compare object a object b int diff try if method null diff comparable method invoke a compare to method invoke b else switch type case class descriptor tp boolean diff field get boolean a field get boolean b 0 1 field get boolean b 1 0 break case class descriptor tp char diff field get char a field get char b break case class descriptor tp byte diff field get byte a field get byte b break case class descriptor tp short diff field get short a field get short b break case class descriptor tp int int l field get int a int r field get int b diff l r 1 l r 0 1 break case class descriptor tp long long l field get long a long r field get long b diff l r 1 l r 0 1 break case class descriptor tp float float l field get float a float r field get float b diff l r 1 l r 0 1 break case class descriptor tp double double l field get double a double r field get double b diff l r 1 l r 0 1 break default diff comparable field get a compare to field get b break catch illegal access exception x x print stack trace throw new illegal access error catch invocation target exception x x print stack trace throw new illegal access error if diff 0 next null return next compare a b if ascent diff diff return diff compareto classdescriptor tpboolean getboolean getboolean getboolean classdescriptor tpchar getchar getchar classdescriptor tpbyte getbyte getbyte classdescriptor tpshort getshort getshort classdescriptor tpint getint getint classdescriptor tplong getlong getlong classdescriptor tpfloat getfloat getfloat classdescriptor tpdouble getdouble getdouble compareto illegalaccessexception printstacktrace illegalaccesserror invocationtargetexception printstacktrace illegalaccesserror void resolve name class cls field class descriptor locate field cls field name if field null method query impl lookup method cls field name query impl default profile if method null throw new jsql no such field exception cls field name resolvename classdescriptor locatefield fieldname queryimpl lookupmethod fieldname queryimpl defaultprofile jsqlnosuchfieldexception fieldname order node int type field field this type type this field field ascent true ordernode ascent true order node method method this method method ascent true ordernode ascent true order node string name field name name ascent true ordernode fieldname int index public boolean equals object o return o instanceof parameter node parameter node o index index parameternode parameternode boolean evaluate bool filter iterator t return boolean params get index boolean value evaluatebool filteriterator booleanvalue return boolean params get index boolean value long evaluate int filter iterator t return number params get index long value booleanvalue evaluateint filteriterator longvalue return number params get index long value double evaluate real filter iterator t return number params get index double value longvalue evaluatereal filteriterator doublevalue return number params get index double value string evaluate str filter iterator t return string params get index doublevalue evaluatestr filteriterator return string params get index date evaluate date filter iterator t return date params get index evaluatedate filteriterator object get value return params get index getvalue parameter node array list parameter list super tp unknown op parameter params parameter list index params size params add null parameternode arraylist parameterlist tpunknown opparameter parameterlist int tkn symbol int tkn this tkn tkn binding string ident int loop binding chain name ident used false next chain loop id loop loopid public iterable iterator t select class cls iterator t iterator string query throws compile error this query query buf query to char array str new char buf length this cls cls compile return execute iterator iterableiterator compileerror tochararray public iterable iterator t select string class name iterator t iterator string query throws compile error cls class descriptor load class storage class name return select cls iterator query iterableiterator classname compileerror classdescriptor loadclass classname public void set parameter int index object value parameters set index 1 value setparameter public void set int parameter int index long value set parameter index new long value setintparameter setparameter public void set real parameter int index double value set parameter index new double value setrealparameter setparameter public void set bool parameter int index boolean value set parameter index new boolean value setboolparameter setparameter public void prepare class cls string query this query query buf query to char array str new char buf length this cls cls compile tochararray public void prepare string class name string query cls class descriptor load class storage class name this query query buf query to char array str new char buf length compile classname classdescriptor loadclass classname tochararray public iterable iterator t execute iterator t iterator iterable iterator t result iterable iterator t apply index tree if result null if storage listener null storage listener sequential search performed query result new filter iterator t this iterator tree if order null array list t list new array list t while result has next list add result next sort list return new iterator wrapper t list iterator return result iterableiterator iterableiterator iterableiterator applyindex sequentialsearchperformed filteriterator arraylist arraylist hasnext iteratorwrapper private void sort array list t selection int i j k n order node order this order t top if selection size 0 return for order node ord order ord null ord ord next if ord field name null ord resolve name selection get 0 get class for n selection size i n 2 j i i 1 i k i top selection get k 1 do if k 2 n order compare selection get k 2 1 selection get k 2 0 if order compare top selection get k 2 1 0 break selection set k 1 selection get k 2 1 k k 2 else if order compare top selection get k 2 0 break selection set k 1 selection get k 2 k k 2 1 while k j selection set k 1 top for i n i 2 i top selection get i 1 selection set i 1 selection get 0 selection set 0 top for k 1 j i 1 2 k j if k 2 i 1 order compare selection get k 2 1 selection get k 2 0 if order compare top selection get k 2 1 0 break selection set k 1 selection get k 2 1 k k 2 else if order compare top selection get k 2 0 break selection set k 1 selection get k 2 k k 2 1 selection set k 1 top arraylist ordernode ordernode fieldname resolvename getclass public void report runtime error jsql runtime exception x if runtime errors reporting string buffer buf new string buffer buf append x get message class cls x get target if cls null buf append cls get name buf append string field name x get field name if field name null buf append field name system err println buf if storage null storage listener null storage listener jsql runtime error x reportruntimeerror jsqlruntimeexception runtimeerrorsreporting stringbuffer stringbuffer getmessage gettarget getname fieldname getfieldname fieldname fieldname jsqlruntimeerror public void enable runtime error reporting boolean enabled runtime errors reporting enabled enableruntimeerrorreporting runtimeerrorsreporting resolver resolver resolve mapping class resolved resolver resolver this resolved resolved this resolver resolver resolvemapping public void set resolver class original class resolved resolver resolver if resolve map null resolve map new hash map resolve map put original new resolve mapping resolved resolver setresolver resolvemap resolvemap hashmap resolvemap resolvemapping public void add index string key generic index t index if indices null indices new hash map indices put key index addindex genericindex hashmap private final generic index t get index string key return indices null generic index indices get key null genericindex getindex genericindex private static key key literal class type node node boolean inclusive object value literal node node get value if type equals long class return new key number value long value inclusive else if type equals int class return new key number value int value inclusive else if type equals byte class return new key number value byte value inclusive else if type equals short class return new key number value short value inclusive else if type equals char class return new key value instanceof number char number value int value character value char value inclusive else if type equals float class return new key number value float value inclusive else if type equals double class return new key number value double value inclusive else if type equals string class return new key string value inclusive else if type equals date class return new key date value inclusive return null keyliteral literalnode getvalue longvalue intvalue bytevalue shortvalue intvalue charvalue floatvalue doublevalue public query impl storage storage this storage storage impl storage parameters new array list runtime errors reporting true queryimpl storageimpl arraylist runtimeerrorsreporting static date parse date string source parse position pos new parse position 0 date result synchronized date format result date format parse source pos if pos get index 0 throw new error parse error for date source at position pos get error index return result parsedate parseposition parseposition dateformat dateformat getindex geterrorindex final int scan int p pos int eol buf length char ch 0 int i while p eol character is whitespace ch buf p p 1 if p eol return tkn eof pos p switch ch case return tkn add case return tkn sub case return tkn mul case return tkn div case return tkn dot case return tkn comma case return tkn lpar case return tkn rpar case return tkn lbr case return tkn rbr case return tkn col case return tkn power case return tkn param case if p eol if buf p pos 1 return tkn le if buf p pos 1 return tkn ne return tkn lt case if p eol buf p pos 1 return tkn ge return tkn gt case return tkn eq case if p eol buf p throw new compile error invalid token p 1 pos 1 return tkn ne case if p eol buf p throw new compile error invalid token p 1 pos 1 return tkn add case i 0 while true if p eol throw new compile error unexpected end of string constant p if buf p if p eol buf p svalue new string str 0 i pos p return tkn sconst str i buf p case 0 case 1 case 2 case 3 case 4 case 5 case 6 case 7 case 8 case 9 i p 1 while p eol character is digit ch buf p p 1 if ch ch e ch e while p eol character is digit buf p buf p e buf p e buf p ch e ch e buf p buf p pos p try fvalue double value of query substring i p double value catch number format exception x throw new compile error bad floating point constant i return tkn fconst else pos p try ivalue long parse long query substring i p 10 catch number format exception x throw new compile error bad floating point constant i return tkn iconst default if character is letter ch ch ch i p 1 while p eol character is letter or digit ch buf p ch ch p 1 pos p ident query substring i p symbol s symbol symtab get ident return s null tkn ident s tkn else throw new compile error invalid symbol ch p 1 iswhitespace tkneof tknadd tknsub tknmul tkndiv tkndot tkncomma tknlpar tknrpar tknlbr tknrbr tkncol tknpower tknparam tknle tknne tknlt tknge tkngt tkneq compileerror tknne compileerror tknadd compileerror tknsconst isdigit isdigit valueof doublevalue numberformatexception compileerror tknfconst parselong numberformatexception compileerror tkniconst isletter _ isletterordigit _ tknident compileerror final node disjunction node left conjunction if lex tkn or int p pos node right disjunction if left type node tp int right type node tp int left new bin op node node tp int node op int or left right else if left type node tp bool right type node tp bool left new bin op node node tp bool node op bool or left right else if left type node tp any right type node tp any left new bin op node node tp any node op any or left right else throw new compile error bad operands for or operator p return left tknor tpint tpint binopnode tpint opintor tpbool tpbool binopnode tpbool opboolor tpany tpany binopnode tpany opanyor compileerror final node conjunction node left comparison if lex tkn and int p pos node right conjunction if left type node tp int right type node tp int left new bin op node node tp int node op int and left right else if left type node tp bool right type node tp bool left new bin op node node tp bool node op bool and left right else if left type node tp any right type node tp any left new bin op node node tp any node op any and left right else throw new compile error bad operands for and operator p return left tknand tpint tpint binopnode tpint opintand tpbool tpbool binopnode tpbool opbooland tpany tpany binopnode tpany opanyand compileerror final static node int2real node expr if expr tag node op int const return new real literal node double int literal node expr value return new unary op node node tp real node op int to real expr opintconst realliteralnode intliteralnode unaryopnode tpreal opinttoreal final static node str2date node expr if expr tag node op str const return new date literal node parse date str literal node expr value return new unary op node node tp date node op str to date expr opstrconst dateliteralnode parsedate strliteralnode unaryopnode tpdate opstrtodate final int compare node expr bin op node list int n 1 if list left null n compare expr bin op node list left node elem list right int cop node op nop if elem type node tp unknown elem type expr type if expr type node tp int if elem type node tp real expr new unary op node node tp real node op int to real expr cop node op real eq else if elem type node tp int cop node op int eq else if expr type node tp real if elem type node tp real cop node op real eq else if elem type node tp int cop node op real eq elem int2real elem else if expr type node tp date elem type node tp date cop node op date eq else if expr type node tp str elem type node tp str cop node op str eq else if expr type node tp obj elem type node tp obj cop node op obj eq else if expr type node tp bool elem type node tp bool cop node op bool eq else if expr type node tp any cop node op any eq if cop node op nop throw new compile error expression n in right part of in operator has incompatible type pos list type node tp bool if list left null list right new bin op node node tp bool cop expr elem list tag node op bool or else list left expr list right elem list tag cop return n binopnode binopnode opnop tpunknown tpint tpreal unaryopnode tpreal opinttoreal oprealeq tpint opinteq tpreal tpreal oprealeq tpint oprealeq tpdate tpdate opdateeq tpstr tpstr opstreq tpobj tpobj opobjeq tpbool tpbool opbooleq tpany opanyeq opnop compileerror tpbool binopnode tpbool opboolor final node comparison int left pos pos node left right left addition int cop lex if cop tkn eq cop tkn ne cop tkn gt cop tkn ge cop tkn le cop tkn lt cop tkn between cop tkn like cop tkn not cop tkn is cop tkn in int right pos pos boolean not false if cop tkn not not true cop scan if cop tkn like cop tkn between cop tkn in throw new compile error like between or in expected right pos right pos pos else if cop tkn is if left type node tp obj throw new compile error is not null predicate can be applied only to references arrays or string right pos right pos pos if cop scan tkn null left new unary op node node tp bool node op is null left else if cop tkn not right pos pos if scan tkn null left new unary op node node tp bool node op bool not new unary op node node tp bool node op is null left else throw new compile error null expected right pos else throw new compile error not null expected right pos lex scan return left right addition if cop tkn in int type if right type node tp list left type node tp any right type node tp any left new bin op node node tp bool node op in any left right else switch right type case node tp collection left new bin op node node tp bool node op scan collection left right break case node tp array bool if left type node tp bool throw new compile error incompatible types of in operator operands right pos left new bin op node node tp bool node op scan array bool left right break case node tp array int1 if left type node tp int throw new compile error incompatible types of in operator operands right pos left new bin op node node tp bool node op scan array int1 left right break case node tp array char if left type node tp int throw new compile error incompatible types of in operator operands right pos left new bin op node node tp bool node op scan array char left right break case node tp array int2 if left type node tp int throw new compile error incompatible types of in operator operands right pos left new bin op node node tp bool node op scan array int2 left right break case node tp array int4 if left type node tp int throw new compile error incompatible types of in operator operands right pos left new bin op node node tp bool node op scan array int4 left right break case node tp array int8 if left type node tp int throw new compile error incompatible types of in operator operands right pos left new bin op node node tp bool node op scan array int8 left right break case node tp array real4 if left type node tp int left int2real left else if left type node tp real throw new compile error incompatible types of in operator operands right pos left new bin op node node tp bool node op scan array real4 left right break case node tp array real8 if left type node tp int left int2real left else if left type node tp real throw new compile error incompatible types of in operator operands right pos left new bin op node node tp bool node op scan array real8 left right break case node tp array obj if left type node tp obj throw new compile error incompatible types of in operator operands right pos left new bin op node node tp bool node op scan array obj left right break case node tp array str if left type node tp str throw new compile error incompatible types of in operator operands right pos left new bin op node node tp bool node op scan array str left right break case node tp str if left type node tp str throw new compile error left operand of in expression hasn t string type left pos left new bin op node node tp bool node op in string left right break case node tp list compare left bin op node right left right break default throw new compile error list of expressions or array expected right pos else if cop tkn between int and pos pos if lex tkn and throw new compile error and expected pos node right2 addition if right type node tp unknown right type left type if right2 type node tp unknown right2 type left type if left type node tp any right type node tp any right2 type node tp any left new compare node node op any between left right right2 else if left type node tp real right type node tp real right2 type node tp real if left type node tp int left int2real left else if left type node tp real throw new compile error operand of between operator should be of integer real or string type left pos if right type node tp int right int2real right else if right type node tp real throw new compile error operand of between operator should be of integer real or string type right pos if right2 type node tp int right2 int2real right2 else if right2 type node tp real throw new compile error operand of between operator should be of integer real or string type leftpos tkneq tknne tkngt tknge tknle tknlt tknbetween tknlike tknnot tknis tknin rightpos tknnot tknlike tknbetween tknin compileerror rightpos rightpos tknis tpobj compileerror rightpos rightpos tknnull unaryopnode tpbool opisnull tknnot rightpos tknnull unaryopnode tpbool opboolnot unaryopnode tpbool opisnull compileerror rightpos compileerror rightpos tknin tplist tpany tpany binopnode tpbool opinany tpcollection binopnode tpbool opscancollection tparraybool tpbool compileerror rightpos binopnode tpbool opscanarraybool tparrayint1 tpint compileerror rightpos binopnode tpbool opscanarrayint1 tparraychar tpint compileerror rightpos binopnode tpbool opscanarraychar tparrayint2 tpint compileerror rightpos binopnode tpbool opscanarrayint2 tparrayint4 tpint compileerror rightpos binopnode tpbool opscanarrayint4 tparrayint8 tpint compileerror rightpos binopnode tpbool opscanarrayint8 tparrayreal4 tpint tpreal compileerror rightpos binopnode tpbool opscanarrayreal4 tparrayreal8 tpint tpreal compileerror rightpos binopnode tpbool opscanarrayreal8 tparrayobj tpobj compileerror rightpos binopnode tpbool opscanarrayobj tparraystr tpstr compileerror rightpos binopnode tpbool opscanarraystr tpstr tpstr compileerror leftpos binopnode tpbool opinstring tplist binopnode compileerror rightpos tknbetween andpos tknand compileerror tpunknown tpunknown tpany tpany tpany comparenode opanybetween tpreal tpreal tpreal tpint tpreal compileerror leftpos tpint tpreal compileerror rightpos tpint tpreal compileerror final node addition int left pos pos node left multiplication while lex tkn add lex tkn sub int cop lex int right pos pos node right multiplication if left type node tp any right type node tp any left new bin op node node tp any cop tkn add node op any add node op any sub left right else if left type node tp real right type node tp real if left type node tp int left int2real left else if left type node tp real throw new compile error operands of arithmetic operators should be of integer or real type left pos if right type node tp int right int2real right else if right type node tp real throw new compile error operands of arithmetic operator should be of integer or real type right pos left new bin op node node tp real cop tkn add node op real add node op real sub left right else if left type node tp int right type node tp int left new bin op node node tp int cop tkn add node op int add node op int sub left right else if left type node tp str right type node tp str if cop tkn add left new bin op node node tp str node op str concat left right else throw new compile error operation is not defined for strings right pos else throw new compile error operands of arithmentic operator should be of integer or real type right pos left pos right pos return left leftpos tknadd tknsub rightpos tpany tpany binopnode tpany tknadd opanyadd opanysub tpreal tpreal tpint tpreal compileerror leftpos tpint tpreal compileerror rightpos binopnode tpreal tknadd oprealadd oprealsub tpint tpint binopnode tpint tknadd opintadd opintsub tpstr tpstr tknadd binopnode tpstr opstrconcat compileerror rightpos compileerror rightpos leftpos rightpos final node multiplication int left pos pos node left power while lex tkn mul lex tkn div int cop lex int right pos pos node right power if left type node tp any right type node tp any left new bin op node node tp any cop tkn mul node op any mul node op any div left right else if left type node tp real right type node tp real if left type node tp int left int2real left else if left type node tp real throw new compile error operands of arithmetic operators should be of integer or real type left pos if right type node tp int right int2real right else if right type node tp real throw new compile error operands of arithmetic operator should be of integer or real type right pos left new bin op node node tp real cop tkn mul node op real mul node op real div left right else if left type node tp int right type node tp int left new bin op node node tp int cop tkn mul node op int mul node op int div left right else throw new compile error operands of arithmentic operator should be of integer or real type right pos left pos right pos return left leftpos tknmul tkndiv rightpos tpany tpany binopnode tpany tknmul opanymul opanydiv tpreal tpreal tpint tpreal compileerror leftpos tpint tpreal compileerror rightpos binopnode tpreal tknmul oprealmul oprealdiv tpint tpint binopnode tpint tknmul opintmul opintdiv compileerror rightpos leftpos rightpos final node power int left pos pos node left term if lex tkn power int right pos pos node right power if left type node tp any right type node tp any left new bin op node node tp any node op any pow left right else if left type node tp real right type node tp real if left type node tp int left int2real left else if left type node tp real throw new compile error operands of arithmetic operators should be of integer or real type left pos if right type node tp int right int2real right else if right type node tp real throw new compile error operands of arithmetic operator should be of integer or real type right pos left new bin op node node tp real node op real pow left right else if left type node tp int right type node tp int left new bin op node node tp int node op int pow left right else throw new compile error operands of arithmentic operator should be of integer or real type right pos return left leftpos tknpower rightpos tpany tpany binopnode tpany opanypow tpreal tpreal tpint tpreal compileerror leftpos tpint tpreal compileerror rightpos binopnode tpreal oprealpow tpint tpint binopnode tpint opintpow compileerror rightpos static method lookup method class cls string ident class profile method m null for class scope cls scope null scope scope get superclass try m scope get declared method ident profile break catch exception x if m null profile length 0 ident get character to upper case ident char at 0 ident substring 1 for class scope cls scope null scope scope get superclass try m scope get declared method ident profile break catch exception x if m null try m set accessible true catch exception x return m lookupmethod getsuperclass getdeclaredmethod touppercase charat getsuperclass getdeclaredmethod setaccessible final object resolve object obj if resolve map null resolve mapping rm resolve mapping resolve map get obj get class if rm null obj rm resolver resolve obj return obj resolvemap resolvemapping resolvemapping resolvemap getclass final node component node base class cls string c string ident this ident field f lex scan if lex tkn lpar if base null contains null f class descriptor locate field contains contains field class ident if f null return new element node contains contains expr get field name f else if cls null f class descriptor locate field cls ident if f null return new load node base f class profile default profile node arguments no arguments if lex tkn lpar array list argument list new array list do argument list add disjunction while lex tkn comma if lex tkn rpar throw new compile error expected pos lex scan profile new class argument list size arguments new node profile length boolean unknown profile false for int i 0 i profile length i node arg node argument list get i arguments i arg class arg type switch arg type case node tp int arg type long class break case node tp real arg type double class break case node tp str arg type string class break case node tp date arg type date class break case node tp bool arg type boolean class break case node tp obj arg type arg get type break case node tp array bool arg type boolean class break case node tp array char arg type char class break case node tp array int1 arg type byte class break case node tp array int2 arg type short class break case node tp array int4 arg type int class break case node tp array int8 arg type long class break case node tp array real4 arg type float class break case node tp array real8 arg type double class break case node tp array str arg type string class break case node tp array obj arg type object class break case node tp unknown case node tp any arg type object class unknown profile true break default throw new compile error invalid method argument type pos profile i arg type if unknown profile if cls equals object class base null contains null return new invoke any node base ident arguments null else return new invoke any node base ident arguments contains contains expr get field name method m null if base null contains null m lookup method contains contains field class ident profile if m null return new invoke element node m arguments contains contains expr get field name if arguments no arguments cls null f class descriptor locate field cls ident if f null return new load node base f if cls null m lookup method cls ident profile if m null return new invoke node base m arguments if object class equals cls return profile length 0 node new load any node base ident null node new invoke any node base ident arguments null else if base null contains null contains contains field class equals object class string arr field name contains contains expr get field name return profile length 0 node new load any node base ident arr field name node new invoke any node base ident arguments arr field name else throw new compile error no field or method ident in class cls null contains contains field class cls get name pos tknlpar classdescriptor locatefield containsfieldclass elementnode containsexpr getfieldname classdescriptor locatefield loadnode defaultprofile noarguments tknlpar arraylist argumentlist arraylist argumentlist tkncomma tknrpar compileerror argumentlist unknownprofile argumentlist argtype tpint argtype tpreal argtype tpstr argtype tpdate argtype tpbool argtype tpobj argtype gettype tparraybool argtype tparraychar argtype tparrayint1 argtype tparrayint2 argtype tparrayint4 argtype tparrayint8 argtype tparrayreal4 argtype tparrayreal8 argtype tparraystr argtype tparrayobj argtype tpunknown tpany argtype unknownprofile compileerror argtype unknownprofile invokeanynode invokeanynode containsexpr getfieldname lookupmethod containsfieldclass invokeelementnode containsexpr getfieldname noarguments classdescriptor locatefield loadnode lookupmethod invokenode loadanynode invokeanynode containsfieldclass arrfieldname containsexpr getfieldname loadanynode arrfieldname invokeanynode arrfieldname compileerror containsfieldclass getname final node field node expr int p pos int type int tag class cls expr get type while true if resolve map null expr type node tp obj cls null resolve mapping rm resolve mapping resolve map get cls if rm null expr new resolve node expr rm resolver rm resolved cls rm resolved switch lex case tkn dot if scan tkn ident throw new compile error identifier expected p if expr type node tp obj expr type node tp any expr type node tp collection throw new compile error left operand of should be reference p if contains null contains contains expr equals expr expr component null null else if expr type node tp collection throw new compile error left operand of should be reference p expr component expr cls cls expr get type continue case tkn lbr switch expr type case node tp array bool tag node op get at bool type node tp bool break case node tp array char tag node op get at char type node tp int break case node tp str tag node op str get at type node tp int break case node tp array int1 tag node op get at int1 type node tp int break case node tp array int2 tag node op get at int2 type node tp int break case node tp array int4 tag node op get at int4 type node tp int break case node tp array int8 tag node op get at int8 type node tp int break case node tp array real4 tag node op get at real4 type node tp real break case node tp array real8 tag node op get at real8 type node tp real break case node tp array str tag node op get at str type node tp str break case node tp array obj tag node op get at obj cls cls get component type type cls is array node tp array obj cls equals object class node tp any node tp obj break case node tp any tag node op get at obj type node tp any break default throw new compile error index can be applied only to arrays p p pos node index disjunction if lex tkn rbr throw new compile error expected pos if index type node tp any index new convert any node node tp int index else if index type node tp int index type node tp free var throw new compile error index should have integer type p expr new get at node type tag expr index lex scan continue default return expr gettype resolvemap tpobj resolvemapping resolvemapping resolvemap resolvenode tkndot tknident compileerror tpobj tpany tpcollection compileerror containsexpr tpcollection compileerror gettype tknlbr tparraybool opgetatbool tpbool tparraychar opgetatchar tpint tpstr opstrgetat tpint tparrayint1 opgetatint1 tpint tparrayint2 opgetatint2 tpint tparrayint4 opgetatint4 tpint tparrayint8 opgetatint8 tpint tparrayreal4 opgetatreal4 tpreal tparrayreal8 opgetatreal8 tpreal tparraystr opgetatstr tpstr tparrayobj opgetatobj getcomponenttype isarray tparrayobj tpany tpobj tpany opgetatobj tpany compileerror tknrbr compileerror tpany convertanynode tpint tpint tpfreevar compileerror getatnode final node contains element int p pos node contains expr term class arr class contains expr get type if arr class null arr class is array arr class equals object class collection class is assignable from arr class throw new compile error contains clause can be applied only to arrays or collections p class arr elem type arr class is array arr class get component type object class p pos node with condition null contains node outer contains contains contains node inner contains new contains node contains expr arr elem type contains inner contains if resolve map null resolve mapping rm resolve mapping resolve map get arr elem type if rm null inner contains resolver rm resolver arr elem type rm resolved if lex tkn with inner contains with expr check type node tp bool disjunction if lex tkn group p pos if scan tkn by throw new compile error group by expected p p pos if scan tkn ident throw new compile error group by field expected p if arr elem type equals object class inner contains group by field name ident else field group by field class descriptor locate field arr elem type ident if group by field null method group by method lookup method arr elem type ident default profile if group by method null throw new compile error field ident is not found p inner contains group by method group by method class rt group by method get return type if rt equals void class rt is primitive comparable class is assignable from rt throw new compile error result type rt of sort method should be comparable p else class type group by field get type if type is primitive comparable class is assignable from type throw new compile error order by field type type should be comparable p inner contains group by field group by field inner contains group by type node get field type type if scan tkn having throw new compile error having expected pos inner contains having expr check type node tp bool disjunction contains outer contains return inner contains containselement containsexpr arrclass containsexpr gettype arrclass arrclass isarray arrclass isassignablefrom arrclass compileerror arrelemtype arrclass isarray arrclass getcomponenttype withcondition containsnode outercontains containsnode innercontains containsnode containsexpr arrelemtype innercontains resolvemap resolvemapping resolvemapping resolvemap arrelemtype innercontains arrelemtype tknwith innercontains withexpr checktype tpbool tkngroup tknby compileerror tknident compileerror arrelemtype innercontains groupbyfieldname groupbyfield classdescriptor locatefield arrelemtype groupbyfield groupbymethod lookupmethod arrelemtype defaultprofile groupbymethod compileerror innercontains groupbymethod groupbymethod groupbymethod getreturntype isprimitive isassignablefrom compileerror groupbyfield gettype isprimitive isassignablefrom compileerror innercontains groupbyfield groupbyfield innercontains groupbytype getfieldtype tknhaving compileerror innercontains havingexpr checktype tpbool outercontains innercontains final node aggregate function int cop int p pos aggregate function node agr if contains null contains group by field null contains group by method null contains group by field name null throw new compile error aggregate function can be used only inside having clause p if cop tkn count if scan tkn lpar scan tkn mul scan tkn rpar throw new compile error count expected p lex scan agr new aggregate function node node tp int node op count null else node arg term if arg type node tp any arg new convert any node node tp real arg else if arg type node tp int arg type node tp real throw new compile error argument of aggregate function should have scalar type p agr new aggregate function node arg type cop node op avg tkn avg arg agr index contains aggregate functions size contains aggregate functions add agr return agr aggregatefunction aggregatefunctionnode groupbyfield groupbymethod groupbyfieldname compileerror tkncount tknlpar tknmul tknrpar compileerror aggregatefunctionnode tpint opcount tpany convertanynode tpreal tpint tpreal compileerror aggregatefunctionnode opavg tknavg aggregatefunctions aggregatefunctions final node check type int type node expr if expr type type if expr type node tp any expr new convert any node type expr else if expr type node tp unknown expr type type else throw new compile error node type names type expression expected pos return expr checktype tpany convertanynode tpunknown compileerror typenames final node term int cop scan int p pos node expr binding bp switch cop case tkn eof case tkn order lex cop return new empty node case tkn param expr new parameter node parameters break case tkn ident for bp bindings bp null bp bp next if bp name equals ident lex scan bp used true return new index node bp loop id expr component null cls return field expr case tkn contains return contains element case tkn exists if scan tkn ident throw new compile error free variable name expected p bindings bp new binding ident vars bindings if vars filter iterator max index vars throw new compile error too many nested exists clauses p p pos if scan tkn col throw new compile error expected p expr check type node tp bool term if bp used expr new exists node expr vars 1 vars 1 bindings bp next return expr case tkn current lex scan return field new current node cls case tkn false expr new constant node node tp bool node op false break case tkn true expr new constant node node tp bool node op true break case tkn null expr new constant node node tp obj node op null break case tkn iconst expr new int literal node ivalue break case tkn fconst expr new real literal node fvalue break case tkn sconst expr new str literal node svalue lex scan return field expr case tkn sum case tkn min case tkn max case tkn avg case tkn count return aggregate function cop case tkn sin case tkn cos case tkn tan case tkn asin case tkn acos case tkn atan case tkn exp case tkn log case tkn sqrt case tkn ceil case tkn floor expr term if expr type node tp int expr int2real expr else if expr type node tp any expr new convert any node node tp real expr else if expr type node tp real throw new compile error numeric argument expected p return new unary op node node tp real cop node op real sin tkn sin expr case tkn abs expr term if expr type node tp int return new unary op node node tp int node op int abs expr else if expr type node tp real return new unary op node node tp real node op real abs expr else if expr type node tp any return new unary op node node tp any node op any abs expr else throw new compile error abs function can be applied only to integer or real expression p case tkn length expr term if expr type node tp str return new unary op node node tp int node op str length expr else if expr type node tp any return new unary op node node tp int node op any length expr else if expr type node tp array bool return new unary op node node tp int node op length expr else throw new compile error length function is defined only for arrays and strings p case tkn lower return field new unary op node node tp str node op str lower check type node tp str term case tkn upper return field new unary op node node tp str node op str upper check type node tp str term case tkn integer return new unary op node node tp int node op real to int check type node tp real term case tkn real return new unary op node node tp int node op int to real check type node tp int term case tkn string expr term if expr type node tp int return field new unary op node node tp str node op int to str expr else if expr type node tp real return field new unary op node node tp str node op real to str expr else if expr type node tp date return field new unary op node node tp str node op date to str expr else if expr type node tp any return field new unary op node node tp str node op any to str expr throw new compile error string function can be applied only to integer or real expression p case tkn lpar expr disjunction node list null while lex tkn comma list new bin op node node tp list node op nop list expr expr disjunction if lex tkn rpar throw new compile error expected pos if list null expr new bin op node node tp list node op nop list expr break case tkn not expr comparison if expr type node tp int if expr tag node op int const int literal node ic int literal node expr ic value ic value else expr new unary op node node tp int node op int not expr return expr else if expr type node tp bool return new unary op node node tp bool node op bool not expr else if expr type node tp any return new unary op node node tp any node op any not expr else throw new compile error not operator can be applied only to integer or boolean expressions p case tkn add throw new compile error using of unary plus operator has no sense p case tkn sub expr term if expr type node tp int if expr tag node op int const int literal node ic int literal node expr ic value ic value else expr new unary op node node tp int node op int neg expr else if expr type node tp real if expr tag node op real const real literal node fc real literal node expr fc value fc value else expr new unary op node node tp real node op real neg expr else if expr type node tp any expr new unary op node node tp any node op any neg expr else throw new compile error unary minus can be applied only to numeric expressions p return expr default throw new compile error operand expected p lex scan return expr tkneof tknorder emptynode tknparam parameternode tknident indexnode loopid tkncontains containselement tknexists tknident compileerror filteriterator maxindexvars compileerror tkncol compileerror checktype tpbool existsnode tkncurrent currentnode tknfalse constantnode tpbool opfalse tkntrue constantnode tpbool optrue tknnull constantnode tpobj opnull tkniconst intliteralnode tknfconst realliteralnode tknsconst strliteralnode tknsum tknmin tknmax tknavg tkncount aggregatefunction tknsin tkncos tkntan tknasin tknacos tknatan tknexp tknlog tknsqrt tknceil tknfloor tpint tpany convertanynode tpreal tpreal compileerror unaryopnode tpreal oprealsin tknsin tknabs tpint unaryopnode tpint opintabs tpreal unaryopnode tpreal oprealabs tpany unaryopnode tpany opanyabs compileerror tknlength tpstr unaryopnode tpint opstrlength tpany unaryopnode tpint opanylength tparraybool unaryopnode tpint oplength compileerror tknlower unaryopnode tpstr opstrlower checktype tpstr tknupper unaryopnode tpstr opstrupper checktype tpstr tkninteger unaryopnode tpint oprealtoint checktype tpreal tknreal unaryopnode tpint opinttoreal checktype tpint tknstring tpint unaryopnode tpstr opinttostr tpreal unaryopnode tpstr oprealtostr tpdate unaryopnode tpstr opdatetostr tpany unaryopnode tpstr opanytostr compileerror tknlpar tkncomma binopnode tplist opnop tknrpar compileerror binopnode tplist opnop tknnot tpint opintconst intliteralnode intliteralnode unaryopnode tpint opintnot tpbool unaryopnode tpbool opboolnot tpany unaryopnode tpany opanynot compileerror tknadd compileerror tknsub tpint opintconst intliteralnode intliteralnode unaryopnode tpint opintneg tpreal oprealconst realliteralnode realliteralnode unaryopnode tpreal oprealneg tpany unaryopnode tpany opanyneg compileerror compileerror final iterable iterator t filter iterable iterator iterator node condition return new filter iterator t this iterator condition iterableiterator iterableiterator filteriterator final iterable iterator t apply index node condition node filter condition null node expr condition iterator result if expr tag node op bool and filter condition bin op node expr right expr bin op node expr left if expr tag node op contains contains node contains contains node expr if contains with expr null return null if contains having expr null filter condition condition expr contains with expr if expr instanceof bin op node bin op node cmp bin op node expr string key cmp left get field name if key null cmp right instanceof literal node generic index index get index key if index null return null switch expr tag case node op any eq case node op int eq case node op real eq case node op str eq case node op date eq case node op bool eq key value key literal index get key type cmp right true if value null return filter index iterator value value index ascent order filter condition return null case node op int gt case node op real gt case node op str gt case node op date gt case node op any gt key value key literal index get key type cmp right false if value null return filter index iterator value null index ascent order filter condition return null case node op int ge case node op real ge case node op str ge case node op date ge case node op any ge key value key literal index get key type cmp right true if value null return filter index iterator value null index ascent order filter condition return null case node op int lt case node op real lt case node op str lt case node op date lt case node op any lt key value key literal index get key type cmp right false if value null return filter index iterator null value index ascent order filter condition return null case node op int le case node op real le case node op str le case node op date le case node op any le key value key literal index get key type cmp right true if value null return filter index iterator null value index ascent order filter condition return null else if expr instanceof compare node compare node cmp compare node expr string key cmp o1 get field name if key null cmp o2 instanceof literal node cmp o3 null cmp o3 instanceof literal node generic index index get index key if index null return null switch expr tag case node op int between case node op str between case node op real between case node op date between case node op any between key value1 key literal index get key type cmp o2 true key value2 key literal index get key type cmp o3 true if value1 null value2 null return filter index iterator value1 value2 index ascent order filter condition return null case node op str like case node op str like esc string pattern string literal node cmp o2 get value char escape cmp o3 null string literal node cmp o3 get value char at 0 int pref 0 while pref pattern length char ch pattern char at pref if ch ch break else if ch escape pref 2 else pref 1 if pref 0 if pref pattern length key value new key pattern return filter index iterator value value index ascent order filter condition else if filter condition null return filter index prefix iterator pattern substring 0 pref condition return null iterableiterator applyindex filtercondition opbooland filtercondition binopnode binopnode opcontains containsnode containsnode withexpr havingexpr filtercondition withexpr binopnode binopnode binopnode getfieldname literalnode genericindex getindex opanyeq opinteq oprealeq opstreq opdateeq opbooleq keyliteral getkeytype ascent_order filtercondition opintgt oprealgt opstrgt opdategt opanygt keyliteral getkeytype ascent_order filtercondition opintge oprealge opstrge opdatege opanyge keyliteral getkeytype ascent_order filtercondition opintlt opreallt opstrlt opdatelt opanylt keyliteral getkeytype ascent_order filtercondition opintle oprealle opstrle opdatele opanyle keyliteral getkeytype ascent_order filtercondition comparenode comparenode comparenode getfieldname literalnode literalnode genericindex getindex opintbetween opstrbetween oprealbetween opdatebetween opanybetween keyliteral getkeytype keyliteral getkeytype ascent_order filtercondition opstrlike opstrlikeesc literalnode getvalue literalnode getvalue charat charat _ ascent_order filtercondition filtercondition prefixiterator final void compile pos 0 vars 0 tree check type node tp bool disjunction order node last null order null if lex tkn eof return if lex tkn order throw new compile error order by expected pos int tkn int p pos if scan tkn by throw new compile error by expected after order p do p pos if scan tkn ident throw new compile error field name expected p order node node field f class descriptor locate field cls ident if f null method m lookup method cls ident default profile if m null if cls equals object class throw new compile error no field ident in class cls get name p node new order node ident else node new order node m else node new order node class descriptor get type code f get type f if last null last next node else order node last node p pos tkn scan if tkn tkn desc node ascent false tkn scan else if tkn tkn asc tkn scan while tkn tkn comma if tkn tkn eof throw new compile error expected p checktype tpbool ordernode tkneof tknorder compileerror tknby compileerror tknident compileerror ordernode classdescriptor locatefield lookupmethod defaultprofile compileerror getname ordernode ordernode ordernode classdescriptor gettypecode gettype tkndesc tknasc tkncomma tkneof compileerror public class storage factory create new instance of the storage return new instance of the storage unopened you should explicitely invoke open method public storage create storage return new storage impl storagefactory createstorage storageimpl create new instance of the master node of replicated storage there are two kinds of replication slave nodes statically defined and dynamically added first one are specified by replication slave nodes parameter when replication master is started it tries to eastablish connection with all of the specified nodes it is expected that state of each such node is synchronized with state of the master node it is not possible to add or remove static replication slave node without stopping master node dynamic slave nodes can be added at any moment of time replication master will send to such node complete snapshot of the database param port socket port at which replication master will listen for dynamic slave nodes connections if this parameter is 1 then no dynamic slave node conenctions are accepted param replication slave nodes addresses of static replicatin slave nodes i e hosts to which replication will be performed address is specified as name port param async buf size if value of this parameter is greater than zero then replication will be asynchronous done by separate thread and not blocking main application otherwise data is send to the slave nodes by the same thread which updates the database if space asynchronous buffer is exhausted then main thread will be also blocked until the data is send return new instance of the master storage unopened you should explicitely invoke open method public replication master storage create replication master storage int port string replication slave nodes int async buf size return new replication master storage impl port replication slave nodes async buf size replicationslavenodes replicationslavenodes asyncbufsize replicationmasterstorage createreplicationmasterstorage replicationslavenodes asyncbufsize replicationmasterstorageimpl replicationslavenodes asyncbufsize create new instance of the static slave node of replicated storage the address of this host should be sepecified in the replication slave nodes parameter of create replication master storage method when replication master is started it tries to eastablish connection with all of the specified nodes param slave port socket port at which connection from master will be established return new instance of the slave storage unopened you should explicitely invoke open method public replication slave storage create replication slave storage int slave port return new replication static slave storage impl slave port replicationslavenodes createreplicationmasterstorage slaveport replicationslavestorage createreplicationslavestorage slaveport replicationstaticslavestorageimpl slaveport add new instance of the dynamic slave node of replicated storage param replication master node name of the host where replication master is running param master port replication master socket port to which connection should be established return new instance of the slave storage unopened you should explicitely invoke open method public replication slave storage add replication slave storage string replication master node int master port return new replication dynamic slave storage impl replication master node master port replicationmasternode masterport replicationslavestorage addreplicationslavestorage replicationmasternode masterport replicationdynamicslavestorageimpl replicationmasternode masterport get instance of storage factory so new storages should be create in application in the following way code storage factory get instance create storage code return instance of the storage factory public static storage factory get instance return instance storagefactory getinstance createstorage storagefactory getinstance public modify peer simple field set fs this fs fs this identifier fs get identifier fs remove value identifier modifypeer simplefieldset removevalue override public simple field set get field set return new simple field set true simplefieldset getfieldset simplefieldset override public string get name return name getname override public void run fcp connection handler handler node node throws message invalid exception if handler has full access throw new message invalid exception protocol error message access denied modify peer requires full access identifier false string node identifier fs get node identifier if node identifier null throw new message invalid exception protocol error message missing field error node identifier field missing identifier false peer node pn node get peer node node identifier if pn null fcp message msg new unknown node identifier message node identifier identifier handler output handler queue msg return if pn instanceof darknet peer node throw new message invalid exception protocol error message darknet only modify peer only available for darknet peers identifier false darknet peer node dpn darknet peer node pn string is disabled string fs get is disabled if is disabled string null if is disabled string equals if fields string to bool is disabled string false dpn disable peer else dpn enable peer string is listen only string fs get is listen only if is listen only string null if is listen only string equals dpn set listen only fields string to bool is listen only string false string is burst only string fs get is burst only if is burst only string null if is burst only string equals dpn set burst only fields string to bool is burst only string false string ignore source port string fs get ignore source port if ignore source port string null if ignore source port string equals dpn set ignore source port fields string to bool ignore source port string false string allow local addresses string fs get allow local addresses if allow local addresses string null if allow local addresses string equals dpn set allow local addresses fields string to bool allow local addresses string false handler output handler queue new peer message pn true true identifier fcpconnectionhandler messageinvalidexception hasfullaccess messageinvalidexception protocolerrormessage access_denied modifypeer nodeidentifier nodeidentifier nodeidentifier messageinvalidexception protocolerrormessage missing_field nodeidentifier peernode getpeernode nodeidentifier fcpmessage unknownnodeidentifiermessage nodeidentifier outputhandler darknetpeernode messageinvalidexception protocolerrormessage darknet_only modifypeer darknetpeernode darknetpeernode isdisabledstring isdisabled isdisabledstring isdisabledstring stringtobool isdisabledstring disablepeer enablepeer islistenonlystring islistenonly islistenonlystring islistenonlystring setlistenonly stringtobool islistenonlystring isburstonlystring isburstonly isburstonlystring isburstonlystring setburstonly stringtobool isburstonlystring ignoresourceportstring ignoresourceport ignoresourceportstring ignoresourceportstring setignoresourceport stringtobool ignoresourceportstring allowlocaladdressesstring allowlocaladdresses allowlocaladdressesstring allowlocaladdressesstring setallowlocaladdresses stringtobool allowlocaladdressesstring outputhandler peermessage override public void remove from object container container throw new unsupported operation exception removefrom objectcontainer unsupportedoperationexception query node visitor it provides convenient way of iterating through query nodes public void visit full text query visitor visitor visitor visit this fulltextqueryvisitor this method checks that query can be executed by interection of keyword occurrences lists return true if quuery can be executed by full text index false otherwise public boolean is constrained return false fulltextindex isconstrained query node constructor param op operation code public full text query int op this op op fulltextquery it won t reset the message digest for you param input stream param message digest return throws io exception public static void hash input stream is message digest md throws io exception try byte buf new byte 4096 int read bytes is read buf while read bytes 1 md update buf 0 read bytes read bytes is read buf is close finally closer close is inputstream messagedigest ioexception inputstream messagedigest ioexception readbytes readbytes readbytes readbytes create a new sha 256 message digest either succeed or stop the node public synchronized static message digest get message digest try if digests is empty return digests remove digests size 1 return message digest get instance sha 256 catch no such algorithm exception e2 todo maybe we should point to a howto for freejvms logger error node class check your jvm settings especially the jce e2 system err println check your jvm settings especially the jce e2 e2 print stack trace wrapper manager stop node init exception exit crappy jvm throw new runtime exception messagedigest messagedigest getmessagedigest isempty messagedigest getinstance nosuchalgorithmexception printstacktrace wrappermanager nodeinitexception exit_crappy_jvm runtimeexception return a message digest to the pool must be sha 256 public synchronized static void return message digest message digest md256 if md256 null return string algo md256 get algorithm if algo equals sha 256 algo equals sha256 throw new illegal argument exception should be sha 256 but is algo if digests size 16 no cache don t cache too many of them return md256 reset digests add md256 messagedigest returnmessagedigest messagedigest getalgorithm illegalargumentexception nocache public static byte digest byte data message digest md get message digest byte hash md digest data return message digest md return hash messagedigest getmessagedigest returnmessagedigest public static int get digest length return hash size getdigestlength hash_size static oom handler addoom hook new oom hook public void handle low memory throws exception digests clear no cache true oomhandler addoomhook oomhook handlelowmemory nocache public void handle out of memory throws exception digests clear no cache true handleoutofmemory nocache override public void should update logminor logger should log logger minor this logdebug logger should log logger debug this shouldupdate shouldlog shouldlog public base file bucket file file boolean delete on exit if file null throw new null pointer exception this length file length if delete on exit set delete on exit file basefilebucket deleteonexit nullpointerexception deleteonexit setdeleteonexit protected void set delete on exit file file try file delete on exit catch null pointer exception e if wrapper manager has shutdown hook been triggered logger normal this null pointer exception setting delete on exit while shutting down buggy jvm code e e else logger error this caught e doing delete on exit for file jvm bug setdeleteonexit deleteonexit nullpointerexception wrappermanager hasshutdownhookbeentriggered nullpointerexception deleteonexit deleteonexit public output stream get output stream throws io exception synchronized this file file get file if freed throw new io exception file already freed this if is read only throw new io exception bucket is read only this if create file only file exists throw new file exists exception file if streams null streams is empty logger error this streams open on this while opening an output stream streams new exception debug file tempfile create file only get tempfile file long stream number file restart counter file bucket output stream os new file bucket output stream tempfile stream number if logdebug logger debug this creating os new exception debug add stream os return os outputstream getoutputstream ioexception getfile ioexception isreadonly ioexception createfileonly fileexistsexception isempty createfileonly gettempfile streamnumber filerestartcounter filebucketoutputstream filebucketoutputstream streamnumber addstream private synchronized void add stream object stream base file bucket is a very common object and often very long lived so we need to minimize memory usage even at the cost of frequent allocations if streams null streams new vector object 1 1 streams add stream addstream basefilebucket private synchronized void remove stream object stream race condition is possible if streams null return streams remove stream if streams is empty streams null removestream isempty protected abstract boolean create file only createfileonly protected abstract boolean create file only protected abstract boolean delete on exit createfileonly deleteonexit protected abstract boolean delete on exit protected abstract boolean delete on finalize deleteonexit deleteonfinalize protected abstract boolean delete on finalize protected abstract boolean delete on free deleteonfinalize deleteonfree create a temporary file in the same directory as this file protected file get tempfile throws io exception file file get file file f file create temp file file get name freenet tmp file get parent file if delete on exit f delete on exit return f gettempfile ioexception getfile createtempfile getname getparentfile deleteonexit deleteonexit protected synchronized void reset length length 0 resetlength protected file bucket output stream file tempfile long restart count throws file not found exception super tempfile false if logminor logger minor this writing to tempfile for get file this this tempfile tempfile reset length this restart count restart count closed false filebucketoutputstream restartcount filenotfoundexception getfile resetlength restartcount restartcount protected void confirm write synchronized throws io exception synchronized base file bucket this if file restart counter restart count throw new illegal state exception writing to file after restart if freed throw new io exception writing to file after it has been freed if is read only throw new io exception file is read only confirmwritesynchronized ioexception basefilebucket filerestartcounter restartcount illegalstateexception ioexception isreadonly ioexception override public void write byte b throws io exception synchronized base file bucket this confirm write synchronized super write b length b length ioexception basefilebucket confirmwritesynchronized override public void write byte b int off int len throws io exception synchronized base file bucket this confirm write synchronized super write b off len length len ioexception basefilebucket confirmwritesynchronized override public void write int b throws io exception synchronized base file bucket this confirm write synchronized super write b length ioexception basefilebucket confirmwritesynchronized override public void close throws io exception file file synchronized this if closed return closed true file get file remove stream this if logminor logger minor this closing base file bucket this try super close catch io exception e if logminor logger minor this failed closing base file bucket this e e if create file only tempfile delete throw e if create file only if file exists if logminor logger minor this file exists creating file for this tempfile delete throw new file exists exception file if tempfile rename to file if logminor logger minor this cannot rename file for this if file exists throw new file exists exception file tempfile delete if logminor logger minor this deleted cannot rename file for this throw new io exception cannot rename file ioexception getfile removestream basefilebucket ioexception basefilebucket createfileonly createfileonly fileexistsexception renameto fileexistsexception ioexception override public string to string return super to string base file bucket this to string tostring tostring basefilebucket tostring boolean closed public file bucket input stream file f throws io exception super f filebucketinputstream ioexception override public void close throws io exception synchronized this if closed return closed true remove stream this super close ioexception removestream override public string to string return super to string base file bucket this to string tostring tostring basefilebucket tostring public synchronized input stream get input stream throws io exception if freed throw new io exception file already freed this file file get file if file exists logger normal this file does not exist file for this return new null input stream else file bucket input stream is new file bucket input stream file add stream is if logdebug logger debug this creating is new exception debug return is inputstream getinputstream ioexception ioexception getfile nullinputstream filebucketinputstream filebucketinputstream addstream return the name of the file public synchronized string get name return get file get name getname getfile getname public synchronized long size return length actually delete the underlying file called by finalizer will not be called twice but length must still be valid when calling it protected synchronized void delete file if logminor logger minor this deleting get file for this new exception debug get file delete deletefile getfile getfile override protected void finalize if delete on finalize free true deleteonfinalize return directory used for temp files public final synchronized static string get temp dir return temp dir fixme todo locking on temp dir needs to be checked by a java guru for consistency gettempdir tempdir tempdir set temp file directory p the directory must exist public final synchronized static void set temp dir string dir name file dir new file dir name if dir exists dir is directory dir can write throw new illegal argument exception bad temp directory dir get absolute path temp dir dir name fixme todo locking on temp dir needs to be checked by a java guru for consistency settempdir dirname dirname isdirectory canwrite illegalargumentexception getabsolutepath tempdir dirname tempdir public synchronized bucket split int split size if length long integer max value split size throw new illegal argument exception way too big length for split size int bucket count int length split size if length split size 0 bucket count bucket buckets new bucket bucket count file file get file for int i 0 i buckets length i long start at 1l i split size long end at math min start at split size 1l length long len end at start at buckets i new read only file slice bucket file start at len return buckets splitsize max_value splitsize illegalargumentexception splitsize bucketcount splitsize splitsize bucketcount bucketcount getfile startat splitsize endat startat splitsize endat startat readonlyfileslicebucket startat public void free free false public void free boolean force free object to close if logminor logger minor this freeing this new exception debug synchronized this if freed return freed true to close streams null null streams to array streams null if to close null logger error this streams open free ing this arrays to string to close new exception debug for int i 0 i to close length i try if to close i instanceof file bucket output stream file bucket output stream to close i close else file bucket input stream to close i close catch io exception e logger error this caught closing stream in free e e catch throwable t logger error this caught closing stream in free t t file file get file if delete on free force free file exists logger debug this deleting bucket file get name new exception debug delete file if file exists logger error this delete failed on bucket file get name forcefree toclose toclose toarray toclose tostring toclose toclose toclose filebucketoutputstream filebucketoutputstream toclose filebucketinputstream toclose ioexception getfile deleteonfree forcefree getname deletefile getname override public synchronized string to string string buffer sb new string buffer sb append super to string sb append sb append get file get path sb append streams sb append streams null 0 streams size return sb to string tostring stringbuffer stringbuffer tostring getfile getpath tostring returns the file object this buckets data is kept in public abstract file get file getfile public synchronized simple field set to field set if delete on finalize return null simple field set fs new simple field set false fs put single type file bucket fs put single filename get file to string fs put length size return fs simplefieldset tofieldset deleteonfinalize simplefieldset simplefieldset putsingle filebucket putsingle getfile tostring public static bucket create simple field set fs persistent file tracker f throws cannot create from field set exception string tmp fs get filename if tmp null throw new cannot create from field set exception no filename file file file util get canonical file new file tmp if f matches file return persistent temp file bucket create fs f tmp fs get length if tmp null throw new cannot create from field set exception no length try long length fields parse long tmp 1 if length file length throw new cannot create from field set exception invalid length should be length actually file length on file catch number format exception e throw new cannot create from field set exception corrupt length tmp e file bucket bucket new file bucket file false true false false false if file exists no point otherwise f register file return bucket simplefieldset persistentfiletracker cannotcreatefromfieldsetexception cannotcreatefromfieldsetexception fileutil getcanonicalfile persistenttempfilebucket cannotcreatefromfieldsetexception parselong cannotcreatefromfieldsetexception numberformatexception cannotcreatefromfieldsetexception filebucket filebucket archive store context freeneturi key archive manager archive type archive type this key key this archive type archive type my items new doubly linked list impl archive store item archivestorecontext archivemanager archive_type archivetype archivetype archivetype myitems doublylinkedlistimpl archivestoreitem returns the size of the archive last time we fetched it or 1 long get last size return last size getlastsize lastsize sets the size of the archive see get last size void set last size long size last size size getlastsize setlastsize lastsize returns the hash of the archive last time we fetched it or null byte get last hash return last hash getlasthash lasthash sets the hash of the archive see get last hash void set last hash byte real hash last hash real hash getlasthash setlasthash realhash lasthash realhash remove all archive store items with this key from the cache void remove all cached items archive manager manager archive store item item null while true synchronized my items remove cached item will call remove item so don t remove it here item my items head if item null break manager remove cached item item archivestoreitems removeallcacheditems archivemanager archivestoreitem myitems removecacheditem removeitem myitems removecacheditem notify that a new archive store item with this key has been added to the cache void add item archive store item item synchronized my items my items push item additem archivestoreitem myitems myitems notify that an archive store item with this key has been expelled from the cache remove it from our local cache and ask it to free the bucket if necessary void remove item archive store item item synchronized my items if my items remove item null if logger should log logger minor this logger minor this not removing item for this already removed return only removed once item inner close removeitem archivestoreitem myitems myitems shouldlog innerclose public short get archive type return archive type metadataid getarchivetype archivetype public freeneturi get key return key getkey client request scheduler non persistent client request scheduler sched boolean for inserts boolean forss ks super for inserts forss ks this sched sched if for inserts recent successes new linked list base sendable get else recent successes null logminor logger should log logger minor this clientrequestschedulernonpersistent clientrequestscheduler forinserts forssks forinserts forssks forinserts recentsuccesses linkedlist basesendableget recentsuccesses shouldlog override boolean persistent return false object container container return null objectcontainer override public void succeeded base sendable get succeeded object container container do nothing fixme keep a list of recently succeeded client requester s if is insert scheduler return if persistent container activate succeeded 1 if succeeded is empty container return if logminor logger minor this recording successful fetch from succeeded recent successes add succeeded while recent successes size 8 recent successes remove 0 basesendableget objectcontainer clientrequester isinsertscheduler isempty recentsuccesses recentsuccesses recentsuccesses public boolean object can new object container container logger error this not storing client request scheduler non persistent in database new exception error return false objectcannew objectcontainer clientrequestschedulernonpersistent private static string ipv6 address public static final void seti pv6 address string addr ipv6 address addr ipv6_address setipv6address ipv6_address public static final string geti pv6 address return ipv6 address getipv6address ipv6_address public final static int get lease time string cache cont int equ idx cache cont index of int mx 0 try string mx str new string cache cont get bytes equ idx 1 cache cont length equ idx 1 mx integer parse int mx str catch exception e return mx getleasetime cachecont equidx cachecont indexof mxstr cachecont getbytes equidx cachecont equidx parseint mxstr public static boolean enabled false public static final void on enabled true enabled true public static final void off enabled false enabled false public static boolean is on return enabled ison return enabled public static final void message string s if enabled true system out println cyber garage message s cybergarage public static final void message string m1 string m2 if enabled true system out println cyber garage message system out println m1 system out println m2 cybergarage system out println m2 public static final void warning string s system out println cyber garage warning s cybergarage system out println cyber garage warning s public static final void warning string m exception e system out println cyber garage warning m e get message cybergarage cybergarage getmessage system out println cyber garage warning m e get message public static final void warning exception e warning e get message e print stack trace cybergarage getmessage getmessage printstacktrace static final int sizeof object header sizeof 4 4 1 btree objectheader static int check type class c int elem type class descriptor get type code c if elem type class descriptor tp object elem type class descriptor tp enum elem type class descriptor tp array of byte throw new storage error storage error unsupported index type c return elem type checktype elemtype classdescriptor gettypecode elemtype classdescriptor tpobject elemtype classdescriptor tpenum elemtype classdescriptor tparrayofbyte storageerror storageerror unsupported_index_type elemtype int compare byte arrays byte key byte item int offs int length int n key length length length key length for int i 0 i n i int diff key i item i offs if diff 0 return diff return key length length comparebytearrays btree class cls boolean unique this unique unique type check type cls checktype btree int type boolean unique this type type this unique unique btree byte obj int offs height bytes unpack4 obj offs offs 4 n elems bytes unpack4 obj offs offs 4 root bytes unpack4 obj offs offs 4 type bytes unpack4 obj offs offs 4 unique obj offs 0 nelems static final int op overwrite 5 public class get key types return new class get key type op_overwrite getkeytypes getkeytype public class get key type return map key type type getkeytype mapkeytype static class map key type int type switch type case class descriptor tp boolean return boolean class case class descriptor tp byte return byte class case class descriptor tp char return char class case class descriptor tp short return short class case class descriptor tp int return int class case class descriptor tp long return long class case class descriptor tp float return float class case class descriptor tp double return double class case class descriptor tp enum return enum class case class descriptor tp string return string class case class descriptor tp date return date class case class descriptor tp object return i persistent class case class descriptor tp array of byte return byte class default return comparable class mapkeytype classdescriptor tpboolean classdescriptor tpbyte classdescriptor tpchar classdescriptor tpshort classdescriptor tpint classdescriptor tplong classdescriptor tpfloat classdescriptor tpdouble classdescriptor tpenum classdescriptor tpstring classdescriptor tpdate classdescriptor tpobject ipersistent classdescriptor tparrayofbyte key check key key key if key null if key type type throw new storage error storage error incompatible key type if type class descriptor tp object key ival 0 key oval null i persistent obj i persistent key oval get storage make persistent obj key new key obj key inclusion 0 if key oval instanceof string key new key string key oval to char array key inclusion 0 return key checkkey storageerror storageerror incompatible_key_type classdescriptor tpobject ipersistent ipersistent getstorage makepersistent tochararray public t get key key key check key key if root 0 array list list new array list btree page find storage impl get storage root key key this height list if list size 1 throw new storage error storage error key not unique else if list size 0 return null else return t list get 0 return null checkkey arraylist arraylist btreepage storageimpl getstorage storageerror storageerror key_not_unique public array list t prefix search list string key if class descriptor tp string type throw new storage error storage error incompatible key type array list t list new array list t if root 0 btree page prefix search storage impl get storage root key to char array height list return list arraylist prefixsearchlist classdescriptor tpstring storageerror storageerror incompatible_key_type arraylist arraylist btreepage prefixsearch storageimpl getstorage tochararray public i persistent prefix search string key array list t list prefix search list key return i persistent list to array new i persistent list size ipersistent prefixsearch arraylist prefixsearchlist ipersistent toarray ipersistent public array list t get list key from key till array list t list new array list t if root 0 btree page find storage impl get storage root check key from check key till this height list return list arraylist getlist arraylist arraylist btreepage storageimpl getstorage checkkey checkkey public array list t get list object from object till return get list get key from object from get key from object till arraylist getlist getlist getkeyfromobject getkeyfromobject public t get object key return get get key from object key getkeyfromobject public i persistent get key from key till array list t list get list from till return i persistent list to array new i persistent list size ipersistent arraylist getlist ipersistent toarray ipersistent public i persistent get object from object till return get get key from object from get key from object till ipersistent getkeyfromobject getkeyfromobject public boolean put key key t obj return insert key obj false 0 public t set key key t obj int oid insert key obj true return t oid 0 storage impl get storage lookup object oid null null storageimpl getstorage lookupobject final int insert key key t obj boolean overwrite storage impl db storage impl get storage if db null throw new storage error storage error deleted object key check key key if obj is persistent db make persistent obj btree key ins new btree key key obj get oid if root 0 root btree page allocate db 0 type ins height 1 else int result btree page insert db root this ins height unique overwrite if result op overflow root btree page allocate db root type ins height 1 else if result op duplicate return 1 else if result op overwrite return ins old oid update counter 1 n elems 1 modify return 0 storageimpl storageimpl getstorage storageerror storageerror deleted_object checkkey ispersistent makepersistent btreekey btreekey getoid btreepage btreepage op_overflow btreepage op_duplicate op_overwrite oldoid updatecounter nelems public void remove key key t obj remove new btree key check key key obj get oid btreekey checkkey getoid void remove btree key rem if remove if exists rem throw new storage error storage error key not found btreekey removeifexists storageerror storageerror key_not_found boolean remove if exists btree key rem storage impl db storage impl get storage if db null throw new storage error storage error deleted object if root 0 return false int result btree page remove db root this rem height if result op not found return false n elems 1 if result op underflow page pg db get page root if btree page getn items pg 0 int new root 0 if height 1 new root type class descriptor tp string type class descriptor tp array of byte btree page get key str oid pg 0 btree page get reference pg btree page max items 1 db free page root root new root height 1 db pool unfix pg else if result op overflow root btree page allocate db root type rem height 1 update counter 1 modify return true removeifexists btreekey storageimpl storageimpl getstorage storageerror storageerror deleted_object btreepage op_not_found nelems op_underflow getpage btreepage getnitems newroot newroot classdescriptor tpstring classdescriptor tparrayofbyte btreepage getkeystroid btreepage getreference btreepage maxitems freepage newroot op_overflow btreepage updatecounter public t remove key key if unique throw new storage error storage error key not unique btree key rk new btree key check key key 0 storage impl db storage impl get storage remove rk return t db lookup object rk old oid null storageerror storageerror key_not_unique btreekey btreekey checkkey storageimpl storageimpl getstorage lookupobject oldoid static key get key from object object o if o null return null else if o instanceof byte return new key byte o byte value else if o instanceof short return new key short o short value else if o instanceof integer return new key integer o int value else if o instanceof long return new key long o long value else if o instanceof float return new key float o float value else if o instanceof double return new key double o double value else if o instanceof boolean return new key boolean o boolean value else if o instanceof character return new key character o char value else if o instanceof string return new key string o else if o instanceof java util date return new key java util date o else if o instanceof byte return new key byte o else if o instanceof object return new key object o else if o instanceof enum return new key enum o else if o instanceof i persistent return new key i persistent o else if o instanceof comparable return new key comparable o throw new storage error storage error unsupported type getkeyfromobject bytevalue shortvalue intvalue longvalue floatvalue doublevalue booleanvalue charvalue ipersistent ipersistent storageerror storageerror unsupported_type public array list t get prefix list string prefix return get list new key prefix to char array true new key prefix character max value to char array false arraylist getprefixlist getlist tochararray max_value tochararray public i persistent get prefix string prefix return get new key prefix to char array true new key prefix character max value to char array false ipersistent getprefix tochararray max_value tochararray public boolean put object key t obj return put get key from object key obj getkeyfromobject public t set object key t obj return set get key from object key obj getkeyfromobject public void remove object key t obj remove get key from object key obj getkeyfromobject public t remove key object key return remove get key from object key removekey getkeyfromobject public t remove string key return remove new key key public int size return n elems nelems public void clear if root 0 btree page purge storage impl get storage root type height root 0 n elems 0 height 0 update counter 1 modify btreepage storageimpl getstorage nelems updatecounter public i persistent to persistent array i persistent arr new i persistent n elems if root 0 btree page traverse forward storage impl get storage root type height arr 0 return arr ipersistent topersistentarray ipersistent ipersistent nelems btreepage traverseforward storageimpl getstorage public object to array return to persistent array toarray topersistentarray public e e to array e arr if arr length n elems arr e array new instance arr get class get component type n elems if root 0 btree page traverse forward storage impl get storage root type height i persistent arr 0 if arr length n elems arr n elems null return arr toarray nelems newinstance getclass getcomponenttype nelems btreepage traverseforward storageimpl getstorage ipersistent nelems nelems public void deallocate if root 0 btree page purge storage impl get storage root type height super deallocate btreepage storageimpl getstorage public int mark tree if root 0 return btree page mark page storage impl get storage root type height return 0 marktree btreepage markpage storageimpl getstorage protected object unpack enum int val base b tree class has no information about particular enum type so it is not able to correctly unpack enum key return object val unpackenum public void export xml exporter exporter throws java io io exception if root 0 btree page export page storage impl get storage exporter root type height xmlexporter ioexception btreepage exportpage storageimpl getstorage static class btree entry t implements map entry object t public object get key return key btreeentry getkey public t get value return t db lookup object oid null getvalue lookupobject public t set value t value throw new unsupported operation exception setvalue unsupportedoperationexception public boolean equals object o if o instanceof map entry return false map entry e map entry o return get key null e get key null get key equals e get key get value null e get value null get value equals e get value getkey getkey getkey getkey getvalue getvalue getvalue getvalue public int hash code return get key null 0 get key hash code get value null 0 get value hash code hashcode getkey getkey hashcode getvalue getvalue hashcode public string to string return get key get value tostring getkey getvalue btree entry storage impl db object key int oid this db db this key key this oid oid btreeentry storageimpl object unpack key storage impl db page pg int pos byte data pg data int offs btree page first key offs pos class descriptor sizeof type switch type case class descriptor tp boolean return boolean value of data offs 0 case class descriptor tp byte return new byte data offs case class descriptor tp short return short value of bytes unpack2 data offs case class descriptor tp char return new character char bytes unpack2 data offs case class descriptor tp int return new integer bytes unpack4 data offs case class descriptor tp object return db lookup object bytes unpack4 data offs null case class descriptor tp long return new long bytes unpack8 data offs case class descriptor tp date return new date bytes unpack8 data offs case class descriptor tp float return new float float int bits to float bytes unpack4 data offs case class descriptor tp double return new double double long bits to double bytes unpack8 data offs case class descriptor tp enum return unpack enum bytes unpack4 data offs case class descriptor tp string return unpack str key pg pos case class descriptor tp array of byte return unpack byte array key pg pos default assert failed invalid type return null unpackkey storageimpl btreepage firstkeyoffs classdescriptor classdescriptor tpboolean valueof classdescriptor tpbyte classdescriptor tpshort valueof classdescriptor tpchar classdescriptor tpint classdescriptor tpobject lookupobject classdescriptor tplong classdescriptor tpdate classdescriptor tpfloat intbitstofloat classdescriptor tpdouble longbitstodouble classdescriptor tpenum unpackenum classdescriptor tpstring unpackstrkey classdescriptor tparrayofbyte unpackbytearraykey static string unpack str key page pg int pos int len btree page get key str size pg pos int offs btree page first key offs btree page get key str offs pg pos byte data pg data char sval new char len for int j 0 j len j sval j char bytes unpack2 data offs offs 2 return new string sval unpackstrkey btreepage getkeystrsize btreepage firstkeyoffs btreepage getkeystroffs object unpack byte array key page pg int pos int len btree page get key str size pg pos int offs btree page first key offs btree page get key str offs pg pos byte val new byte len system arraycopy pg data offs val 0 len return val unpackbytearraykey btreepage getkeystrsize btreepage firstkeyoffs btreepage getkeystroffs public iterator t iterator return iterator null null ascent order ascent_order public iterable iterator map entry object t entry iterator return entry iterator null null ascent order iterableiterator entryiterator entryiterator ascent_order final int compare byte arrays key key page pg int i return compare byte arrays byte key oval pg data btree page get key str offs pg i btree page first key offs btree page get key str size pg i comparebytearrays comparebytearrays btreepage getkeystroffs btreepage firstkeyoffs btreepage getkeystrsize class btree selection iterator e extends iterable iterator e implements persistent iterator btree selection iterator key from key till int order this from from this till till this order order reset btreeselectioniterator iterableiterator persistentiterator btreeselectioniterator void reset int i l r sp 0 counter update counter if height 0 return int page id root storage impl db storage impl get storage if db null throw new storage error storage error deleted object int h height page stack new int h pos stack new int h if type class descriptor tp string if order ascent order if from null while h 0 pos stack sp 0 page stack sp page id page pg db get page page id page id btree page get key str oid pg 0 end btree page getn items pg db pool unfix pg sp 1 else while h 0 page stack sp page id page pg db get page page id l 0 r btree page getn items pg while l r i l r 1 if btree page compare str from pg i from inclusion l i 1 else r i assert that r l pos stack sp r page id btree page get key str oid pg r db pool unfix pg sp 1 page stack sp page id page pg db get page page id l 0 end r btree page getn items pg while l r i l r 1 if btree page compare str from pg i from inclusion l i 1 else r i assert that r l if r end sp 1 goto next item pg r 1 else pos stack sp r db pool unfix pg if sp 0 till null page pg db get page page stack sp 1 if btree page compare str till pg pos stack sp 1 till inclusion sp 0 db pool unfix pg else descent order if till null while h 0 page stack sp page id page pg db get page page id pos stack sp btree page getn items pg page id btree page get key str oid pg pos stack sp db pool unfix pg sp 1 page stack sp page id page pg db get page page id pos stack sp btree page getn items pg 1 db pool unfix pg else while h 0 page stack sp page id page pg db get page page id l 0 r btree page getn items pg while l r i l r 1 if btree page compare str till pg i 1 till inclusion l i 1 else r i assert that r l pos stack sp r page id btree page get key str oid pg r db pool unfix pg sp 1 page stack sp page id page pg db get page page id l 0 r btree page getn items pg while l r i l r 1 if btree page compare str till pg i 1 till inclusion l i 1 else r i assert that r l if r 0 sp 1 goto next item pg r else pos stack sp r 1 db pool unfix pg if sp 0 from null page pg db get page page stack sp 1 if btree page compare str from pg pos stack sp 1 from inclusion sp 0 db pool unfix pg else if type class descriptor tp array of byte if order ascent order if from null while h 0 pos stack sp 0 page stack sp page id page pg db get page page id page id btree page get key str oid pg 0 end btree page getn items pg db pool unfix pg sp 1 else while h 0 page stack sp page id page pg db get page page id l 0 r btree page getn items pg while l r i l r 1 if compare byte arrays from pg i from inclusion l i 1 else r i assert that r l pos stack sp r page id btree page get key str oid pg r db pool unfix pg sp 1 page stack sp page id page pg db get page page id l 0 end r btree page getn items pg while l r i l r 1 if compare byte arrays from pg i from inclusion l i 1 else r i assert that r l if r end sp 1 goto next item pg r 1 else pos stack sp r db pool unfix pg if sp 0 till null page pg db get page page stack sp 1 if compare byte arrays till pg pos stack sp 1 till inclusion sp 0 db pool unfix pg else descent order if till null while h 0 page stack sp page id page pg db get page page id pos stack sp btree page getn items pg page id btree page get key str oid pg pos stack sp db pool unfix pg sp 1 page stack sp page id page pg db get page page id pos stack sp btree page getn items pg 1 db pool unfix pg else while h 0 page stack sp page id page pg db get page page id l 0 r btree page getn items pg while l r i l r 1 if updatecounter pageid storageimpl storageimpl getstorage storageerror storageerror deleted_object pagestack posstack classdescriptor tpstring ascent_order posstack pagestack pageid getpage pageid pageid btreepage getkeystroid btreepage getnitems pagestack pageid getpage pageid btreepage getnitems btreepage comparestr posstack pageid btreepage getkeystroid pagestack pageid getpage pageid btreepage getnitems btreepage comparestr gotonextitem posstack getpage pagestack btreepage comparestr posstack pagestack pageid getpage pageid posstack btreepage getnitems pageid btreepage getkeystroid posstack pagestack pageid getpage pageid posstack btreepage getnitems pagestack pageid getpage pageid btreepage getnitems btreepage comparestr posstack pageid btreepage getkeystroid pagestack pageid getpage pageid btreepage getnitems btreepage comparestr gotonextitem posstack getpage pagestack btreepage comparestr posstack classdescriptor tparrayofbyte ascent_order posstack pagestack pageid getpage pageid pageid btreepage getkeystroid btreepage getnitems pagestack pageid getpage pageid btreepage getnitems comparebytearrays posstack pageid btreepage getkeystroid pagestack pageid getpage pageid btreepage getnitems comparebytearrays gotonextitem posstack getpage pagestack comparebytearrays posstack pagestack pageid getpage pageid posstack btreepage getnitems pageid btreepage getkeystroid posstack pagestack pageid getpage pageid posstack btreepage getnitems pagestack pageid getpage pageid btreepage getnitems public boolean has next if counter update counter if storage impl get storage concurrent iterator refresh else throw new concurrent modification exception return sp 0 hasnext updatecounter storageimpl getstorage concurrentiterator concurrentmodificationexception public e next if has next throw new no such element exception storage impl db storage impl get storage int pos pos stack sp 1 curr pos pos curr page page stack sp 1 page pg db get page curr page e curr e get current pg pos if db concurrent iterator curr key get current key pg pos goto next item pg pos return curr hasnext nosuchelementexception storageimpl storageimpl getstorage posstack currpos currpage pagestack getpage currpage getcurrent concurrentiterator currkey getcurrentkey gotonextitem public int next oid if has next throw new no such element exception storage impl db storage impl get storage int pos pos stack sp 1 curr pos pos curr page page stack sp 1 page pg db get page curr page int oid get reference pg pos if db concurrent iterator curr key get current key pg pos goto next item pg pos return oid nextoid hasnext nosuchelementexception storageimpl storageimpl getstorage posstack currpos currpage pagestack getpage currpage getreference concurrentiterator currkey getcurrentkey gotonextitem private int get reference page pg int pos return type class descriptor tp string type class descriptor tp array of byte btree page get key str oid pg pos btree page get reference pg btree page max items 1 pos getreference classdescriptor tpstring classdescriptor tparrayofbyte btreepage getkeystroid btreepage getreference btreepage maxitems protected object get current page pg int pos storage impl db storage impl get storage return db lookup object get reference pg pos null getcurrent storageimpl storageimpl getstorage lookupobject getreference protected final void goto next item page pg int pos storage impl db storage impl get storage if type class descriptor tp string if order ascent order if pos end while sp 0 db pool unfix pg pos pos stack sp 1 pg db get page page stack sp 1 if pos btree page getn items pg pos stack sp 1 pos do int page id btree page get key str oid pg pos db pool unfix pg pg db get page page id end btree page getn items pg page stack sp page id pos stack sp pos 0 while sp page stack length break else pos stack sp 1 pos if sp 0 till null btree page compare str till pg pos till inclusion sp 0 else descent order if pos 0 while sp 0 db pool unfix pg pos pos stack sp 1 pg db get page page stack sp 1 if pos 0 pos stack sp 1 pos do int page id btree page get key str oid pg pos db pool unfix pg pg db get page page id page stack sp page id pos stack sp pos btree page getn items pg while sp page stack length pos stack sp 1 pos break else pos stack sp 1 pos if sp 0 from null btree page compare str from pg pos from inclusion sp 0 else if type class descriptor tp array of byte if order ascent order if pos end while sp 0 db pool unfix pg pos pos stack sp 1 pg db get page page stack sp 1 if pos btree page getn items pg pos stack sp 1 pos do int page id btree page get key str oid pg pos db pool unfix pg pg db get page page id end btree page getn items pg page stack sp page id pos stack sp pos 0 while sp page stack length break else pos stack sp 1 pos if sp 0 till null compare byte arrays till pg pos till inclusion sp 0 else descent order if pos 0 while sp 0 db pool unfix pg pos pos stack sp 1 pg db get page page stack sp 1 if pos 0 pos stack sp 1 pos do int page id btree page get key str oid pg pos db pool unfix pg pg db get page page id page stack sp page id pos stack sp pos btree page getn items pg while sp page stack length pos stack sp 1 pos break else pos stack sp 1 pos if sp 0 from null compare byte arrays from pg pos from inclusion sp 0 else scalar type if order ascent order if pos end while sp 0 db pool unfix pg pos pos stack sp 1 pg db get page page stack sp 1 if pos btree page getn items pg pos stack sp 1 pos do int page id btree page get reference pg btree page max items 1 pos db pool unfix pg pg db get page page id end btree page getn items pg page stack sp page id pos stack sp pos 0 while sp page stack length break else pos stack sp 1 pos if sp 0 till null btree page compare till pg pos till inclusion sp 0 else descent order if pos 0 while sp 0 db pool unfix pg pos pos stack sp 1 pg db get page page stack sp 1 if pos 0 pos stack sp 1 pos do int page id btree page get reference pg btree page max items 1 pos db pool unfix pg pg db get page page id page stack sp page id pos stack sp pos btree page getn items pg while sp page stack length pos stack sp 1 pos break else pos stack sp 1 pos if sp 0 from null btree page compare from pg pos from inclusion sp 0 if db concurrent iterator sp 0 next key get current key pg pos db pool unfix pg gotonextitem storageimpl storageimpl getstorage classdescriptor tpstring ascent_order posstack getpage pagestack btreepage getnitems posstack pageid btreepage getkeystroid getpage pageid btreepage getnitems pagestack pageid posstack pagestack posstack btreepage comparestr posstack getpage pagestack posstack pageid btreepage getkeystroid getpage pageid pagestack pageid posstack btreepage getnitems pagestack posstack posstack btreepage comparestr classdescriptor tparrayofbyte ascent_order posstack getpage pagestack btreepage getnitems posstack pageid btreepage getkeystroid getpage pageid btreepage getnitems pagestack pageid posstack pagestack posstack comparebytearrays posstack getpage pagestack posstack pageid btreepage getkeystroid getpage pageid pagestack pageid posstack btreepage getnitems pagestack posstack posstack comparebytearrays ascent_order posstack getpage pagestack btreepage getnitems posstack pageid btreepage getreference btreepage maxitems getpage pageid btreepage getnitems pagestack pageid posstack pagestack posstack btreepage posstack getpage pagestack posstack pageid btreepage getreference btreepage maxitems getpage pageid pagestack pageid posstack btreepage getnitems pagestack posstack posstack btreepage concurrentiterator nextkey getcurrentkey private void refresh if sp 0 if next key null reset else if order ascent order from next key key else till next key key int next next key oid reset storage impl db storage impl get storage while true int pos pos stack sp 1 page pg db get page page stack sp 1 int oid type class descriptor tp string type class descriptor tp array of byte btree page get key str oid pg pos btree page get reference pg btree page max items 1 pos if oid next goto next item pg pos else db pool unfix pg break counter update counter nextkey ascent_order nextkey nextkey nextkey storageimpl storageimpl getstorage posstack getpage pagestack classdescriptor tpstring classdescriptor tparrayofbyte btreepage getkeystroid btreepage getreference btreepage maxitems gotonextitem updatecounter btree key get current key page pg int pos btree key key switch type case class descriptor tp string key new btree key null btree page get key str oid pg pos key get str pg pos break case class descriptor tp array of byte key new btree key null btree page get key str oid pg pos key get byte array pg pos break default key new btree key null btree page get reference pg btree page max items 1 pos key extract pg btree page first key offs pos class descriptor sizeof type type return key btreekey getcurrentkey btreekey classdescriptor tpstring btreekey btreepage getkeystroid getstr classdescriptor tparrayofbyte btreekey btreepage getkeystroid getbytearray btreekey btreepage getreference btreepage maxitems btreepage firstkeyoffs classdescriptor public void remove if curr page 0 throw new no such element exception storage impl db storage impl get storage if db concurrent iterator if counter update counter throw new concurrent modification exception page pg db get page curr page curr key get current key pg curr pos db pool unfix pg if sp 0 int pos pos stack sp 1 pg db get page page stack sp 1 next key get current key pg pos db pool unfix pg system out println deleted key deleted key key ival next key next key key ival btree this remove if exists curr key refresh curr page 0 currpage nosuchelementexception storageimpl storageimpl getstorage concurrentiterator updatecounter concurrentmodificationexception getpage currpage currkey getcurrentkey currpos posstack getpage pagestack nextkey getcurrentkey deletedkey nextkey removeifexists currkey currpage class btree selection entry iterator extends btree selection iterator map entry object t btree selection entry iterator key from key till int order super from till order btreeselectionentryiterator btreeselectioniterator btreeselectionentryiterator protected object get current page pg int pos storage impl db storage impl get storage switch type case class descriptor tp string return new btree entry t db unpack str key pg pos btree page get key str oid pg pos case class descriptor tp array of byte return new btree entry t db unpack byte array key pg pos btree page get key str oid pg pos default return new btree entry t db unpack key db pg pos btree page get reference pg btree page max items 1 pos getcurrent storageimpl storageimpl getstorage classdescriptor tpstring btreeentry unpackstrkey btreepage getkeystroid classdescriptor tparrayofbyte btreeentry unpackbytearraykey btreepage getkeystroid btreeentry unpackkey btreepage getreference btreepage maxitems btree entry start from iterator int start int order super null null order this start start reset btreeentrystartfromiterator void reset super reset int skip order ascent order start n elems start 1 while skip 0 has next next ascent_order nelems hasnext public iterable iterator t iterator key from key till int order return new btree selection iterator t check key from check key till order iterableiterator btreeselectioniterator checkkey checkkey public iterable iterator t prefix iterator string prefix return iterator new key prefix to char array new key prefix character max value to char array false ascent order iterableiterator prefixiterator tochararray max_value tochararray ascent_order public iterable iterator map entry object t entry iterator key from key till int order return new btree selection entry iterator check key from check key till order iterableiterator entryiterator btreeselectionentryiterator checkkey checkkey public iterable iterator t iterator object from object till int order return new btree selection iterator t check key get key from object from check key get key from object till order iterableiterator btreeselectioniterator checkkey getkeyfromobject checkkey getkeyfromobject public iterable iterator map entry object t entry iterator object from object till int order return new btree selection entry iterator check key get key from object from check key get key from object till order iterableiterator entryiterator btreeselectionentryiterator checkkey getkeyfromobject checkkey getkeyfromobject public t get at int i iterable iterator map entry object t iterator if i 0 i n elems throw new index out of bounds exception position i index size n elems if i n elems 2 iterator entry iterator null null ascent order while i 0 iterator next else iterator entry iterator null null descent order i n elems while i 0 iterator next return iterator next get value getat iterableiterator nelems indexoutofboundsexception nelems nelems entryiterator ascent_order entryiterator descent_order nelems getvalue public iterable iterator map entry object t entry iterator int start int order return new btree entry start from iterator start order iterableiterator entryiterator btreeentrystartfromiterator public boolean is unique return unique isunique public put failed message insert exception e string identifier boolean global this code e get mode this code description insert exception get message code this short code description insert exception get short message code this extra description e extra this tracker e error codes this expecteduri e uri this identifier identifier this global global this is fatal insert exception is fatal code putfailedmessage insertexception getmode codedescription insertexception getmessage shortcodedescription insertexception getshortmessage extradescription errorcodes isfatal insertexception isfatal construct from a fieldset used in serialization of persistent requests will need to be made more tolerant of syntax errors if is used in an fcp client library fixme param use verbose fields if true read in verbose fields code description etc if false reconstruct them from the error code throws malformedurl exception public put failed message simple field set fs boolean use verbose fields throws malformedurl exception identifier fs get identifier if identifier null throw new null pointer exception global fs get boolean global false code integer parse int fs get code if use verbose fields code description fs get code description is fatal fields string to bool fs get fatal false short code description fs get short code description else code description insert exception get message code is fatal insert exception is fatal code short code description insert exception get short message code extra description fs get extra description string euri fs get expecteduri if euri null euri length 0 expecteduri new freeneturi euri else expecteduri null simple field set tracker subset fs subset errors if tracker subset null tracker new failure code tracker true tracker subset else tracker null useverbosefields codedescription malformedurlexception putfailedmessage simplefieldset useverbosefields malformedurlexception nullpointerexception getboolean parseint useverbosefields codedescription codedescription isfatal stringtobool shortcodedescription shortcodedescription codedescription insertexception getmessage isfatal insertexception isfatal shortcodedescription insertexception getshortmessage extradescription extradescription simplefieldset trackersubset trackersubset failurecodetracker trackersubset override public simple field set get field set return get field set true simplefieldset getfieldset getfieldset public simple field set get field set boolean verbose simple field set fs new simple field set true fs put single identifier identifier if global fs put single global true fs put code code if verbose fs put single code description code description if extra description null fs put single extra description extra description if tracker null fs tput errors tracker to field set verbose if verbose fs put fatal is fatal if verbose fs put single short code description short code description if expecteduri null fs put single expecteduri expecteduri to string return fs simplefieldset getfieldset simplefieldset simplefieldset putsingle putsingle putsingle codedescription codedescription extradescription putsingle extradescription extradescription tofieldset isfatal putsingle shortcodedescription shortcodedescription putsingle tostring override public string get name return put failed getname putfailed override public void run fcp connection handler handler node node throws message invalid exception throw new message invalid exception protocol error message invalid message put failed goes from server to client not the other way around identifier global fcpconnectionhandler messageinvalidexception messageinvalidexception protocolerrormessage invalid_message putfailed override public void remove from object container container container activate this 5 everything if tracker null tracker remove from container if expecteduri null expecteduri remove from container container delete this removefrom objectcontainer removefrom removefrom simple single file fetcher client key key int max retries fetch context ctx client requester parent get completion callback rcb boolean is essential boolean dont add long l object container container client context context boolean delete fetch context super key max retries ctx parent delete fetch context this rcb rcb this token l if dont add parent add block container if is essential parent add must succeed blocks 1 container parent notify clients container context simplesinglefilefetcher clientkey maxretries fetchcontext clientrequester getcompletioncallback isessential dontadd objectcontainer clientcontext deletefetchcontext maxretries deletefetchcontext dontadd addblock isessential addmustsucceedblocks notifyclients translate it then call the real on failure override public void on failure low level get exception e object req token ignored object container container client context context switch e code case low level get exception data not found on failure new fetch exception fetch exception data not found false container context return case low level get exception data not found in store on failure new fetch exception fetch exception data not found false container context return case low level get exception recently failed on failure new fetch exception fetch exception recently failed false container context return case low level get exception decode failed on failure new fetch exception fetch exception block decode error false container context return case low level get exception internal error on failure new fetch exception fetch exception internal error false container context return case low level get exception rejected overload on failure new fetch exception fetch exception rejected overload false container context return case low level get exception route not found on failure new fetch exception fetch exception route not found false container context return case low level get exception transfer failed on failure new fetch exception fetch exception transfer failed false container context return case low level get exception verify failed on failure new fetch exception fetch exception block decode error false container context return case low level get exception cancelled on failure new fetch exception fetch exception cancelled false container context return default logger error this unknown low level get exception code e code on failure new fetch exception fetch exception internal error false container context return onfailure onfailure lowlevelgetexception reqtokenignored objectcontainer clientcontext lowlevelgetexception data_not_found onfailure fetchexception fetchexception data_not_found lowlevelgetexception data_not_found_in_store onfailure fetchexception fetchexception data_not_found lowlevelgetexception recently_failed onfailure fetchexception fetchexception recently_failed lowlevelgetexception decode_failed onfailure fetchexception fetchexception block_decode_error lowlevelgetexception internal_error onfailure fetchexception fetchexception internal_error lowlevelgetexception rejected_overload onfailure fetchexception fetchexception rejected_overload lowlevelgetexception route_not_found onfailure fetchexception fetchexception route_not_found lowlevelgetexception transfer_failed onfailure fetchexception fetchexception transfer_failed lowlevelgetexception verify_failed onfailure fetchexception fetchexception block_decode_error lowlevelgetexception onfailure fetchexception fetchexception lowlevelgetexception onfailure fetchexception fetchexception internal_error real on failure protected void on failure fetch exception e boolean force fatal object container container client context context if persistent container activate parent 1 container activate rcb 1 boolean logminor logger should log logger minor this if logminor logger minor this on failure e force fatal e if parent is cancelled cancelled if logminor logger minor this failing cancelled e new fetch exception fetch exception cancelled force fatal true if e is fatal force fatal if retry container context if logminor logger minor this retrying return unregister all container context synchronized this finished true if persistent container store this if e is fatal force fatal parent fatally failed block container context else parent failed block container context rcb on failure e this container context onfailure onfailure fetchexception forcefatal objectcontainer clientcontext shouldlog onfailure forcefatal iscancelled fetchexception fetchexception forcefatal isfatal forcefatal unregisterall isfatal forcefatal fatallyfailedblock failedblock onfailure will be overridden by single file fetcher protected void on success fetch result data object container container client context context if persistent container activate parent 1 container activate rcb 1 if parent is cancelled data as bucket free if persistent data as bucket remove from container on failure new fetch exception fetch exception cancelled false container context return rcb on success data this container context singlefilefetcher onsuccess fetchresult objectcontainer clientcontext iscancelled asbucket asbucket removefrom onfailure fetchexception fetchexception onsuccess override public void on success client key block block boolean from store object req token ignored object container container client context context if persistent container activate parent 1 if parent instanceof client getter client getter parent add key to binary blob block container context bucket data extract block container context if data null return failed if block is metadata if key instanceof clientssk try freeneturi uri this key geturi if uri isssk uri isssk forusk uri uri usk forssk usk u usk create uri context usk manager update known good u uri get suggested edition context catch malformedurl exception e logger error this caught e e catch throwable t don t let the usk hint cause us to not succeed on the block logger error this caught t t on success new fetch result client metadata null data container context else on failure new fetch exception fetch exception invalid metadata metadata where expected data false container context onsuccess clientkeyblock fromstore reqtokenignored objectcontainer clientcontext clientgetter clientgetter addkeytobinaryblob ismetadata issskforusk uskforssk uskmanager updateknowngood getsuggestededition malformedurlexception onsuccess fetchresult clientmetadata onfailure fetchexception fetchexception invalid_metadata convert a client key block to a bucket if an error occurs report it via on failure and return null protected bucket extract client key block block object container container client context context bucket data try data block decode context get bucket factory parent persistent int math min ctx max output length integer max value false catch key decode exception e1 if logger should log logger minor this logger minor this decode failure e1 e1 on failure new fetch exception fetch exception block decode error e1 get message false container context return null catch too big exception e on failure new fetch exception fetch exception too big e false container context return null catch io exception e logger error this could not capture data disk full e e on failure new fetch exception fetch exception bucket error e false container context return null return data clientkeyblock onfailure clientkeyblock objectcontainer clientcontext getbucketfactory maxoutputlength max_value keydecodeexception shouldlog onfailure fetchexception fetchexception block_decode_error getmessage toobigexception onfailure fetchexception fetchexception too_big ioexception onfailure fetchexception fetchexception bucket_error get token is not supported public long get token return token gettoken gettoken public void on failed key listener construction exception e object container container client context context on failure e get fetch exception false container context onfailed keylistenerconstructionexception objectcontainer clientcontext onfailure getfetchexception override public void remove from object container container client context context super remove from container context rcb is definitely not our responsibility removefrom objectcontainer clientcontext removefrom override public void cancel object container container client context context super cancel container context if persistent container activate rcb 1 rcb on failure new fetch exception fetch exception cancelled this container context objectcontainer clientcontext onfailure fetchexception fetchexception public class seed server test peer node extends seed server peer node public seed server test peer node simple field set fs node node2 node crypto crypto peer manager peers boolean from local outgoing packet mangler mangler throws fs parse exception peer parse exception reference signature verification exception super fs node2 crypto peers from local mangler seedservertestpeernode seedserverpeernode seedservertestpeernode simplefieldset nodecrypto peermanager fromlocal outgoingpacketmangler fsparseexception peerparseexception referencesignatureverificationexception fromlocal override public simple field set export field set simple field set sfs super export field set sfs put overwrite opennet true return sfs simplefieldset exportfieldset simplefieldset exportfieldset putoverwrite override public boolean should disconnect and remove now return false shoulddisconnectandremovenow override protected void send initial messages sendinitialmessages override public void on remove long last received data packet time last received data packet time if last received data packet time 0 time last connection completed 0 system err println this get identity string removed timeout no packets received after successful connection setup else if time last connection completed 0 system err println this get identity string removed never connected else system err println this get identity string removed unknown cause super on remove onremove lastreceiveddatapackettime lastreceiveddatapackettime lastreceiveddatapackettime timelastconnectioncompleted getidentitystring timelastconnectioncompleted getidentitystring getidentitystring onremove public fate get fate long last received data packet time last received data packet time if is connected if last received data packet time 0 return fate connected no packets received else if this is unroutable older version return fate connected too old else return fate connected success long last connection time time last connection completed if last connection time 0 return fate never connected if last received data packet time 0 return fate connected timeout no packets received return fate connected disconnected unknown getfate lastreceiveddatapackettime lastreceiveddatapackettime isconnected lastreceiveddatapackettime connected_no_packets_received isunroutableolderversion connected_too_old connected_success lastconnectiontime timelastconnectioncompleted lastconnectiontime never_connected lastreceiveddatapackettime connected_timeout_no_packets_received connected_disconnected_unknown public static string get wrapper property string name synchronized wrapper config class if overrides contains key name return overrides get name return wrapper manager get properties get property name null getwrapperproperty wrapperconfig containskey wrappermanager getproperties getproperty public static boolean can change properties if wrapper manager is controlled by native wrapper logger normal wrapper config class cannot alter properties not running under wrapper return false file f new file wrapper conf if f exists logger normal wrapper config class cannot alter properties wrapper conf does not exist return false if f can read logger normal wrapper config class cannot alter properties wrapper conf not readable return false if f can write logger normal wrapper config class cannot alter properties wrapper conf not writable return false if file util get canonical file f get parent file can write logger normal wrapper config class cannot alter properties parent dir not writable return false can we create a file in order to rename over wrapper conf return true canchangeproperties wrappermanager iscontrolledbynativewrapper wrapperconfig wrapperconfig canread wrapperconfig canwrite wrapperconfig fileutil getcanonicalfile getparentfile canwrite wrapperconfig synchronized because we only want one instance running at once param name the property to set param value the value to set it to return true if the property was successfully updated public static synchronized boolean set wrapper property string name string value some of this copied from update deploy context hence no gpl header on this file as none there file old config new file wrapper conf file new config new file wrapper conf new file input stream fis null file output stream fos null try fis new file input stream old config buffered input stream bis new buffered input stream fis input stream reader isr new input stream reader bis buffered reader br new buffered reader isr fos new file output stream new config output stream writer osw new output stream writer fos buffered writer bw new buffered writer osw string line boolean written false boolean written reload false while line br read line null if line starts with name bw write name value n written true else if line equals ignore case wrapper restart reload configuration true written reload true else bw write line n br close fis null if written bw write name value n if written reload bw write wrapper restart reload configuration true n bw close fos null catch io exception e closer close fis closer close fos fis null fos null if old config exists new config delete logger error wrapper config class cannot update wrapper property name e e system err println unable to update wrapper property name e return false finally closer close fis closer close fos if new config rename to old config file old old config new file wrapper conf old if old old config exists old old config delete try old old config file create temp file wrapper conf old tmp new file catch io exception e string error unable to create temporary file and unable to copy wrapper conf to wrapper conf old could not update wrapper conf trying to set property name logger error wrapper config class error system err println error return false if old config rename to old old config string error unable to change property name could not move old config file old config so could not rename new config file new config over it already tried without deleting logger error wrapper config class error system err println error return false if new config rename to old config string error unable to rename new config to old config even after moving the old config file out of the way trying to restore previous config file so the node will start up logger error wrapper config class error system err println error if old old config rename to old config system err println catastrophic update error unable to rename backup copy of config file over the current config file after failing to update config file the node will not boot until you get a new wrapper conf n the old config file is saved in old old config and it should be renamed to wrapper conf system exit node init exception exit broke wrapper conf wrapper properties are read only so don t set property overrides put name value return true setwrapperproperty updatedeploycontext oldconfig newconfig fileinputstream fileoutputstream fileinputstream oldconfig bufferedinputstream bufferedinputstream inputstreamreader inputstreamreader bufferedreader bufferedreader fileoutputstream newconfig outputstreamwriter outputstreamwriter bufferedwriter bufferedwriter writtenreload readline startswith equalsignorecase reload_configuration writtenreload writtenreload reload_configuration ioexception oldconfig newconfig wrapperconfig newconfig renameto oldconfig oldoldconfig oldoldconfig oldoldconfig oldoldconfig createtempfile ioexception wrapperconfig oldconfig renameto oldoldconfig oldconfig newconfig wrapperconfig newconfig renameto oldconfig newconfig oldconfig wrapperconfig oldoldconfig renameto oldconfig oldoldconfig nodeinitexception exit_broke_wrapper_conf setproperty private stack fstack public ber encoder this byte 0x30 berencoder public ber encoder byte id fields new id vector id fstack new stack fstack add fields berencoder idvector public int to bytes byte buf while fields size 1 end sequence int len vec to bytes fields buf 0 byte tmpbt remember this function writes backwards first for int i 0 i len 2 i tmpbt buf i buf i buf len 1 i buf len 1 i tmpbt return len tobytes endsequence vectobytes private int vec to bytes id vector v byte buf int offset int inoffset offset for int i v size 1 i 0 i object o v get i if o instanceof integer int dlen int to bytes integer o int value buf offset if o null buf offset 0x00 buf offset 0x05 else if o instanceof long int dlen int to bytes long o long value buf offset offset dlen offset int tober bytes dlen buf offset buf offset 0x02 else if o instanceof snmp type wrapper num int dlen int to bytes snmp type wrapper num o get value buf offset offset dlen offset int tober bytes dlen buf offset buf offset snmp type wrapper num o get typeid else if o instanceof id vector int dlen vec to bytes id vector o buf offset offset dlen offset int tober bytes dlen buf offset buf offset id vector o get vid else if o instanceof byte arr wrapper byte barr byte arr wrapper o arr for int j 0 j barr length j buf offset j barr barr length 1 j offset barr length offset int tober bytes barr length buf offset buf offset byte arr wrapper o id myoffset int to bytes v get i buf myoffset return offset inoffset vectobytes idvector inttobytes intvalue inttobytes longvalue inttoberbytes snmptypewrappernum inttobytes snmptypewrappernum getvalue inttoberbytes snmptypewrappernum gettypeid idvector vectobytes idvector inttoberbytes idvector getvid bytearrwrapper bytearrwrapper inttoberbytes bytearrwrapper inttobytes private int int to bytes long i byte buf int offset todo handle negative numbers also int inoffset offset if i 0 buf offset 0 else for i 0 i i 256 buf offset byte i 256 offset make the number unsigned no we should allow signed numbers if buf offset 1 0 buf offset 0 return offset inoffset inttobytes private int int tober bytes long i byte buf int offset string bs long to binary string i int len bs length 7 bs 0000000 bs substring len char bits bs to char array int eatenbits 0 buf offset 0 int inoffset offset for int j bits length 1 j 0 j long j i system out print int tober bytes i if i 0 offset else for j 0 j j 128 buf offset byte j 128 buf offset byte j 127 128 0 system out print j 128 j 127 128 0 j 128 j 127 128 0 now turn it around if offset inoffset 1 system err println started at inoffset ended at offset for int p 0 p offset inoffset 2 p system err println stap offset p 1 inoffset p byte tmp buf offset p 1 buf offset p 1 buf inoffset p buf inoffset p tmp system err println for int j 0 j bits length j if eatenbits 7 buf offset 128 offset eatenbits 0 buf offset 0 buf offset bits j 1 1 0 6 eatenbits eatenbits offset return offset inoffset inttoberbytes tobinarystring tochararray inttoberbytes public void putsnmp type wrapper num snmp type wrapper num o add to top o clone putsnmptypewrappernum snmptypewrappernum addtotop add to top new integer i public void put timeticks long i add to top new snmp time ticks i addtotop puttimeticks addtotop snmptimeticks public void put integer long i add to top new long i putinteger addtotop public void put counter32 long i add to top new snmp counter32 i putcounter32 addtotop snmpcounter32 public void put null add to top null putnull addtotop public void put octet string byte buf add to top new byte arr wrapper byte buf clone byte 0x04 putoctetstring addtotop bytearrwrapper public void putoid long buf byte bufa new byte 10 buf length int offset 1 bufa 0 0x2b for int i 2 i buf length i offset int tober bytes buf i bufa offset byte bufb new byte offset for int i 0 i bufb length i bufb i bufa i add to top new byte arr wrapper bufb byte 0x06 inttoberbytes addtotop bytearrwrapper public void start sequence start sequence byte 0x30 startsequence startsequence public void start sequence byte id id vector v new id vector id add to top v fstack add v startsequence idvector idvector addtotop public void end sequence fstack pop endsequence private void add to top object o id vector fstack peek add element o addtotop idvector addelement public byte id public byte arr wrapper byte arr byte id this arr arr this id id bytearrwrapper byte vid byte 0x30 public id vector byte id super vid id idvector public byte get vid return vid getvid public class ssdp search socket extends httpmu socket implements runnable public ssdp search socket ssdpsearchsocket httpmusocket ssdpsearchsocket public ssdp search socket string bind addr open bind addr ssdpsearchsocket bindaddr bindaddr public boolean open string bind addr string addr ssdp address if host interface isi pv6 address bind addr true addr ssdp geti pv6 address return open addr ssdp port bind addr bindaddr hostinterface isipv6address bindaddr getipv6address bindaddr private listener list device search listener list new listener list public void add search listener search listener listener device search listener list add listener listenerlist devicesearchlistenerlist listenerlist addsearchlistener searchlistener devicesearchlistenerlist public void remove search listener search listener listener device search listener list remove listener removesearchlistener searchlistener devicesearchlistenerlist public void perform search listener ssdp packet ssdp packet int listener size device search listener list size for int n 0 n listener size n search listener listener search listener device search listener list get n listener device search received ssdp packet performsearchlistener ssdppacket ssdppacket listenersize devicesearchlistenerlist listenersize searchlistener searchlistener devicesearchlistenerlist devicesearchreceived ssdppacket public void run thread this thread thread current thread while device search thread this thread thread yield ssdp packet packet receive thanks for mikael hakman 04 20 05 if packet null continue if packet is discover true perform search listener packet thisthread currentthread devicesearchthread thisthread ssdppacket isdiscover performsearchlistener public void start device search thread new thread this u pnp ssdp search socket device search thread set daemon true device search thread start devicesearchthread upnp ssdpsearchsocket devicesearchthread setdaemon devicesearchthread public void stop thanks for mikael hakman 04 20 05 close device search thread null devicesearchthread private static final long serial versionuid 1l public updater parser exception string msg super msg serialversionuid updaterparserexception public plugin manager node node logminor logger should log logger minor this logdebug logger should log logger debug this config toadlet list new hash map string fred plugin plugin wrappers new vector plugin info wrapper plugins failed load new vector string this node node this core node client core if logminor logger minor this starting plugin manager if logdebug logger debug this initialize plugin manager config client core make client request starter interactive priority class true callback executor executor new serial executor native thread norm priority executor start node executor pm callback executor pmconfig new sub config pluginmanager node config pmconfig register configfile fplugins ini 9 true true plugin config config file plugin config config file long new string callback public string get return config file public void set string val throws invalid config value exception config file val config file pmconfig get string configfile pmconfig register installdir fplugins 9 true true plugin config install dir plugin config install dir long new string callback public string get return install dir return get config load string public void set string val throws invalid config value exception install dir val if store dir equals new file val return fixme throw new invalid config value exception l10n get string plugin manager cannot set once loaded install dir pmconfig get string installdir start plugins in the config pmconfig register loadplugin null 0 true false plugin manager loaded on startup plugin manager loaded on startup long new string arr callback override public string get return get config load string override public void set string val throws invalid config value exception if store dir equals new file val return fixme throw new invalid config value exception l10n get string plugin manager cannot set once loaded override public boolean is read only return true to start pmconfig get string arr loadplugin pmconfig finished initialization fproxy theme theme theme from name node config get fproxy get string css selfinstance this pluginmanager shouldlog shouldlog toadletlist hashmap fredplugin pluginwrappers plugininfowrapper pluginsfailedload clientcore makeclient requeststarter interactive_priority_class serialexecutor nativethread norm_priority subconfig pluginconfig configfile pluginconfig configfilelong stringcallback configfile invalidconfigvalueexception configfile configfile getstring pluginconfig installdir pluginconfig installdirlong stringcallback installdir getconfigloadstring invalidconfigvalueexception installdir storedir invalidconfigvalueexception getstring pluginmanager cannotsetonceloaded installdir getstring pluginmanager loadedonstartup pluginmanager loadedonstartuplong stringarrcallback getconfigloadstring invalidconfigvalueexception storedir invalidconfigvalueexception getstring pluginmanager cannotsetonceloaded isreadonly tostart getstringarr finishedinitialization fproxytheme themefromname getstring new string arr callback override public string get return get config load string stringarrcallback getconfigloadstring override public void set string val throws invalid config value exception if store dir equals new file val return fixme throw new invalid config value exception l10n get string plugin manager cannot set once loaded invalidconfigvalueexception storedir invalidconfigvalueexception getstring pluginmanager cannotsetonceloaded override public boolean is read only return true isreadonly public void start config config if to start null for string name to start start plugin auto name false synchronized plugin wrappers started true to start null tostart tostart startpluginauto pluginwrappers tostart private string get config load string vector string v new vector string synchronized plugin wrappers if started return to start for plugin info wrapper pi plugin wrappers v add pi get filename for string s plugins failed load v add s return v to array new string v size getconfigloadstring pluginwrappers tostart plugininfowrapper pluginwrappers getfilename pluginsfailedload toarray returns a set of all currently starting plugins return all currently starting plugins public set plugin progress get starting plugins synchronized starting plugins return new hash set plugin progress starting plugins pluginprogress getstartingplugins startingplugins hashset pluginprogress startingplugins try to guess around public void start plugin auto final string pluginname boolean store if is official plugin pluginname start plugin official pluginname store return try new freeneturi pluginname test for malformedurl exception start plugin freenet pluginname store return catch malformedurl exception e not a freenet key file roots file list roots for file f roots if pluginname starts with f get name new file pluginname exists start plugin file pluginname store return start pluginurl pluginname store startpluginauto isofficialplugin startpluginofficial malformedurlexception startpluginfreenet malformedurlexception listroots startswith getname startpluginfile startpluginurl public void start plugin official final string pluginname boolean store real start plugin new plugin down loader official pluginname store startpluginofficial realstartplugin plugindownloaderofficial public void start plugin file final string filename boolean store real start plugin new plugin down loader file filename store startpluginfile realstartplugin plugindownloaderfile public void start pluginurl final string filename boolean store real start plugin new plugin down loaderurl filename store startpluginurl realstartplugin plugindownloaderurl public void start plugin freenet final string filename boolean store real start plugin new plugin down loader freenet client filename store startpluginfreenet realstartplugin plugindownloaderfreenet private void real start plugin final plugin down loader pdl final string filename final boolean store if filename trim length 0 return final plugin progress plugin progress new plugin progress filename synchronized starting plugins starting plugins add plugin progress logger normal this loading plugin filename fred plugin plug try plug load plugin pdl filename if plug null return already loaded plugin progress set progress plugin progress starting plugin info wrapper pi plugin handler start plugin plugin manager this filename plug new plugin respirator node plugin manager this plug synchronized plugin wrappers plugin wrappers add pi plugins failed load remove filename logger normal this plugin loaded filename catch plugin not found exception e logger normal this loading plugin failed filename e string message e get message synchronized plugin wrappers plugins failed load add filename core alerts register new plugin load failed user alert filename pdl instanceof plugin down loader official message catch unsupported class version error e logger error this could not load plugin filename e e system err println could not load plugin filename e e print stack trace system err println plugin filename appears to require a later jvm logger error this plugin filename appears to require a later jvm synchronized plugin wrappers plugins failed load add filename core alerts register new plugin load failed user alert filename pdl instanceof plugin down loader official l10n plugin req newerjvm title name filename finally synchronized starting plugins starting plugins remove plugin progress try not to destroy the config synchronized this if store core store config realstartplugin plugindownloader pluginprogress pluginprogress pluginprogress startingplugins startingplugins pluginprogress fredplugin loadplugin pluginprogress setprogress pluginprogress plugininfowrapper pluginhandler startplugin pluginmanager pluginrespirator pluginmanager pluginwrappers pluginwrappers pluginsfailedload pluginnotfoundexception getmessage pluginwrappers pluginsfailedload pluginloadfaileduseralert plugindownloaderofficial unsupportedclassversionerror printstacktrace pluginwrappers pluginsfailedload pluginloadfaileduseralert plugindownloaderofficial pluginreqnewerjvmtitle startingplugins startingplugins pluginprogress storeconfig public plugin load failed user alert string filename boolean official string message this filename filename this official official this message message pluginloadfaileduseralert public string dismiss button text return l10n delete failed plugin button dismissbuttontext deletefailedpluginbutton public void on dismiss synchronized plugin wrappers plugins failed load remove filename ondismiss pluginwrappers pluginsfailedload public string anchor return pluginfailed filename public html node gethtml text html node p new html node p p add child l10n plugin loading failed with message new string name message new string filename message if official html node reload form p add child form new string action method new string plugins post reload form add child input new string type name value new string hidden form password node client core form password reload form add child input new string type name value new string hidden plugin name filename reload form add child input new string type name value new string submit submit official l10n official plugin load failed try again return p htmlnode gethtmltext htmlnode htmlnode addchild pluginloadingfailedwithmessage htmlnode reloadform addchild reloadform addchild formpassword clientcore formpassword reloadform addchild reloadform addchild officialpluginloadfailedtryagain public short get priority class return user alert error getpriorityclass useralert public string get short text return l10n plugin loading failed short name filename getshorttext pluginloadingfailedshort public string get text return l10n plugin loading failed with message new string name message new string filename message gettext pluginloadingfailedwithmessage public string get title return l10n plugin loading failed title gettitle pluginloadingfailedtitle public object get user identifier return plugin manager class getuseridentifier pluginmanager public boolean is event notification return false iseventnotification public boolean is valid boolean success synchronized plugin wrappers success plugins failed load contains filename if success core alerts unregister this return success isvalid pluginwrappers pluginsfailedload public void is valid boolean validity isvalid public boolean should unregister on dismiss return true shouldunregisterondismiss public boolean user can dismiss return true usercandismiss void register fred plugin plug plugin info wrapper pi handles f proxy if so register if pi is pproxy plugin register toadlet plug if pi isip detector plugin node ip detector registerip detector plugin fred pluginip detector plug if pi is port forward plugin node ip detector register port forward plugin fred plugin port forward plug if pi is bandwidth indicator node ip detector register bandwidth indicator plugin fred plugin bandwidth indicator plug fredplugin plugininfowrapper fproxy ispproxyplugin registertoadlet isipdetectorplugin ipdetector registeripdetectorplugin fredpluginipdetector isportforwardplugin ipdetector registerportforwardplugin fredpluginportforward isbandwidthindicator ipdetector registerbandwidthindicatorplugin fredpluginbandwidthindicator returns the translation of the given key prefixed by the short name of the current class param key the key to fetch return the translation private string l10n string key return l10n get string plugin manager key getstring pluginmanager private string l10n string key string pattern string value return l10n get string plugin manager key pattern value getstring pluginmanager returns the translation of the given key replacing each occurence of code em pattern em code with code value code param key the key to fetch param patterns the patterns to replace param values the values to substitute return the translation private string l10n string key string patterns string values return l10n get string plugin manager key patterns values getstring pluginmanager private void register toadlet fred plugin pl toadlet list put e get stack trace 1 get class to string pl synchronized toadlet list toadlet list put pl get class get name pl logger normal this added http handler for plugins pl get class get name registertoadlet fredplugin toadletlist getstacktrace getclass tostring toadletlist toadletlist getclass getname getclass getname remove a plugin from the plugin list public void remove plugin plugin info wrapper pi synchronized plugin wrappers if plugin wrappers remove pi return core store config removeplugin plugininfowrapper pluginwrappers pluginwrappers storeconfig removes the cached copy of the given plugin from the plugins directory param plugin specification the plugin specification public void remove cached copy string plugin specification int last slash plugin specification last index of file plugin file if last slash 1 windows maybe last slash plugin specification last index of file plugin directory new file node get node dir plugins if last slash 1 it s an official plugin plugin file new file plugin directory plugin specification jar else plugin file new file plugin directory plugin specification substring last slash 1 if logdebug logger minor this delete plugin plugname plugin specification filename plugin file get absolute path new exception debug if plugin file exists plugin file delete pluginspecification removecachedcopy pluginspecification lastslash pluginspecification lastindexof pluginfile lastslash lastslash pluginspecification lastindexof plugindirectory getnodedir lastslash pluginfile plugindirectory pluginspecification pluginfile plugindirectory pluginspecification lastslash pluginspecification pluginfile getabsolutepath pluginfile pluginfile public void unregister plugin toadlet plugin info wrapper pi synchronized toadlet list try toadlet list remove pi get plugin class name logger normal this removed http handler for plugins pi get plugin class name new exception debug catch throwable ex logger error this removing plugin ex unregisterplugintoadlet plugininfowrapper toadletlist toadletlist getpluginclassname getpluginclassname public void add toadlet symlinks plugin info wrapper pi synchronized toadlet list try string targets pi get plugin toadlet symlinks if targets null return for int i 0 i targets length i toadlet list remove targets i logger normal this removed http symlink targets i plugins pi get plugin class name catch throwable ex logger error this removing toadlet link ex addtoadletsymlinks plugininfowrapper toadletlist getplugintoadletsymlinks toadletlist getpluginclassname public void remove toadlet symlinks plugin info wrapper pi synchronized toadlet list string rm null try string targets pi get plugin toadlet symlinks if targets null return for int i 0 i targets length i rm targets i toadlet list remove targets i pi remove plugin toadlet symlink targets i logger normal this removed http symlink targets i plugins pi get plugin class name catch throwable ex logger error this removing toadlet link rm ex removetoadletsymlinks plugininfowrapper toadletlist getplugintoadletsymlinks toadletlist removeplugintoadletsymlink getpluginclassname public string dump plugins string builder out new string builder synchronized plugin wrappers for int i 0 i plugin wrappers size i plugin info wrapper pi plugin wrappers get i out append pi to string out append n return out to string dumpplugins stringbuilder stringbuilder pluginwrappers pluginwrappers plugininfowrapper pluginwrappers tostring tostring public set plugin info wrapper get plugins hash set plugin info wrapper out new hash set plugin info wrapper synchronized plugin wrappers for int i 0 i plugin wrappers size i plugin info wrapper pi plugin wrappers get i out add pi return out plugininfowrapper getplugins hashset plugininfowrapper hashset plugininfowrapper pluginwrappers pluginwrappers plugininfowrapper pluginwrappers look for plugin info for a fcp plugin with given classname param plugname return the plugin info or null if not found public plugin info wrapper getfcp plugin info string plugname synchronized plugin wrappers for int i 0 i plugin wrappers size i plugin info wrapper pi plugin wrappers get i if pi get plugin class name equals plugname return pi return null plugininfo fcpplugin plugininfo plugininfowrapper getfcpplugininfo pluginwrappers pluginwrappers plugininfowrapper pluginwrappers getpluginclassname look for a fcp plugin with given classname param plugname return the plugin or null if not found public fred pluginfcp getfcp plugin string plugname synchronized plugin wrappers for int i 0 i plugin wrappers size i plugin info wrapper pi plugin wrappers get i if pi isfcp plugin pi get plugin class name equals plugname return fred pluginfcp pi plug return null fcpplugin fredpluginfcp getfcpplugin pluginwrappers pluginwrappers plugininfowrapper pluginwrappers isfcpplugin getpluginclassname fredpluginfcp look for a plugin with given classname param plugname return the true if not found public boolean is plugin loaded string plugname synchronized plugin wrappers for int i 0 i plugin wrappers size i plugin info wrapper pi plugin wrappers get i if pi get plugin class name equals plugname return true return false ispluginloaded pluginwrappers pluginwrappers plugininfowrapper pluginwrappers getpluginclassname public string handlehttp get string plugin http request request throws pluginhttp exception fred plugin handler null synchronized toadlet list handler toadlet list get plugin if handler null return null class loader old class loader thread current thread get context class loader class loader plugin class loader handler get class get class loader thread current thread set context class loader plugin class loader try if handler instanceof fred pluginhttp return fred pluginhttp handler handlehttp get request finally thread current thread set context class loader old class loader throw new not found pluginhttp exception plugin not found plugins handlehttpget httprequest pluginhttpexception fredplugin toadletlist toadletlist classloader oldclassloader currentthread getcontextclassloader classloader pluginclassloader getclass getclassloader currentthread setcontextclassloader pluginclassloader fredpluginhttp fredpluginhttp handlehttpget currentthread setcontextclassloader oldclassloader notfoundpluginhttpexception public string handlehttp post string plugin http request request throws pluginhttp exception fred plugin handler null synchronized toadlet list handler toadlet list get plugin if handler null throw new not found pluginhttp exception plugin plugin not found plugins class loader old class loader thread current thread get context class loader class loader plugin class loader handler get class get class loader thread current thread set context class loader plugin class loader try if handler instanceof fred pluginhttp return fred pluginhttp handler handlehttp post request finally thread current thread set context class loader old class loader throw new not found pluginhttp exception plugin plugin not found plugins handlehttppost httprequest pluginhttpexception fredplugin toadletlist toadletlist notfoundpluginhttpexception classloader oldclassloader currentthread getcontextclassloader classloader pluginclassloader getclass getclassloader currentthread setcontextclassloader pluginclassloader fredpluginhttp fredpluginhttp handlehttppost currentthread setcontextclassloader oldclassloader notfoundpluginhttpexception public void kill plugin string name int max wait time plugin info wrapper pi null boolean found false synchronized plugin wrappers for int i 0 i plugin wrappers size found i pi plugin wrappers get i if pi get thread name equals name found true break if found pi stop plugin this max wait time killplugin maxwaittime plugininfowrapper pluginwrappers pluginwrappers pluginwrappers getthreadname stopplugin maxwaittime public void kill plugin fred plugin plugin int max wait time plugin info wrapper pi null boolean found false synchronized plugin wrappers for int i 0 i plugin wrappers size found i pi plugin wrappers get i if pi plug plugin found true if found pi stop plugin this max wait time killplugin fredplugin maxwaittime plugininfowrapper pluginwrappers pluginwrappers pluginwrappers stopplugin maxwaittime official plugin description string name boolean essential long min ver this name name this essential essential this minimum version min ver officialplugindescription minver minimumversion minver static void add official plugin string name official plugins put name new official plugin description name false 1 addofficialplugin officialplugins officialplugindescription static void add official plugin string name boolean essential long min ver official plugins put name new official plugin description name essential min ver addofficialplugin minver officialplugins officialplugindescription minver returns a list of the names of all available official plugins right now this list is hardcoded but in future we could retrieve this list from emu or from freenet itself return a list of all available plugin names public list string find available plugins list string available plugins new array list string available plugins add all official plugins key set return available plugins findavailableplugins availableplugins arraylist availableplugins addall officialplugins keyset availableplugins public boolean is official plugin string name if name null name trim length 0 return false list string available plugins find available plugins for string n available plugins if n equals name return true return false isofficialplugin availableplugins findavailableplugins availableplugins tries to load a plugin from the given name if the name only contains the name of a plugin it is loaded from the plugin directory if found otherwise it s loaded from the project server if the name contains a complete url and the short file already exists in the plugin directory it s loaded from the plugin directory otherwise it s retrieved from the remote server param pdl param name the specification of the plugin return an instanciated object of the plugin throws plugin not found exception if anything goes wrong private fred plugin load plugin plugin down loader pdl string name throws plugin not found exception pdl set source name check for plugin directory file plugin directory new file node get node dir plugins if plugin directory exists plugin directory is directory plugin directory exists plugin directory mkdirs logger error this could not create plugin directory throw new plugin not found exception could not create plugin directory get plugin filename string filename pdl get plugin name name file plugin file new file plugin directory filename check if file needs to be downloaded if logminor logger minor this plugin file plugin file get absolute path exists plugin file exists downloader pdl name name int retries 5 for int i 0 i retries i if plugin file exists plugin file length 0 try system err println downloading plugin name wrapper manager signal starting 5 60 1000 file temp plugin file null output stream plugin output stream null input stream plugin input stream null try temp plugin file file create temp file plugin jar plugin directory temp plugin file delete on exit plugin output stream new file output stream temp plugin file plugin input stream pdl get input stream byte buffer new byte 1024 int read while read plugin input stream read buffer 1 plugin output stream write buffer 0 read plugin output stream close if temp plugin file length 0 throw new plugin not found exception downloaded zero length file if file util rename to temp plugin file plugin file logger error this could not rename temp file to plugin file throw new plugin not found exception could not rename temp file to plugin file try strongest first string testsum null string digest pdl getsha256sum if digest null digest pdl getsha1sum else testsum get file digest plugin file sha 256 if digest null testsum null testsum get file digest plugin file sha 1 if digest null if digest equals ignore case testsum logger error this checksum verification failed should be digest but was testsum throw new plugin not found exception checksum verification failed should be digest but was testsum catch io exception ioe1 logger error this could not load plugin ioe1 if temp plugin file null temp plugin file delete throw new plugin not found exception could not load plugin ioe1 get message ioe1 finally closer close plugin output stream closer close plugin input stream catch plugin not found exception e if i retries 1 logger normal this failed to load plugin e e continue else throw e we do quite a lot inside the lock use a dedicated one synchronized plugin load sync object if this is plugin loaded filename logger error this plugin already loaded filename return null now get the manifest file jar file plugin jar file null string plugin main class name null try plugin jar file new jar file plugin file manifest manifest plugin jar file get manifest if manifest null logger error this could not load manifest from plugin file plugin file delete throw new plugin not found exception could not load manifest from plugin file attributes main attributes manifest get main attributes if main attributes null logger error this manifest does not contain attributes plugin file delete throw new plugin not found exception manifest does not contain attributes plugin main class name main attributes get value plugin main class if plugin main class name null logger error this manifest does not contain a plugin main class attribute plugin file delete throw new plugin not found exception manifest does not contain a plugin main class attribute catch jar exception je1 logger error this could not process jar file je1 plugin file delete throw new plugin not found exception could not process jar file je1 catch zip exception ze1 logger error this could not process jar file ze1 plugin file delete throw new plugin not found exception could not process jar file ze1 catch io exception ioe1 logger error this error processing jar file ioe1 plugin file delete throw new plugin not found exception error procesesing jar file ioe1 finally closer close plugin jar file try jar class loader jar class loader new jar class loader plugin file class plugin main class jar class loader load class plugin main class name object object plugin main class new instance if object instanceof fred plugin logger error this plugin main class is not a plugin plugin file delete throw new plugin not found exception plugin main class is not a plugin if object instanceof fred plugin with class loader fred plugin with class loader object set class loader jar class loader if pdl instanceof plugin down loader official system err println loading official plugin name check the version after loading it building it into the manifest would be better in that it would avoid having to unload but building it into the manifest is problematic specifically it involves either platform specific scripts that aren t distributed and devs won t use when they build locally or executing java code which would mean we have to protect the versioning info either way is bad the latter is less bad if we don t auto build ugh this is just as messy ideas maybe we need to have os detection and use grep sed on unix and find on windows official plugin description desc official plugins get name long min ver desc minimum version long ver 1 if min ver 1 if object instanceof fred plugin real versioned ver fred plugin real versioned object get real version if ver min ver system err println failed to load plugin name too old need at least version min ver but is ver logger error this failed to load plugin name too old need at least version min ver but is ver try if object instanceof fred plugin threadless fred plugin object run plugin new plugin respirator node plugin manager this fred plugin object catch throwable t logger error this failed to start plugin to prevent np es while terminating it because it is too old t t try fred plugin object terminate catch throwable t logger error this plugin failed to terminate t t try jar class loader close catch throwable t logger error this failed to close jar classloader for plugin t t throw new plugin not found exception plugin too old need at least version min ver return fred plugin object catch io exception ioe1 logger error this could not load plugin ioe1 plugin file delete throw new plugin not found exception could not load plugin ioe1 catch class not found exception cnfe1 logger error this could not find plugin class cnfe1 plugin file delete throw new plugin not found exception could not find plugin class cnfe1 catch instantiation exception ie1 logger error this could not instantiate plugin ie1 plugin file delete throw new plugin not found exception could not instantiate plugin ie1 catch illegal access exception iae1 logger error this could not access plugin main class iae1 plugin file delete throw new plugin not found exception could not access plugin main class iae1 catch no class def found error ncdfe1 logger error this could not find class def may a missing lib ncdfe1 plugin file delete throw new plugin not found exception could not find class def may a missing lib ncdfe1 catch throwable t logger error this unexpected error while plugin loading t plugin file delete throw new plugin not found exception unexpected error while plugin loading t t pluginnotfoundexception fredplugin loadplugin plugindownloader pluginnotfoundexception setsource plugindirectory getnodedir plugindirectory plugindirectory isdirectory plugindirectory plugindirectory pluginnotfoundexception getpluginname pluginfile plugindirectory pluginfile getabsolutepath pluginfile pluginfile pluginfile wrappermanager signalstarting temppluginfile outputstream pluginoutputstream inputstream plugininputstream temppluginfile createtempfile plugindirectory temppluginfile deleteonexit pluginoutputstream fileoutputstream temppluginfile plugininputstream getinputstream plugininputstream pluginoutputstream pluginoutputstream temppluginfile pluginnotfoundexception fileutil renameto temppluginfile pluginfile pluginnotfoundexception getfiledigest pluginfile getfiledigest pluginfile equalsignorecase pluginnotfoundexception ioexception temppluginfile temppluginfile pluginnotfoundexception getmessage pluginoutputstream plugininputstream pluginnotfoundexception pluginloadsyncobject ispluginloaded jarfile pluginjarfile pluginmainclassname pluginjarfile jarfile pluginfile pluginjarfile getmanifest pluginfile pluginnotfoundexception mainattributes getmainattributes mainattributes pluginfile pluginnotfoundexception pluginmainclassname mainattributes getvalue pluginmainclassname pluginfile pluginnotfoundexception jarexception pluginfile pluginnotfoundexception zipexception pluginfile pluginnotfoundexception ioexception pluginfile pluginnotfoundexception pluginjarfile jarclassloader jarclassloader jarclassloader pluginfile pluginmainclass jarclassloader loadclass pluginmainclassname pluginmainclass newinstance fredplugin pluginfile pluginnotfoundexception fredpluginwithclassloader fredpluginwithclassloader setclassloader jarclassloader plugindownloaderofficial officialplugindescription officialplugins minver minimumversion minver fredpluginrealversioned fredpluginrealversioned getrealversion minver minver minver fredpluginthreadless fredplugin runplugin pluginrespirator pluginmanager fredplugin npes fredplugin jarclassloader pluginnotfoundexception minver fredplugin ioexception pluginfile pluginnotfoundexception classnotfoundexception pluginfile pluginnotfoundexception instantiationexception pluginfile pluginnotfoundexception illegalaccessexception pluginfile pluginnotfoundexception noclassdeffounderror pluginfile pluginnotfoundexception pluginfile pluginnotfoundexception private string get file digest file file string digest throws plugin not found exception final int buffersize 4096 message digest hash null file input stream fis null buffered input stream bis null boolean was from digest256 pool false string result try if sha 256 equals digest hash sha256 get message digest grab digest from pool was from digest256 pool true else hash message digest get instance digest we compute the hash http java sun com developer tech tips 1998 tt0915 html tip2 fis new file input stream file bis new buffered input stream fis int len 0 byte buffer new byte buffersize while len bis read buffer 1 hash update buffer 0 len result hex util bytes to hex hash digest if was from digest256 pool sha256 return message digest hash catch exception e throw new plugin not found exception error while computing hash digest of the downloaded plugin e e finally closer close bis closer close fis return result getfiledigest pluginnotfoundexception messagedigest fileinputstream bufferedinputstream wasfromdigest256pool getmessagedigest wasfromdigest256pool messagedigest getinstance techtips fileinputstream bufferedinputstream hexutil bytestohex wasfromdigest256pool returnmessagedigest pluginnotfoundexception ticker get ticker return node get ticker getticker getticker private constructor for state constants private plugin progress pluginprogress creates a new progress tracker for a plugin that is loaded by the given name param name the name by which the plugin is loaded plugin progress string name this name name plugin progress downloading pluginprogress pluginprogress returns the number of milliseconds this plugin is already being loaded return the time this plugin is already being loaded in milliseconds public long get time return system current time millis starting time gettime currenttimemillis startingtime returns the name by which the plugin is loaded return the name by which the plugin is loaded public string get name return name getname returns the current state of the plugin start procedure return the current state of the plugin public plugin progress get progress return plugin progress pluginprogress getprogress pluginprogress sets the current state of the plugin start procedure param plugin progress the current state void set progress plugin progress plugin progress this plugin progress plugin progress pluginprogress setprogress pluginprogress pluginprogress pluginprogress pluginprogress if this object is one of the constants link downloading or link starting the name of those constants will be returned otherwise a textual representation of the plugin progress is returned return the name of a constant or the plugin progress override public string to string if this downloading return downloading else if this starting return starting return plugin progress name name starting time starting time progress plugin progress tostring pluginprogress startingtime startingtime pluginprogress public void setf proxy theme final theme css name if fproxy theme equals css name return fproxy theme css name synchronized plugin wrappers for plugin info wrapper pi plugin wrappers pi pr get page maker set theme css name if pi is themed plugin final fred plugin themed plug fred plugin themed pi plug executor execute new runnable public void run try plug set theme css name catch throwable t logger error this cought trowable in callback t callback setfproxytheme cssname fproxytheme cssname fproxytheme cssname pluginwrappers plugininfowrapper pluginwrappers getpagemaker settheme cssname isthemedplugin fredpluginthemed fredpluginthemed settheme cssname executor execute new runnable public void run try plug set theme css name catch throwable t logger error this cought trowable in callback t settheme cssname public static void set language language lang if selfinstance null return selfinstance set plugin language lang setlanguage setpluginlanguage private void set plugin language final language lang synchronized plugin wrappers for plugin info wrapper pi plugin wrappers if pi isl10n plugin final fred pluginl10n plug fred pluginl10n pi plug executor execute new runnable public void run try plug set language lang catch throwable t logger error this cought trowable in callback t callback setpluginlanguage pluginwrappers plugininfowrapper pluginwrappers isl10nplugin fredpluginl10n fredpluginl10n setlanguage executor execute new runnable public void run try plug set language lang catch throwable t logger error this cought trowable in callback t setlanguage public theme getf proxy theme return fproxy theme getfproxytheme fproxytheme static logger register log threshold callback new log threshold callback override public void should update logminor logger should log logger minor this registerlogthresholdcallback logthresholdcallback shouldupdate shouldlog public final file seedfile a file to which seed data should be dumped periodically public yarrow this prng seed sha1 rijndael true true public yarrow boolean can block this prng seed sha1 rijndael true can block canblock canblock public yarrow string seed string digest string cipher boolean update seed boolean can block this new file seed digest cipher update seed can block updateseed canblock updateseed canblock public yarrow file seed string digest string cipher boolean update seed boolean can block this seed digest cipher update seed can block true updateseed canblock updateseed canblock unset reseed on startup only in unit test yarrow file seed string digest string cipher boolean update seed boolean can block boolean reseed on startup secure random s try s secure random get instance sha1prng catch no such algorithm exception e s null sr s try accumulator init digest reseed init digest generator init cipher catch no such algorithm exception e logger error this could not init pools trying to get instance digest e e throw new runtime exception cannot initialize yarrow e e if update seed seed to string equals dev urandom dont try to update the seedfile if we know that it wont be possible anyways seedfile seed else seedfile null if reseed on startup entropy init seed reseed on startup seed from external stuff can block if we don t reseed at this point we will be predictable because the startup entropy won t cause a reseed fast pool reseed slow pool reseed else read seed seed reseedonstartup updateseed canblock reseedonstartup securerandom securerandom getinstance nosuchalgorithmexception accumulator_init reseed_init generator_init nosuchalgorithmexception getinstance runtimeexception updateseed tostring reseedonstartup entropy_init reseedonstartup seedfromexternalstuff canblock fast_pool_reseed slow_pool_reseed read_seed private void seed from external stuff boolean can block byte buf new byte 32 if file separator char data input stream dis null file input stream fis null file hwrng new file dev hwrng if hwrng exists hwrng can read try fis new file input stream hwrng dis new data input stream fis dis read fully buf consume bytes buf dis read fully buf consume bytes buf dis close catch throwable t logger normal this can t read dev hwrng even though exists and is readable t t finally closer close dis closer close fis boolean is system entropy available true read some bits from dev urandom try fis new file input stream dev urandom dis new data input stream fis dis read fully buf consume bytes buf dis read fully buf consume bytes buf catch throwable t logger normal this can t read dev urandom t t we can t read it let s skip dev random and seed from secure random generate seed can block true is system entropy available false finally closer close dis closer close fis if can block is system entropy available read some bits from dev random try fis new file input stream dev random dis new data input stream fis dis read fully buf consume bytes buf dis read fully buf consume bytes buf catch throwable t logger normal this can t read dev random t t finally closer close dis closer close fis fis null else force generate seed since we can t read random data from anywhere else anyway windows s capi won t block can block true if can block secure random hopefully acts as a proxy for capi on windows buf sr generate seed 32 consume bytes buf buf sr generate seed 32 consume bytes buf a few more bits consume string long to hex string runtime get runtime free memory consume string long to hex string runtime get runtime total memory seedfromexternalstuff canblock separatorchar datainputstream fileinputstream canread fileinputstream datainputstream readfully consumebytes readfully consumebytes issystementropyavailable fileinputstream datainputstream readfully consumebytes readfully consumebytes securerandom generateseed canblock issystementropyavailable canblock issystementropyavailable fileinputstream datainputstream readfully consumebytes readfully consumebytes generateseed canblock canblock securerandom generateseed consumebytes generateseed consumebytes consumestring tohexstring getruntime freememory consumestring tohexstring getruntime totalmemory private void entropy init file seed boolean reseed on startup if reseed on startup properties sys system get properties entropy source startup entropy new entropy source consume the system properties list for enumeration enu sys property names enu has more elements string key string enu next element consume string key consume string sys get property key consume the local ip address try consume string inet address get local host to string catch exception e ignore read startup entropy startup entropy read seed seed entropy_init reseedonstartup reseedonstartup getproperties entropysource startupentropy entropysource propertynames hasmoreelements nextelement consumestring consumestring getproperty consumestring inetaddress getlocalhost tostring readstartupentropy startupentropy read_seed protected void read startup entropy entropy source startup entropy consume the current time accept entropy startup entropy system current time millis 0 accept entropy startup entropy system nano time 0 free memory accept entropy startup entropy runtime get runtime free memory 0 total memory accept entropy startup entropy runtime get runtime total memory 0 readstartupentropy entropysource startupentropy acceptentropy startupentropy currenttimemillis acceptentropy startupentropy nanotime acceptentropy startupentropy getruntime freememory acceptentropy startupentropy getruntime totalmemory seed handling private void read seed file filename file input stream fis null buffered input stream bis null data input stream dis null try fis new file input stream filename bis new buffered input stream fis dis new data input stream bis entropy source seed file new entropy source try for int i 0 i 32 i accept entropy seed file dis read long 64 catch eof exception f dis close catch io exception e logger error this ioe trying to read the seedfile from disk e get message finally closer close dis closer close bis closer close fis fast pool reseed read_seed fileinputstream bufferedinputstream datainputstream fileinputstream bufferedinputstream datainputstream entropysource seedfile entropysource acceptentropy seedfile readlong eofexception ioexception getmessage fast_pool_reseed private long time last wrote seed 1 private void write seed file filename write seed filename false timelastwroteseed write_seed write_seed public void write seed file filename boolean force if force synchronized this long now system current time millis if now time last wrote seed 60 60 1000 once per hour return else time last wrote seed now file output stream fos null buffered output stream bos null data output stream dos null try fos new file output stream filename bos new buffered output stream fos dos new data output stream bos for int i 0 i 32 i dos write long next long dos flush dos close catch io exception e logger error this ioe while saving the seed file e get message finally closer close dos closer close bos closer close fos write_seed currenttimemillis timelastwroteseed timelastwroteseed fileoutputstream bufferedoutputstream dataoutputstream fileoutputstream bufferedoutputstream dataoutputstream writelong nextlong ioexception getmessage private void generator init string cipher cipher ctx util get cipher by name cipher output buffer new byte cipher ctx get block size 8 counter new byte cipher ctx get block size 8 all zero string new byte cipher ctx get block size 8 tmp new byte cipher ctx get key size 8 fetch counter output buffer length generator_init cipher_ctx getcipherbyname output_buffer cipher_ctx getblocksize cipher_ctx getblocksize allzerostring cipher_ctx getblocksize cipher_ctx getkeysize fetch_counter output_buffer private final void counter inc for int i counter length 1 i 0 i if counter i 0 break counterinc private final void generate output counter inc output buffer new byte counter length cipher ctx encipher counter output buffer if output count pg output count 0 next bytes tmp rekey tmp generateoutput counterinc output_buffer cipher_ctx output_buffer output_count output_count nextbytes private void rekey byte key cipher ctx initialize key counter new byte all zero string length cipher ctx encipher all zero string counter arrays fill key byte 0 cipher_ctx allzerostring cipher_ctx allzerostring an offset to the bytes private synchronized int get bytes int count if fetch counter count output buffer length fetch counter 0 generate output return get bytes count int rv fetch counter fetch counter count return rv getbytes fetch_counter output_buffer fetch_counter generateoutput getbytes fetch_counter fetch_counter when this was not synchronized we were getting repeats override protected synchronized int next int bits int parameters bit table bits int offset get bytes parameters 0 int val output buffer offset if parameters 0 4 val output buffer offset 1 24 output buffer offset 2 16 output buffer offset 3 8 else if parameters 0 3 val output buffer offset 1 16 output buffer offset 2 8 else if parameters 0 2 val output buffer offset 2 8 return val parameters 1 bittable getbytes output_buffer output_buffer output_buffer output_buffer output_buffer output_buffer output_buffer private void accumulator init string digest throws no such algorithm exception fast pool message digest get instance digest slow pool message digest get instance digest entropy seen new hash map entropy source int accumulator_init nosuchalgorithmexception fast_pool messagedigest getinstance slow_pool messagedigest getinstance entropyseen hashmap entropysource override public int accept entropy entropy source source long data int entropy guess return accept entropy source data entropy guess 1 0 acceptentropy entropysource entropyguess acceptentropy entropyguess override public int accept entropy bytes entropy source source byte buf int offset int length double bias int total real entropy 0 for int i 0 i length i 8 long thingy 0 int bytes 0 for int j 0 j math min length i 8 j thingy thingy 8 buf j bytes total real entropy accept entropy source thingy bytes 8 bias return total real entropy acceptentropybytes entropysource totalrealentropy totalrealentropy acceptentropy totalrealentropy private int accept entropy entropy source source long data int entropy guess double bias return accept entropy data source int bias math min 32 math min estimate entropy source data entropy guess acceptentropy entropysource entropyguess accept_entropy estimateentropy entropyguess private int accept entropy long data entropy source source int actual entropy boolean performed pool reseed false byte b new byte byte data byte data 8 byte data 16 byte data 24 byte data 32 byte data 40 byte data 48 byte data 56 synchronized this fast select fast select message digest pool fast select fast pool slow pool pool update b if fast select fast entropy actual entropy if fast entropy fast threshold fast pool reseed performed pool reseed true else slow entropy actual entropy if source null int contributed entropy entropy seen get source if contributed entropy null contributed entropy new int actual entropy entropy seen put source contributed entropy else contributed entropy 0 actual entropy if slow entropy slow threshold 2 int kc 0 for map entry entropy source int e entropy seen entry set entropy source key e get key int v e get value if debug logger normal this key key v if v 0 slow threshold kc if kc slow k slow pool reseed performed pool reseed true break if debug core logger log this fast pool fast entropy t slow pool slow entropy logger normal system err println fast pool fast entropy t slow pool slow entropy if performed pool reseed seedfile null dont do this while synchronized on this since opening a file seems to be suprisingly slow on windows if logminor logger minor this writing seedfile write seed seedfile if logminor logger minor this written seedfile return actual entropy accept_entropy entropysource actualentropy performedpoolreseed fast_select fast_select messagedigest fast_select fast_pool slow_pool fast_select fast_entropy actualentropy fast_entropy fast_threshold fast_pool_reseed performedpoolreseed slow_entropy actualentropy contributedentropy entropyseen contributedentropy contributedentropy actualentropy entropyseen contributedentropy contributedentropy actualentropy slow_entropy slow_threshold entropysource entropyseen entryset entropysource getkey getvalue slow_threshold slow_k slow_pool_reseed performedpoolreseed fast_entropy tslow slow_entropy fast_entropy tslow slow_entropy performedpoolreseed write_seed actualentropy private int estimate entropy entropy source source long new val int delta int new val source last val int delta2 delta source last delta source last delta delta int delta3 delta2 source last delta2 source last delta2 delta2 if delta 0 delta delta if delta2 0 delta2 delta2 if delta3 0 delta3 delta3 if delta delta2 delta delta2 if delta delta3 delta delta3 delta is now minimum absolute delta round down by 1 bit on general principles and limit entropy entimate to 12 bits delta 1 delta 1 12 1 smear msbit right to make an n bit mask delta delta 8 delta delta 4 delta delta 2 delta delta 1 remove one bit to make this a logarithm delta 1 count the bits set in the word delta delta 1 0x555 delta delta 0x333 delta 2 0x333 delta delta 4 delta delta 8 source last val new val return delta 15 estimateentropy entropysource newval newval lastval lastdelta lastdelta lastdelta2 lastdelta2 lastval newval override public int accept timer entropy entropy source timer return accept timer entropy timer 1 0 accepttimerentropy entropysource accepttimerentropy override public int accept timer entropy entropy source timer double bias long now system current time millis return accept entropy timer now timer last val 32 bias accepttimerentropy entropysource currenttimemillis acceptentropy lastval if entropy estimation is supported this method will block until the specified number of bits of entropy are available if estimation isn t supported this method will return immediately override public void wait for entropy int bits waitforentropy private message digest reseed ctx private void reseed init string digest throws no such algorithm exception reseed ctx message digest get instance digest messagedigest reseed_ctx reseed_init nosuchalgorithmexception reseed_ctx messagedigest getinstance private void fast pool reseed long start time system current time millis byte v0 fast pool digest byte vi v0 for byte i 0 i pt i reseed ctx update vi 0 vi length reseed ctx update v0 0 v0 length reseed ctx update i vi reseed ctx digest v pt vi util make key vi tmp 0 tmp length rekey tmp arrays fill v0 byte 0 blank out for security fast entropy 0 if debug long end time system current time millis if end time start time 5000 logger normal this fast pool reseed took end time start time ms fast_pool_reseed starttime currenttimemillis fast_pool reseed_ctx reseed_ctx reseed_ctx reseed_ctx vpt makekey fast_entropy endtime currenttimemillis endtime starttime endtime starttime private void slow pool reseed byte slow hash slow pool digest fast pool update slow hash 0 slow hash length fast pool reseed slow entropy 0 entropy seen clear slow_pool_reseed slow_hash slow_pool fast_pool slow_hash slow_hash fast_pool_reseed slow_entropy entropyseen if the random source has any resources it wants to close it can do so when this method is called override public void close randomsource test routine public static void main string args throws exception yarrow r new yarrow new file dev urandom sha1 rijndael true false byte b new byte 1024 if args length 0 args 0 equals ignore case latency if args length 2 b new byte integer parse int args 1 long start system current time millis for int i 0 i 100 i r next bytes b system out println double system current time millis start 100 b length 1024 ms k start system current time millis for int i 0 i 1000 i r next int system out println double system current time millis start 1000 ms int start system current time millis for int i 0 i 1000 i r next long system out println double system current time millis start 1000 ms long else if args 0 equals ignore case randomness int kb integer parse int args 1 for int i 0 i kb i r next bytes b system out write b else if args 0 equals ignore case gathering system gc entropy source t new entropy source long start system current time millis for int i 0 i 100000 i r accept entropy t system current time millis 32 system err println double system current time millis start 100000 system gc start system current time millis for int i 0 i 100000 i r accept timer entropy t system err println double system current time millis start 100000 else if args 0 equals ignore case volume b new byte 1020 long duration system current time millis integer parse int args 1 while system current time millis duration r next bytes b system out write b else if args 0 equals stream rand file f new rand file args 1 entropy source rf new entropy source byte buffer new byte 131072 while true r accept entropy rf f next long 32 r next bytes buffer system out write buffer else if args 0 equals ignore case bitstream while true int v r next int for int i 0 i 32 i if v i 1 1 system out print 1 else system out print 0 else if args 0 equals ignore case sample if args length 1 args 1 equals general system out println next int for int i 0 i 3 i system out println r next int system out println next long for int i 0 i 3 i system out println r next long system out println next float for int i 0 i 3 i system out println r next float system out println next double for int i 0 i 3 i system out println r next double system out println next full float for int i 0 i 3 i system out println r next full float system out println next full double for int i 0 i 3 i system out println r next full double else if args 1 equals normalized for int i 0 i 20 i system out println r next double equalsignorecase parseint currenttimemillis nextbytes currenttimemillis currenttimemillis nextint currenttimemillis currenttimemillis nextlong currenttimemillis equalsignorecase parseint nextbytes equalsignorecase entropysource entropysource currenttimemillis acceptentropy currenttimemillis currenttimemillis currenttimemillis accepttimerentropy currenttimemillis equalsignorecase currenttimemillis parseint currenttimemillis nextbytes randfile randfile entropysource entropysource acceptentropy nextlong nextbytes equalsignorecase nextint equalsignorecase nextint nextint nextlong nextlong nextfloat nextfloat nextdouble nextdouble nextfullfloat nextfullfloat nextfulldouble nextfulldouble nextdouble private void consume string string str byte b try b str get bytes utf 8 catch unsupported encoding exception e throw new error impossible jvm doesn t support utf 8 e e consume bytes b consumestring getbytes unsupportedencodingexception consumebytes private void consume bytes byte bytes if fast select fast pool update bytes 0 bytes length else slow pool update bytes 0 bytes length fast select fast select consumebytes fast_select fast_pool slow_pool fast_select fast_select logger register log threshold callback new log threshold callback override public void should update logminor logger should log logger minor this registerlogthresholdcallback logthresholdcallback shouldupdate shouldlog private final string possible values new string client request scheduler priority hard client request scheduler priority soft priority scheduler callback client request scheduler cs this cs cs possiblevalues clientrequestscheduler priority_hard clientrequestscheduler priority_soft priorityschedulercallback clientrequestscheduler override public string get if cs null return cs get choosen priority scheduler else return client request scheduler priority hard getchoosenpriorityscheduler clientrequestscheduler priority_hard override public void set string val throws invalid config value exception string value if val null val equals ignore case get return if val equals ignore case client request scheduler priority hard value client request scheduler priority hard else if val equals ignore case client request scheduler priority soft value client request scheduler priority soft else throw new invalid config value exception invalid priority scheme cs set priority scheduler value invalidconfigvalueexception equalsignorecase equalsignorecase clientrequestscheduler priority_hard clientrequestscheduler priority_hard equalsignorecase clientrequestscheduler priority_soft clientrequestscheduler priority_soft invalidconfigvalueexception setpriorityscheduler public string get possible values return possible values getpossiblevalues possiblevalues public client request scheduler boolean for inserts boolean forss ks random source random request starter starter node node node client core core sub config sc string name client context context this is insert scheduler for inserts this isssk scheduler forss ks sched core client request scheduler core create node for inserts forss ks node db cooldown period core client database executor this context sched transient new client request scheduler non persistent this for inserts forss ks persistent cooldown queue sched core persistent cooldown queue this database executor core client database executor this datastore checker core store checker this starter starter this random random this node node this client context context this name name sc register name priority policy priority hard name hash code true false request starter group scheduler forss ks ssk chk for inserts inserts requests request starter group scheduler long new priority scheduler callback this this choosen priority scheduler sc get string name priority policy if for inserts offered keys new offered keys list request starter number of priority classes for short i 0 i request starter number of priority classes i offered keys i new offered keys list core random i forss ks else offered keys null if for inserts transient cooldown queue new request cooldown queue cooldown period else transient cooldown queue null job runner client context job runner clientrequestscheduler forinserts forssks randomsource requeststarter nodeclientcore subconfig clientcontext isinsertscheduler forinserts issskscheduler forssks schedcore clientrequestschedulercore forinserts forssks cooldown_period clientdatabaseexecutor schedtransient clientrequestschedulernonpersistent forinserts forssks persistentcooldownqueue schedcore persistentcooldownqueue databaseexecutor clientdatabaseexecutor datastorechecker storechecker clientcontext _priority_policy priority_hard hashcode requeststartergroup forssks forinserts requeststartergroup schedulerlong priorityschedulercallback choosenpriorityscheduler getstring _priority_policy forinserts offeredkeys offeredkeyslist requeststarter number_of_priority_classes requeststarter number_of_priority_classes offeredkeys offeredkeyslist forssks offeredkeys forinserts transientcooldownqueue requestcooldownqueue cooldown_period transientcooldownqueue jobrunner clientcontext jobrunner public static void load key listeners final object container container client context context object set has key listener results db4o bugs query container has key listener class for has key listener l results container activate l 1 try if l is cancelled container continue key listener listener l make key listener container context if listener null if listener isssk context get ssk fetch scheduler add persistent pending keys listener else context get chk fetch scheduler add persistent pending keys listener system err println loaded request key listener listener for l catch key listener construction exception e system err println failed to load request bloom filters e print stack trace logger error client request scheduler core class failed to load request bloom filters e e catch throwable t probably an error on last startup logger error client request scheduler core class failed to load request t t system err println failed to load request t t print stack trace container deactivate l 1 loadkeylisteners objectcontainer clientcontext objectset haskeylistener db4obugs haskeylistener haskeylistener iscancelled keylistener makekeylistener getsskfetchscheduler addpersistentpendingkeys getchkfetchscheduler addpersistentpendingkeys keylistenerconstructionexception printstacktrace clientrequestschedulercore clientrequestschedulercore printstacktrace public void start node client core core sched core start core queue fill request starter queue nodeclientcore schedcore queuefillrequeststarterqueue called by the config callback param val protected synchronized void set priority scheduler string val choosen priority scheduler val setpriorityscheduler choosenpriorityscheduler public void register insert final sendable request req boolean persistent boolean regme only object container container register insert req persistent regme only database executor on thread container registerinsert sendablerequest regmeonly objectcontainer registerinsert regmeonly databaseexecutor onthread public void register insert final sendable request req boolean persistent boolean regme only boolean on database thread object container container if is insert scheduler throw new illegal argument exception adding a sendable insert to a request scheduler if persistent if on database thread if regme only long bootid 0 boolean queue full job runner get queue size native thread norm priority queue threshold if queue full bootid this node bootid final register me regme new register me req req get priority class container sched core null bootid container store regme if logminor logger minor this added insert register me regme if queue full job runner queue new db job public void run object container container client context context container delete regme if req is cancelled container if logminor logger minor this request already cancelled return if container ext is active req logger error this already active req in delayed insert register container activate req 1 register insert req true false true container container deactivate req 1 native thread norm priority false else sched core rerun register me runner job runner container deactivate req 1 return sched core inner register req random container null starter wake up else job runner queue new db job public void run object container container client context context if container ext is active req logger error this already active req in off thread insert register container activate req 1 sched core inner register req random container null container deactivate req 1 native thread norm priority false else sched transient inner register req random null null starter wake up registerinsert sendablerequest regmeonly ondatabasethread objectcontainer isinsertscheduler illegalargumentexception sendableinsert ondatabasethread regmeonly queuefull jobrunner getqueuesize nativethread norm_priority queue_threshold queuefull registerme registerme getpriorityclass schedcore registerme queuefull jobrunner dbjob objectcontainer clientcontext iscancelled isactive registerinsert nativethread norm_priority schedcore rerunregistermerunner jobrunner schedcore innerregister wakeup jobrunner dbjob objectcontainer clientcontext isactive schedcore innerregister nativethread norm_priority schedtransient innerregister wakeup register a group of requests not inserts a got key listener and or one or more sendable get s param listener listens for specific keys can be null if the listener is already registered i e on retrying param getters the actual requests to register to the request sender queue param persistent true if the request is persistent param on database thread true if we are running on the database thread note delayed store check probably not in store is unnecessary because we only register the listener once throws fetch exception public void register final has key listener has listener final sendable get getters final boolean persistent boolean on database thread object container container final block set blocks final boolean no check store throws key listener construction exception if logminor logger minor this register persistent has listener getters if is insert scheduler illegal state exception e new illegal state exception finish register on an insert scheduler throw e if persistent if on database thread inner register has listener getters blocks no check store container else job runner queue new db job public void run object container container client context context register off thread would be pointless because this is a separate job if has listener null if container ext is active has listener logger error this already active in delayed register has listener container activate has listener 1 if getters null for int i 0 i getters length i if container ext is active getters i logger error this already active in delayed register getters i container activate getters i 1 try inner register has listener getters blocks no check store container catch key listener construction exception e logger error this registration failed to create bloom filters e on has listener e if has listener null container deactivate has listener 1 if getters null for int i 0 i getters length i container deactivate getters i 1 native thread norm priority false else final key listener listener if has listener null listener has listener make key listener container client context if listener null sched transient add pending keys listener else logger normal this no key listener for has listener else listener null if getters null no check store for sendable get getter getters datastore checker queue transient request getter blocks else boolean any valid false for int i 0 i getters length i if getters i is cancelled null getters i is empty null any valid true finish register getters false on database thread container any valid null gotkeylistener sendableget ondatabasethread delayedstorecheck probablynotinstore fetchexception haskeylistener haslistener sendableget ondatabasethread objectcontainer blockset nocheckstore keylistenerconstructionexception haslistener isinsertscheduler illegalstateexception illegalstateexception finishregister ondatabasethread innerregister haslistener nocheckstore jobrunner dbjob objectcontainer clientcontext registeroffthread haslistener isactive haslistener haslistener haslistener isactive innerregister haslistener nocheckstore keylistenerconstructionexception haslistener haslistener haslistener nativethread norm_priority keylistener haslistener haslistener makekeylistener clientcontext schedtransient addpendingkeys keylistener haslistener nocheckstore sendableget datastorechecker queuetransientrequest anyvalid iscancelled isempty anyvalid finishregister ondatabasethread anyvalid private void inner register final has key listener has listener final sendable get getters final block set blocks boolean no check store object container container throws key listener construction exception final key listener listener if has listener null listener has listener make key listener container client context sched core add pending keys listener container store has listener else listener null avoid np es due to deactivation if getters null for sendable get getter getters container activate getter 1 container store getter if is insert scheduler throw new illegal state exception finish register on an insert scheduler if no check store check the datastore before proceding for sendable get getter getters container activate getter 1 datastore checker queue persistent request getter blocks container container deactivate getter 1 else we have already checked the datastore this is a retry the listener hasn t been unregistered this finish register getters true true container true null innerregister haskeylistener haslistener sendableget blockset nocheckstore objectcontainer keylistenerconstructionexception keylistener haslistener haslistener makekeylistener clientcontext schedcore addpendingkeys haslistener npes sendableget isinsertscheduler illegalstateexception finishregister nocheckstore sendableget datastorechecker queuepersistentrequest finishregister void finish register final sendable get getters boolean persistent boolean on database thread object container container final boolean any valid final datastore checker item reg if is insert scheduler illegal state exception e new illegal state exception finish register on an insert scheduler if on database thread persistent for int i 0 i getters length i if persistent container activate getters i 1 getters i internal error e this container client context persistent if persistent container deactivate getters i 1 throw e if persistent add to the persistent registration queue if on database thread if database executor on thread throw new illegal state exception not on database thread if persistent container activate getters 1 if logminor logger minor this finish register for getters if any valid boolean were any valid false for int i 0 i getters length i sendable get getter getters i container activate getter 1 if getter is cancelled container getter is empty container were any valid true getter pre register container client context true sched core inner register getter random container getters else getter pre register container client context false if were any valid logger normal this no requests valid getters else logger normal this no valid requests passed in getters if reg null container delete reg maybe fill starter queue container client context getters starter wake up else job runner queue new db job public void run object container container client context context if logminor logger minor this finish register for getters boolean were any valid false for sendable get getter getters if container ext is active getter logger error this already active in delayed finish register getter container activate getter 1 if getter is cancelled container getter is empty container were any valid true getter pre register container client context true sched core inner register getter random container getters else getter pre register container client context false container deactivate getter 1 if were any valid logger normal this no requests valid getters if reg null container delete reg maybe fill starter queue container context getters starter wake up native thread norm priority 1 false else register immediately for int i 0 i getters length i if any valid getters i is cancelled null getters i is empty null getters i pre register container client context false continue else getters i pre register container client context true sched transient inner register getters i random null getters starter wake up finishregister sendableget ondatabasethread objectcontainer anyvalid datastorecheckeritem isinsertscheduler illegalstateexception illegalstateexception finishregister ondatabasethread internalerror clientcontext ondatabasethread databaseexecutor onthread illegalstateexception finishregister anyvalid wereanyvalid sendableget iscancelled isempty wereanyvalid preregister clientcontext schedcore innerregister preregister clientcontext wereanyvalid maybefillstarterqueue clientcontext wakeup jobrunner dbjob objectcontainer clientcontext finishregister wereanyvalid sendableget isactive finishregister iscancelled isempty wereanyvalid preregister clientcontext schedcore innerregister preregister clientcontext wereanyvalid maybefillstarterqueue wakeup nativethread norm_priority anyvalid iscancelled isempty preregister clientcontext preregister clientcontext schedtransient innerregister wakeup private void maybe fill starter queue object container container client context context sendable request might be active synchronized this if starter queue size max starter queue size 2 return fill request starter queue container context might be active maybefillstarterqueue objectcontainer clientcontext sendablerequest mightbeactive starterqueue max_starter_queue_size fillrequeststarterqueue mightbeactive public chosen block get better non persistent request short prio int retry count short fuzz 1 if priority soft equals choosen priority scheduler fuzz 1 else if priority hard equals choosen priority scheduler fuzz 0 return sched core remove first transient fuzz random offered keys starter sched transient prio retry count client context null chosenblock getbetternonpersistentrequest retrycount priority_soft choosenpriorityscheduler priority_hard choosenpriorityscheduler schedcore removefirsttransient offeredkeys schedtransient retrycount clientcontext public void remove running request sendable request request synchronized starter queue for int i 0 i running persistent requests size i if running persistent requests get i request running persistent requests remove i i if logminor logger minor this removed running request request size now running persistent requests size removerunningrequest sendablerequest starterqueue runningpersistentrequests runningpersistentrequests runningpersistentrequests runningpersistentrequests public boolean is running or queued persistent request sendable request request synchronized starter queue for int i 0 i running persistent requests size i if running persistent requests get i request return true for persistent chosen request req starter queue if req request request return true return false isrunningorqueuedpersistentrequest sendablerequest starterqueue runningpersistentrequests runningpersistentrequests persistentchosenrequest starterqueue called by request starter to find a request to run public chosen block grab request while true persistent chosen request req group null synchronized starter queue short best priority short max value int best retry count integer max value for persistent chosen request req starter queue if req prio best priority req prio best priority req retry count best retry count best priority req prio best retry count req retry count req group req if req group null try to find a better non persistent request if logminor logger minor this persistent request req group prio req group prio retry count req group retry count chosen block better get better non persistent request req group prio req group retry count if better null if better get priority req group prio logger error this selected better as better than req group but isn t better return better if req group null queue fill request starter queue return get better non persistent request short max value integer max value chosen block block int final length 0 synchronized starter queue block req group grab not started client context fast weak random this if block null for int i 0 i starter queue size i if starter queue get i req group starter queue remove i if logminor logger minor this removed req group from starter queue because is empty i else final length starter queue get i size not started continue else prevent this request being selected even though we may remove the pcr from the starter queue in the very near future when the pcr finishes the requests will be un blocked if running persistent requests contains req group request running persistent requests add req group request if final length max starter queue size queue fill request starter queue if logminor logger minor this grab request returning block for req group return block requeststarter chosenblock grabrequest persistentchosenrequest reqgroup starterqueue bestpriority max_value bestretrycount max_value persistentchosenrequest starterqueue bestpriority bestpriority retrycount bestretrycount bestpriority bestretrycount retrycount reqgroup reqgroup reqgroup reqgroup retrycount reqgroup retrycount chosenblock getbetternonpersistentrequest reqgroup reqgroup retrycount getpriority reqgroup reqgroup reqgroup queuefillrequeststarterqueue getbetternonpersistentrequest max_value max_value chosenblock finallength starterqueue reqgroup grabnotstarted clientcontext fastweakrandom starterqueue starterqueue reqgroup starterqueue reqgroup finallength starterqueue sizenotstarted runningpersistentrequests reqgroup runningpersistentrequests reqgroup finallength max_starter_queue_size queuefillrequeststarterqueue grabrequest reqgroup public void queue fill request starter queue if system current time millis next queue fill request starter queue return if starter queue length max starter queue size 2 return job runner queue request starter queue filler native thread max priority true queuefillrequeststarterqueue currenttimemillis nextqueuefillrequeststarterqueue starterqueuelength max_starter_queue_size jobrunner requeststarterqueuefiller nativethread max_priority private int starter queue length int length 0 synchronized starter queue for persistent chosen request request starter queue length request size not started return length starterqueuelength starterqueue persistentchosenrequest starterqueue sizenotstarted param request param container return true if the queue is now full over full boolean add to starter queue sendable request request object container container if logminor logger minor this adding to starter queue request container activate request 1 persistent chosen request chosen try chosen new persistent chosen request request request get priority class container request get retry count container client request scheduler this client context catch no valid blocks exception e return false if logminor logger minor this created pcr chosen container deactivate request 1 boolean dump new false synchronized starter queue for persistent chosen request req starter queue if req request request logger error this already on starter queue req for request new exception debug dump new true break if dump new starter queue add chosen int length starter queue length length chosen size not started running persistent requests add request if logminor logger minor this added to running persistent requests size now running persistent requests size request return length max starter queue size if dump new chosen on dumped sched core container false return false addtostarterqueue sendablerequest objectcontainer persistentchosenrequest persistentchosenrequest getpriorityclass getretrycount clientrequestscheduler clientcontext novalidblocksexception dumpnew starterqueue persistentchosenrequest starterqueue dumpnew dumpnew starterqueue starterqueuelength sizenotstarted runningpersistentrequests runningpersistentrequests max_starter_queue_size dumpnew ondumped schedcore void remove from starter queue sendable request req object container container boolean req already active persistent chosen request dumped null synchronized starter queue for int i 0 i starter queue size i persistent chosen request pcr starter queue get i if pcr request req starter queue remove i dumped pcr break if dumped null dumped on dumped sched core container req already active removefromstarterqueue sendablerequest objectcontainer reqalreadyactive persistentchosenrequest starterqueue starterqueue persistentchosenrequest starterqueue starterqueue ondumped schedcore reqalreadyactive int starter queue size synchronized starter queue return starter queue size starterqueuesize starterqueue starterqueue private db job request starter queue filler new db job public void run object container container client context context fill request starter queue container context null dbjob requeststarterqueuefiller dbjob objectcontainer clientcontext fillrequeststarterqueue private void fill request starter queue object container container client context context sendable request might be active if logminor logger minor this filling request queue ssk isssk scheduler insert is insert scheduler long no later than long max value if is insert scheduler no later than move keys from cooldown queue persistent cooldown queue true container no later than math min no later than move keys from cooldown queue transient cooldown queue false container if anything has been re added the request starter will have been woken up short fuzz 1 if priority soft equals choosen priority scheduler fuzz 1 else if priority hard equals choosen priority scheduler fuzz 0 boolean added false synchronized starter queue if logminor isssk scheduler is insert scheduler logger minor this scheduling chk fetches for sendable request req running persistent requests boolean was active container ext is active req if was active container activate req 1 logger minor this running persistent request req if was active container deactivate req 1 recompute starter queue length int length 0 persistent chosen request old null for persistent chosen request req starter queue if old req logger error this duplicate chosen requests on queue req if old null old request req request logger error this duplicate request on queue old vs req both req request boolean ignore active false if might be active null for sendable request tmp might be active if tmp req request ignore active true if ignore active if container ext is active req request logger error this request already activated req request for req while checking request queue in filling request queue else if logminor logger minor this not already activated for req in while checking request queue in filling request queue else if logminor logger minor this ignoring active because just registered req request req prune duplicates client request scheduler this old req length req size not started if logminor logger minor this queue size length ssk isssk scheduler insert is insert scheduler if length max starter queue size 3 4 if length warning starter queue size logger error this queue already full length return if isssk scheduler is insert scheduler logger minor this scheduling chk fetches boolean added more false while true sendable request request sched core remove first inner fuzz random offered keys starter sched transient false true short max value integer max value context container if request null synchronized client request scheduler this don t wake up for a while but no later than the time we expect the next item to come off the cooldown queue if added next queue fill request starter queue system current time millis wait after nothing to start if next queue fill request starter queue no later than next queue fill request starter queue no later than 1 if added more starter wake up return boolean full add to starter queue request container container deactivate request 1 if added starter wake up else added more true added true if full if added more starter wake up return fillrequeststarterqueue objectcontainer clientcontext sendablerequest mightbeactive issskscheduler isinsertscheduler nolaterthan max_value isinsertscheduler nolaterthan movekeysfromcooldownqueue persistentcooldownqueue nolaterthan nolaterthan movekeysfromcooldownqueue transientcooldownqueue priority_soft choosenpriorityscheduler priority_hard choosenpriorityscheduler starterqueue issskscheduler isinsertscheduler sendablerequest runningpersistentrequests wasactive isactive wasactive wasactive starterqueuelength persistentchosenrequest persistentchosenrequest starterqueue ignoreactive mightbeactive sendablerequest mightbeactive ignoreactive ignoreactive isactive pruneduplicates clientrequestscheduler sizenotstarted issskscheduler isinsertscheduler max_starter_queue_size warning_starter_queue_size issskscheduler isinsertscheduler addedmore sendablerequest schedcore removefirstinner offeredkeys schedtransient max_value max_value clientrequestscheduler nextqueuefillrequeststarterqueue currenttimemillis wait_after_nothing_to_start nextqueuefillrequeststarterqueue nolaterthan nextqueuefillrequeststarterqueue nolaterthan addedmore wakeup addtostarterqueue wakeup addedmore addedmore wakeup compare a recently registered sendable request to what is already on the starter queue if it is better kick out stuff from the queue until we are just over the limit param req param container public void maybe add to starter queue sendable request req object container container sendable request might be active short prio req get priority class container int retry count req get retry count if logminor logger minor this maybe adding to starter queue prio prio retry count retry count boolean logdebug logger should log logger debug this synchronized starter queue boolean better than some false int size 0 persistent chosen request prev null for persistent chosen request old starter queue if old request req wait for a reselect otherwise we can starve other requests note that this happens with persistent sbi s they are added at the new retry count before being removed at the old retry count if logminor logger minor this already on starter queue old for req return if prev old logger error this on starter queue twice prev for prev request if prev null prev request old request logger error this request on starter queue twice prev for prev request vs old for old request boolean ignore active false if might be active null for sendable request tmp might be active if tmp old request ignore active true if ignore active if container ext is active old request logger error this request already activated old request for old while checking request queue in maybe add to starter queue for req else if logdebug logger debug this not already activated for old in while checking request queue in maybe add to starter queue for req else if logminor logger minor this ignoring active because just registered old request in maybe add to starter queue for req size old size not started if old prio prio old prio prio old retry count retry count better than some true if old request req return prev old if size max starter queue size better than some if logminor logger minor this not adding to starter queue over limit and req not better than any queued requests return add to starter queue req container trim starter queue container sendablerequest maybeaddtostarterqueue sendablerequest objectcontainer sendablerequest mightbeactive getpriorityclass retrycount getretrycount retrycount shouldlog starterqueue betterthansome persistentchosenrequest persistentchosenrequest starterqueue ignoreactive mightbeactive sendablerequest mightbeactive ignoreactive ignoreactive isactive maybeaddtostarterqueue maybeaddtostarterqueue maybeaddtostarterqueue sizenotstarted retrycount retrycount betterthansome max_starter_queue_size betterthansome addtostarterqueue trimstarterqueue private void trim starter queue object container container array list persistent chosen request dumped null synchronized starter queue int length starter queue length while length max starter queue size find the lowest priority retry count request if we can dump it without going below the limit then do so if we can t return persistent chosen request worst null short worst prio 1 int worst retry count 1 int worst index 1 int worst length 1 if starter queue is empty break length 0 for int i 0 i starter queue size i persistent chosen request req starter queue get i short prio req prio int retry count req retry count int size req size not started length size if prio worst prio prio worst prio retry count worst retry count worst prio prio worst retry count retry count worst req worst index i worst length size continue int length after length worst length if length after max starter queue size if dumped null dumped new array list persistent chosen request 2 dumped add worst starter queue remove worst index if length after max starter queue size break else can t remove any more break if dumped null return for persistent chosen request req dumped req on dumped sched core container false trimstarterqueue objectcontainer arraylist persistentchosenrequest starterqueue starterqueuelength max_starter_queue_size persistentchosenrequest worstprio worstretrycount worstindex worstlength starterqueue isempty starterqueue persistentchosenrequest starterqueue retrycount retrycount sizenotstarted worstprio worstprio retrycount worstretrycount worstprio worstretrycount retrycount worstindex worstlength lengthafter worstlength lengthafter max_starter_queue_size arraylist persistentchosenrequest starterqueue worstindex lengthafter max_starter_queue_size persistentchosenrequest ondumped schedcore remove a key listener from the list of key listeners param getter param complain public void remove pending keys key listener getter boolean complain boolean found sched transient remove pending keys getter found sched core remove pending keys getter if complain found logger error this listener not found when removing getter keylistener keylisteners removependingkeys keylistener schedtransient removependingkeys schedcore removependingkeys remove a key listener from the list of key listeners param getter param complain public void remove pending keys has key listener getter boolean complain boolean found sched transient remove pending keys getter found sched core remove pending keys getter if complain found logger error this listener not found when removing getter keylistener keylisteners removependingkeys haskeylistener schedtransient removependingkeys schedcore removependingkeys public void reregister all final client requester request object container container sched transient reregister all request random this null client context sched core reregister all request random this container client context starter wake up reregisterall clientrequester objectcontainer schedtransient reregisterall clientcontext schedcore reregisterall clientcontext wakeup public string get choosen priority scheduler return choosen priority scheduler getchoosenpriorityscheduler choosenpriorityscheduler public synchronized void succeeded final base sendable get succeeded boolean persistent if persistent job runner queue new db job public void run object container container client context context if container ext is active succeeded logger error this already active in succeeded succeeded container activate succeeded 1 sched core succeeded succeeded container container deactivate succeeded 1 trip pending priority false boost the priority so the persistent chosen request gets deleted reasonably quickly else sched transient succeeded succeeded null basesendableget jobrunner dbjob objectcontainer clientcontext isactive schedcore trip_pending_priority persistentchosenrequest schedtransient public void run object container container client context context if container ext is active succeeded logger error this already active in succeeded succeeded container activate succeeded 1 sched core succeeded succeeded container container deactivate succeeded 1 objectcontainer clientcontext isactive schedcore public void trip pending key final key block block if logminor logger minor this trip pending key block get key if offered keys null for int i 0 i offered keys length i offered keys i remove block get key final key key block get key sched transient trip pending key key block null client context if sched core any probably want key key client context job runner queue new db job public void run object container container client context context if logminor logger minor this trip pending key for key sched core trip pending key key block container client context trip pending priority false else sched core count negative trippendingkey keyblock trippendingkey getkey offeredkeys offeredkeys offeredkeys getkey getkey schedtransient trippendingkey clientcontext schedcore anyprobablywantkey clientcontext jobrunner dbjob objectcontainer clientcontext trippendingkey schedcore trippendingkey clientcontext trip_pending_priority schedcore countnegative job runner queue new db job public void run object container container client context context if logminor logger minor this trip pending key for key sched core trip pending key key block container client context jobrunner dbjob objectcontainer clientcontext trippendingkey schedcore trippendingkey clientcontext if we want the offered key or if force is enabled queue it public void maybe queue offered key final key key boolean force if logminor logger minor this maybe queue offered key key force short priority short max value if force fixme what priority priority request starter bulk splitfile priority class priority sched transient get key prio key priority null client context if priority short max value offered keys priority queue key key starter wake up final short old prio priority job runner queue new db job public void run object container container client context context don t activate deactivate the key because it s not persistent in the first place short priority sched core get key prio key old prio container context if priority old prio return already on list at priority offered keys priority queue key key clone key starter wake up native thread norm priority false maybequeueofferedkey maybequeueofferedkey max_value requeststarter bulk_splitfile_priority_class schedtransient getkeyprio clientcontext max_value offeredkeys queuekey wakeup oldprio jobrunner dbjob objectcontainer clientcontext schedcore getkeyprio oldprio oldprio offeredkeys queuekey clonekey wakeup nativethread norm_priority public void run object container container client context context don t activate deactivate the key because it s not persistent in the first place short priority sched core get key prio key old prio container context if priority old prio return already on list at priority offered keys priority queue key key clone key starter wake up objectcontainer clientcontext schedcore getkeyprio oldprio oldprio offeredkeys queuekey clonekey wakeup public void dequeue offered key key key for int i 0 i offered keys length i offered keys i remove key dequeueofferedkey offeredkeys offeredkeys must be called from database thread public long queue cooldown client key key sendable get getter object container container if getter persistent return persistent cooldown queue add key get node key getter container else return transient cooldown queue add key get node key getter null queuecooldown clientkey sendableget objectcontainer persistentcooldownqueue getnodekey transientcooldownqueue getnodekey restore keys from the given cooldown queue find any keys that are due to be restored restore all requests both persistent and non persistent for those keys param queue param persistent param container return long max value if nothing is queued in the next wait after nothing to start millis the time at which the next key is due to be restored if there are keys queued to be restarted in the near future private long move keys from cooldown queue cooldown queue queue boolean persistent object container container if queue null return long max value long now system current time millis only go around once we will be called again if there are keys to move then request starter will not sleep because it will start them then it will come back here if we are off thread i e on the database thread then we will wake it up if we find keys and we ll be scheduled again fixme i think we need to restore all the listeners for a single key simultaneously to avoid some kind of race condition or could we just restore the one request on the queue maybe it s just a misguided optimisation iirc we had some severe problems when we didn t have this related to requests somehow being lost altogether is it essential we can save a query if it s not is this about requests or about keys should we limit all requests across any sendable request s to 3 every half hour for a specific key probably yes in which case can the cooldown queue be entirely in ram and would it be useful for it to be less disk more ram for fast nodes with little ram it would be bad final int max keys 20 object ret queue remove key before now wait after nothing to start container max keys if ret null return long max value if ret instanceof long return long ret key keys key ret for int j 0 j keys length j key key keys j if persistent container activate key 5 if logminor logger minor this restoring key key sendable get reqs sched core requests for key key container client context sendable get transient reqs sched transient requests for key key container client context if reqs null transient reqs null not an error as this can happen due to race conditions etc if logminor logger minor this restoring key but no keys queued for key if reqs null for int i 0 i reqs length i requests may or may not be returned activated from requests for key so don t check but do deactivate them once we re done with them container activate reqs i 1 reqs i requeue after cooldown key now container client context container deactivate reqs i 1 if transient reqs null for int i 0 i transient reqs length i transient reqs i requeue after cooldown key now container client context if persistent container deactivate key 5 return long max value max_value wait_after_nothing_to_start movekeysfromcooldownqueue cooldownqueue objectcontainer max_value currenttimemillis requeststarter sendablerequest max_keys removekeybefore wait_after_nothing_to_start max_keys max_value sendableget schedcore requestsforkey clientcontext sendableget transientreqs schedtransient requestsforkey clientcontext transientreqs requestsforkey requeueaftercooldown clientcontext transientreqs transientreqs transientreqs requeueaftercooldown clientcontext max_value public long count transient queued requests return sched transient count queued requests null client context counttransientqueuedrequests schedtransient countqueuedrequests clientcontext public keys fetching locally fetching keys return sched core keysfetchinglocally fetchingkeys schedcore public void remove fetching key key key sched core remove fetching key key removefetchingkey schedcore removefetchingkey public void remove transient insert fetching sendable insert insert object token sched core remove transient insert fetching insert token removetransientinsertfetching sendableinsert schedcore removetransientinsertfetching public void call failure final sendable get get final low level get exception e int prio boolean persistent if persistent get on failure e null null client context else job runner queue new db job public void run object container container client context context if container ext is active get logger error this already active get in call failure request container activate get 1 get on failure e null container client context container deactivate get 1 prio false callfailure sendableget lowlevelgetexception onfailure clientcontext jobrunner dbjob objectcontainer clientcontext isactive callfailure onfailure clientcontext public void run object container container client context context if container ext is active get logger error this already active get in call failure request container activate get 1 get on failure e null container client context container deactivate get 1 objectcontainer clientcontext isactive callfailure onfailure clientcontext public void call failure final sendable insert insert final low level put exception e int prio boolean persistent if persistent insert on failure e null null client context else job runner queue new db job public void run object container container client context context if container ext is active insert logger error this already active insert in call failure insert container activate insert 1 insert on failure e null container context container deactivate insert 1 prio false callfailure sendableinsert lowlevelputexception onfailure clientcontext jobrunner dbjob objectcontainer clientcontext isactive callfailure onfailure public void run object container container client context context if container ext is active insert logger error this already active insert in call failure insert container activate insert 1 insert on failure e null container context container deactivate insert 1 objectcontainer clientcontext isactive callfailure onfailure public fec queue getfec queue return client context fec queue fecqueue getfecqueue clientcontext fecqueue public client context get context return client context clientcontext getcontext clientcontext return true unless the key was already present public boolean add to fetching key key return sched core add to fetching key addtofetching schedcore addtofetching public boolean add transient insert fetching sendable insert insert object token return sched core add transient insert fetching insert token addtransientinsertfetching sendableinsert schedcore addtransientinsertfetching public boolean has fetching key key key return sched core has key key hasfetchingkey schedcore haskey public long count persistent waiting keys object container container return sched core count waiting keys container countpersistentwaitingkeys objectcontainer schedcore countwaitingkeys public long count persistent queued requests object container container return sched core count queued requests container client context countpersistentqueuedrequests objectcontainer schedcore countqueuedrequests clientcontext public boolean is queue almost empty return starter queue size max starter queue size 4 isqueuealmostempty starterqueuesize max_starter_queue_size public boolean is insert scheduler return is insert scheduler isinsertscheduler isinsertscheduler public void remove from all requests by client request client requester client request sendable request get boolean dont complain object container container if get persistent sched core remove from all requests by client request get client request dont complain container else sched transient remove from all requests by client request get client request dont complain null removefromallrequestsbyclientrequest clientrequester clientrequest sendablerequest dontcomplain objectcontainer schedcore removefromallrequestsbyclientrequest clientrequest dontcomplain schedtransient removefromallrequestsbyclientrequest clientrequest dontcomplain public byte salt key key key message digest md sha256 get message digest md update key get routing key md update sched core global salt byte ret md digest sha256 return message digest md return ret saltkey messagedigest getmessagedigest getroutingkey schedcore globalsalt returnmessagedigest void add persistent pending keys key listener listener sched core add pending keys listener addpersistentpendingkeys keylistener schedcore addpendingkeys public boolean object can new object container container logger error this not storing client request scheduler in database new exception error return false objectcannew objectcontainer clientrequestscheduler public void wake starter starter wake up wakestarter wakeup public boolean cache inserts return this node client core cache inserts cacheinserts clientcore cacheinserts class alt persistent set t extends i persistent extends alt btree t implements i persistent set t alt persistent set type class descriptor tp object unique true altpersistentset ipersistent altbtree ipersistentset altpersistentset classdescriptor tpobject public boolean is empty return n elems 0 isempty nelems public boolean contains object o if o instanceof i persistent key key new key i persistent o iterator i iterator key key ascent order return i has next return false ipersistent ipersistent ascent_order hasnext public object to array return to persistent array toarray topersistentarray public e e to array e arr return e super to array t arr toarray toarray public boolean add t obj return put new key obj obj public boolean remove object o t obj t o return remove if exists new btree key check key new key obj obj removeifexists btreekey checkkey public boolean equals object o if o this return true if o instanceof set return false collection c collection o if c size size return false return contains all c containsall public int hash code int h 0 iterator i iterator while i has next h i persistent i next get oid return h hashcode hasnext ipersistent getoid param baseuri base uri of the index exclude the tt index xml tt part param plugin respirator public index string baseuri plugin respirator plugin respirator if baseuri ends with baseuri this baseuri baseuri this pr plugin respirator pluginrespirator pluginrespirator pluginrespirator endswith pluginrespirator fetch the main index file throws io exception throws fetch exception throws sax exception public synchronized void fetch throws io exception fetch exception sax exception fetch new progress ioexception fetchexception saxexception ioexception fetchexception saxexception public synchronized void fetch progress progress throws io exception fetch exception sax exception if fetched return progress set getting base index bucket bucket util fetch bucket baseuri default file pr progress set fetched base index try input stream is bucket get input stream parse is is close finally bucket free fetched true ioexception fetchexception saxexception fetchbucket default_file inputstream getinputstream private void parse input stream is throws sax exception io exception sax parser factory factory sax parser factory new instance try factory set namespace aware true factory set feature http xml org sax features namespaces true factory set feature http apache org xml features disallow doctype decl true sax parser sax parser factory newsax parser main index parser parser new main index parser sax parser parse is parser version parser get version if version 1 title parser get header title owner name parser get header owner owner email parser get header email sub indice list new array list string sub indice new tree map string string for string key parser get sub indice sub indice list add key sub indice put key index key xml collections sort sub indice list catch parser configuration exception e logger error this sax parser configuration exception e throw new sax exception e inputstream saxexception ioexception saxparserfactory saxparserfactory newinstance setnamespaceaware setfeature setfeature saxparser saxparser newsaxparser mainindexparser mainindexparser saxparser getversion getheader ownername getheader owneremail getheader subindicelist arraylist subindice treemap getsubindice subindicelist subindice index_ subindicelist parserconfigurationexception parserconfigurationexception saxexception protected string get sub index string keyword string md5 xml librarian md5 keyword int idx collections binary search sub indice list md5 if idx 0 idx idx 2 return sub indice get sub indice list get idx getsubindex xmllibrarian binarysearch subindicelist subindice subindicelist protected list uri wrapper search string keyword throws exception return search keyword new progress uriwrapper protected list uri wrapper search string keyword progress progress throws exception list uri wrapper result new linked list uri wrapper string sub index get sub index keyword try progress set getting subindex sub index to search for keyword bucket bucket util fetch bucket baseuri sub index pr progress set fetched subindex sub index to search for keyword sax parser factory factory sax parser factory new instance try factory set feature http apache org xml features disallow doctype decl true sax parser sax parser factory newsax parser input stream is bucket get input stream sax parser parse is new librarian handler keyword result is close catch throwable err err print stack trace throw new exception could not parse xml err to string finally bucket free catch exception e logger error this baseuri sub index could not be opened e to string e throw e return result uriwrapper uriwrapper linkedlist uriwrapper subindex getsubindex subindex fetchbucket subindex subindex saxparserfactory saxparserfactory newinstance setfeature saxparser saxparser newsaxparser inputstream getinputstream saxparser librarianhandler printstacktrace tostring subindex tostring public list uri wrapper search string keywords throws exception return search keywords new progress uriwrapper public list uri wrapper search string keywords progress progress throws exception list uri wrapper result null for string keyword keywords if keyword length 3 continue list uri wrapper s search keyword progress if result null result s else result retain all s if result null result new linked list uri wrapper return result uriwrapper uriwrapper uriwrapper retainall linkedlist uriwrapper protected byte buffer buf public byte buffer input stream byte array this array 0 array length bytebuffer bytebufferinputstream public byte buffer input stream byte array int offset int length this byte buffer wrap array offset length bytebufferinputstream bytebuffer this byte buffer wrap array offset length public byte buffer input stream byte buffer buf this buf buf bytebuffer bytebufferinputstream bytebuffer override public int read throws io exception try return buf get integer max value catch buffer underflow exception e return 1 ioexception max_value bufferunderflowexception public int remaining return buf remaining public boolean read boolean throws io exception try return buf get 0 catch buffer underflow exception e eof exception ioe new eof exception ioe init cause e throw ioe readboolean ioexception bufferunderflowexception eofexception eofexception initcause public byte read byte throws io exception try return buf get catch buffer underflow exception e eof exception ioe new eof exception ioe init cause e throw ioe readbyte ioexception bufferunderflowexception eofexception eofexception initcause public char read char throws io exception try return buf get char catch buffer underflow exception e eof exception ioe new eof exception ioe init cause e throw ioe readchar ioexception getchar bufferunderflowexception eofexception eofexception initcause public double read double throws io exception try return buf get double catch buffer underflow exception e eof exception ioe new eof exception ioe init cause e throw ioe readdouble ioexception getdouble bufferunderflowexception eofexception eofexception initcause public float read float throws io exception try return buf get float catch buffer underflow exception e eof exception ioe new eof exception ioe init cause e throw ioe readfloat ioexception getfloat bufferunderflowexception eofexception eofexception initcause public void read fully byte b throws io exception try buf get b catch buffer underflow exception e eof exception ioe new eof exception ioe init cause e throw ioe readfully ioexception bufferunderflowexception eofexception eofexception initcause public void read fully byte b int off int len throws io exception try buf get b off len catch buffer underflow exception e eof exception ioe new eof exception ioe init cause e throw ioe readfully ioexception bufferunderflowexception eofexception eofexception initcause public int read int throws io exception try return buf get int catch buffer underflow exception e eof exception ioe new eof exception ioe init cause e throw ioe readint ioexception getint bufferunderflowexception eofexception eofexception initcause public long read long throws io exception try return buf get long catch buffer underflow exception e eof exception ioe new eof exception ioe init cause e throw ioe readlong ioexception getlong bufferunderflowexception eofexception eofexception initcause public short read short throws io exception try return buf get short catch buffer underflow exception e eof exception ioe new eof exception ioe init cause e throw ioe readshort ioexception getshort bufferunderflowexception eofexception eofexception initcause public int read unsigned byte throws io exception try return buf get integer max value catch buffer underflow exception e eof exception ioe new eof exception ioe init cause e throw ioe readunsignedbyte ioexception max_value bufferunderflowexception eofexception eofexception initcause public int read unsigned short throws io exception try return buf get short integer max value catch buffer underflow exception e eof exception ioe new eof exception ioe init cause e throw ioe readunsignedshort ioexception getshort max_value bufferunderflowexception eofexception eofexception initcause public int skip bytes int n throws io exception int skip math min n buf remaining buf position buf position skip return skip skipbytes ioexception public string readutf throws io exception return data input stream readutf this ioexception datainputstream deprecated link data input stream read line is deprecated so why not deprecated public string read line throws io exception hmmmm bad return new data input stream this read line datainputstream readline readline ioexception datainputstream readline slice a piece of byte buffer into a new byte buffer input stream param size public byte buffer input stream slice int size throws io exception try if buf remaining size throw new eof exception byte buffer bf2 buf slice bf2 limit size skip size return new byte buffer input stream bf2 catch buffer underflow exception e eof exception ioe new eof exception ioe init cause e throw ioe bytebuffer bytebufferinputstream bytebufferinputstream ioexception eofexception bytebuffer bytebufferinputstream bufferunderflowexception eofexception eofexception initcause private final linked list toadlet element toadlets private static class toadlet element public toadlet element toadlet t2 string url prefix t t2 prefix url prefix linkedlist toadletelement toadletelement toadletelement urlprefix urlprefix config callbacks private class f proxyssl callback extends boolean callback override public boolean get return ssl fproxysslcallback booleancallback override public void set boolean val throws invalid config value exception if get equals val return if ssl available throw new invalid config value exception enable ssl support before use ssl with fproxy ssl val throw new invalid config value exception cannot change ssl on the fly please restart freenet invalidconfigvalueexception invalidconfigvalueexception invalidconfigvalueexception throw new invalid config value exception cannot change ssl on the fly please restart freenet override public boolean is read only return true invalidconfigvalueexception isreadonly private static class f proxy passthru max size extends long callback override public long get return f proxy toadlet max length fproxypassthrumaxsize longcallback fproxytoadlet max_length override public void set long val throws invalid config value exception if get equals val return f proxy toadlet max length val invalidconfigvalueexception fproxytoadlet max_length private integer saved port override public integer get if saved port null saved port port return saved port savedport savedport savedport savedport override public void set integer new port throws node need restart exception if saved port int new port saved port port throw new node need restart exception port cannot change on the fly newport nodeneedrestartexception savedport newport savedport nodeneedrestartexception private class f proxy bindto callback extends string callback override public string get return bind to fproxybindtocallback stringcallback bindto override public void set string bind to throws invalid config value exception if bind to equals get try network interface set bind to bind to false simple toadlet server this bind to bind to catch io exception e this is an advanced option for reasons of reducing clutter but it is expected to be used by regular users not devs so we translate the error messages throw new invalid config value exception l10n could not change bind to error e get localized message bindto invalidconfigvalueexception bindto networkinterface setbindto bindto simpletoadletserver bindto bindto ioexception invalidconfigvalueexception couldnotchangebindto getlocalizedmessage private class f proxy allowed hosts callback extends string callback override public string get return network interface get allowed hosts fproxyallowedhostscallback stringcallback networkinterface getallowedhosts override public void set string allowed hosts if allowed hosts equals get network interface set allowed hosts allowed hosts allowedhosts allowedhosts networkinterface setallowedhosts allowedhosts private class f proxycss name callback extends string callback implements enumerable option callback override public string get return css theme code fproxycssnamecallback stringcallback enumerableoptioncallback csstheme override public void set string css name throws invalid config value exception if css name index of 1 css name index of 1 throw new invalid config value exception l10n illegalcss name css theme theme theme from name css name page maker set theme css theme if core node plugin manager null core node plugin manager setf proxy theme css theme cssname invalidconfigvalueexception cssname indexof cssname indexof invalidconfigvalueexception illegalcssname csstheme themefromname cssname pagemaker settheme csstheme pluginmanager pluginmanager setfproxytheme csstheme public string get possible values return theme possible values getpossiblevalues possiblevalues private class f proxycss override callback extends string callback override public string get return css override null css override to string fproxycssoverridecallback stringcallback cssoverride cssoverride tostring override public void set string val throws invalid config value exception if core null return if val equals get val equals css override null else file tmp new file val trim if core allow upload from tmp throw new invalid config value exception l10n css override not in uploads filename tmp to string else if tmp can read tmp is file throw new invalid config value exception l10n css override cant read filename tmp to string css override tmp get absolute file page maker set override css override invalidconfigvalueexception cssoverride allowuploadfrom invalidconfigvalueexception cssoverridenotinuploads tostring canread isfile invalidconfigvalueexception cssoverridecantread tostring cssoverride getabsolutefile pagemaker setoverride cssoverride private class f proxy enabled callback extends boolean callback override public boolean get synchronized simple toadlet server this return my thread null fproxyenabledcallback booleancallback simpletoadletserver mythread override public void set boolean val throws invalid config value exception if get equals val return synchronized simple toadlet server this if val start it my thread new thread simple toadlet server this simple toadlet server else my thread interrupt my thread null return create fproxy my thread set daemon true my thread start invalidconfigvalueexception simpletoadletserver mythread simpletoadletserver simpletoadletserver mythread mythread createfproxy mythread setdaemon mythread private final simple toadlet server ts f proxy advanced mode enabled callback simple toadlet server ts this ts ts simpletoadletserver fproxyadvancedmodeenabledcallback simpletoadletserver override public boolean get return ts is advanced mode enabled isadvancedmodeenabled override public void set boolean val throws invalid config value exception if get equals val return ts enable advanced mode val invalidconfigvalueexception enableadvancedmode private final simple toadlet server ts f proxy javascript enabled callback simple toadlet server ts this ts ts simpletoadletserver fproxyjavascriptenabledcallback simpletoadletserver override public boolean get return ts isf proxy javascript enabled isfproxyjavascriptenabled override public void set boolean val throws invalid config value exception if get equals val return ts enablef proxy javascript val invalidconfigvalueexception enablefproxyjavascript public void create fproxy synchronized this if have calledf proxy return have calledf proxy true bookmark manager new bookmark manager core try f proxy toadlet maybe createf proxy etc core core node core node config this bookmark manager catch io exception e logger error this could not start fproxy e e system err println could not start fproxy e print stack trace createfproxy havecalledfproxy havecalledfproxy bookmarkmanager bookmarkmanager fproxytoadlet maybecreatefproxyetc bookmarkmanager ioexception printstacktrace public synchronized void set core node client core core this core core setcore nodeclientcore create a simple toadlet server using the settings from the sub config the fproxy config public simple toadlet server sub config fproxy config bucket factory bucket factory executor executor throws io exception invalid config value exception this executor executor int config item order 0 fproxy config register enabled true config item order true true simple toadlet server enabled simple toadlet server enabled long new f proxy enabled callback boolean enabled fproxy config get boolean enabled fproxy config register ssl false config item order true true simple toadlet server ssl simple toadlet server ssl long new f proxyssl callback fproxy config register port default fproxy port config item order true true simple toadlet server port simple toadlet server port long new f proxy port callback false fproxy config register bind to network interface default bind to config item order true true simple toadlet server bind to simple toadlet server bind to long new f proxy bindto callback fproxy config register css clean config item order false false simple toadlet server css name simple toadlet server css name long new f proxycss name callback fproxy config register css override config item order true false simple toadlet server css override simple toadlet server css override long new f proxycss override callback fproxy config register advanced mode enabled false config item order true false simple toadlet server advanced mode simple toadlet server advanced mode long new f proxy advanced mode enabled callback this fproxy config register javascript enabled false config item order true false simple toadlet server enablejs simple toadlet server enablejs long new f proxy javascript enabled callback this fproxy config register has completed wizard false config item order true false simple toadlet server has completed wizard simple toadlet server has completed wizard long new boolean callback override public boolean get return fproxy has completed wizard override public void set boolean val throws invalid config value exception node need restart exception if get equals val return fproxy has completed wizard val fproxy has completed wizard fproxy config get boolean has completed wizard fproxy config register show panic button false config item order true true simple toadlet server panic button simple toadlet server panic button long new boolean callback override public boolean get return simple toadlet server is panic button to be shown override public void set boolean value if value simple toadlet server is panic button to be shown return else simple toadlet server is panic button to be shown value fproxy config register public gateway mode false config item order true true simple toadlet server public gateway mode simple toadlet server public gateway mode long new boolean callback override public boolean get return public gateway mode override public void set boolean val throws invalid config value exception node need restart exception public gateway mode val public gateway mode fproxy config get boolean public gateway mode this is off by default because for example firefox has a limit of 2 persistent connections per server but 8 non persistent connections per server we need 8 conns more than we need the efficiency gain of reusing connections especially on first install fproxy config register enable persistent connections false config item order true false simple toadlet server enable persistent connections simple toadlet server enable persistent connections long new boolean callback override public boolean get synchronized simple toadlet server this return enable persistent connections override public void set boolean val throws invalid config value exception synchronized simple toadlet server this enable persistent connections val enable persistent connections fproxy config get boolean enable persistent connections off by default i had hoped it would yield a significant performance boost to bootstrap performance on browsers with low numbers of simultaneous connections unfortunately the bottleneck appears to be that the node does very few local requests compared to external requests for anonymity s sake fproxy config register enable inline prefetch false config item order true false simple toadlet server enable inline prefetch simple toadlet server enable inline prefetch long new boolean callback override public boolean get synchronized simple toadlet server this return enable inline prefetch override public void set boolean val throws invalid config value exception synchronized simple toadlet server this enable inline prefetch val enable inline prefetch fproxy config get boolean enable inline prefetch fproxy config register enable activelinks false config item order false false simple toadlet server enable activelinks simple toadlet server enable activelinks long new boolean callback override public boolean get return enable activelinks override public void set boolean val throws invalid config value exception node need restart exception enable activelinks val enable activelinks fproxy config get boolean enable activelinks fproxy config register passthrough max size 2l 1024 1024 config item order true false simple toadlet server passthrough max size simple toadlet server passthrough max size long new f proxy passthru max size true f proxy toadlet max length fproxy config get long passthrough max size fproxy config register allowed hosts 127 0 0 1 0 0 0 0 0 0 0 1 config item order true true simple toadlet server allowed hosts simple toadlet server allowed hosts long new f proxy allowed hosts callback fproxy config register allowed hosts full access 127 0 0 1 0 0 0 0 0 0 0 1 config item order true true simple toadlet server allowed full access simple toadlet server allowed full access long new string callback override public string get return allowed full access get allowed hosts override public void set string val throws invalid config value exception allowed full access set allowed hosts val allowed full access new allowed hosts fproxy config get string allowed hosts full access fproxy config register do robots false config item order true false simple toadlet server do robots simple toadlet server do robots long new boolean callback override public boolean get return do robots override public void set boolean val throws invalid config value exception do robots val do robots fproxy config get boolean do robots simple toadlet server is panic button to be shown fproxy config get boolean show panic button this bf bucket factory port fproxy config get int port bind to fproxy config get string bind to string css name fproxy config get string css if css name index of 1 css name index of 1 throw new invalid config value exception css name must not contain slashes or colons css theme theme theme from name css name page maker new page maker css theme if fproxy config get option css override is default css override new file fproxy config get string css override page maker set override css override else css override null this advanced mode enabled fproxy config get boolean advanced mode enabled toadlets new linked list toadlet element if ssl available ssl fproxy config get boolean ssl this allowed hosts fproxy config get string allowed hosts if enabled logger normal simple toadlet server this not starting f proxy as it s disabled system out println not starting f proxy as it s disabled else maybe get network interface my thread new thread this simple toadlet server my thread set daemon true register static toadlet and startup toadlet static toadlet statictoadlet new static toadlet register statictoadlet static false false freenet is starting up page to be removed at remove startup toadlet startup toadlet new startup toadlet statictoadlet register startup toadlet false false simpletoadletserver subconfig simpletoadletserver subconfig fproxyconfig bucketfactory bucketfactory ioexception invalidconfigvalueexception configitemorder fproxyconfig configitemorder simpletoadletserver simpletoadletserver enabledlong fproxyenabledcallback fproxyconfig getboolean fproxyconfig configitemorder simpletoadletserver simpletoadletserver ssllong fproxysslcallback fproxyconfig default_fproxy_port configitemorder simpletoadletserver simpletoadletserver portlong fproxyportcallback fproxyconfig bindto networkinterface default_bind_to configitemorder simpletoadletserver bindto simpletoadletserver bindtolong fproxybindtocallback fproxyconfig configitemorder simpletoadletserver cssname simpletoadletserver cssnamelong fproxycssnamecallback fproxyconfig cssoverride configitemorder simpletoadletserver cssoverride simpletoadletserver cssoverridelong fproxycssoverridecallback fproxyconfig advancedmodeenabled configitemorder simpletoadletserver advancedmode simpletoadletserver advancedmodelong fproxyadvancedmodeenabledcallback fproxyconfig javascriptenabled configitemorder simpletoadletserver simpletoadletserver enablejslong fproxyjavascriptenabledcallback fproxyconfig hascompletedwizard configitemorder simpletoadletserver hascompletedwizard simpletoadletserver hascompletedwizardlong booleancallback fproxyhascompletedwizard invalidconfigvalueexception nodeneedrestartexception fproxyhascompletedwizard fproxyhascompletedwizard fproxyconfig getboolean hascompletedwizard fproxyconfig showpanicbutton configitemorder simpletoadletserver panicbutton simpletoadletserver panicbuttonlong booleancallback simpletoadletserver ispanicbuttontobeshown simpletoadletserver ispanicbuttontobeshown simpletoadletserver ispanicbuttontobeshown fproxyconfig publicgatewaymode configitemorder simpletoadletserver publicgatewaymode simpletoadletserver publicgatewaymodelong booleancallback publicgatewaymode invalidconfigvalueexception nodeneedrestartexception publicgatewaymode publicgatewaymode fproxyconfig getboolean publicgatewaymode fproxyconfig enablepersistentconnections configitemorder simpletoadletserver enablepersistentconnections simpletoadletserver enablepersistentconnectionslong booleancallback simpletoadletserver enablepersistentconnections invalidconfigvalueexception simpletoadletserver enablepersistentconnections enablepersistentconnections fproxyconfig getboolean enablepersistentconnections fproxyconfig enableinlineprefetch configitemorder simpletoadletserver enableinlineprefetch simpletoadletserver enableinlineprefetchlong booleancallback simpletoadletserver enableinlineprefetch invalidconfigvalueexception simpletoadletserver enableinlineprefetch enableinlineprefetch fproxyconfig getboolean enableinlineprefetch fproxyconfig enableactivelinks configitemorder simpletoadletserver enableactivelinks simpletoadletserver enableactivelinkslong booleancallback enableactivelinks invalidconfigvalueexception nodeneedrestartexception enableactivelinks enableactivelinks fproxyconfig getboolean enableactivelinks fproxyconfig passthroughmaxsize configitemorder simpletoadletserver passthroughmaxsize simpletoadletserver passthroughmaxsizelong fproxypassthrumaxsize fproxytoadlet max_length fproxyconfig getlong passthroughmaxsize fproxyconfig allowedhosts configitemorder simpletoadletserver allowedhosts simpletoadletserver allowedhostslong fproxyallowedhostscallback fproxyconfig allowedhostsfullaccess configitemorder simpletoadletserver allowedfullaccess simpletoadletserver allowedfullaccesslong stringcallback allowedfullaccess getallowedhosts invalidconfigvalueexception allowedfullaccess setallowedhosts allowedfullaccess allowedhosts fproxyconfig getstring allowedhostsfullaccess fproxyconfig dorobots configitemorder simpletoadletserver dorobots simpletoadletserver dorobotslong booleancallback dorobots invalidconfigvalueexception dorobots dorobots fproxyconfig getboolean dorobots simpletoadletserver ispanicbuttontobeshown fproxyconfig getboolean showpanicbutton bucketfactory fproxyconfig getint bindto fproxyconfig getstring bindto cssname fproxyconfig getstring cssname indexof cssname indexof invalidconfigvalueexception csstheme themefromname cssname pagemaker pagemaker csstheme fproxyconfig getoption cssoverride isdefault cssoverride fproxyconfig getstring cssoverride pagemaker setoverride cssoverride cssoverride advancedmodeenabled fproxyconfig getboolean advancedmodeenabled linkedlist toadletelement fproxyconfig getboolean allowedhosts fproxyconfig getstring allowedhosts simpletoadletserver fproxy fproxy maybegetnetworkinterface mythread simpletoadletserver mythread setdaemon statictoadlet statictoadlet removestartuptoadlet startuptoadlet startuptoadlet startuptoadlet fproxy config register has completed wizard false config item order true false simple toadlet server has completed wizard simple toadlet server has completed wizard long new boolean callback override public boolean get return fproxy has completed wizard fproxyconfig hascompletedwizard configitemorder simpletoadletserver hascompletedwizard simpletoadletserver hascompletedwizardlong booleancallback fproxyhascompletedwizard override public void set boolean val throws invalid config value exception node need restart exception if get equals val return fproxy has completed wizard val invalidconfigvalueexception nodeneedrestartexception fproxyhascompletedwizard fproxy config register show panic button false config item order true true simple toadlet server panic button simple toadlet server panic button long new boolean callback override public boolean get return simple toadlet server is panic button to be shown fproxyconfig showpanicbutton configitemorder simpletoadletserver panicbutton simpletoadletserver panicbuttonlong booleancallback simpletoadletserver ispanicbuttontobeshown override public void set boolean value if value simple toadlet server is panic button to be shown return else simple toadlet server is panic button to be shown value simpletoadletserver ispanicbuttontobeshown simpletoadletserver ispanicbuttontobeshown fproxy config register public gateway mode false config item order true true simple toadlet server public gateway mode simple toadlet server public gateway mode long new boolean callback override public boolean get return public gateway mode fproxyconfig publicgatewaymode configitemorder simpletoadletserver publicgatewaymode simpletoadletserver publicgatewaymodelong booleancallback publicgatewaymode override public void set boolean val throws invalid config value exception node need restart exception public gateway mode val invalidconfigvalueexception nodeneedrestartexception publicgatewaymode override public boolean get synchronized simple toadlet server this return enable persistent connections simpletoadletserver enablepersistentconnections override public void set boolean val throws invalid config value exception synchronized simple toadlet server this enable persistent connections val invalidconfigvalueexception simpletoadletserver enablepersistentconnections override public boolean get synchronized simple toadlet server this return enable inline prefetch simpletoadletserver enableinlineprefetch override public void set boolean val throws invalid config value exception synchronized simple toadlet server this enable inline prefetch val invalidconfigvalueexception simpletoadletserver enableinlineprefetch fproxy config register enable activelinks false config item order false false simple toadlet server enable activelinks simple toadlet server enable activelinks long new boolean callback override public boolean get return enable activelinks fproxyconfig enableactivelinks configitemorder simpletoadletserver enableactivelinks simpletoadletserver enableactivelinkslong booleancallback enableactivelinks override public void set boolean val throws invalid config value exception node need restart exception enable activelinks val invalidconfigvalueexception nodeneedrestartexception enableactivelinks new string callback override public string get return allowed full access get allowed hosts stringcallback allowedfullaccess getallowedhosts override public void set string val throws invalid config value exception allowed full access set allowed hosts val invalidconfigvalueexception allowedfullaccess setallowedhosts fproxy config register do robots false config item order true false simple toadlet server do robots simple toadlet server do robots long new boolean callback override public boolean get return do robots fproxyconfig dorobots configitemorder simpletoadletserver dorobots simpletoadletserver dorobotslong booleancallback dorobots return do robots override public void set boolean val throws invalid config value exception do robots val dorobots invalidconfigvalueexception dorobots public void remove startup toadlet unregister startup toadlet ready to be g ced startup toadlet null not in the navbar removestartuptoadlet startuptoadlet gced startuptoadlet private void maybe get network interface throws io exception if this network interface null return if ssl this network interface ssl network interface create port this bind to allowed hosts executor true else this network interface network interface create port this bind to allowed hosts executor true maybegetnetworkinterface ioexception networkinterface networkinterface sslnetworkinterface bindto allowedhosts networkinterface networkinterface bindto allowedhosts public boolean do robots return do robots dorobots dorobots public boolean public gateway mode return public gateway mode publicgatewaymode publicgatewaymode public void start if my thread null try maybe get network interface my thread start logger normal this starting f proxy on bind to port system out println starting f proxy on bind to port catch io exception e logger error this could not bind network port for f proxy e mythread maybegetnetworkinterface mythread fproxy bindto fproxy bindto ioexception fproxy public void register toadlet t string url prefix boolean at front boolean full only register t url prefix at front null null full only null urlprefix atfront fullonly urlprefix atfront fullonly public void register toadlet t string url prefix boolean at front string name string title boolean full only link enabled callback cb toadlet element te new toadlet element t url prefix if at front toadlets add first te else toadlets add last te t container this if name null page maker add navigation link url prefix name title full only cb urlprefix atfront fullonly linkenabledcallback toadletelement toadletelement urlprefix atfront addfirst addlast pagemaker addnavigationlink urlprefix fullonly public synchronized void unregister toadlet t for iterator toadlet element i toadlets iterator i has next toadlet element e i next if e t t i remove return toadletelement hasnext toadletelement public startup toadlet get startup toadlet return startup toadlet startuptoadlet getstartuptoadlet startuptoadlet public toadlet find toadlet uri uri throws permanent redirect exception string path uri get path show the wizard until dismissed by the user see bug 2624 if fproxy has completed wizard if core null core node null core node is opennet enabled core node get peer nodes length 0 if path starts with first time wizard toadlet toadlet url path starts with static toadlet root url try throw new permanent redirect exception new uri first time wizard toadlet toadlet url catch uri syntax exception e throw new error e iterator toadlet element i toadlets iterator while i has next toadlet element te i next if path starts with te prefix return te t if te prefix length 0 te prefix char at te prefix length 1 if path equals te prefix substring 0 te prefix length 1 uri newuri try newuri new uri te prefix catch uri syntax exception e throw new error e throw new permanent redirect exception newuri return null findtoadlet permanentredirectexception getpath fproxyhascompletedwizard isopennetenabled getpeernodes startswith firsttimewizardtoadlet toadlet_url startswith statictoadlet root_url permanentredirectexception firsttimewizardtoadlet toadlet_url urisyntaxexception toadletelement hasnext toadletelement startswith charat urisyntaxexception permanentredirectexception public void run try network interface set so timeout 500 catch socket exception e1 logger error this could not set so timeout to 500ms on the fly disabling of the interface will not work while true synchronized this if my thread null return socket conn network interface accept if conn null continue timeout if logger should log logger minor this logger minor this accepted connection socket handler sh new socket handler conn sh start networkinterface setsotimeout socketexception mythread networkinterface shouldlog sockethandler sockethandler socket sock public socket handler socket conn this sock conn sockethandler void start executor execute this http socket handler hash code hashcode public void run freenet support logger os thread logpid this boolean logminor logger should log logger minor this if logminor logger minor this handling connection try toadlet context impl handle sock simple toadlet server this page maker catch out of memory error e oom handler handleoom e system err println simple toadlet server request above failed logger error this oom in socket handler catch throwable t system err println caught in simple toadlet server t t print stack trace logger error this caught in simple toadlet server t t if logminor logger minor this handled connection osthread shouldlog toadletcontextimpl simpletoadletserver pagemaker outofmemoryerror oomhandler simpletoadletserver sockethandler simpletoadletserver printstacktrace simpletoadletserver public theme get theme return this css theme gettheme csstheme public void setcss name theme theme this css theme theme setcssname csstheme public synchronized boolean is advanced mode enabled return this advanced mode enabled isadvancedmodeenabled advancedmodeenabled public synchronized void enable advanced mode boolean b advanced mode enabled b enableadvancedmode advancedmodeenabled public synchronized boolean isf proxy javascript enabled return this f proxy javascript enabled isfproxyjavascriptenabled fproxyjavascriptenabled public synchronized void enablef proxy javascript boolean b f proxy javascript enabled b enablefproxyjavascript fproxyjavascriptenabled public string get form password if core null return return core form password getformpassword formpassword public boolean is allowed full access inet address remote addr return this allowed full access allowed remote addr isallowedfullaccess inetaddress remoteaddr allowedfullaccess remoteaddr private static string l10n string key string pattern string value return l10n get string simple toadlet server key pattern value getstring simpletoadletserver private static string l10n string key return l10n get string simple toadlet server key getstring simpletoadletserver public html node add form child html node parent node string target string id html node form node parent node add child form new string action method enctype id accept charset new string target post multipart form data id utf 8 add child div form node add child input new string type name value new string hidden form password get form password return form node htmlnode addformchild htmlnode parentnode htmlnode formnode parentnode addchild addchild formnode addchild formpassword getformpassword formnode public void set bucket factory bucket factory temp bucket factory this bf temp bucket factory setbucketfactory bucketfactory tempbucketfactory tempbucketfactory public boolean is enabled return my thread null isenabled mythread public bookmark manager get bookmarks return bookmark manager bookmarkmanager getbookmarks bookmarkmanager public freeneturi get bookmarkur is if bookmark manager null return new freeneturi 0 return bookmark manager get bookmarkur is getbookmarkuris bookmarkmanager bookmarkmanager getbookmarkuris public boolean enable persistent connections return enable persistent connections enablepersistentconnections enablepersistentconnections public boolean enable inline prefetch return enable inline prefetch enableinlineprefetch enableinlineprefetch public synchronized boolean allow posts return bf instanceof array bucket factory allowposts arraybucketfactory public synchronized bucket factory get bucket factory return bf bucketfactory getbucketfactory public boolean enable activelinks return enable activelinks enableactivelinks enableactivelinks logger register log threshold callback new log threshold callback override public void should update logminor logger should log logger minor this registerlogthresholdcallback logthresholdcallback shouldupdate shouldlog private final int hash code override public int hash code return hash code hashcode hashcode hashcode public split file fetcher metadata metadata get completion callback rcb client requester parent2 fetch context new ctx boolean delete fetch context list decompressors2 client metadata client metadata archive context actx int recursion level bucket return bucket long token2 object container container client context context throws fetch exception metadata parse exception this persistent parent2 persistent this delete fetch context delete fetch context if logminor logger minor this persistence persistent from parent2 new exception debug int hash super hash code if hash 0 hash 1 this hash code hash this finished false this return bucket return bucket this fetch context new ctx if new ctx null throw new null pointer exception this archive context actx this decompressors persistent new array list decompressors2 decompressors2 if decompressors size 1 logger error this multiple decompressors decompressors size this is almost certainly a bug new exception debug this client metadata client metadata null new client metadata client metadata clone copy it as in single file fetcher this cb rcb this recursion level recursion level 1 this parent parent2 local salt new byte 32 context random next bytes local salt if parent2 is cancelled throw new fetch exception fetch exception cancelled override length metadata data length this splitfile type metadata get splitfile type clientchk splitfile data blocks metadata get splitfile data keys clientchk splitfile check blocks metadata get splitfile check keys if persistent clear them here so they don t get deleted and we don t need to clone them metadata clear splitfile keys container store metadata for int i 0 i splitfile data blocks length i if splitfile data blocks i null throw new metadata parse exception null data block i of splitfile data blocks length for int i 0 i splitfile check blocks length i if splitfile check blocks i null throw new metadata parse exception null check block i of splitfile check blocks length long final length 1l splitfile data blocks length chk block data length if final length override length if final length override length chk block data length throw new fetch exception fetch exception invalid metadata splitfile is final length but length is final length final length override length long eventual length math max override length metadata uncompressed data length boolean was active true if persistent was active container ext is active cb if was active container activate cb 1 cb on expected size eventual length container context string mime type metadata getmime type if mime type null cb on expectedmime mime type container context if metadata uncompressed data length 0 cb on finalized metadata container if was active container deactivate cb 1 if eventual length 0 new ctx max output length 0 eventual length new ctx max output length throw new fetch exception fetch exception too big eventual length true client metadata getmime type this token token2 if splitfile type metadata splitfile nonredundant don t need to do much just fetch everything and piece it together blocks per segment 1 check blocks per segment 1 segment count 1 if splitfile check blocks length 0 logger error this splitfile type is splitfile nonredundant yet splitfile check blocks length check blocks found this throw new fetch exception fetch exception invalid metadata splitfile type is non redundant yet have splitfile check blocks length check blocks else if splitfile type metadata splitfile onion standard byte params metadata splitfile params if params null params length 8 throw new metadata parse exception no splitfile params blocks per segment fields bytes to int params 0 int check blocks fields bytes to int params 4 fixme remove this eventually will break compat with a few files inserted between 1135 and 1136 work around a bug around build 1135 we were splitting as 128 255 but we were then setting the check blocks per segment to 64 detect this if check blocks 64 blocks per segment 128 splitfile check blocks length splitfile data blocks length splitfile data blocks length 128 logger normal this activating 1135 wrong check blocks per segment workaround for this check blocks 127 check blocks per segment check blocks if blocks per segment fetch context max data blocks per segment check blocks per segment fetch context max check blocks per segment throw new fetch exception fetch exception too many blocks per segment too many blocks per segment blocks per segment data check blocks per segment check segment count splitfile data blocks length blocks per segment splitfile data blocks length blocks per segment 0 0 1 onion 128 192 will be segmented else throw new metadata parse exception unknown splitfile format splitfile type this max temp length fetch context max temp length if logminor logger minor this algorithm splitfile type blocks per segment blocks per segment check blocks per segment check blocks per segment segments segment count data blocks splitfile data blocks length check blocks splitfile check blocks length segments new split file fetcher segment segment count initially null on all entries setup bloom parameters if persistent fixme should this be encrypted it s protected to some degree by the salt since it isn t encrypted it s likely to be very sparse we should name it appropriately try main bloom file context persistentfg make random file alt bloom file context persistentfg make random file catch io exception e throw new fetch exception fetch exception bucket error unable to create bloom filter files e else not persistent keep purely in ram main bloom file null alt bloom file null int main elements per key default main bloom elements per key int orig size splitfile data blocks length splitfile check blocks length main bloomk int main elements per key 0 7 long elements long orig size main elements per key redflag size limit 3 36tb limit if elements long integer max value throw new fetch exception fetch exception too big cannot fetch splitfiles with more than integer max value main elements per key keys approx 3 3tb int main size bits int elements long counting filter if main size bits 7 0 main size bits 8 main size bits 7 main bloom filter size bytes main size bits 8 2 counting filter double acceptable false positives acceptable bloom false positives all segments segments length int per segment bits per key int math ceil math log acceptable false positives math log 0 6185 int seg blocks blocks per segment check blocks per segment if seg blocks orig size seg blocks orig size int per segment size per segment bits per key seg blocks if per segment size 7 0 per segment size 8 per segment size 7 per segment bloom filter size bytes per segment size 8 per segmentk bloom filter optimialk per segment size seg blocks key count orig size now create it if logminor logger minor this creating block filter for this keys splitfile data blocks length splitfile check blocks length main bloom size main bloom filter size bytes bytes k main bloomk filename main bloom file alt bloom filter filename alt bloom file segments segments length each is per segment bloom filter size bytes bytes k per segmentk try temp listener new split file fetcher key listener this key count main bloom file alt bloom file main bloom filter size bytes main bloomk fetch context cache local requests local salt segments length per segment bloom filter size bytes per segmentk persistent true catch io exception e throw new fetch exception fetch exception bucket error unable to write bloom filters for splitfile if persistent container store this block fetch context new fetch context fetch context fetch context splitfile default block mask true null if segment count 1 splitfile will be overwritten this is bad so copy them clientchk new splitfile data blocks new clientchk splitfile data blocks length clientchk new splitfile check blocks new clientchk splitfile check blocks length system arraycopy splitfile data blocks 0 new splitfile data blocks 0 splitfile data blocks length if splitfile check blocks length 0 system arraycopy splitfile check blocks 0 new splitfile check blocks 0 splitfile check blocks length segments 0 new split file fetcher segment splitfile type new splitfile data blocks new splitfile check blocks this archive context block fetch context max temp length recursion level parent 0 true for int i 0 i new splitfile data blocks length i if logminor logger minor this added data block i new splitfile data blocks i get node key temp listener add key new splitfile data blocks i get node key 0 context for int i 0 i new splitfile check blocks length i if logminor logger minor this added check block i new splitfile check blocks i get node key temp listener add key new splitfile check blocks i get node key 0 context if persistent container store segments 0 segments 0 deactivate keys container container deactivate segments 0 1 else int data blocks ptr 0 splitfilefetcher getcompletioncallback clientrequester fetchcontext newctx deletefetchcontext clientmetadata clientmetadata archivecontext recursionlevel returnbucket objectcontainer clientcontext fetchexception metadataparseexception deletefetchcontext deletefetchcontext hashcode hashcode returnbucket returnbucket fetchcontext newctx newctx nullpointerexception archivecontext arraylist clientmetadata clientmetadata clientmetadata clientmetadata singlefilefetcher recursionlevel recursionlevel localsalt nextbytes localsalt iscancelled fetchexception fetchexception overridelength datalength splitfiletype getsplitfiletype splitfiledatablocks getsplitfiledatakeys splitfilecheckblocks getsplitfilecheckkeys clearsplitfilekeys splitfiledatablocks splitfiledatablocks metadataparseexception splitfiledatablocks splitfilecheckblocks splitfilecheckblocks metadataparseexception splitfilecheckblocks finallength splitfiledatablocks chkblock data_length finallength overridelength finallength overridelength chkblock data_length fetchexception fetchexception invalid_metadata finallength finallength finallength overridelength eventuallength overridelength uncompresseddatalength wasactive wasactive isactive wasactive onexpectedsize eventuallength mimetype getmimetype mimetype onexpectedmime mimetype uncompresseddatalength onfinalizedmetadata wasactive eventuallength newctx maxoutputlength eventuallength newctx maxoutputlength fetchexception fetchexception too_big eventuallength clientmetadata getmimetype splitfiletype splitfile_nonredundant blockspersegment checkblockspersegment segmentcount splitfilecheckblocks splitfile_nonredundant splitfilecheckblocks fetchexception fetchexception invalid_metadata splitfilecheckblocks splitfiletype splitfile_onion_standard splitfileparams metadataparseexception blockspersegment bytestoint checkblocks bytestoint checkblockspersegment checkblocks blockspersegment splitfilecheckblocks splitfiledatablocks splitfiledatablocks checkblocks checkblockspersegment checkblocks blockspersegment fetchcontext maxdatablockspersegment checkblockspersegment fetchcontext maxcheckblockspersegment fetchexception fetchexception too_many_blocks_per_segment blockspersegment checkblockspersegment segmentcount splitfiledatablocks blockspersegment splitfiledatablocks blockspersegment metadataparseexception splitfiletype maxtemplength fetchcontext maxtemplength splitfiletype blockspersegment checkblockspersegment segmentcount splitfiledatablocks splitfilecheckblocks splitfilefetchersegment segmentcount mainbloomfile makerandomfile altbloomfile makerandomfile ioexception fetchexception fetchexception bucket_error mainbloomfile altbloomfile mainelementsperkey default_main_bloom_elements_per_key origsize splitfiledatablocks splitfilecheckblocks mainbloomk mainelementsperkey elementslong origsize mainelementsperkey elementslong max_value fetchexception fetchexception too_big max_value mainelementsperkey mainsizebits elementslong mainsizebits mainsizebits mainsizebits mainbloomfiltersizebytes mainsizebits acceptablefalsepositives acceptable_bloom_false_positives_all_segments persegmentbitsperkey acceptablefalsepositives segblocks blockspersegment checkblockspersegment segblocks origsize segblocks origsize persegmentsize persegmentbitsperkey segblocks persegmentsize persegmentsize persegmentsize persegmentbloomfiltersizebytes persegmentsize persegmentk bloomfilter persegmentsize segblocks keycount origsize splitfiledatablocks splitfilecheckblocks mainbloomfiltersizebytes mainbloomk mainbloomfile altbloomfile persegmentbloomfiltersizebytes persegmentk templistener splitfilefetcherkeylistener keycount mainbloomfile altbloomfile mainbloomfiltersizebytes mainbloomk fetchcontext cachelocalrequests localsalt persegmentbloomfiltersizebytes persegmentk ioexception fetchexception fetchexception bucket_error blockfetchcontext fetchcontext fetchcontext fetchcontext splitfile_default_block_mask segmentcount newsplitfiledatablocks splitfiledatablocks newsplitfilecheckblocks splitfilecheckblocks splitfiledatablocks newsplitfiledatablocks splitfiledatablocks splitfilecheckblocks splitfilecheckblocks newsplitfilecheckblocks splitfilecheckblocks splitfilefetchersegment splitfiletype newsplitfiledatablocks newsplitfilecheckblocks archivecontext blockfetchcontext maxtemplength recursionlevel newsplitfiledatablocks newsplitfiledatablocks getnodekey templistener addkey newsplitfiledatablocks getnodekey newsplitfilecheckblocks newsplitfilecheckblocks getnodekey templistener addkey newsplitfilecheckblocks getnodekey deactivatekeys datablocksptr return the final status of the fetch throws an exception or returns a bucket containing the fetched data throws fetch exception if the fetch failed for some reason private bucket final status object container container client context context throws fetch exception long final length 0 for int i 0 i segments length i split file fetcher segment s segments i if persistent container activate s 1 if s succeeded throw new illegal state exception not all finished s throw error container if still here it succeeded long sz s decoded length container final length sz if logminor logger minor this segment i decoded length sz total length now final length for s data buckets length blocks which should be s data buckets length nodechk block size healing is done by segment if final length override length if final length override length chk block data length throw new fetch exception fetch exception invalid metadata splitfile is final length but length is final length final length override length long bytes written 0 output stream os null bucket output if persistent container activate decompressors 5 if return bucket null container activate return bucket 5 try if return bucket null decompressors is empty output return bucket else output context get bucket factory parent persistent make bucket final length os output get output stream for int i 0 i segments length i split file fetcher segment s segments i long max final length 0 0 final length bytes written bytes written s write decoded data to os max s free decoded data container catch io exception e throw new fetch exception fetch exception bucket error e finally if os null try os close catch io exception e if it fails to close it may return corrupt data throw new fetch exception fetch exception bucket error e if final length output size logger error this final length is supposed to be final length but only written output size return output fetchexception finalstatus objectcontainer clientcontext fetchexception finallength splitfilefetchersegment illegalstateexception throwerror decodedlength finallength finallength databuckets databuckets block_size finallength overridelength finallength overridelength chkblock data_length fetchexception fetchexception invalid_metadata finallength finallength finallength overridelength byteswritten outputstream returnbucket returnbucket returnbucket isempty returnbucket getbucketfactory makebucket finallength getoutputstream splitfilefetchersegment finallength finallength byteswritten byteswritten writedecodeddatato freedecodeddata ioexception fetchexception fetchexception bucket_error ioexception fetchexception fetchexception bucket_error finallength finallength public void segment finished split file fetcher segment segment object container container client context context if persistent container activate this 1 if logminor logger minor this finished segment segment boolean finish false synchronized this boolean all done true for int i 0 i segments length i if persistent container activate segments i 1 if segments i succeeded if logminor logger minor this segment segments i is not finished all done false if all done if all segments finished logger error this was already finished segment finished segment new exception debug else all segments finished true finish true else for int i 0 i segments length i if segments i segment continue if persistent container deactivate segments i 1 notify all if persistent container store this if finish finish container context segmentfinished splitfilefetchersegment objectcontainer clientcontext alldone alldone alldone allsegmentsfinished segmentfinished allsegmentsfinished notifyall private void finish object container container client context context if persistent container activate cb 1 context get chk fetch scheduler remove pending keys this true boolean cb was active true try synchronized this if other failure null throw other failure if finished logger error this was already finished return finished true if persistent container store this bucket data final status container context decompress if persistent container activate decompressors 5 container activate return bucket 5 cb was active container ext is active cb if cb was active container activate cb 1 container activate fetch context 1 if fetch context null logger error this fetch context is null if container ext is active fetch context logger error this fetch context is null and splitfile is not activated new exception error container activate this 1 container activate decompressors 5 container activate return bucket 5 container activate fetch context 1 else logger error this fetch context is null and splitfile is activated new exception error container activate fetch context 1 int count 0 while decompressors is empty compressor c compressor decompressors remove decompressors size 1 if logminor logger minor this decompressing with c long max len math max fetch context max temp length fetch context max output length bucket orig data try bucket out return bucket if decompressors is empty out null data c decompress data context get bucket factory parent persistent max len max len 4 out catch io exception e if e get message equals not in gzip format count 1 logger error this attempting to decompress twice failed returning first round data this break cb on failure new fetch exception fetch exception bucket error e this container context return catch compression output size exception e if logminor logger minor this too big max size fetch context max output length max temp size fetch context max temp length cb on failure new fetch exception fetch exception too big e estimated size false fixme client metadata getmime type this container context return finally if orig data orig free if persistent orig remove from container count cb on success new fetch result client metadata data this container context catch fetch exception e cb on failure e this container context catch out of memory error e oom handler handleoom e system err println failing above attempted fetch cb on failure new fetch exception fetch exception internal error e this container context catch throwable t logger error this caught t t cb on failure new fetch exception fetch exception internal error t this container context if cb was active container deactivate cb 1 objectcontainer clientcontext getchkfetchscheduler removependingkeys cbwasactive otherfailure otherfailure finalstatus returnbucket cbwasactive isactive cbwasactive fetchcontext fetchcontext isactive fetchcontext returnbucket fetchcontext fetchcontext isempty maxlen fetchcontext maxtemplength fetchcontext maxoutputlength returnbucket isempty getbucketfactory maxlen maxlen ioexception getmessage onfailure fetchexception fetchexception bucket_error compressionoutputsizeexception maxsize fetchcontext maxoutputlength maxtempsize fetchcontext maxtemplength onfailure fetchexception fetchexception too_big estimatedsize clientmetadata getmimetype removefrom onsuccess fetchresult clientmetadata fetchexception onfailure outofmemoryerror oomhandler onfailure fetchexception fetchexception internal_error onfailure fetchexception fetchexception internal_error cbwasactive public void schedule object container container client context context throws key listener construction exception if persistent container activate this 1 if logminor logger minor this scheduling this sendable get getters new sendable get segments length for int i 0 i segments length i if logminor logger minor this scheduling segment i segments i if persistent container activate segments i 1 getters i segments i schedule container context if persistent container deactivate segments i 1 block set blocks fetch context blocks context get chk fetch scheduler register this getters persistent true container blocks false objectcontainer clientcontext keylistenerconstructionexception sendableget sendableget blockset fetchcontext getchkfetchscheduler public void cancel object container container client context context boolean persist persistent if persist container activate this 1 for int i 0 i segments length i if logminor logger minor this cancelling segment i if segments null persist container ext is active this fixme is this normal if so just reactivate logger error this deactivated mid cancel on this new exception error container activate this 1 if segments i null synchronized this if finished not unusual if some of the later segments are already finished when cancel is called if logminor logger minor this finished mid cancel on this return if persist container activate segments i 1 segments i cancel container context objectcontainer clientcontext isactive public long get token return token gettoken make our split file fetcher key listener returns the one we created in the constructor if possible otherwise makes a new one we must have already constructed one at some point maybe before a restart throws fetch exception public key listener make key listener object container container client context context throws key listener construction exception synchronized this if finished return null if temp listener null recently constructed return temp listener file main file alt boolean cache local requests if fetch context null logger error this fetch context deleted without splitfile being deleted return null if persistent container activate main bloom file 5 container activate alt bloom file 5 main new file main bloom file get path alt new file alt bloom file get path container deactivate main bloom file 1 container deactivate alt bloom file 1 container activate fetch context 1 cache local requests fetch context cache local requests container deactivate fetch context 1 else main null alt null cache local requests fetch context cache local requests try if logminor logger minor this attempting to read bloom filter for this main file main alt file alt temp listener new split file fetcher key listener this key count main alt main bloom filter size bytes main bloomk cache local requests local salt segments length per segment bloom filter size bytes per segmentk persistent false catch io exception e logger error this unable to read bloom filter for this attempting to reconstruct e main delete alt delete try main bloom file context fg make random file alt bloom file context fg make random file if persistent container store this catch io exception e1 throw new key listener construction exception new fetch exception fetch exception bucket error unable to create bloom filter files in reconstruction e1 try temp listener new split file fetcher key listener this key count main bloom file alt bloom file main bloom filter size bytes main bloomk fetch context cache local requests local salt segments length per segment bloom filter size bytes per segmentk persistent true catch io exception e1 throw new key listener construction exception new fetch exception fetch exception bucket error unable to reconstruct bloom filters e1 e1 return temp listener splitfilefetcherkeylistener fetchexception keylistener makekeylistener objectcontainer clientcontext keylistenerconstructionexception templistener templistener cachelocalrequests fetchcontext fetchcontext mainbloomfile altbloomfile mainbloomfile getpath altbloomfile getpath mainbloomfile altbloomfile fetchcontext cachelocalrequests fetchcontext cachelocalrequests fetchcontext cachelocalrequests fetchcontext cachelocalrequests templistener splitfilefetcherkeylistener keycount mainbloomfiltersizebytes mainbloomk cachelocalrequests localsalt persegmentbloomfiltersizebytes persegmentk ioexception mainbloomfile makerandomfile altbloomfile makerandomfile ioexception keylistenerconstructionexception fetchexception fetchexception bucket_error templistener splitfilefetcherkeylistener keycount mainbloomfile altbloomfile mainbloomfiltersizebytes mainbloomk fetchcontext cachelocalrequests localsalt persegmentbloomfiltersizebytes persegmentk ioexception keylistenerconstructionexception fetchexception fetchexception bucket_error templistener public synchronized boolean is cancelled object container container return finished iscancelled objectcontainer public split file fetcher segment get segment int i return segments i splitfilefetchersegment getsegment public void remove my pending keys split file fetcher segment segment object container container client context context key count temp listener kill segment segment container context removemypendingkeys splitfilefetchersegment objectcontainer clientcontext keycount templistener killsegment void set key count int key count2 object container container this key count key count2 if persistent container store this setkeycount keycount2 objectcontainer keycount keycount2 public void on failed key listener construction exception e object container container client context context other failure e get fetch exception cancel container context onfailed keylistenerconstructionexception objectcontainer clientcontext otherfailure getfetchexception public void remove from object container container client context context if logminor logger minor this remove from on this new exception debug if container ext is stored this logger error this already removed on this new exception error return container activate block fetch context 1 block fetch context remove from container if delete fetch context container activate fetch context 1 fetch context remove from container container activate client metadata 1 client metadata remove from container container activate decompressors 1 container delete decompressors for int i 0 i segments length i split file fetcher segment segment segments i segments i null container activate segment 1 segment fetcher finished container context container activate main bloom file 5 container activate alt bloom file 5 if main bloom file null main bloom file delete main bloom file exists logger error this unable to delete main bloom file main bloom file for this else if main bloom file null logger error this main bloom file is null on this else if logminor logger minor this deleted main bloom file main bloom file if alt bloom file null alt bloom file delete alt bloom file exists logger error this unable to delete alt bloom file alt bloom file for this else if alt bloom file null logger error this alt bloom file is null on this else if logminor logger minor this deleted alt bloom file alt bloom file container delete main bloom file container delete alt bloom file container delete this removefrom objectcontainer clientcontext removefrom isstored blockfetchcontext blockfetchcontext removefrom deletefetchcontext fetchcontext fetchcontext removefrom clientmetadata clientmetadata removefrom splitfilefetchersegment fetcherfinished mainbloomfile altbloomfile mainbloomfile mainbloomfile mainbloomfile mainbloomfile mainbloomfile mainbloomfile mainbloomfile altbloomfile altbloomfile altbloomfile altbloomfile altbloomfile altbloomfile altbloomfile mainbloomfile altbloomfile public boolean object can update object container container if hash code 0 logger error this trying to update with hash 0 already deleted active container ext is active this stored container ext is stored this new exception error return false return true objectcanupdate objectcontainer hashcode isactive isstored public boolean object can new object container container if hash code 0 logger error this trying to write with hash 0 already deleted active container ext is active this stored container ext is stored this new exception error return false return true objectcannew objectcontainer hashcode isactive isstored public xml pull parser exception string s super s xmlpullparserexception public xml pull parser exception string msg xml pull parser parser throwable chain super msg null msg parser null position parser get position description chain null caused by chain if parser null this row parser get line number this column parser get column number this detail chain xmlpullparserexception xmlpullparser getpositiondescription getlinenumber getcolumnnumber public throwable get detail return detail getdetail public throwable get detail return detail public void set detail throwable cause this detail cause public int get line number return row getdetail setdetail getlinenumber public void set detail throwable cause this detail cause public int get line number return row public int get column number return column setdetail getlinenumber getcolumnnumber note code that prints this and detail is difficult in j2me public void print stack trace if detail null super print stack trace else synchronized system err system err println super get message nested exception is detail print stack trace printstacktrace printstacktrace getmessage printstacktrace private float interpolation public interpolate filter interpolatefilter set the destination image param destination the destination image see get destination public void set destination buffered image destination this destination destination getdestination setdestination bufferedimage get the destination image return the destination image see set destination public buffered image get destination return destination setdestination bufferedimage getdestination set the interpolation factor param interpolation the interpolation factor see get interpolation public void set interpolation float interpolation this interpolation interpolation getinterpolation setinterpolation get the interpolation factor return the interpolation factor see set interpolation public float get interpolation return interpolation setinterpolation getinterpolation public buffered image filter buffered image src buffered image dst int width src get width int height src get height int type src get type writable raster src raster src get raster if dst null dst create compatible dest image src null writable raster dst raster dst get raster if destination null width math min width destination get width height math min height destination get width int pixels1 null int pixels2 null for int y 0 y height y pixels1 getrgb src 0 y width 1 pixels1 pixels2 getrgb destination 0 y width 1 pixels2 for int x 0 x width x int rgb1 pixels1 x int rgb2 pixels2 x int a1 rgb1 24 0xff int r1 rgb1 16 0xff int g1 rgb1 8 0xff int b1 rgb1 0xff int a2 rgb2 24 0xff int r2 rgb2 16 0xff int g2 rgb2 8 0xff int b2 rgb2 0xff r1 pixel utils clamp image math lerp interpolation r1 r2 g1 pixel utils clamp image math lerp interpolation g1 g2 b1 pixel utils clamp image math lerp interpolation b1 b2 pixels1 x a1 24 r1 16 g1 8 b1 setrgb dst 0 y width 1 pixels1 return dst bufferedimage bufferedimage bufferedimage getwidth getheight gettype writableraster srcraster getraster createcompatibledestimage writableraster dstraster getraster getwidth getwidth pixelutils imagemath pixelutils imagemath pixelutils imagemath override public string to string return effects interpolate tostring suppress warnings serial public class invalid config value exception extends config exception public invalid config value exception string msg super msg suppresswarnings invalidconfigvalueexception configexception invalidconfigvalueexception public final class color dodge composite extends rgb composite public color dodge composite float alpha super alpha colordodgecomposite rgbcomposite colordodgecomposite public composite context create context color model src color model color model dst color model rendering hints hints return new context extra alpha src color model dst color model compositecontext createcontext colormodel srccolormodel colormodel dstcolormodel renderinghints extraalpha srccolormodel dstcolormodel static class context extends rgb composite context public context float alpha color model src color model color model dst color model super alpha src color model dst color model rgbcompositecontext colormodel srccolormodel colormodel dstcolormodel srccolormodel dstcolormodel override public void composergb int src int dst float alpha int w src length for int i 0 i w i 4 int sr src i int dir dst i int sg src i 1 int dig dst i 1 int sb src i 2 int dib dst i 2 int sa src i 3 int dia dst i 3 int dor dog dob if sr 255 dor math min dir 8 255 sr 255 else dor sr if sg 255 dog math min dig 8 255 sg 255 else dog sg if sb 255 dob math min dib 8 255 sb 255 else dob sb float a alpha sa 255f float ac 1 a dst i int a dor ac dir dst i 1 int a dog ac dig dst i 2 int a dob ac dib dst i 3 int sa alpha dia ac public final static boolean is root device string nt value if nt value null return false return nt value starts with rootdevice isrootdevice ntvalue ntvalue ntvalue startswith public sun14 reflection provider try class object stream class class for name java io object stream class field reflector field unsafe field object stream class get declared field unsafe unsafe field set accessible true unsafe unsafe unsafe field get null java lang object constructor object class get declared constructor new class 0 factory reflection factory get reflection factory constructor hash new hash map catch exception x throw new error failed to initialize reflection provider sun14reflectionprovider objectstreamclass forname objectstreamclass fieldreflector unsafefield objectstreamclass getdeclaredfield unsafefield setaccessible unsafefield javalangobjectconstructor getdeclaredconstructor reflectionfactory getreflectionfactory constructorhash hashmap public constructor get default constructor class cls throws exception constructor cons constructor constructor hash get cls if cons null try cons cls get declared constructor default constructor profile catch no such method exception x cons factory new constructor for serialization cls java lang object constructor constructor hash put cls cons return cons getdefaultconstructor constructorhash getdeclaredconstructor defaultconstructorprofile nosuchmethodexception newconstructorforserialization javalangobjectconstructor constructorhash public void set int field field object object int value throws exception unsafe put int object unsafe object field offset field value setint putint objectfieldoffset public void set long field field object object long value throws exception unsafe put long object unsafe object field offset field value setlong putlong objectfieldoffset public void set short field field object object short value throws exception unsafe put short object unsafe object field offset field value setshort putshort objectfieldoffset public void set char field field object object char value throws exception unsafe put char object unsafe object field offset field value setchar putchar objectfieldoffset public void set byte field field object object byte value throws exception unsafe put byte object unsafe object field offset field value setbyte putbyte objectfieldoffset public void set float field field object object float value throws exception unsafe put float object unsafe object field offset field value setfloat putfloat objectfieldoffset public void set double field field object object double value throws exception unsafe put double object unsafe object field offset field value setdouble putdouble objectfieldoffset public void set boolean field field object object boolean value throws exception unsafe put boolean object unsafe object field offset field value setboolean putboolean objectfieldoffset public void set field field object object object value throws exception unsafe put object object unsafe object field offset field value putobject objectfieldoffset public class null file implements i file public void write long pos byte buf nullfile ifile public void write long pos byte buf public int read long pos byte buf return 0 public void sync public void sync public boolean try lock boolean shared return true trylock public void lock boolean shared public void unlock public void close public void close public long length return 0 public class pubkey store extends store callback override public boolean collision possible return false pubkeystore storecallback collisionpossible override public storable block construct byte data byte headers byte routing key byte full key throws key verify exception if data null throw new pubkey verify exception need data to construct pubkey try return dsa public key create data catch crypt format exception e throw new pubkey verify exception e storableblock routingkey fullkey keyverifyexception pubkeyverifyexception dsapublickey cryptformatexception pubkeyverifyexception public dsa public key fetch byte hash boolean dont promote throws io exception return dsa public key store fetch hash null dont promote dsapublickey dontpromote ioexception dsapublickey dontpromote public void put byte hash dsa public key key throws io exception try store put key key get routing key key get full key key as padded bytes empty false catch key collision exception e logger error this impossible for pubkey store e e dsapublickey ioexception getroutingkey getfullkey aspaddedbytes keycollisionexception pubkeystore override public int data length return dsa public key padded size datalength dsapublickey padded_size override public int full key length return dsa public key hash length fullkeylength dsapublickey hash_length override public int header length return 0 headerlength override public int routing key length return dsa public key hash length routingkeylength dsapublickey hash_length override public boolean store full keys return false storefullkeys override public boolean construct needs key return false constructneedskey override public byte routing key from full key byte key buf return key buf routingkeyfromfullkey keybuf keybuf public final class difference composite extends rgb composite public difference composite float alpha super alpha differencecomposite rgbcomposite differencecomposite public composite context create context color model src color model color model dst color model rendering hints hints return new context extra alpha src color model dst color model compositecontext createcontext colormodel srccolormodel colormodel dstcolormodel renderinghints extraalpha srccolormodel dstcolormodel static class context extends rgb composite context public context float alpha color model src color model color model dst color model super alpha src color model dst color model rgbcompositecontext colormodel srccolormodel colormodel dstcolormodel srccolormodel dstcolormodel override public void composergb int src int dst float alpha int w src length for int i 0 i w i 4 int sr src i int dir dst i int sg src i 1 int dig dst i 1 int sb src i 2 int dib dst i 2 int sa src i 3 int dia dst i 3 int dor dog dob dor dir sr if dor 0 dor dor dog dig sg if dog 0 dog dog dob dib sb if dob 0 dob dob float a alpha sa 255f float ac 1 a dst i int a dor ac dir dst i 1 int a dog ac dig dst i 2 int a dob ac dib dst i 3 int sa alpha dia ac public class cannot create from field set exception extends exception private static final long serial versionuid 1l public cannot create from field set exception string msg super msg cannotcreatefromfieldsetexception serialversionuid cannotcreatefromfieldsetexception public cannot create from field set exception string msg exception e super msg e e cannotcreatefromfieldsetexception static logger register log threshold callback new log threshold callback override public void should update logminor logger should log logger minor this registerlogthresholdcallback logthresholdcallback shouldupdate shouldlog public nodeip detector node node this node node ip detector manager new ip detector plugin manager node this ip detector new ip address detector 10 1000 this invalid address override alert new invalid address override user alert node primaryip undetected alert new ip undetected user alert node port detectors new nodeip port detector 0 nodeipdetector ipdetectormanager ipdetectorpluginmanager ipdetector ipaddressdetector invalidaddressoverridealert invalidaddressoverrideuseralert primaryipundetectedalert ipundetecteduseralert portdetectors nodeipportdetector public synchronized void add port detector nodeip port detector detector nodeip port detector new detectors new nodeip port detector port detectors length 1 system arraycopy port detectors 0 new detectors 0 port detectors length new detectors port detectors length detector port detectors new detectors addportdetector nodeipportdetector nodeipportdetector newdetectors nodeipportdetector portdetectors portdetectors newdetectors portdetectors newdetectors portdetectors portdetectors newdetectors what is my ip address use all globally available information everything which isn t specific to a given port i e opennet or darknet to determine our current ip addresses will include more than one ip in many cases when we are not strictly multi homed for example if we have a dns name set we will usually return an ip as well will warn the user with a user alert if we don t have sufficient information freenet inet address detect primaryip address boolean dump local addresses boolean added validip false logger minor this redetecting i ps array list freenet inet address addresses new array list freenet inet address if overrideip address null if the ip is overridden and the override is valid the override has to be the first element overrideip address will be null if the override is invalid addresses add overrideip address if overrideip address is real internet address false true false added validip true if node dont detect added validip inner detect addresses if node client core null boolean had validip synchronized this had validip has validip has validip added validip if first detection had validip added validip first detection false if had validip added validip if added validip if logminor logger minor this got valid ip on added validip else if logminor logger minor this no valid ip on not added validip else if logminor logger minor this client core not loaded synchronized this has validip added validip lastip address addresses to array new freenet inet address addresses size if dump local addresses array list freenet inet address filtered new array list freenet inet address lastip address length for int i 0 i lastip address length i if lastip address i null continue if lastip address i overrideip address lastip address i has hostname noip filtered add lastip address i else if lastip address i has hostname noip continue else if ip util is valid address lastip address i get address false filtered add lastip address i return filtered to array new freenet inet address filtered size return lastip address useralert freenetinetaddress detectprimaryipaddress dumplocaladdresses addedvalidip ips arraylist freenetinetaddress arraylist freenetinetaddress overrideipaddress overrideipaddress overrideipaddress overrideipaddress isrealinternetaddress addedvalidip dontdetect addedvalidip innerdetect clientcore hadvalidip hadvalidip hasvalidip hasvalidip addedvalidip firstdetection hadvalidip addedvalidip firstdetection hadvalidip addedvalidip addedvalidip onaddedvalidip onnotaddedvalidip hasvalidip addedvalidip lastipaddress toarray freenetinetaddress dumplocaladdresses arraylist freenetinetaddress arraylist freenetinetaddress lastipaddress lastipaddress lastipaddress lastipaddress overrideipaddress lastipaddress hashostnamenoip lastipaddress lastipaddress hashostnamenoip iputil isvalidaddress lastipaddress getaddress lastipaddress toarray freenetinetaddress lastipaddress boolean has validip synchronized this return has validip hasvalidip hasvalidip private void on added validip node client core alerts unregister primaryip undetected alert node on added validip onaddedvalidip clientcore primaryipundetectedalert onaddedvalidip private void on not added validip node client core alerts register primaryip undetected alert onnotaddedvalidip clientcore primaryipundetectedalert core of the ip detection algorithm param addresses param added validip return private boolean inner detect list freenet inet address addresses boolean added validip false inet address detected addrs ip detector get address assert detected addrs null synchronized this has detectediad true for int i 0 i detected addrs length i freenet inet address addr new freenet inet address detected addrs i if addresses contains addr logger normal this detected ip address addr addresses add addr if addr is real internet address false false false added validip true if plugin detectedi ps null plugin detectedi ps length 0 for int i 0 i plugin detectedi ps length i inet address addr plugin detectedi ps i public address if addr null continue freenet inet address a new freenet inet address addr if addresses contains a logger normal this plugin detected ip address a addresses add a if a is real internet address false false false added validip true if added validip oldip address null oldip address equals overrideip address addresses add oldip address don t set added validip there is an excellent chance that this is out of date so we still want to nag the user until we have some confirmation try to pick it up from our connections if node peers null peer node peer list node peers my peers hash map freenet inet address integer counts by peer new hash map freenet inet address integer fixme use a standard mutable int object we have one somewhere for int i 0 i peer list length i if peer list i is connected if logminor logger minor this not connected continue if peer list i is real connection only let seed server connections through we have to trust them anyway if peer list i instanceof seed server peer node continue if logminor logger minor this not a real connection and not a seed node peer list i if logminor logger minor this maybe a usable connection for ip peer list i peer p peer list i get remote detected peer if logminor logger minor this remote detected peer p if p null p is null continue freenet inet address addr p get freenet address if logminor logger minor this address addr if addr null continue if ip util is valid address addr get address false false if logminor logger minor this address not valid continue if logminor logger minor this peer peer list i get peer thinks we are addr if counts by peer contains key addr counts by peer put addr counts by peer get addr 1 else counts by peer put addr 1 if counts by peer size 1 iterator freenet inet address it counts by peer key set iterator freenet inet address addr it next logger minor this everyone agrees we are addr if addresses contains addr if addr is real internet address false false false added validip true addresses add addr else if counts by peer size 1 take two most popular addresses freenet inet address best null freenet inet address second best null int best popularity 0 int second best popularity 0 for map entry freenet inet address integer entry counts by peer entry set freenet inet address cur entry get key int cur pop entry get value logger minor this detected peer cur popularity cur pop if cur pop best popularity second best popularity best popularity best popularity cur pop second best best best cur if best null boolean has real detected address false for int i 0 i detected addrs length i if ip util is valid address detected addrs i false has real detected address true if best popularity 1 has real detected address if addresses contains best logger minor this adding best peer best best popularity addresses add best if best is real internet address false false false added validip true if second best null second best popularity 1 if addresses contains second best logger minor this adding second best peer second best second best addresses add second best if second best is real internet address false false false added validip true return added validip addedvalidip innerdetect freenetinetaddress addedvalidip inetaddress detectedaddrs ipdetector getaddress detectedaddrs hasdetectediad detectedaddrs freenetinetaddress freenetinetaddress detectedaddrs isrealinternetaddress addedvalidip plugindetectedips plugindetectedips plugindetectedips inetaddress plugindetectedips publicaddress freenetinetaddress freenetinetaddress isrealinternetaddress addedvalidip addedvalidip oldipaddress oldipaddress overrideipaddress oldipaddress addedvalidip peernode peerlist mypeers hashmap freenetinetaddress countsbypeer hashmap freenetinetaddress peerlist peerlist isconnected peerlist isrealconnection peerlist seedserverpeernode peerlist peerlist peerlist getremotedetectedpeer isnull freenetinetaddress getfreenetaddress iputil isvalidaddress getaddress peerlist getpeer countsbypeer containskey countsbypeer countsbypeer countsbypeer countsbypeer freenetinetaddress countsbypeer keyset freenetinetaddress isrealinternetaddress addedvalidip countsbypeer freenetinetaddress freenetinetaddress secondbest bestpopularity secondbestpopularity freenetinetaddress countsbypeer entryset freenetinetaddress getkey curpop getvalue curpop curpop bestpopularity secondbestpopularity bestpopularity bestpopularity curpop secondbest hasrealdetectedaddress detectedaddrs iputil isvalidaddress detectedaddrs hasrealdetectedaddress bestpopularity hasrealdetectedaddress bestpopularity isrealinternetaddress addedvalidip secondbest secondbestpopularity secondbest secondbest secondbest secondbest secondbest isrealinternetaddress addedvalidip addedvalidip private string l10n string key return l10n get string nodeip detector key getstring nodeipdetector private string l10n string key string pattern string value return l10n get string nodeip detector key pattern value getstring nodeipdetector freenet inet address get primaryip address boolean dump local if lastip address null return detect primaryip address dump local return lastip address freenetinetaddress getprimaryipaddress dumplocal lastipaddress detectprimaryipaddress dumplocal lastipaddress public boolean has directly detectedip inet address addrs ip detector get address if addrs null addrs length 0 return false for int i 0 i addrs length i if ip util is valid address addrs i false if logminor logger minor this has a directly detected ip addrs i return true return false hasdirectlydetectedip inetaddress ipdetector getaddress iputil isvalidaddress process a list of detectedip s from the ip detector plugin manager detectedip s can tell us what kind of nat we are behind as well as our public ip address public void process detectedi ps detectedip list plugin detectedi ps list for int i 0 i plugin detectedi ps length i int mtu plugin detectedi ps i mtu if minimummtu mtu mtu 0 minimummtu mtu logger normal this reducing the mtu to minimummtu if mtu udp socket handler min mtu node on too lowmtu minimummtu udp socket handler min mtu redetect address processdetectedips plugindetectedips plugindetectedips plugindetectedips udpsockethandler min_mtu ontoolowmtu udpsockethandler min_mtu redetectaddress public void redetect address freenet inet address newip detect primaryip address false nodeip port detector detectors synchronized this if arrays equals newip lastip return lastip newip detectors port detectors for int i 0 i detectors length i detectors i update node write node file redetectaddress freenetinetaddress detectprimaryipaddress nodeipportdetector portdetectors writenodefile public void set oldip address freenet inet address freenet address this oldip address freenet address setoldipaddress freenetinetaddress freenetaddress oldipaddress freenetaddress public int register configs sub config node config int sort order ip address override node config register ip address override sort order true false nodeip dectector ip override nodeip dectector ip override long new string callback override public string get if overrideip address string null return else return overrideip address string override public void set string val throws invalid config value exception boolean had valid address override has valid address override fixme do we need to tell anyone if val length 0 set to null overrideip address string val overrideip address null lastip address null redetect address return freenet inet address addr try addr new freenet inet address val false true catch hostname syntax exception e throw new invalid config value exception l10n unknown host error inip override error hostname or ip address syntax error catch unknown host exception e throw new invalid config value exception l10n unknown host error inip override error e get message compare as i ps if addr equals overrideip address return overrideip address string val overrideip address addr lastip address null synchronized this has valid address override true if had valid address override on get valid address override redetect address has valid address override true overrideip address string node config get string ip address override if overrideip address string length 0 overrideip address null else try overrideip address new freenet inet address overrideip address string false true catch hostname syntax exception e synchronized this has valid address override false string msg invalid ip override syntax overrideip address string in config e get message logger error this msg system err println msg but starting up anyway ignoring the configured ip override overrideip address null catch unknown host exception e fixme this never happens for this reason with current freenet inet address string boolean boolean code perhaps it needs review string msg unknown host overrideip address string in config e get message logger error this msg system err println msg but starting up anyway with no ip override overrideip address null temporary ip address hint node config register tempip address hint sort order true false nodeip dectector temp address hint nodeip dectector temp address hint long new string callback override public string get return override public void set string val throws invalid config value exception if val length 0 return if overrideip address null return try oldip address new freenet inet address val false catch unknown host exception e throw new invalid config value exception unknown host e get message redetect address string ip hint string node config get string tempip address hint if ip hint string length 0 try oldip address new freenet inet address ip hint string false catch unknown host exception e string msg unknown host ip hint string in config e get message logger error this msg system err println msg oldip address null return sort order registerconfigs subconfig nodeconfig sortorder nodeconfig ipaddressoverride sortorder nodeipdectector ipoverride nodeipdectector ipoverridelong stringcallback overrideipaddressstring overrideipaddressstring invalidconfigvalueexception hadvalidaddressoverride hasvalidaddressoverride overrideipaddressstring overrideipaddress lastipaddress redetectaddress freenetinetaddress freenetinetaddress hostnamesyntaxexception invalidconfigvalueexception unknownhosterrorinipoverride unknownhostexception invalidconfigvalueexception unknownhosterrorinipoverride getmessage ips overrideipaddress overrideipaddressstring overrideipaddress lastipaddress hasvalidaddressoverride hadvalidaddressoverride ongetvalidaddressoverride redetectaddress hasvalidaddressoverride overrideipaddressstring nodeconfig getstring ipaddressoverride overrideipaddressstring overrideipaddress overrideipaddress freenetinetaddress overrideipaddressstring hostnamesyntaxexception hasvalidaddressoverride overrideipaddressstring getmessage overrideipaddress unknownhostexception freenetinetaddress overrideipaddressstring getmessage overrideipaddress nodeconfig tempipaddresshint sortorder nodeipdectector tempaddresshint nodeipdectector tempaddresshintlong stringcallback invalidconfigvalueexception overrideipaddress oldipaddress freenetinetaddress unknownhostexception invalidconfigvalueexception getmessage redetectaddress iphintstring nodeconfig getstring tempipaddresshint iphintstring oldipaddress freenetinetaddress iphintstring unknownhostexception iphintstring getmessage oldipaddress sortorder override public string get if overrideip address string null return else return overrideip address string overrideipaddressstring overrideipaddressstring override public void set string val throws invalid config value exception boolean had valid address override has valid address override fixme do we need to tell anyone if val length 0 set to null overrideip address string val overrideip address null lastip address null redetect address return freenet inet address addr try addr new freenet inet address val false true catch hostname syntax exception e throw new invalid config value exception l10n unknown host error inip override error hostname or ip address syntax error catch unknown host exception e throw new invalid config value exception l10n unknown host error inip override error e get message compare as i ps if addr equals overrideip address return overrideip address string val overrideip address addr lastip address null synchronized this has valid address override true if had valid address override on get valid address override redetect address invalidconfigvalueexception hadvalidaddressoverride hasvalidaddressoverride overrideipaddressstring overrideipaddress lastipaddress redetectaddress freenetinetaddress freenetinetaddress hostnamesyntaxexception invalidconfigvalueexception unknownhosterrorinipoverride unknownhostexception invalidconfigvalueexception unknownhosterrorinipoverride getmessage ips overrideipaddress overrideipaddressstring overrideipaddress lastipaddress hasvalidaddressoverride hadvalidaddressoverride ongetvalidaddressoverride redetectaddress node config register tempip address hint sort order true false nodeip dectector temp address hint nodeip dectector temp address hint long new string callback override public string get return nodeconfig tempipaddresshint sortorder nodeipdectector tempaddresshint nodeipdectector tempaddresshintlong stringcallback override public void set string val throws invalid config value exception if val length 0 return if overrideip address null return try oldip address new freenet inet address val false catch unknown host exception e throw new invalid config value exception unknown host e get message redetect address invalidconfigvalueexception overrideipaddress oldipaddress freenetinetaddress unknownhostexception invalidconfigvalueexception getmessage redetectaddress start all ip detection related processes public void start boolean have valid address override has valid address override if have valid address override on not get valid address override node executor execute ip detector ip address re detector redetect address 60 second delay for inserting ark to avoid reinserting more than necessary if we don t detect ip on startup not a fast runnable as it can take a while to start the insert node get ticker queue timed job new runnable public void run nodeip port detector detectors synchronized this detectors port detectors for int i 0 i detectors length i detectors i startark 60 1000 havevalidaddressoverride hasvalidaddressoverride havevalidaddressoverride onnotgetvalidaddressoverride ipdetector redetectaddress fastrunnable getticker queuetimedjob nodeipportdetector portdetectors node get ticker queue timed job new runnable public void run nodeip port detector detectors synchronized this detectors port detectors for int i 0 i detectors length i detectors i startark getticker queuetimedjob nodeipportdetector portdetectors public void on connected peer ip detector manager maybe run onconnectedpeer ipdetectormanager mayberun public void registerip detector plugin fred pluginip detector detector ip detector manager register detector plugin detector registeripdetectorplugin fredpluginipdetector ipdetectormanager registerdetectorplugin public void unregisterip detector plugin fred pluginip detector detector ip detector manager unregister detector plugin detector unregisteripdetectorplugin fredpluginipdetector ipdetectormanager unregisterdetectorplugin public synchronized boolean is detecting return has detectedpm has detectediad isdetecting hasdetectedpm hasdetectediad void has detectedpm if logminor logger minor this has detectedpm called new exception debug synchronized this has detectedpm true hasdetectedpm hasdetectedpm hasdetectedpm public int get minimum detectedmtu return minimummtu 0 minimummtu 1500 getminimumdetectedmtu public void set maybe symmetric if ip detector manager null ip detector manager is empty if maybe symmetric alert null maybe symmetric alert new simple user alert true l10n maybe symmetric title l10n maybe symmetric l10n maybe symmetric short user alert error if node client core null node client core alerts null node client core alerts register maybe symmetric alert else if maybe symmetric alert null node client core alerts unregister maybe symmetric alert setmaybesymmetric ipdetectormanager ipdetectormanager isempty maybesymmetricalert maybesymmetricalert simpleuseralert maybesymmetrictitle maybesymmetric maybesymmetricshort useralert clientcore clientcore clientcore maybesymmetricalert maybesymmetricalert clientcore maybesymmetricalert public void register port forward plugin fred plugin port forward forward ip detector manager register port forward plugin forward registerportforwardplugin fredpluginportforward ipdetectormanager registerportforwardplugin public void unregister port forward plugin fred plugin port forward forward ip detector manager unregister port forward plugin forward unregisterportforwardplugin fredpluginportforward ipdetectormanager unregisterportforwardplugin todo ugly deal with multiple instances properly public synchronized void register bandwidth indicator plugin fred plugin bandwidth indicator indicator bandwidth indicator indicator registerbandwidthindicatorplugin fredpluginbandwidthindicator bandwidthindicator bandwidth indicator indicator public synchronized void unregister bandwidth indicator plugin fred plugin bandwidth indicator indicator bandwidth indicator null bandwidthindicator unregisterbandwidthindicatorplugin fredpluginbandwidthindicator bandwidthindicator bandwidth indicator null public synchronized fred plugin bandwidth indicator get bandwidth indicator return bandwidth indicator bandwidthindicator fredpluginbandwidthindicator getbandwidthindicator bandwidthindicator boolean has valid address override synchronized this return has valid address override hasvalidaddressoverride hasvalidaddressoverride private void on get valid address override node client core alerts unregister invalid address override alert ongetvalidaddressoverride clientcore invalidaddressoverridealert private void on not get valid address override node client core alerts register invalid address override alert onnotgetvalidaddressoverride clientcore invalidaddressoverridealert public void add connection type box html node content node ip detector manager add connection type box content node addconnectiontypebox htmlnode contentnode ipdetectormanager addconnectiontypebox contentnode public boolean no detect plugins return ip detector manager has detectors nodetectplugins ipdetectormanager hasdetectors transient field fld alt btree field index altbtreefieldindex private final void locate field fld class descriptor locate field cls field name if fld null throw new storage error storage error indexed field not found class name field name locatefield classdescriptor locatefield fieldname storageerror storageerror indexed_field_not_found classname fieldname public class get indexed class return cls getindexedclass public field get key fields return new field fld getkeyfields public void on load cls class descriptor load class get storage class name locate field onload classdescriptor loadclass getstorage classname locatefield alt btree field index class cls string field name boolean unique this cls cls this unique unique this field name field name this class name class descriptor get class name cls locate field type check type fld get type altbtreefieldindex fieldname fieldname fieldname classname classdescriptor getclassname locatefield checktype gettype private key extract key i persistent obj try field f fld key key null switch type case class descriptor tp boolean key new key f get boolean obj break case class descriptor tp byte key new key f get byte obj break case class descriptor tp short key new key f get short obj break case class descriptor tp char key new key f get char obj break case class descriptor tp int key new key f get int obj break case class descriptor tp object i persistent ptr i persistent f get obj if ptr null ptr is persistent get storage make persistent ptr key new key ptr break case class descriptor tp long key new key f get long obj break case class descriptor tp date key new key date f get obj break case class descriptor tp float key new key f get float obj break case class descriptor tp double key new key f get double obj break case class descriptor tp enum key new key enum f get obj break case class descriptor tp string key new key string f get obj break case class descriptor tp raw key new key comparable f get obj break default assert failed invalid type return key catch exception x throw new storage error storage error access violation x extractkey ipersistent classdescriptor tpboolean getboolean classdescriptor tpbyte getbyte classdescriptor tpshort getshort classdescriptor tpchar getchar classdescriptor tpint getint classdescriptor tpobject ipersistent ipersistent ispersistent getstorage makepersistent classdescriptor tplong getlong classdescriptor tpdate classdescriptor tpfloat getfloat classdescriptor tpdouble getdouble classdescriptor tpenum classdescriptor tpstring classdescriptor tpraw storageerror storageerror access_violation public boolean put t obj return super insert extract key obj obj false null extractkey public t set t obj return super set extract key obj obj extractkey public void remove t obj super remove extract key obj obj extractkey public boolean contains object t obj key key extract key obj if unique return super get key null else i persistent mbrs get key key for int i 0 i mbrs length i if mbrs i obj return true return false containsobject extractkey ipersistent public boolean contains t obj key key extract key obj if unique return super get key null else i persistent mbrs get key key for int i 0 i mbrs length i if mbrs i equals obj return true return false extractkey ipersistent public synchronized void append t obj key key try switch type case class descriptor tp int key new key int autoinc count fld set int obj int autoinc count break case class descriptor tp long key new key autoinc count fld set long obj autoinc count break default throw new storage error storage error unsupported index type fld get type catch exception x throw new storage error storage error access violation x autoinc count 1 obj modify super insert key obj false classdescriptor tpint autoinccount setint autoinccount classdescriptor tplong autoinccount setlong autoinccount storageerror storageerror unsupported_index_type gettype storageerror storageerror access_violation autoinccount public t get prefix string prefix array list t list get list new key prefix true new key prefix character max value false return t list to array t array new instance cls list size getprefix arraylist getlist max_value toarray newinstance public t prefix search string key array list t list prefix search list key return t list to array t array new instance cls list size prefixsearch arraylist prefixsearchlist toarray newinstance public t get key from key till array list t list new array list if root null root find check key from check key till height list return t list to array t array new instance cls list size arraylist arraylist checkkey checkkey toarray newinstance public t to persistent array t arr t array new instance cls n elems if root null root traverse forward height arr 0 return arr topersistentarray newinstance nelems traverseforward public iterable iterator t query by example t obj key key extract key obj return iterator key key ascent order iterableiterator querybyexample extractkey ascent_order public iterable iterator t select string predicate query t query new query impl t get storage return query select cls iterator predicate iterableiterator queryimpl getstorage public boolean is case insensitive return false iscaseinsensitive class alt btree case insensitive field index t extends i persistent extends alt btree field index t alt btree case insensitive field index altbtreecaseinsensitivefieldindex ipersistent altbtreefieldindex altbtreecaseinsensitivefieldindex alt btree case insensitive field index alt btree case insensitive field index class cls string field name boolean unique super cls field name unique altbtreecaseinsensitivefieldindex altbtreecaseinsensitivefieldindex fieldname fieldname key check key key key if key null key oval instanceof string key new key string key oval to lower case key inclusion 0 return super check key key checkkey tolowercase checkkey public boolean is case insensitive return true iscaseinsensitive construct a spcetrum color map public spectrum colormap spectrumcolormap convert a value in the range 0 1 to an rgb color param v a value in the range 0 1 return an rgb color public int get color float v return spectrum wavelength torgb 380 400 image math clamp v 0 1 0f getcolor wavelengthtorgb imagemath private int edge color 0xff000000 public crystallize filter set scale 16 set randomness 0 0f edgecolor crystallizefilter setscale setrandomness public void set edge thickness float edge thickness this edge thickness edge thickness setedgethickness edgethickness edgethickness edgethickness public float get edge thickness return edge thickness getedgethickness edgethickness public void set fade edges boolean fade edges this fade edges fade edges setfadeedges fadeedges fadeedges fadeedges public boolean get fade edges return fade edges getfadeedges fadeedges public void set edge color int edge color this edge color edge color setedgecolor edgecolor edgecolor edgecolor public int get edge color return edge color getedgecolor edgecolor override public int get pixel int x int y int in pixels int width int height float nx m00 x m01 y float ny m10 x m11 y nx scale ny scale stretch nx 1000 ny 1000 reduce artifacts around 0 0 float f evaluate nx ny float f1 results 0 distance float f2 results 1 distance int srcx image math clamp int results 0 x 1000 scale 0 width 1 int srcy image math clamp int results 0 y 1000 scale 0 height 1 int v in pixels srcy width srcx f f2 f1 edge thickness f image math smooth step 0 edge thickness f if fade edges srcx image math clamp int results 1 x 1000 scale 0 width 1 srcy image math clamp int results 1 y 1000 scale 0 height 1 int v2 in pixels srcy width srcx v2 image math mix colors 0 5f v2 v v image math mix colors f v2 v else v image math mix colors f edge color v return v getpixel inpixels imagemath imagemath inpixels edgethickness imagemath smoothstep edgethickness fadeedges imagemath imagemath inpixels imagemath mixcolors imagemath mixcolors imagemath mixcolors edgecolor override public string to string return stylize crystallize tostring logger register log threshold callback new log threshold callback override public void should update logdebug logger should log logger debug this registerlogthresholdcallback logthresholdcallback shouldupdate shouldlog public would block exception string string super string wouldblockexception public would block exception super wouldblockexception http blogs sun com jrose entry longjumps considered inexpensive resubmit damnit override public final synchronized throwable fill in stack trace if logdebug return super fill in stack trace return null longjumps_considered_inexpensive fillinstacktrace fillinstacktrace public static bloom filter create filter int length int k boolean counting if length 0 return new null bloom filter length k if counting return new counting bloom filter length k else return new binary bloom filter length k bloomfilter createfilter nullbloomfilter countingbloomfilter binarybloomfilter public static bloom filter create filter file file int length int k boolean counting throws io exception if length 0 return new null bloom filter length k if counting return new counting bloom filter file length k else return new binary bloom filter file length k bloomfilter createfilter ioexception nullbloomfilter countingbloomfilter binarybloomfilter protected bloom filter int length int k if length 8 0 length length 8 this length length this k k bloomfilter core public void add key byte key random hashes get hashes key lock write lock lock try for int i 0 i k i set bit hashes next int length finally lock write lock unlock if forked filter null forked filter add key key addkey gethashes writelock setbit nextint writelock forkedfilter forkedfilter addkey add to the forked filter only public void add key forked byte key if forked filter null forked filter add key key addkeyforked forkedfilter forkedfilter addkey public boolean check filter byte key random hashes get hashes key lock read lock lock try for int i 0 i k i if get bit hashes next int length return false finally lock read lock unlock return true checkfilter gethashes readlock getbit nextint readlock public void remove key byte key random hashes get hashes key lock write lock lock try for int i 0 i k i unset bit hashes next int length finally lock write lock unlock if forked filter null forked filter remove key key removekey gethashes writelock unsetbit nextint writelock forkedfilter forkedfilter removekey bits and hashes protected abstract boolean get bit int offset getbit protected abstract boolean get bit int offset protected abstract void set bit int offset getbit setbit protected abstract void set bit int offset protected abstract void unset bit int offset setbit unsetbit wierd impl s should override public void unset all int x filter limit for int i 0 i x i filter put i byte 0 unsetall protected random get hashes byte key return new mersenne twister key gethashes mersennetwister create an empty in memory copy of bloom filter new updates are written to both filters this is written back to disk on merge public void merge lock write lock lock try if forked filter null return lock forked lock forked filter lock write lock forked lock lock try filter position 0 forked filter filter position 0 filter put forked filter filter filter position 0 forked filter close forked filter null finally forked lock unlock finally lock write lock unlock writelock forkedfilter forkedlock forkedfilter writelock forkedlock forkedfilter forkedfilter forkedfilter forkedfilter forkedlock writelock public void discard lock write lock lock try if forked filter null return forked filter close forked filter null finally lock write lock unlock writelock forkedfilter forkedfilter forkedfilter writelock misc calculate optimal k value param filter length filter length in bits param max key return optimal k public static int optimialk int filter length long max key long k math round math log 2 filter length max key if k 64 k 64 if k 1 k 1 return int k filterlength maxkey filterlength maxkey filterlength maxkey public int getk return k public boolean need rebuild boolean needrebuild need rebuild need rebuild false return needrebuild needrebuild _needrebuild needrebuild needrebuild _needrebuild public void force if filter instanceof mapped byte buffer mapped byte buffer filter force mappedbytebuffer mappedbytebuffer public void close if filter null force filter null forked filter null forkedfilter override protected void finalize close private int total public failure code tracker boolean insert this insert insert failurecodetracker create a failure code tracker from a simple field set param is insert whether this is an insert param fs the simple field set containing the field set non verbose form of the tracker public failure code tracker boolean is insert simple field set fs this insert is insert iterator string i fs direct subset name iterator while i has next string name i next simple field set f fs subset name we ignore the description if there is one we just want the count int num integer parse int name int count integer parse int f get count if count 0 throw new illegal argument exception count 0 map put integer value of num new item count total count failurecodetracker simplefieldset isinsert simplefieldset fieldset failurecodetracker isinsert simplefieldset isinsert directsubsetnameiterator hasnext simplefieldset parseint parseint illegalargumentexception valueof private static class item item int count this x count item this x 0 public synchronized void inc int k if map null map new hash map integer item integer key k item i map get key if i null map put key i new item i x total hashmap public synchronized void inc integer k int val if map null map new hash map integer item integer key k item i map get key if i null map put key i new item i x val total val hashmap public synchronized string to verbose string if map null return super to string empty string builder sb new string builder for map entry integer item e map entry set integer x e get key item val e get value string s insert insert exception get message x int value fetch exception get message x int value sb append val x sb append t sb append s sb append n return sb to string toverbosestring tostring stringbuilder stringbuilder entryset getkey getvalue insertexception getmessage intvalue fetchexception getmessage intvalue tostring override public synchronized string to string if map null return super to string empty string builder sb new string builder super to string sb append if map size 0 sb append empty else if map size 1 sb append one integer code integer map key set to array 0 sb append code sb append sb append map get code x else sb append map size return sb to string tostring tostring stringbuilder stringbuilder tostring keyset toarray tostring merge codes from another tracker into this one public synchronized failure code tracker merge failure code tracker source if source map null return this if map null map new hash map integer item for map entry integer item e source map entry set integer k e get key item item e get value inc k item x return this failurecodetracker failurecodetracker hashmap entryset getkey getvalue public void merge fetch exception e if insert throw new illegal state exception merging a fetch exception in an insert if e error codes null merge e error codes increment mode anyway so we get the splitfile error as well inc e mode fetchexception illegalstateexception fetchexception errorcodes errorcodes public synchronized int total count return total totalcount copy verbosely to a simple field set public synchronized simple field set to field set boolean verbose simple field set sfs new simple field set false if map null for map entry integer item e map entry set integer k e get key item item e get value int code k int value prefix num description code description prefix num count count if verbose sfs put single integer to string code description insert insert exception get message code fetch exception get message code sfs put integer to string code count item x return sfs simplefieldset simplefieldset tofieldset simplefieldset simplefieldset entryset getkey getvalue intvalue putsingle tostring insertexception getmessage fetchexception getmessage tostring public synchronized boolean is one code only return map size 1 isonecodeonly public synchronized int get first code return integer map key set to array 0 int value getfirstcode keyset toarray intvalue public synchronized boolean is fatal boolean insert if map null return false for map entry integer item e map entry set integer code e get key if e get value x 0 continue if insert if insert exception is fatal code int value return true else if fetch exception is fatal code int value return true return false isfatal entryset getkey getvalue insertexception isfatal intvalue fetchexception isfatal intvalue public void merge insert exception e if insert throw new illegal argument exception this is not an insert yet merge e called if e error codes null merge e error codes inc e get mode insertexception illegalargumentexception errorcodes errorcodes getmode public synchronized boolean is empty return map null map is empty isempty isempty public void remove from object container container item items integer ints synchronized this items map null null map values to array new item map size ints map null null map key set to array new integer map size if map null map clear if items null for int i 0 i items length i container delete items i container delete ints i if map null container activate map 5 container delete map container delete this removefrom objectcontainer toarray keyset toarray public void object on activate object container container if map null container activate map 5 objectonactivate objectcontainer override public failure code tracker clone failure code tracker tracker new failure code tracker insert tracker merge this return tracker failurecodetracker failurecodetracker failurecodetracker private static final long serial versionuid 1 public ssk verify exception string string super string serialversionuid sskverifyexception public redirect dir put file simple field set subset string identifier boolean global throws message invalid exception super subset identifier global string target subset get targeturi if target null throw new message invalid exception protocol error message missing field targeturi missing but upload from redirect identifier global try targeturi new freeneturi target catch malformedurl exception e throw new message invalid exception protocol error message invalid field invalid targeturi e identifier global if logger should log logger minor this logger minor this targeturi targeturi redirectdirputfile simplefieldset messageinvalidexception messageinvalidexception protocolerrormessage missing_field uploadfrom malformedurlexception messageinvalidexception protocolerrormessage invalid_field shouldlog override public bucket get data return null getdata override public manifest element get element return new manifest element name targeturi getmime type manifestelement getelement manifestelement getmimetype override public void remove from object container container container activate targeturi 5 targeturi remove from container container delete this removefrom objectcontainer removefrom private int contour color 0xff000000 public contour filter contourcolor contourfilter public void set levels float levels this levels levels setlevels public float get levels return levels getlevels specifies the scale of the contours param scale the scale of the contours min value 0 max value 1 see get scale public void set scale float scale this scale scale getscale setscale returns the scale of the contours return the scale of the contours see set scale public float get scale return scale setscale getscale public void set offset float offset this offset offset setoffset public float get offset return offset getoffset public void set contour color int contour color this contour color contour color setcontourcolor contourcolor contourcolor contourcolor public int get contour color return contour color getcontourcolor contourcolor override protected int filter pixels int width int height int in pixels rectangle transformed space int index 0 short r new short 3 width int out pixels new int width height short table new short 256 int offsetl int offset 256 levels for int i 0 i 256 i table i short pixel utils clamp int 255 math floor levels i offsetl 256 levels 1 offsetl for int x 0 x width x int rgb in pixels x r 1 x short pixel utils brightness rgb for int y 0 y height y boolean y in y 0 y height 1 int next row index index width if y height 1 for int x 0 x width x int rgb in pixels next row index r 2 x short pixel utils brightness rgb for int x 0 x width x boolean x in x 0 x width 1 int w x 1 int e x 1 int v 0 if y in x in short nwb r 0 w short neb r 0 x short swb r 1 w short seb r 1 x short nw table nwb short ne table neb short sw table swb short se table seb if nw ne nw sw ne se sw se v int scale math abs nwb neb math abs nwb swb math abs neb seb math abs swb seb v 255 if v 255 v 255 if v 0 out pixels index pixel utils combine pixels in pixels index contour color pixel utils normal v out pixels index pixel utils combine pixels contour color 0xff v 24 in pixels index pixel utils normal else out pixels index in pixels index index short t t r 0 r 0 r 1 r 1 r 2 r 2 t return out pixels filterpixels inpixels transformedspace outpixels pixelutils inpixels pixelutils yin nextrowindex inpixels nextrowindex pixelutils xin yin xin outpixels pixelutils combinepixels inpixels contourcolor pixelutils outpixels pixelutils combinepixels contourcolor inpixels pixelutils outpixels inpixels outpixels override public string to string return stylize contour tostring public static void main string args throws fs parse exception peer parse exception invalid threshold exception node init exception reference signature verification exception logger setup stdout logging logger normal freenet node cpu adjusting swap request interval minor freenet node location manager debug freenet node fnp packet manager normal freenet io comm message core debug system out println secret ping cram test using real nodes system out println string wd real node secret ping test new file wd mkdir note global test init returns in ignored random source node starter global test init wd false logger error freenet node location normal freenet node simulator real node secret ping test normal freenet node networkid manager normal true dummy random source random new dummy random source diffie hellman init random node nodes new node number of nodes logger normal real node routing test class creating nodes executor executor new pooled executor allow secret pings but don t automatically send them this is the test for them freenet node networkid manager disable secret pings false freenet node networkid manager disable secret pinger true for int i 0 i number of nodes i nodes i node starter create test node 5001 i 0 wd false true true max htl 0 no dropped packets random executor 500 number of nodes store size true true false false false true true 0 true false null logger normal real node routing test class created node i logger normal real node routing test class created number of nodes nodes now link them up make kleinberg network nodes logger normal real node routing test class added small world links for int i 0 i number of nodes i nodes i start false now sit back and watch the fireworks int cycle number 0 running average avg2 new bootstrapping decaying running average 0 0 0 0 1 0 100 null while true cycle number try thread sleep 2000 catch interrupted exception e ignore node source nodes random next int number of nodes peer node verify source peers get random peer peer node pathway source peers get random peer verify logger error source verify get port number verify through get port number pathway so far avg2 current value long uid random next long long secret random next long if verify null logger error source verify peernode is null continue if pathway null logger error source pathway peernode is null continue try send the fnp store secret message to the verify node verify send sync dmt createfnp store secret uid secret null if get ack source verify uid logger error source did not get storesecret ack for uid avg2 report 0 0 continue send the request for the secret through the pathway node pathway send sync dmt createfnp secret ping uid verify get location ping htl dawn htl 0 verify get identity null long result get secret ping response source pathway uid if result secret logger error source not matched secret result avg2 report 0 0 else logger error source match secret avg2 report 1 0 catch not connected exception e logger error source what e avg2 report 0 0 catch disconnected exception e logger error source huh e avg2 report 0 0 fsparseexception peerparseexception invalidthresholdexception nodeinitexception referencesignatureverificationexception setupstdoutlogging cpuadjustingswaprequestinterval locationmanager fnppacketmanager messagecore secretping realnodesecretpingtest globaltestinit nodestarter globaltestinit realnodesecretpingtest networkidmanager dummyrandomsource dummyrandomsource diffiehellman number_of_nodes realnoderoutingtest pooledexecutor networkidmanager disablesecretpings networkidmanager disablesecretpinger number_of_nodes nodestarter createtestnode max_htl number_of_nodes storesize realnoderoutingtest realnoderoutingtest number_of_nodes makekleinbergnetwork realnoderoutingtest number_of_nodes cyclenumber runningaverage bootstrappingdecayingrunningaverage cyclenumber interruptedexception nextint number_of_nodes peernode getrandompeer peernode getrandompeer getportnumber getportnumber currentvalue nextlong nextlong fnpstoresecret sendsync createfnpstoresecret getack sendsync createfnpsecretping getlocation ping_htl dawn_htl getidentity getsecretpingresponse notconnectedexception disconnectedexception private static boolean get ack node source peer node pathway long uid throws disconnected exception wait for an accepted message filter mf accepted message filter create set source pathway set field dmt uid uid set timeout secretpong timeout set type dmt fnp accepted message msg source getusm wait for mf accepted null if msg null return false if msg get spec dmt fnp accepted return true logger error source got msg return false getack peernode disconnectedexception messagefilter mfaccepted messagefilter setsource setfield settimeout secretpong_timeout settype fnpaccepted waitfor mfaccepted getspec fnpaccepted private static long get secret ping response node source peer node pathway long uid throws disconnected exception wait for a reject or pong message filter mf pong message filter create set source pathway set field dmt uid uid set timeout secretpong timeout set type dmt fnp secret pong message filter mf reject loop message filter create set source pathway set field dmt uid uid set timeout secretpong timeout set type dmt fnp rejected loop message msg source getusm wait for mf pong or mf reject loop null if msg null logger error source fatal timeout in waiting for secretpong from get port number pathway return 2 if msg get spec dmt fnp secret pong int supplied counter msg get int dmt counter long secret msg get long dmt secret logger normal source got secret counter supplied counter return secret if msg get spec dmt fnp rejected loop logger error source top level secret ping should not reject get port number source get port number pathway return 1 return 3 getsecretpingresponse peernode disconnectedexception messagefilter mfpong messagefilter setsource setfield settimeout secretpong_timeout settype fnpsecretpong messagefilter mfrejectloop messagefilter setsource setfield settimeout secretpong_timeout settype fnprejectedloop waitfor mfpong mfrejectloop getportnumber getspec fnpsecretpong suppliedcounter getint getlong suppliedcounter getspec fnprejectedloop getportnumber getportnumber static void make kleinberg network node nodes for int i 0 i nodes length i node a nodes i normalise the probabilities double norm 0 0 for int j 0 j nodes length j node b nodes j if a get location b get location continue norm 1 0 distance a b create degree 2 outgoing connections for int k 0 k nodes length k node b nodes k if a get location b get location continue double p 1 0 distance a b norm for int n 0 n degree 2 n if math random p try a connect b b connect a catch fs parse exception e logger error real node secret ping test class cannot connect e catch peer parse exception e logger error real node secret ping test class cannot connect 2 e catch freenet io comm reference signature verification exception e logger error real node secret ping test class cannot connect 3 e break makekleinbergnetwork getlocation getlocation getlocation getlocation fsparseexception realnodesecretpingtest peerparseexception realnodesecretpingtest referencesignatureverificationexception realnodesecretpingtest static double distance node a node b double al a get location double bl b get location return location distance al bl getlocation getlocation static string get port number peer node p if p null p get peer null return null return integer to string p get peer get port getportnumber peernode getpeer tostring getpeer getport static string get port number node n if n null return null return integer to string n get darknet port number getportnumber tostring getdarknetportnumber private boolean resize true public shear filter shearfilter public void set resize boolean resize this resize resize setresize public boolean is resize return resize isresize public void setx angle float xangle this xangle xangle initialize setxangle public float getx angle return xangle getxangle public void sety angle float yangle this yangle yangle initialize setyangle public float gety angle return yangle getyangle private void initialize shx float math sin xangle shy float math sin yangle override protected void transform space rectangle r float tangent float math tan xangle xoffset r height tangent if tangent 0 0 tangent tangent r width int r height tangent r width 0 999999f tangent float math tan yangle yoffset r width tangent if tangent 0 0 tangent tangent r height int r width tangent r height 0 999999f transformspace override protected void transform inverse int x int y float out out 0 x xoffset y shx out 1 y yoffset x shy transforminverse override public string to string return distort shear tostring see plugins mdns discovery javax jmdns service info create string string int string public service info impl string type string name int port string text this type name port 0 0 text mdnsdiscovery serviceinfo serviceinfoimpl see plugins mdns discovery javax jmdns service info create string string int int int string public service info impl string type string name int port int weight int priority string text this type name port weight priority byte null try byte array output stream out new byte array output stream text length writeutf out text byte data out to byte array this set text new byte data length 1 this get text 0 byte data length system arraycopy data 0 this get text 1 data length catch io exception e throw new runtime exception unexpected exception e mdnsdiscovery serviceinfo serviceinfoimpl bytearrayoutputstream bytearrayoutputstream tobytearray settext gettext gettext ioexception runtimeexception see plugins mdns discovery javax jmdns service info create string string int int int hashtable public service info impl string type string name int port int weight int priority hashtable props this type name port weight priority new byte 0 if props null try byte array output stream out new byte array output stream 256 for enumeration e props keys e has more elements string key string e next element object val props get key byte array output stream out2 new byte array output stream 100 writeutf out2 key if val instanceof string out2 write writeutf out2 string val else if val instanceof byte out2 write byte bval byte val out2 write bval 0 bval length else if val no value throw new illegal argument exception invalid property value val byte data out2 to byte array out write data length out write data 0 data length this set text out to byte array catch io exception e throw new runtime exception unexpected exception e mdnsdiscovery serviceinfo serviceinfoimpl bytearrayoutputstream bytearrayoutputstream hasmoreelements nextelement bytearrayoutputstream bytearrayoutputstream no_value illegalargumentexception tobytearray settext tobytearray ioexception runtimeexception see plugins mdns discovery javax jmdns service info create string string int int int byte public service info impl string type string name int port int weight int priority byte text this type type this name name this port port this weight weight this priority priority this set text text mdnsdiscovery serviceinfo serviceinfoimpl settext construct a service record during service discovery service info impl string type string name if type ends with throw new illegal argument exception type must be fully qualified dns name ending in type this type type this name name serviceinfoimpl endswith illegalargumentexception during recovery we need to duplicate service info to reregister them service info impl service info impl info if info null this type info type this name info name this port info port this weight info weight this priority info priority this set text info get text serviceinfoimpl serviceinfoimpl settext gettext see plugins mdns discovery javax jmdns service info get type public string get type return type mdnsdiscovery serviceinfo gettype gettype see plugins mdns discovery javax jmdns service info get name public string get name return name mdnsdiscovery serviceinfo getname getname sets the service instance name param name unqualified service instance name such as code foobar code void set name string name this name name setname see plugins mdns discovery javax jmdns service info get qualified name public string get qualified name return name type mdnsdiscovery serviceinfo getqualifiedname getqualifiedname see plugins mdns discovery javax jmdns service info get server public string get server return server mdnsdiscovery serviceinfo getserver getserver see plugins mdns discovery javax jmdns service info get host address public string get host address return addr null addr get host address mdnsdiscovery serviceinfo gethostaddress gethostaddress gethostaddress public inet address get address return addr inetaddress getaddress see plugins mdns discovery javax jmdns service info get inet address public inet address get inet address return addr mdnsdiscovery serviceinfo getinetaddress inetaddress getinetaddress see plugins mdns discovery javax jmdns service info get port public int get port return port mdnsdiscovery serviceinfo getport getport see plugins mdns discovery javax jmdns service info get priority public int get priority return priority mdnsdiscovery serviceinfo getpriority getpriority see plugins mdns discovery javax jmdns service info get weight public int get weight return weight mdnsdiscovery serviceinfo getweight getweight see plugins mdns discovery javax jmdns service info get text bytes public byte get text bytes return get text mdnsdiscovery serviceinfo gettextbytes gettextbytes gettext see plugins mdns discovery javax jmdns service info get text string public string get text string if get text null get text length 0 get text length 1 get text 0 0 return null return readutf get text 0 get text length mdnsdiscovery serviceinfo gettextstring gettextstring gettext gettext gettext gettext gettext gettext see plugins mdns discovery javax jmdns service info geturl public string geturl return geturl http mdnsdiscovery serviceinfo see plugins mdns discovery javax jmdns service info geturl java lang string public string geturl string protocol string url protocol get host address get port string path get property string path if path null if path index of 0 url path else url path starts with path path return url mdnsdiscovery serviceinfo gethostaddress getport getpropertystring indexof startswith see plugins mdns discovery javax jmdns service info get property bytes java lang string public synchronized byte get property bytes string name return byte get properties get name mdnsdiscovery serviceinfo getpropertybytes getpropertybytes getproperties see plugins mdns discovery javax jmdns service info get property string java lang string public synchronized string get property string string name byte data byte get properties get name if data null return null if data no value return true return readutf data 0 data length mdnsdiscovery serviceinfo getpropertystring getpropertystring getproperties no_value see plugins mdns discovery javax jmdns service info get property names public enumeration get property names hashtable props get properties return props null props keys new vector elements mdnsdiscovery serviceinfo getpropertynames getpropertynames getproperties write a utf string with a length to a stream void writeutf output stream out string str throws io exception for int i 0 len str length i len i int c str char at i if c 0x0001 c 0x007f out write c else if c 0x07ff out write 0xe0 c 12 0x0f out write 0x80 c 6 0x3f out write 0x80 c 0 0x3f else out write 0xc0 c 6 0x1f out write 0x80 c 0 0x3f outputstream ioexception charat read data bytes as a utf stream string readutf byte data int off int len string buffer buf new string buffer for int end off len off end int ch data off 0xff switch ch 4 case 0 case 1 case 2 case 3 case 4 case 5 case 6 case 7 0xxxxxxx break case 12 case 13 if off len return null 110x xxxx 10xx xxxx ch ch 0x1f 6 data off 0x3f break case 14 if off 2 len return null 1110 xxxx 10xx xxxx 10xx xxxx ch ch 0x0f 12 data off 0x3f 6 data off 0x3f break default if off 1 len return null 10xx xxxx 1111 xxxx ch ch 0x3f 4 data off 0x0f break buf append char ch return buf to string stringbuffer stringbuffer tostring synchronized hashtable get properties if props null get text null hashtable props new hashtable int off 0 while off get text length length of the next key value pair int len get text off 0xff if len 0 off len get text length props clear break look for the int i 0 for i len get text off i i get the property name string name readutf get text off i if name null props clear break if i len props put name no value else byte value new byte len i system arraycopy get text off i value 0 len i props put name value off len this props props return props getproperties gettext gettext gettext gettext gettext gettext no_value gettext jmdns callback to update a dns record public void update record jmdns impl jmdns long now dns record rec if rec null rec is expired now switch rec type case dns constants type a i pv4 case dns constants type aaaa i pv6 fixme pjyf oct 14 2004 this has not been tested if rec name equals server addr dns record address rec get address break case dns constants type srv if rec name equals get qualified name dns record service srv dns record service rec server srv server port srv port weight srv weight priority srv priority addr null changed to use get cache instead jeffs update record jmdns now dns record jmdns cache get server type a class in update record jmdns now dns record jmdns get cache get server dns constants type a dns constants class in break case dns constants type txt if rec name equals get qualified name dns record text txt dns record text rec set text txt text break future design pattern this is done to notify the wait loop in method jmdns get service info type name timeout if has data get dns null get dns handle service resolved this set dns null synchronized this notify all updaterecord jmdnsimpl dnsrecord isexpired dnsconstants type_a ipv4 dnsconstants type_aaaa ipv6 dnsrecord getaddress dnsconstants type_srv getqualifiedname dnsrecord dnsrecord getcache updaterecord dnsrecord type_a class_in updaterecord dnsrecord getcache dnsconstants type_a dnsconstants class_in dnsconstants type_txt getqualifiedname dnsrecord dnsrecord settext getserviceinfo hasdata getdns getdns handleserviceresolved setdns notifyall returns true if the service info is filled with data public boolean has data return server null addr null get text null hasdata gettext state machine sets the state and notifies all objects that wait on the service info public synchronized void advance state state state advance notify all serviceinfo advancestate notifyall sets the state and notifies all objects that wait on the service info synchronized void revert state state state revert notify all serviceinfo revertstate notifyall sets the state and notifies all objects that wait on the service info synchronized void cancel state dns state canceled notify all serviceinfo dnsstate notifyall returns the current state of this info public dns state get state return state dnsstate getstate public int hash code return get qualified name hash code hashcode getqualifiedname hashcode public boolean equals object obj return obj instanceof service info impl get qualified name equals service info impl obj get qualified name serviceinfoimpl getqualifiedname serviceinfoimpl getqualifiedname public string get nice text string string buffer buf new string buffer for int i 0 len get text length i len i if i 20 buf append break int ch get text i 0xff if ch ch 127 buf append 0 buf append integer to string ch 8 else buf append char ch return buf to string getnicetextstring stringbuffer stringbuffer gettext gettext tostring tostring public string to string string buffer buf new string buffer buf append service buf append get qualified name buf append buf append get address buf append buf append port buf append buf append get nice text string buf append return buf to string tostring stringbuffer stringbuffer getqualifiedname getaddress getnicetextstring tostring public void add answers dns outgoing out int ttl host info local host throws io exception out add answer new pointer type dns constants type ptr dns constants class in ttl get qualified name 0 out add answer new service get qualified name dns constants type srv dns constants class in dns constants class unique ttl priority weight port local host get name 0 out add answer new text get qualified name dns constants type txt dns constants class in dns constants class unique ttl get text 0 addanswers dnsoutgoing hostinfo localhost ioexception addanswer dnsconstants type_ptr dnsconstants class_in getqualifiedname addanswer getqualifiedname dnsconstants type_srv dnsconstants class_in dnsconstants class_unique localhost getname addanswer getqualifiedname dnsconstants type_txt dnsconstants class_in dnsconstants class_unique gettext public void set task timer task task this task task settask timertask public timer task get task return task timertask gettask public void set text byte text this text text settext public byte get text return text gettext public void set dns jmdns impl dns this dns dns setdns jmdnsimpl public jmdns impl get dns return dns jmdnsimpl getdns public config data node node boolean with current boolean with defaults boolean with sort order boolean with expert flag boolean with force write flag boolean with short description boolean with long description boolean with data types string identifier this node node this with current with current this with defaults with defaults this with sort order with sort order this with expert flag with expert flag this with force write flag with force write flag this with short description with short description this with long description with long description this with data types with data types this identifier identifier configdata withcurrent withdefaults withsortorder withexpertflag withforcewriteflag withshortdescription withlongdescription withdatatypes withcurrent withcurrent withdefaults withdefaults withsortorder withsortorder withexpertflag withexpertflag withforcewriteflag withforcewriteflag withshortdescription withshortdescription withlongdescription withlongdescription withdatatypes withdatatypes override public simple field set get field set simple field set fs new simple field set true if with current simple field set current node config export field set config request type current settings true if current is empty fs put current current if with defaults simple field set default settings node config export field set config request type default settings false if default settings is empty fs put default default settings if with sort order simple field set sort order node config export field set config request type sort order false if sort order is empty fs put sort order sort order if with expert flag simple field set expert flag node config export field set config request type expert flag false if expert flag is empty fs put expert flag expert flag if with force write flag simple field set force write flag node config export field set config request type force write flag false if force write flag is empty fs put force write flag force write flag if with short description simple field set short description node config export field set config request type short description false if short description is empty fs put short description short description if with long description simple field set long description node config export field set config request type long description false if long description is empty fs put long description long description if with data types simple field set type node config export field set config request type data type false if type is empty fs put data type type if identifier null fs put single identifier identifier return fs simplefieldset getfieldset simplefieldset simplefieldset withcurrent simplefieldset exportfieldset requesttype current_settings isempty withdefaults simplefieldset defaultsettings exportfieldset requesttype default_settings defaultsettings isempty defaultsettings withsortorder simplefieldset sortorder exportfieldset requesttype sort_order sortorder isempty sortorder sortorder withexpertflag simplefieldset expertflag exportfieldset requesttype expert_flag expertflag isempty expertflag expertflag withforcewriteflag simplefieldset forcewriteflag exportfieldset requesttype force_write_flag forcewriteflag isempty forcewriteflag forcewriteflag withshortdescription simplefieldset shortdescription exportfieldset requesttype short_description shortdescription isempty shortdescription shortdescription withlongdescription simplefieldset longdescription exportfieldset requesttype long_description longdescription isempty longdescription longdescription withdatatypes simplefieldset exportfieldset requesttype data_type isempty datatype putsingle override public string get name return name getname override public void run fcp connection handler handler node node throws message invalid exception throw new message invalid exception protocol error message invalid message config data goes from server to client not the other way around null false fcpconnectionhandler messageinvalidexception messageinvalidexception protocolerrormessage invalid_message configdata override public void remove from object container container container delete this removefrom objectcontainer protected boolean alpha false public image function2d buffered image image this image false imagefunction2d bufferedimage public image function2d buffered image image boolean alpha this image zero alpha imagefunction2d bufferedimage public image function2d buffered image image int edge action boolean alpha init getrgb image 0 0 image get width image get height null image get width image get height edge action alpha imagefunction2d bufferedimage edgeaction getwidth getheight getwidth getheight edgeaction public image function2d int pixels int width int height int edge action boolean alpha init pixels width height edge action alpha imagefunction2d edgeaction edgeaction public image function2d image image this image zero false imagefunction2d public image function2d image image int edge action boolean alpha pixel grabber pg new pixel grabber image 0 0 1 1 null 0 1 try pg grab pixels catch interrupted exception e throw new runtime exception interrupted waiting for pixels if pg status image observer abort 0 throw new runtime exception image fetch aborted init int pg get pixels pg get width pg get height edge action alpha imagefunction2d edgeaction pixelgrabber pixelgrabber grabpixels interruptedexception runtimeexception imageobserver runtimeexception getpixels getwidth getheight edgeaction a convenience method for getting argb pixels from an image this tries to avoid the performance penalty of buffered image getrgb unmanaging the image public int getrgb buffered image image int x int y int width int height int pixels int type image get type if type buffered image type int argb type buffered image type int rgb return int image get raster get data elements x y width height pixels return image getrgb x y width height pixels 0 width bufferedimage bufferedimage gettype bufferedimage type_int_argb bufferedimage type_int_rgb getraster getdataelements public void init int pixels int width int height int edge action boolean alpha this pixels pixels this width width this height height this edge action edge action this alpha alpha edgeaction edgeaction edgeaction public float evaluate float x float y int ix int x int iy int y if edge action wrap ix image math mod ix width iy image math mod iy height else if ix 0 iy 0 ix width iy height if edge action zero return 0 if ix 0 ix 0 else if ix width ix width 1 if iy 0 iy 0 else if iy height iy height 1 return alpha pixels iy width ix 24 0xff 255 0f pixel utils brightness pixels iy width ix 255 0f edgeaction imagemath imagemath edgeaction pixelutils public void set edge action int edge action this edge action edge action setedgeaction edgeaction edgeaction edgeaction public int get edge action return edge action getedgeaction edgeaction public int get width return width getwidth public int get height return height getheight public int get pixels return pixels getpixels final string prefix public output stream logger int prio string prefix this prio prio this prefix prefix outputstreamlogger override public void write int b logger log static this prefix char b prio logstatic override public void write byte buf int offset int length logger log static this prefix new string buf offset length prio logstatic override public void write byte buf write buf 0 buf length private static final long serial versionuid 1 public dummy random source serialversionuid dummyrandomsource public dummy random source public dummy random source long seed set seed seed dummyrandomsource dummyrandomsource setseed override public int accept entropy entropy source source long data int entropy guess return 0 acceptentropy entropysource entropyguess override public int accept timer entropy entropy source timer return 0 accepttimerentropy entropysource override public int accept timer entropy entropy source fnp timing source double bias return 0 accepttimerentropy entropysource fnptimingsource override public int accept entropy bytes entropy source my packet data source byte buf int offset int length double bias return 0 acceptentropybytes entropysource mypacketdatasource override public void close private static final long serial versionuid 1 public packet sequence exception string string super string serialversionuid packetsequenceexception override public void should update logminor logger should log logger minor this logdebug logger should log logger debug this shouldupdate shouldlog shouldlog public split file inserter segment split file inserter parent boolean persistent base client putter putter short splitfile algo int check block count bucket orig data blocks insert context block insert context boolean getchk only int seg no object container container super persistent this parent parent this getchk only getchk only this persistent persistent this errors new failure code tracker true this block insert context block insert context this splitfile algo splitfile algo this data blocks orig data blocks check blocks new bucket check block count checkur is new clientchk check block count dataur is new clientchk orig data blocks length data retries new int orig data blocks length check retries new int check block count data finished new boolean orig data blocks length check finished new boolean check block count data failed new boolean orig data blocks length check failed new boolean check block count data consecutivern fs new int orig data blocks length check consecutivern fs new int check block count blocks new array list integer putter add blocks dataur is length checkur is length container putter add must succeed blocks dataur is length checkur is length container this seg no seg no if persistent container activate block insert context 1 max retries block insert context max insert retries this putter putter splitfileinsertersegment splitfileinserter baseclientputter splitfilealgo checkblockcount origdatablocks insertcontext blockinsertcontext getchkonly segno objectcontainer getchkonly getchkonly failurecodetracker blockinsertcontext blockinsertcontext splitfilealgo splitfilealgo datablocks origdatablocks checkblocks checkblockcount checkuris checkblockcount datauris origdatablocks dataretries origdatablocks checkretries checkblockcount datafinished origdatablocks checkfinished checkblockcount datafailed origdatablocks checkfailed checkblockcount dataconsecutivernfs origdatablocks checkconsecutivernfs checkblockcount arraylist addblocks datauris checkuris addmustsucceedblocks datauris checkuris segno segno blockinsertcontext maxretries blockinsertcontext maxinsertretries resume an insert segment throws resume exception public split file inserter segment split file inserter parent boolean persistent base client putter putter simple field set fs short splitfile algorithm insert context ctx boolean getchk only int seg no client context context object container container throws resume exception super persistent this parent parent this splitfile algo splitfile algorithm this getchk only getchk only this persistent persistent this block insert context ctx this max retries ctx max insert retries this seg no seg no if split file inserter segment equals fs get type throw new resume exception wrong type fs get type finished fields string to bool fs get finished false encoded true started fields string to bool fs get started false simple field set errorsfs fs subset errors if errorsfs null this errors new failure code tracker true errorsfs else this errors new failure code tracker true if finished errors is empty to throw insert exception construct errors blocks goturi 0 blocks completed 0 simple field set datafs fs subset data blocks if datafs null throw new resume exception no data blocks string tmp datafs get count if tmp null throw new resume exception no data block count int data block count try data block count integer parse int tmp catch number format exception e throw new resume exception corrupt data blocks count e tmp hasur is true data blocks new bucket data block count dataur is new clientchk data block count data retries new int data block count data consecutivern fs new int data block count data finished new boolean data block count data failed new boolean data block count blocks new array list integer this putter putter check blocks first because if there are missing check blocks we need all the data blocks so we can re encode simple field set checkfs fs subset check blocks if checkfs null tmp checkfs get count if tmp null throw new resume exception check blocks but no check block count int check block count try check block count integer parse int tmp catch number format exception e throw new resume exception corrupt check blocks count e tmp check blocks new bucket check block count checkur is new clientchk check block count check retries new int check block count check consecutivern fs new int check block count check finished new boolean check block count check failed new boolean check block count for int i 0 i check block count i string index integer to string i simple field set blockfs checkfs subset index if blockfs null hasur is false encoded false logger normal this clearing encoded because block i of seg no missing continue tmp blockfs get uri if tmp null try checkur is i clientchk client key get base key new freeneturi tmp blocks goturi catch malformedurl exception e throw new resume exception corrupt uri e tmp else hasur is false boolean block finished fields string to bool blockfs get finished false checkur is i null if block finished checkur is i null logger error this no uri for check block i of seg no yet apparently finished encoded false read data only necessary if the block isn t finished if block finished simple field set bucketfs blockfs subset data if bucketfs null try check blocks i serializable to field set bucket util create bucketfs context random ctx persistent file tracker if logminor logger minor this check block i check blocks i catch cannot create from field set exception e logger error this failed to deserialize check block i of seg no e e re encode it check blocks i null encoded false if check blocks i null throw new resume exception check block i of seg no not finished but no data create returned null don t create fetcher yet that happens in start else blocks completed if check blocks i null checkur is i null logger normal this clearing encoded because block i of seg no missing encoded false checkfs remove subset index if check blocks length data blocks length work around 1135 bug fixme remove throw new resume exception detected 1135 insert bug you must restart the insert else logger normal this not encoded because no check blocks encoded false fec codec splitfile algo fec codec get codec splitfile algorithm data block count int check blocks count splitfile algo count check blocks this checkur is new clientchk check blocks count this check blocks new bucket check blocks count check retries new int check blocks count check consecutivern fs new int check blocks count check finished new boolean check blocks count check failed new boolean check blocks count hasur is false for int i 0 i data block count i string index integer to string i simple field set blockfs datafs subset index if blockfs null throw new resume exception no data block i on segment seg no tmp blockfs get uri if tmp null try dataur is i clientchk client key get base key new freeneturi tmp blocks goturi catch malformedurl exception e throw new resume exception corrupt uri e tmp else hasur is false boolean block finished fields string to bool blockfs get finished false if block finished dataur is i null throw new resume exception block i of seg no finished but no uri if block finished finished false else blocks completed read data simple field set bucketfs blockfs subset data if bucketfs null if block finished throw new resume exception block i of seg no not finished but no data else if splitfile algorithm 0 encoded throw new resume exception block i of seg no data not available even though not encoded else try data blocks i serializable to field set bucket util create bucketfs context random ctx persistent file tracker if logminor logger minor this data block i data blocks i catch cannot create from field set exception e throw new resume exception failed to deserialize block i of seg no e e if data blocks i null throw new resume exception block i of seg no could not serialize data create returned null from bucketfs don t create fetcher yet that happens in start datafs remove subset index if encoded finished false hasur is false for int i 0 i data blocks length i if data blocks i null throw new resume exception missing data block i and need to reconstruct check blocks putter add blocks dataur is length checkur is length container putter add must succeed blocks dataur is length checkur is length container resumeexception splitfileinsertersegment splitfileinserter baseclientputter simplefieldset splitfilealgorithm insertcontext getchkonly segno clientcontext objectcontainer resumeexception splitfilealgo splitfilealgorithm getchkonly getchkonly blockinsertcontext maxretries maxinsertretries segno segno splitfileinsertersegment resumeexception stringtobool stringtobool simplefieldset failurecodetracker failurecodetracker isempty tothrow insertexception blocksgoturi blockscompleted simplefieldset datablocks resumeexception resumeexception datablockcount datablockcount parseint numberformatexception resumeexception hasuris datablocks datablockcount datauris datablockcount dataretries datablockcount dataconsecutivernfs datablockcount datafinished datablockcount datafailed datablockcount arraylist simplefieldset checkblocks resumeexception checkblockcount checkblockcount parseint numberformatexception resumeexception checkblocks checkblockcount checkuris checkblockcount checkretries checkblockcount checkconsecutivernfs checkblockcount checkfinished checkblockcount checkfailed checkblockcount checkblockcount tostring simplefieldset hasuris segno checkuris clientkey getbasekey blocksgoturi malformedurlexception resumeexception hasuris blockfinished stringtobool checkuris blockfinished checkuris segno blockfinished simplefieldset checkblocks serializabletofieldsetbucketutil persistentfiletracker checkblocks cannotcreatefromfieldsetexception segno checkblocks checkblocks resumeexception segno blockscompleted checkblocks checkuris segno removesubset checkblocks datablocks resumeexception feccodec splitfilealgo feccodec getcodec splitfilealgorithm datablockcount checkblockscount splitfilealgo countcheckblocks checkuris checkblockscount checkblocks checkblockscount checkretries checkblockscount checkconsecutivernfs checkblockscount checkfinished checkblockscount checkfailed checkblockscount hasuris datablockcount tostring simplefieldset resumeexception segno datauris clientkey getbasekey blocksgoturi malformedurlexception resumeexception hasuris blockfinished stringtobool blockfinished datauris resumeexception segno blockfinished blockscompleted simplefieldset blockfinished resumeexception segno splitfilealgorithm resumeexception segno datablocks serializabletofieldsetbucketutil persistentfiletracker datablocks cannotcreatefromfieldsetexception resumeexception segno datablocks resumeexception segno removesubset hasuris datablocks datablocks resumeexception addblocks datauris checkuris addmustsucceedblocks datauris checkuris public void start object container container client context context throws insert exception always called by parent so don t activate or deactivate parent if persistent container activate parent 1 container activate parent parent 1 container activate blocks 2 if logminor if parent null throw new null pointer exception logger minor this starting segment seg no of parent parent data length this finished finished encoded encoded hasur is hasur is persistent persistent boolean fin true for int i 0 i data blocks length i if data blocks i null else already finished on creation fin false synchronized this blocks add i else parent parent completed block true container context parent parent notify clients started true fec job job null fec codec splitfile algo null if encoded if logminor logger minor this segment seg no of parent parent data length is not encoded splitfile algo fec codec get codec this splitfile algo data blocks length check blocks length if logminor logger minor this encoding segment seg no of parent parent data length persistent persistent encode blocks synchronized this if encoded fixme necessary the queue is persistence aware won t it activate them if persistent for int i 0 i data blocks length i container activate data blocks i 5 job encode job new fec job splitfile algo context fec queue data blocks check blocks chk block data length persistent block insert context persistent bucket factory context temp bucket factory this false parent parent get priority class persistent fin false else for int i 0 i check blocks length i if check blocks i null synchronized this blocks add i data blocks length fin false else parent parent completed block true container context on encoded segment container context null data blocks check blocks null null if hasur is parent segment hasur is this container context boolean fetchable synchronized this fetchable blocks completed data blocks length if persistent container store this container store blocks if fetchable parent segment fetchable this container if fin finish container context parent else schedule container context if finished finish container context parent if job null splitfile algo add to queue job context fec queue container objectcontainer clientcontext insertexception nullpointerexception segno datalength hasuris hasuris datablocks datablocks completedblock notifyclients fecjob feccodec splitfilealgo segno datalength splitfilealgo feccodec getcodec splitfilealgo datablocks checkblocks segno datalength datablocks datablocks encodejob fecjob splitfilealgo fecqueue datablocks checkblocks chkblock data_length blockinsertcontext persistentbucketfactory tempbucketfactory getpriorityclass checkblocks checkblocks datablocks completedblock onencodedsegment datablocks checkblocks hasuris segmenthasuris blockscompleted datablocks segmentfetchable splitfilealgo addtoqueue fecqueue private void schedule object container container client context context if getchk only this get scheduler context register insert this persistent false container else try encode container context objectcontainer clientcontext getchkonly getscheduler registerinsert tryencode public void try encode object container container client context context for int i 0 i data blocks length i if dataur is i null data blocks i null try boolean deactivate false if persistent deactivate container ext is active data blocks i if deactivate container activate data blocks i 1 clientchk key clientchk encode bucket data blocks i get client key if deactivate container deactivate data blocks i 1 on encode i key container context catch chk encode exception e fail new insert exception insert exception internal error e null container context catch io exception e fail new insert exception insert exception bucket error e null container context else if dataur is i null data blocks i null fail new insert exception insert exception internal error data block i cannot be encoded no data null container context if encoded for int i 0 i check blocks length i if checkur is i null check blocks i null try boolean deactivate false if persistent deactivate container ext is active check blocks i if deactivate container activate check blocks i 1 clientchk key clientchk encode bucket check blocks i get client key if deactivate container deactivate check blocks i 1 on encode i data blocks length key container context catch chk encode exception e fail new insert exception insert exception internal error e null container context catch io exception e fail new insert exception insert exception bucket error e null container context else if checkur is i null check blocks i null fail new insert exception insert exception internal error data block i cannot be encoded no data null container context tryencode objectcontainer clientcontext datablocks datauris datablocks isactive datablocks datablocks encodebucket datablocks getclientkey datablocks onencode chkencodeexception insertexception insertexception internal_error ioexception insertexception insertexception bucket_error datauris datablocks insertexception insertexception internal_error checkblocks checkuris checkblocks isactive checkblocks checkblocks encodebucket checkblocks getclientkey checkblocks onencode datablocks chkencodeexception insertexception insertexception internal_error ioexception insertexception insertexception bucket_error checkuris checkblocks insertexception insertexception internal_error public void on decoded segment object container container client context context fec job job bucket data buckets bucket check buckets splitfile block data block status splitfile block check block status irrevelant ondecodedsegment objectcontainer clientcontext fecjob databuckets checkbuckets splitfileblock datablockstatus splitfileblock checkblockstatus public void on encoded segment object container container client context context fec job job bucket data buckets bucket check buckets splitfile block data block status splitfile block check block status if persistent container activate parent 1 container activate parent parent 1 container activate blocks 2 boolean fin synchronized this fin finished encode job null if remove on encode if logminor logger minor this removing on encode this free buckets array container data buckets free buckets array container check buckets remove from container context return if fin logger error this encoded segment even though segment finished freeing buckets free buckets array container data buckets free buckets array container check buckets return start the inserts try if logminor logger minor this scheduling check blocks length check blocks for int i 0 i check blocks length i see comments on fec callback we must copy the data back check blocks i check buckets i if check blocks i null if logminor logger minor this skipping check block i is null continue if persistent check blocks i store to container if persistent container deactivate check blocks i 1 synchronized this for int i 0 i check blocks length i blocks add data blocks length i if persistent container store blocks catch throwable t logger error this caught t while encoding this t insert exception ex new insert exception insert exception internal error t null finish ex container context parent if persistent container deactivate parent 1 return synchronized this encoded true if persistent container store this container activate parent 1 tell parent only after have started the inserts because of the counting parent encoded segment this container context synchronized this free buckets array container data blocks if persistent container store this container deactivate parent 1 schedule container context onencodedsegment objectcontainer clientcontext fecjob databuckets checkbuckets splitfileblock datablockstatus splitfileblock checkblockstatus encodejob removeonencode freebucketsarray databuckets freebucketsarray checkbuckets removefrom freebucketsarray databuckets freebucketsarray checkbuckets checkblocks checkblocks feccallback checkblocks checkbuckets checkblocks checkblocks storeto checkblocks checkblocks datablocks insertexception insertexception insertexception internal_error encodedsegment freebucketsarray datablocks caller must activate and pass in parent param ex param container param context param parent void finish insert exception ex object container container client context context split file inserter parent if logminor logger minor this finishing this with ex ex synchronized this if finished return finished true to throw ex if persistent container store this parent segment finished this container context free buckets array container data blocks free buckets array container check blocks insertexception objectcontainer clientcontext splitfileinserter tothrow segmentfinished freebucketsarray datablocks freebucketsarray checkblocks caller must activate and pass in parent param container param context param parent private void finish object container container client context context split file inserter parent if logminor logger minor this finishing this if persistent container activate errors 5 synchronized this if finished return finished true if blocks succeeded blocks completed to throw insert exception construct errors if persistent container store this container deactivate errors 5 unregister container context parent segment finished this container context free buckets array container data blocks free buckets array container check blocks objectcontainer clientcontext splitfileinserter blockssucceeded blockscompleted tothrow insertexception segmentfinished freebucketsarray datablocks freebucketsarray checkblocks private void on encode int x clientchk key object container container client context context if logminor logger minor this encoded block x on this synchronized this if finished return if x data blocks length if checkur is x data blocks length null return checkur is x data blocks length key else if dataur is x null return dataur is x key blocks goturi if persistent container store this if logminor logger minor this blocks got uri blocks goturi of data blocks length check blocks length if blocks goturi data blocks length check blocks length return double check for int i 0 i checkur is length i if checkur is i null logger error this check uri i is null return for int i 0 i dataur is length i if dataur is i null logger error this data uri i is null return hasur is true if persistent container activate parent 1 container store this parent segment hasur is this container context if persistent container deactivate parent 1 onencode objectcontainer clientcontext datablocks checkuris datablocks checkuris datablocks datauris datauris blocksgoturi blocksgoturi datablocks checkblocks blocksgoturi datablocks checkblocks checkuris checkuris datauris datauris hasuris segmenthasuris public synchronized boolean is finished return finished isfinished public boolean is encoded return encoded isencoded public int count check blocks return check blocks length countcheckblocks checkblocks public int count data blocks return data blocks length countdatablocks datablocks public clientchk get checkch ks return checkur is getcheckchks checkuris public clientchk get datach ks return dataur is getdatachks datauris get the insert exception for this segment note this will be deleted when the segment is deleted do not store it or pass it on insert exception get exception synchronized this return to throw insertexception insertexception getexception tothrow public void cancel object container container client context context synchronized this if finished return finished true if to throw null to throw new insert exception insert exception cancelled cancel inner container context objectcontainer clientcontext tothrow tothrow insertexception insertexception cancelinner private void cancel inner object container container client context context if logminor logger minor this cancelling this super unregister container context if persistent container store this container activate parent 1 parent segment finished this container context free buckets array container data blocks free buckets array container check blocks cancelinner objectcontainer clientcontext segmentfinished freebucketsarray datablocks freebucketsarray checkblocks public void on transition client put state old state client put state new state object container container logger error this illegal transition in split file inserter segment old state new state ontransition clientputstate oldstate clientputstate newstate objectcontainer splitfileinsertersegment oldstate newstate public void on metadata metadata m client put state state object container container client context context logger error this got on metadata from state onmetadata clientputstate objectcontainer clientcontext onmetadata public void on block set finished client put state state object container container client context context ignore logger error this should not happen on block set finished state on this onblocksetfinished clientputstate objectcontainer clientcontext onblocksetfinished public synchronized boolean hasur is return hasur is hasuris hasuris public synchronized boolean is fetchable return blocks completed data blocks length isfetchable blockscompleted datablocks public void on fetchable client put state state object container container ignore onfetchable clientputstate objectcontainer force the remaining blocks which haven t been encoded so far to be encoded asap public void force encode object container container client context context context background block encoder queue this container context forceencode objectcontainer clientcontext backgroundblockencoder public void fail insert exception e object container container client context context synchronized this if finished logger error this failing but already finished on this return finished true logger error this insert segment failed e for this e this to throw e if persistent container store this cancel inner container context insertexception objectcontainer clientcontext tothrow cancelinner public void on failed throwable t object container container client context context synchronized this if finished logger error this fec decode or encode failed but already finished t t return finished true logger error this insert segment failed t for this t this to throw new insert exception insert exception internal error fec failure t null cancel inner container context onfailed objectcontainer clientcontext tothrow insertexception insertexception internal_error cancelinner bucket get bucket int block num if block num data blocks length return check blocks block num data blocks length else return data blocks block num getbucket blocknum blocknum datablocks checkblocks blocknum datablocks datablocks blocknum private block item get block item object container container client context context int block num throws io exception bucket source data get bucket block num if source data null logger error this selected block block num but is null already finished on this return null boolean deactivate bucket false if persistent deactivate bucket container ext is active source data if deactivate bucket container activate source data 1 bucket data source data create shadow if data null data context temp bucket factory make bucket source data size bucket tools copy source data data if logminor logger minor this block block num bucket source data shadow data if persistent if deactivate bucket container deactivate source data 1 return new block item this block num data persistent blockitem getblockitem objectcontainer clientcontext blocknum ioexception sourcedata getbucket blocknum sourcedata blocknum deactivatebucket deactivatebucket isactive sourcedata deactivatebucket sourcedata sourcedata createshadow tempbucketfactory makebucket sourcedata buckettools sourcedata blocknum sourcedata deactivatebucket sourcedata blockitem blocknum private int hash code for block int block num fixme standard hash code pattern assumes both inputs are evenly distributed this is not true here return hash code block num 1 hashcodeforblock blocknum hashcode hashcode blocknum block item split file inserter segment parent int block num bucket bucket boolean persistent throws io exception this parent parent this block num block num this copy bucket bucket this hash code parent hash code for block block num this persistent persistent blockitem splitfileinsertersegment blocknum ioexception blocknum blocknum copybucket hashcode hashcodeforblock blocknum public void dump copy bucket free copybucket override public int hash code return hash code hashcode hashcode override public boolean equals object o if o instanceof block item if block item o parent parent block item o block num block num return true else if o instanceof fake block item if fake block item o get parent parent fake block item o block num block num return true return false blockitem blockitem blockitem blocknum blocknum fakeblockitem fakeblockitem getparent fakeblockitem blocknum blocknum fake block item int block num this block num block num this hash code hash code for block block num fakeblockitem blocknum blocknum blocknum hashcode hashcodeforblock blocknum public void dump do nothing public split file inserter segment get parent return split file inserter segment this splitfileinsertersegment getparent splitfileinsertersegment override public int hash code return hash code hashcode hashcode override public boolean equals object o if o instanceof block item if block item o parent split file inserter segment this block item o block num block num return true else if o instanceof fake block item if fake block item o get parent split file inserter segment this fake block item o block num block num return true return false blockitem blockitem splitfileinsertersegment blockitem blocknum blocknum fakeblockitem fakeblockitem getparent splitfileinsertersegment fakeblockitem blocknum blocknum override public void on failure low level put exception e object key num object container container client context context block item block block item key num synchronized this if finished return first report the error if persistent container activate errors 5 switch e code case low level put exception collision logger error this collision on a chk fail new insert exception insert exception internal error collision on a chk null container context return case low level put exception internal error logger error this internal error e e fail new insert exception insert exception internal error e to string null container context return case low level put exception rejected overload errors inc insert exception rejected overload break case low level put exception route not found errors inc insert exception route not found break case low level put exception route really not found errors inc insert exception route really not found break default logger error this unknown low level put exception code e code fail new insert exception insert exception internal error e to string null container context return if persistent container store errors boolean isrnf e code low level put exception route not found e code low level put exception route really not found int block num block block num if logminor logger minor this block block num failed on this e boolean treat as success false boolean failed block false int completed int succeeded synchronized this if block num data blocks length check block int check num block num data blocks length if check finished check num if check failed check num logger error this got on failure but block has already failed check block check num on this else logger error this got on failure but block has already succeeded check block check num on this return if isrnf check consecutivern fs check num if persistent container activate block insert context 1 if logminor logger minor this consecutive rn fs check consecutivern fs check num block insert context consecutivern fs count as success if check consecutivern fs check num block insert context consecutivern fs count as success treat as success treat as success true else check consecutivern fs check num 0 if treat as success check retries check num if check retries check num max retries max retries 1 failed block true treat as failed check finished check num true check failed check num true blocks completed if persistent container activate blocks 2 blocks remove integer value of block num if persistent container store blocks if check blocks check num null if persistent container activate check blocks check num 1 check blocks check num free if persistent check blocks check num remove from container check blocks check num null if logminor logger minor this failed to insert check block check num on this else logger error this check block check num failed on this but bucket is already nulled out else we are still registered but will have to be re selected for persistent requests the current persistent chosen request will not re run the same block this is okay else better handle it here to minimize race conditions check finished check num true check failed check num false treating as succeeded blocks completed blocks succeeded if persistent container activate blocks 2 blocks remove integer value of block num if persistent container store blocks if check blocks check num null if persistent container activate check blocks check num 1 check blocks check num free if persistent check blocks check num remove from container check blocks check num null if logminor logger minor this repeated rnf treating as success for check block check num on this else logger error this check block check num succeeded sort of on this but bucket is already nulled out else data block if data finished block num if data failed block num logger error this got on failure but block has already failed data block block num on this else logger error this got on failure but block has already succeeded data block block num on this return if isrnf data consecutivern fs block num if persistent container activate block insert context 1 if logminor logger minor this consecutive rn fs data consecutivern fs block num block insert context consecutivern fs count as success if data consecutivern fs block num block insert context consecutivern fs count as success treat as success treat as success true else data consecutivern fs block num 0 if treat as success data retries block num if data retries block num max retries max retries 1 failed block true treat as failed data finished block num true data failed block num true blocks completed if persistent container activate blocks 2 blocks remove integer value of block num if persistent container store blocks if data blocks block num null if persistent container activate data blocks block num 1 data blocks block num free if persistent data blocks block num remove from container data blocks block num null if logminor logger minor this failed to insert data block block num on this else logger error this data block block num failed on this but bucket is already nulled out else we are still registered but will have to be re selected for persistent requests the current persistent chosen request will not re run the same block this is okay else better handle it here to minimize race conditions data finished block num true data failed block num false treating as succeeded blocks completed blocks succeeded if persistent container activate blocks 2 blocks remove integer value of block num if persistent container store blocks if data blocks block num null encoded if persistent container activate data blocks block num 1 data blocks block num free if persistent data blocks block num remove from container data blocks block num null if logminor logger minor this repeated rnf treating as success for data block block num on this else logger error this data block block num succeeded sort of on this but bucket is already nulled out if persistent container store this completed blocks completed succeeded blocks succeeded if persistent container activate putter 1 if failed block putter failed block container context else if treat as success putter completed block false container context if persistent container deactivate putter 1 if treat as success succeeded data blocks length if persistent container activate parent 1 parent segment fetchable this container if persistent container deactivate parent 1 else if completed data blocks length check blocks length if persistent container activate parent 1 finish container context parent if persistent container deactivate parent 1 onfailure lowlevelputexception keynum objectcontainer clientcontext blockitem blockitem keynum lowlevelputexception insertexception insertexception internal_error lowlevelputexception internal_error insertexception insertexception internal_error tostring lowlevelputexception rejected_overload insertexception rejected_overload lowlevelputexception route_not_found insertexception route_not_found lowlevelputexception route_really_not_found insertexception route_really_not_found lowlevelputexception insertexception insertexception internal_error tostring lowlevelputexception route_not_found lowlevelputexception route_really_not_found blocknum blocknum blocknum treatassuccess failedblock blocknum datablocks checknum blocknum datablocks checkfinished checknum checkfailed checknum onfailure checknum onfailure checknum checkconsecutivernfs checknum blockinsertcontext rnfs checkconsecutivernfs checknum blockinsertcontext consecutivernfscountassuccess checkconsecutivernfs checknum blockinsertcontext consecutivernfscountassuccess treatassuccess checkconsecutivernfs checknum treatassuccess checkretries checknum checkretries checknum maxretries maxretries failedblock checkfinished checknum checkfailed checknum blockscompleted valueof blocknum checkblocks checknum checkblocks checknum checkblocks checknum checkblocks checknum removefrom checkblocks checknum checknum checknum persistentchosenrequest checkfinished checknum checkfailed checknum blockscompleted blockssucceeded valueof blocknum checkblocks checknum checkblocks checknum checkblocks checknum checkblocks checknum removefrom checkblocks checknum checknum checknum datafinished blocknum datafailed blocknum onfailure blocknum onfailure blocknum dataconsecutivernfs blocknum blockinsertcontext rnfs dataconsecutivernfs blocknum blockinsertcontext consecutivernfscountassuccess dataconsecutivernfs blocknum blockinsertcontext consecutivernfscountassuccess treatassuccess dataconsecutivernfs blocknum treatassuccess dataretries blocknum dataretries blocknum maxretries maxretries failedblock datafinished blocknum datafailed blocknum blockscompleted valueof blocknum datablocks blocknum datablocks blocknum datablocks blocknum datablocks blocknum removefrom datablocks blocknum blocknum blocknum persistentchosenrequest datafinished blocknum datafailed blocknum blockscompleted blockssucceeded valueof blocknum datablocks blocknum datablocks blocknum datablocks blocknum datablocks blocknum removefrom datablocks blocknum blocknum blocknum blockscompleted blockssucceeded failedblock failedblock treatassuccess completedblock treatassuccess datablocks segmentfetchable datablocks checkblocks override public void on success object key num object container container client context context block item block block item key num int block num block block num int completed int succeeded if logminor logger minor this block block num succeeded on this synchronized this if finished return if block num data blocks length check block int check num block num data blocks length if check finished check num check finished check num true check failed check num false blocks completed blocks succeeded if persistent container activate blocks 2 blocks remove integer value of block num if persistent container store blocks else if check failed check num logger error this got on success but block has already failed check block check num on this else logger error this got on success but block has already succeeded check block check num on this return if check blocks check num null if persistent container activate check blocks check num 1 check blocks check num free if persistent check blocks check num remove from container check blocks check num null else logger error this check block check num succeeded on this but bucket is already nulled out else data block if data finished block num data finished block num true data failed block num false blocks completed blocks succeeded if persistent container activate blocks 2 blocks remove integer value of block num if persistent container store blocks else if data failed block num logger error this got on success but block has already failed data block block num on this else logger error this got on success but block has already succeeded data block block num on this return data blocks may not be freed until after we have encoded the check blocks if encoded data blocks block num null if persistent container activate data blocks block num 1 data blocks block num free if persistent data blocks block num remove from container data blocks block num null else if data blocks block num null logger error this data block block num succeeded on this but bucket is already nulled out if persistent logger minor this activation state container ext is active this if persistent container store this completed blocks completed succeeded blocks succeeded if persistent container activate putter 1 putter completed block false container context if persistent container deactivate putter 1 if succeeded data blocks length if persistent container activate parent 1 parent segment fetchable this container if persistent container deactivate parent 1 else if completed data blocks length check blocks length if persistent container activate parent 1 finish container context parent if persistent container deactivate parent 1 onsuccess keynum objectcontainer clientcontext blockitem blockitem keynum blocknum blocknum blocknum blocknum datablocks checknum blocknum datablocks checkfinished checknum checkfinished checknum checkfailed checknum blockscompleted blockssucceeded valueof blocknum checkfailed checknum onsuccess checknum onsuccess checknum checkblocks checknum checkblocks checknum checkblocks checknum checkblocks checknum removefrom checkblocks checknum checknum datafinished blocknum datafinished blocknum datafailed blocknum blockscompleted blockssucceeded valueof blocknum datafailed blocknum onsuccess blocknum onsuccess blocknum datablocks blocknum datablocks blocknum datablocks blocknum datablocks blocknum removefrom datablocks blocknum datablocks blocknum blocknum isactive blockscompleted blockssucceeded completedblock datablocks segmentfetchable datablocks checkblocks override public long count all keys object container container client context context return count sendable keys container context countallkeys objectcontainer clientcontext countsendablekeys override public sendable request item choose key keys fetching locally keys object container container client context context if persistent container activate this 1 container activate blocks 1 synchronized this if finished return null if blocks is empty if logminor logger minor this no blocks to remove return null for int i 0 i 10 i integer ret int x if blocks size 0 return null x context random next int blocks size ret blocks get x int num ret check whether it is already running if persistent if keys has transient insert this new fake block item num return null try return get block item container context num catch io exception e fail new insert exception insert exception bucket error e null container context return null return null sendablerequestitem choosekey keysfetchinglocally objectcontainer clientcontext isempty nextint hastransientinsert fakeblockitem getblockitem ioexception insertexception insertexception bucket_error override public request client get client object container container if persistent container activate putter 1 return putter get client requestclient getclient objectcontainer getclient override public client requester get client request return putter clientrequester getclientrequest override public short get priority class object container container if persistent container activate putter 1 return putter get priority class getpriorityclass objectcontainer getpriorityclass override public int get retry count no point scheduling inserts by retry count fixme either implement sub segments to schedule by retry count or more likely imho make the scheduler not care about retry counts for inserts return 0 getretrycount override public sendable request sender get sender object container container client context context return new sendable request sender public boolean send node client core core request scheduler sched final client context context chosen block req ignore key num key since we re only sending one block try block item block block item req token if logminor logger minor this starting request split file inserter segment this block number block block num clientchk block b try b encode bucket block copy bucket catch chk encode exception e throw new low level put exception low level put exception internal error e to string e get message e catch malformedurl exception e throw new low level put exception low level put exception internal error e to string e get message e catch io exception e throw new low level put exception low level put exception internal error e to string e get message e finally block copy bucket free if b null logger error this asked to send empty block on split file inserter segment this new exception error return false final clientchk key clientchk b get client key final int num block block num if block persistent context job runner queue new db job public void run object container container client context context if container ext is stored split file inserter segment this return container activate split file inserter segment this 1 on encode num key container context container deactivate split file inserter segment this 1 native thread norm priority 1 false else context main executor execute new runnable public void run on encode num key null context got uri core real put b req cache local requests catch low level put exception e req on failure e context if logminor logger minor this request failed split file inserter segment this for e return true if logminor logger minor this request succeeded split file inserter segment this req on insert success context return true sendablerequestsender getsender objectcontainer clientcontext sendablerequestsender nodeclientcore requestscheduler clientcontext chosenblock keynum blockitem blockitem splitfileinsertersegment blocknum clientchkblock encodebucket copybucket chkencodeexception lowlevelputexception lowlevelputexception internal_error tostring getmessage malformedurlexception lowlevelputexception lowlevelputexception internal_error tostring getmessage ioexception lowlevelputexception lowlevelputexception internal_error tostring getmessage copybucket splitfileinsertersegment getclientkey blocknum jobrunner dbjob objectcontainer clientcontext isstored splitfileinsertersegment splitfileinsertersegment onencode splitfileinsertersegment nativethread norm_priority mainexecutor onencode realput cachelocalrequests lowlevelputexception onfailure splitfileinsertersegment splitfileinsertersegment oninsertsuccess public boolean send node client core core request scheduler sched final client context context chosen block req ignore key num key since we re only sending one block try block item block block item req token if logminor logger minor this starting request split file inserter segment this block number block block num clientchk block b try b encode bucket block copy bucket catch chk encode exception e throw new low level put exception low level put exception internal error e to string e get message e catch malformedurl exception e throw new low level put exception low level put exception internal error e to string e get message e catch io exception e throw new low level put exception low level put exception internal error e to string e get message e finally block copy bucket free if b null logger error this asked to send empty block on split file inserter segment this new exception error return false final clientchk key clientchk b get client key final int num block block num if block persistent context job runner queue new db job public void run object container container client context context if container ext is stored split file inserter segment this return container activate split file inserter segment this 1 on encode num key container context container deactivate split file inserter segment this 1 native thread norm priority 1 false else context main executor execute new runnable public void run on encode num key null context got uri core real put b req cache local requests catch low level put exception e req on failure e context if logminor logger minor this request failed split file inserter segment this for e return true if logminor logger minor this request succeeded split file inserter segment this req on insert success context return true nodeclientcore requestscheduler clientcontext chosenblock keynum blockitem blockitem splitfileinsertersegment blocknum clientchkblock encodebucket copybucket chkencodeexception lowlevelputexception lowlevelputexception internal_error tostring getmessage malformedurlexception lowlevelputexception lowlevelputexception internal_error tostring getmessage ioexception lowlevelputexception lowlevelputexception internal_error tostring getmessage copybucket splitfileinsertersegment getclientkey blocknum jobrunner dbjob objectcontainer clientcontext isstored splitfileinsertersegment splitfileinsertersegment onencode splitfileinsertersegment nativethread norm_priority mainexecutor onencode realput cachelocalrequests lowlevelputexception onfailure splitfileinsertersegment splitfileinsertersegment oninsertsuccess public void run object container container client context context if container ext is stored split file inserter segment this return container activate split file inserter segment this 1 on encode num key container context container deactivate split file inserter segment this 1 objectcontainer clientcontext isstored splitfileinsertersegment splitfileinsertersegment onencode splitfileinsertersegment context main executor execute new runnable public void run on encode num key null context mainexecutor onencode protected clientchk block encode bucket bucket copy bucket throws chk encode exception io exception return clientchk block encode copy bucket false true short 1 chk block data length clientchkblock encodebucket copybucket chkencodeexception ioexception clientchkblock copybucket chkblock data_length override public boolean is cancelled object container container return finished iscancelled objectcontainer override public boolean isssk return false override public list persistent chosen block make blocks persistent chosen request request request scheduler sched object container container client context context if persistent container activate blocks 1 integer block numbers synchronized this block numbers blocks to array new integer blocks size array list persistent chosen block ret new array list persistent chosen block arrays sort block numbers int prev block number 1 for int i 0 i block numbers length i int block number block numbers i if block number prev block number logger error this duplicate block number in make blocks in this two copies of block number continue prev block number block number sendable request item item try item get block item container context block number catch io exception e fail new insert exception insert exception bucket error e null container context return null persistent chosen block block new persistent chosen block true request item null null sched if logminor logger minor this created block block for block number block number on this ret add block if persistent container deactivate blocks 1 if logminor logger minor this returning ret size blocks return ret persistentchosenblock makeblocks persistentchosenrequest requestscheduler objectcontainer clientcontext blocknumbers blocknumbers toarray arraylist persistentchosenblock arraylist persistentchosenblock blocknumbers prevblocknumber blocknumbers blocknumber blocknumbers blocknumber prevblocknumber makeblocks blocknumber prevblocknumber blocknumber sendablerequestitem getblockitem blocknumber ioexception insertexception insertexception bucket_error persistentchosenblock persistentchosenblock blocknumber override public synchronized long count sendable keys object container container client context context if persistent container activate blocks 1 int sz blocks size if persistent container deactivate blocks 1 return sz countsendablekeys objectcontainer clientcontext public synchronized boolean is empty object container container if persistent container activate blocks 2 boolean ret finished blocks is empty if persistent container deactivate blocks 1 return ret isempty objectcontainer isempty public void remove from object container container client context context if encode job null if encode job cancel container context synchronized this remove on encode true if logminor logger minor this will remove after encode finished this container store this return encode job null parent putter can deal with themselves free buckets array container data blocks free buckets array container check blocks for clientchk chk dataur is if chk null if logminor logger minor this datauri is null on this container activate chk 5 chk remove from container for clientchk chk checkur is if chk null if logminor logger minor this checkuri is null on this container activate chk 5 chk remove from container container activate blocks 5 for integer i blocks container activate i 1 container delete i container delete blocks if to throw null container activate to throw 5 to throw remove from container if errors null container activate errors 1 errors remove from container container delete this removefrom objectcontainer clientcontext encodejob encodejob removeonencode encodejob freebucketsarray datablocks freebucketsarray checkblocks datauris removefrom checkuris removefrom tothrow tothrow tothrow removefrom removefrom override public boolean cache inserts object container container boolean deactivate false if persistent deactivate container ext is active block insert context if deactivate container activate block insert context 1 boolean retval block insert context cache local requests if deactivate container deactivate block insert context 1 return retval cacheinserts objectcontainer isactive blockinsertcontext blockinsertcontext blockinsertcontext cachelocalrequests blockinsertcontext public boolean object can new object container container if finished logger error this storing this when already finished new exception error return false if logdebug logger debug this storing this activated container ext is active this stored container ext is stored this new exception debug return true objectcannew objectcontainer isactive isstored private void free buckets array object container container bucket buckets for int i 0 i buckets length i if buckets i null continue if persistent container activate buckets i 1 buckets i free if persistent buckets i remove from container buckets i null freebucketsarray objectcontainer removefrom private static final long serial versionuid 4542976419025644806l throttle deprecated exception packet throttle target this target target serialversionuid throttledeprecatedexception packetthrottle creates an exception param name the name of the element where the error is located param message a message describing what went wrong dl dl dt b preconditions b dt dd ul li code message null code ul dd dl dl dt b postconditions b dt dd ul li get line nr no line ul dd dl dl public xml parse exception string name string message super xml parse exception during parsing of name null the xml definition a name element message this line nr xml parse exception no line getlinenr no_line xmlparseexception linenr xmlparseexception no_line creates an exception param name the name of the element where the error is located param line nr the number of the line in the input param message a message describing what went wrong dl dl dt b preconditions b dt dd ul li code message null code li code line nr gt 0 code ul dd dl dl dt b postconditions b dt dd ul li get line nr line nr ul dd dl dl public xml parse exception string name int line nr string message super xml parse exception during parsing of name null the xml definition a name element at line line nr message this line nr line nr linenr linenr getlinenr linenr xmlparseexception linenr linenr linenr linenr where the error occurred or code no line code if the line number is unknown see nanoxml xml parse exception no line public int get line nr return this line nr no_line xmlparseexception no_line getlinenr linenr public usk byte pub key hash byte crypto key byte extra string site name long suggested edition throws malformedurl exception this pub key hash pub key hash this crypto key crypto key this site name site name this suggested edition suggested edition if extra null throw new malformedurl exception no extra bytes third bit in usk if pub key hash null throw new malformedurl exception no pubkey hash first bit in usk if crypto key null throw new malformedurl exception no crypto key second bit in usk verify extra bytes get crypto algorithm fixme this should be a static method or something clientssk tmp new clientssk site name pub key hash extra null crypto key crypto algorithm tmp crypto algorithm if pub key hash length nodessk pubkey hash size throw new malformedurl exception pubkey hash wrong length pub key hash length should be nodessk pubkey hash size if crypto key length clientssk crypto key length throw new malformedurl exception decryption key wrong length crypto key length should be clientssk crypto key length hash code fields hash code pub key hash fields hash code crypto key site name hash code int suggested edition int suggested edition 32 pubkeyhash cryptokey sitename suggestededition malformedurlexception pubkeyhash pubkeyhash cryptokey cryptokey sitename sitename suggestededition suggestededition malformedurlexception pubkeyhash malformedurlexception cryptokey malformedurlexception cryptoalgorithm sitename pubkeyhash cryptokey cryptoalgorithm cryptoalgorithm pubkeyhash pubkey_hash_size malformedurlexception pubkeyhash pubkey_hash_size cryptokey crypto_key_length malformedurlexception cryptokey crypto_key_length hashcode hashcode pubkeyhash hashcode cryptokey sitename hashcode suggestededition suggestededition public static usk create freeneturi uri throws malformedurl exception if uri isusk throw new malformedurl exception not a usk return new usk uri get routing key uri get crypto key uri get extra uri get doc name uri get suggested edition malformedurlexception malformedurlexception getroutingkey getcryptokey getextra getdocname getsuggestededition protected usk byte pub key hash2 byte crypto key2 string site name2 long suggested edition2 byte crypto algorithm this pub key hash pub key hash2 this crypto key crypto key2 this site name site name2 this suggested edition suggested edition2 this crypto algorithm crypto algorithm hash code fields hash code pub key hash fields hash code crypto key site name hash code int suggested edition int suggested edition 32 pubkeyhash2 cryptokey2 sitename2 suggestededition2 cryptoalgorithm pubkeyhash pubkeyhash2 cryptokey cryptokey2 sitename sitename2 suggestededition suggestededition2 cryptoalgorithm cryptoalgorithm hashcode hashcode pubkeyhash hashcode cryptokey sitename hashcode suggestededition suggestededition fixme be careful with this constructor there must not be an edition in the clientssk public usk clientssk ssk long myark number this pub key hash ssk pub key hash this crypto key ssk crypto key this site name ssk doc name this suggested edition myark number this crypto algorithm ssk crypto algorithm if site name matches 0 9 not error just possible bug logger normal this possible bug edition in clientssk ssk new exception debug hash code fields hash code pub key hash fields hash code crypto key site name hash code int suggested edition int suggested edition 32 myarknumber pubkeyhash pubkeyhash cryptokey cryptokey sitename docname suggestededition myarknumber cryptoalgorithm cryptoalgorithm sitename hashcode hashcode pubkeyhash hashcode cryptokey sitename hashcode suggestededition suggestededition public usk usk usk this pub key hash new byte usk pub key hash length system arraycopy usk pub key hash 0 pub key hash 0 usk pub key hash length this crypto algorithm usk crypto algorithm this crypto key usk crypto key this site name usk site name this suggested edition usk suggested edition hash code fields hash code pub key hash fields hash code crypto key site name hash code int suggested edition int suggested edition 32 pubkeyhash pubkeyhash pubkeyhash pubkeyhash pubkeyhash cryptoalgorithm cryptoalgorithm cryptokey cryptokey sitename sitename suggestededition suggestededition hashcode hashcode pubkeyhash hashcode cryptokey sitename hashcode suggestededition suggestededition override public freeneturi geturi return new freeneturi pub key hash crypto key clientssk get extra bytes crypto algorithm site name suggested edition pubkeyhash cryptokey getextrabytes cryptoalgorithm sitename suggestededition public clientssk getssk long ver try return new clientssk site name separator ver pub key hash clientssk get extra bytes crypto algorithm null crypto key catch malformedurl exception e logger error this caught e should not be possible in usk getssk e throw new error e sitename pubkeyhash getextrabytes cryptoalgorithm cryptokey malformedurlexception public client key getssk return getssk suggested edition clientkey suggestededition public usk copy long edition if suggested edition edition return this return new usk pub key hash crypto key site name edition crypto algorithm suggestededition pubkeyhash cryptokey sitename cryptoalgorithm public usk clear copy return copy 0 clearcopy override public usk clone return new usk this override public boolean equals object o if o null o instanceof usk return false return equals o true public boolean equals object o boolean include version if o instanceof usk usk u usk o if arrays equals pub key hash u pub key hash return false if arrays equals crypto key u crypto key return false if site name equals u site name return false if include version suggested edition u suggested edition return false return true return false includeversion pubkeyhash pubkeyhash cryptokey cryptokey sitename sitename includeversion suggestededition suggestededition override public int hash code return hash code hashcode hashcode public freeneturi get basessk return new freeneturi ssk site name pub key hash crypto key clientssk get extra bytes crypto algorithm getbasessk sitename pubkeyhash cryptokey getextrabytes cryptoalgorithm override public string to string return super to string geturi tostring tostring public freeneturi turn myssk intousk freeneturi uri if uri get key type equals ssk arrays equals uri get routing key pub key hash arrays equals uri get crypto key crypto key arrays equals uri get extra clientssk get extra bytes crypto algorithm uri get doc name null uri get doc name starts with site name string doc uri get doc name doc doc substring site name length if doc length 2 doc char at 0 return uri doc doc substring 1 long edition try edition long parse long doc catch number format exception e logger normal this trying to turn ssk back into usk uri doc doc caught e e return uri if doc equals long to string edition return uri return new freeneturi usk site name uri get all meta strings pub key hash crypto key clientssk get extra bytes crypto algorithm edition return uri turnmysskintousk getkeytype getroutingkey pubkeyhash getcryptokey cryptokey getextra getextrabytes cryptoalgorithm getdocname getdocname startswith sitename getdocname sitename charat parselong numberformatexception tostring sitename getallmetastrings pubkeyhash cryptokey getextrabytes cryptoalgorithm public void remove from object container container container delete this removefrom objectcontainer public unsubscribeusk message simple field set fs throws message invalid exception this identifier fs get identifier if identifier null throw new message invalid exception protocol error message missing field no identifier null false unsubscribeuskmessage simplefieldset messageinvalidexception messageinvalidexception protocolerrormessage missing_field override public simple field set get field set throw new unsupported operation exception simplefieldset getfieldset unsupportedoperationexception override public string get name return name getname override public void remove from object container container throw new unsupported operation exception removefrom objectcontainer unsupportedoperationexception override public void run fcp connection handler handler node node throws message invalid exception handler unsubscribe identifier fcpconnectionhandler messageinvalidexception multidimensional comparator t comparator private kd tree multidimensionalcomparator kdtree private kd tree kd tree storage storage multidimensional comparator t comparator super storage this comparator comparator kdtree kdtree multidimensionalcomparator kd tree storage storage class cls string field names boolean treate zero as undefined value super storage this comparator new reflection multidimensional comparator t storage cls field names treate zero as undefined value kdtree fieldnames treatezeroasundefinedvalue reflectionmultidimensionalcomparator fieldnames treatezeroasundefinedvalue public multidimensional comparator t get comparator return comparator multidimensionalcomparator getcomparator boolean deleted kd tree node t obj this obj obj kdtreenode private kd tree node kdtreenode private kd tree node public void load super load obj load kdtreenode public boolean recursive loading return false recursiveloading int insert t ins multidimensional comparator t comparator int level load int diff comparator compare ins obj level comparator get number of dimensions if diff multidimensional comparator eq deleted obj deallocate modify obj ins deleted false return level else if diff multidimensional comparator gt if left null modify left new kd tree node t ins return level 1 else return left insert ins comparator level 1 else if right null modify right new kd tree node t ins return level 1 else return right insert ins comparator level 1 multidimensionalcomparator getnumberofdimensions multidimensionalcomparator multidimensionalcomparator kdtreenode kdtreenode int remove t rem multidimensional comparator t comparator int level load if obj rem if left null right null deallocate return truncate else modify obj comparator clone field obj level comparator get number of dimensions deleted true return ok int diff comparator compare rem obj level comparator get number of dimensions if diff multidimensional comparator gt left null int result left remove rem comparator level 1 if result truncate modify left null return ok else if result ok return ok if diff multidimensional comparator lt right null int result right remove rem comparator level 1 if result truncate modify right null return ok else if result ok return ok return not found multidimensionalcomparator clonefield getnumberofdimensions getnumberofdimensions multidimensionalcomparator multidimensionalcomparator not_found public void deallocate load if deleted obj deallocate if left null left deallocate if right null right deallocate super deallocate public void optimize iterator t itr iterator int n n members i persistent members new i persistent n for int i 0 i n i members i itr next random rnd new random for int i 0 i n i int j rnd next int n i persistent tmp members j members j members i members i tmp clear for int i 0 i n i add t members i nmembers ipersistent ipersistent nextint ipersistent public boolean add t obj modify if root null root new kd tree node t obj height 1 else int level root insert obj comparator 0 if level height height level 1 n members 1 return true kdtreenode nmembers public boolean remove t obj if root null return false int result root remove obj comparator 0 if result not found return false modify if result truncate root null n members 1 return true not_found nmembers public iterator t iterator return iterator null null public iterable iterator t iterator t pattern return iterator pattern pattern iterableiterator public iterable iterator t iterator t low t high return new kd tree iterator low high iterableiterator kdtreeiterator public array list t query by example t pattern return query by example pattern pattern arraylist querybyexample querybyexample public array list t query by example t low t high iterator t i iterator low high array list t list new array list t while i has next list add i next return list arraylist querybyexample arraylist arraylist hasnext public object to array return query by example null null to array toarray querybyexample toarray public e e to array e arr return query by example null null to array arr toarray querybyexample toarray public int size return n members nmembers public int get height return height getheight public void clear if root null root deallocate modify root null n members 0 height 0 nmembers public boolean contains t member iterator t i iterator member while i has next if i next member return true return false hasnext public void deallocate if root null root deallocate super deallocate int compare all components t pattern t obj int n comparator get number of dimensions int result multidimensional comparator eq for int i 0 i n i int diff comparator compare pattern obj i if diff multidimensional comparator right undefined return diff else if diff multidimensional comparator lt if result multidimensional comparator gt return multidimensional comparator ne else result multidimensional comparator lt else if diff multidimensional comparator gt if result multidimensional comparator lt return multidimensional comparator ne else result multidimensional comparator gt return result compareallcomponents getnumberofdimensions multidimensionalcomparator multidimensionalcomparator right_undefined multidimensionalcomparator multidimensionalcomparator multidimensionalcomparator multidimensionalcomparator multidimensionalcomparator multidimensionalcomparator multidimensionalcomparator multidimensionalcomparator kd tree iterator t low t high this low low this high high n dims comparator get number of dimensions stack new stack kd tree node t get min root kdtreeiterator ndims getnumberofdimensions kdtreenode getmin public int get level return curr level getlevel currlevel private boolean get min kd tree node t node if node null while true node load stack push node int diff low null multidimensional comparator left undefined comparator compare low node obj stack size 1 n dims if diff multidimensional comparator gt node left null node node left else return true return false getmin kdtreenode multidimensionalcomparator left_undefined ndims multidimensionalcomparator public boolean has next if next null return true while stack empty kd tree node t node stack pop if node null if node deleted int result if low null result compare all components low node obj multidimensional comparator lt result multidimensional comparator eq high null result compare all components high node obj multidimensional comparator gt result multidimensional comparator eq next node curr level stack size if node right null high null comparator compare high node obj stack size n dims multidimensional comparator lt stack push null if get min node right stack pop if next null return true return false hasnext kdtreenode compareallcomponents multidimensionalcomparator multidimensionalcomparator compareallcomponents multidimensionalcomparator multidimensionalcomparator currlevel ndims multidimensionalcomparator getmin public t next if has next throw new no such element exception curr next next null return curr obj hasnext nosuchelementexception public int next oid return next get oid nextoid getoid public void remove if curr null throw new illegal state exception curr modify curr obj comparator clone field curr obj curr level n dims curr deleted true curr null illegalstateexception clonefield currlevel ndims public static string get simplified architecture string arch if system get property os arch to lower case matches i x0 9 86 64 amd64 arch amd64 else if system get property os arch to lower case matches ppc arch ppc else we want to try the i386 libraries if the architecture is unknown wrappers must fallback to plain java implementation if loading native libraries fails arch i386 return arch getsimplifiedarchitecture getproperty tolowercase 86_64 getproperty tolowercase public static boolean load native string path string library name boolean success false final boolean is windows file path separator char final string prefix is windows dll system get property os name to lower case starts with mac jnilib so final string library name with prefix is windows lib library name final string library name with prefix and arch library name with prefix get simplified architecture final string library name with prefix and arch and suffix library name with prefix and arch prefix string resource name path library name with prefix and arch and suffix file native lib new file system get property java library path lib library name prefix if native lib exists system out println attempting to load the native thread library library name system load library library name success true else try get the resource url resource library loader class get resource resource name get input stream from jar resource input stream input stream resource open stream copy resource to filesystem in a temp folder with a unique name file temporary lib file create temp file library name with prefix and arch tmp delete on exit the dll temporary lib delete on exit file output stream output stream new file output stream temporary lib byte array new byte 2048 int read 0 while read input stream read array 0 output stream write array 0 read output stream close finally load the dll system out println attempting to load the library name library resource system load temporary lib get path success true catch throwable e system err println caught the following exception attempting to load resource name e print stack trace return success loadnative libraryname iswindows pathseparatorchar iswindows getproperty tolowercase startswith librarynamewithprefix iswindows libraryname librarynamewithprefixandarch librarynamewithprefix getsimplifiedarchitecture librarynamewithprefixandarchandsuffix librarynamewithprefixandarch resourcename librarynamewithprefixandarchandsuffix nativelib getproperty libraryname nativelib nativethread libraryname loadlibrary libraryname libraryloader getresource resourcename inputstream inputstream openstream temporarylib createtempfile librarynamewithprefixandarch temporarylib deleteonexit fileoutputstream outputstream fileoutputstream temporarylib inputstream outputstream outputstream libraryname temporarylib getpath resourcename printstacktrace creates a new own identities page param my web interface a reference to the web interface which created the page used to get resources the page needs param my request the request sent by the user public create identity page web interface my web interface http request my request super my web interface my request ownidentitiespage mywebinterface webinterface myrequest createidentitypage webinterface mywebinterface httprequest myrequest mywebinterface myrequest public void make if request is part set create identity try own identity new identity wot create own identity request get part as string inserturi 1024 request get part as string requesturi 1024 request get part as string nickname 1024 request get part as string publish trust list 5 equals true freetalk fixme freetalk should do that itself fixme inline the own identities page first we need to modify our base class to be able to do so see freetalk add content box your identity was created add child please go to the own identities page and solve introduction puzzles otherwise nobody will see the identity catch exception e add error box identity creation failed e get message else make create form request get part as string nickname 1024 ispartset createidentity ownidentity newidentity createownidentity getpartasstring getpartasstring getpartasstring getpartasstring publishtrustlist addcontentbox addchild adderrorbox getmessage makecreateform getpartasstring creates a form with pre filled keypair to create an new own identity param client a reference to a high level simple client param pr a reference to the plugin respirator param nick name the nick name supplied by the user private void make create form string nick name html node box content add content box identity creation freeneturi keypair wot get plugin respirator gethl simple client generate key pair wot html node create form pr add form child box content uri create identity create form add child input new string type name value new string hidden page create identity create form add child request uri create form add child input new string type name size value new string text requesturi 70 keypair 1 to string create form add child br create form add child insert uri create form add child input new string type name size value new string text inserturi 70 keypair 0 to string create form add child br create form add child publish trust list create form add child input new string type name value checked new string checkbox publish trust list true checked create form add child br create form add child input new string type name value new string hidden nickname nick name create form add child input new string type name value new string submit create identity create it ownidentity highlevelsimpleclient pluginrespirator nickname nickname makecreateform nickname htmlnode boxcontent addcontentbox getpluginrespirator gethlsimpleclient generatekeypair htmlnode createform addformchild boxcontent createidentity createform addchild createidentity createform addchild createform addchild tostring createform addchild createform addchild createform addchild tostring createform addchild createform addchild createform addchild publishtrustlist createform addchild createform addchild nickname createform addchild createidentity public void add last message item item if item msg null if items noid null items noid new linked list message item items noid add last item return object o item msg get object dmt uid if o null o instanceof long if items noid null items noid new linked list message item items noid add last item return long id long o linked list message item list if items byid null items byid new hash map long linked list message item items withid new array list linked list message item itemsi ds new array list long list new linked list message item items withid add list itemsi ds add id items byid put id list else list items byid get id if list null list new linked list message item items withid add list items byid put id list itemsi ds add id list add last item addlast messageitem itemsnoid itemsnoid linkedlist messageitem itemsnoid addlast getobject itemsnoid itemsnoid linkedlist messageitem itemsnoid addlast linkedlist messageitem itemsbyid itemsbyid hashmap linkedlist messageitem itemswithid arraylist linkedlist messageitem itemsids arraylist linkedlist messageitem itemswithid itemsids itemsbyid itemsbyid linkedlist messageitem itemswithid itemsbyid itemsids addlast public void add first message item item if item msg null if items noid null items noid new linked list message item items noid add first item return object o item msg get object dmt uid if o null o instanceof long if items noid null items noid new linked list message item items noid add first item return long id long o linked list message item list if items byid null items byid new hash map long linked list message item items withid new array list linked list message item itemsi ds new array list long list new linked list message item items withid add list itemsi ds add id items byid put id list else list items byid get id if list null list new linked list message item items withid add list itemsi ds add id items byid put id list list add first item addfirst messageitem itemsnoid itemsnoid linkedlist messageitem itemsnoid addfirst getobject itemsnoid itemsnoid linkedlist messageitem itemsnoid addfirst linkedlist messageitem itemsbyid itemsbyid hashmap linkedlist messageitem itemswithid arraylist linkedlist messageitem itemsids arraylist linkedlist messageitem itemswithid itemsids itemsbyid itemsbyid linkedlist messageitem itemswithid itemsids itemsbyid addfirst public int size int size 0 if items noid null size items noid size if items withid null for linked list message item list items withid size list size return size itemsnoid itemsnoid itemswithid linkedlist messageitem itemswithid public int add to message item output int ptr if items noid null for message item item items noid output ptr item if items withid null for linked list message item list items withid for message item item list output ptr item return ptr addto messageitem itemsnoid messageitem itemsnoid itemswithid linkedlist messageitem itemswithid messageitem public long get next urgent time long t long now if items noid null t math min t items noid get first submitted packet sender max coalescing delay if t now return t if items withid null for linked list message item items items withid t math min t items get first submitted packet sender max coalescing delay if t now return t return t getnexturgenttime itemsnoid itemsnoid getfirst packetsender max_coalescing_delay itemswithid linkedlist messageitem itemswithid getfirst packetsender max_coalescing_delay public int add size int length int max size if items noid null for message item item items noid int this len item get length length this len if length max size return length if items withid null for linked list message item list items withid for message item item list int this len item get length length this len if length max size return length return length addsize maxsize itemsnoid messageitem itemsnoid thislen getlength thislen maxsize itemswithid linkedlist messageitem itemswithid messageitem thislen getlength thislen maxsize private int add messages int size int min size int max size long now array list message item messages boolean is urgent int lists 0 if items noid null lists if items withid null lists items withid size for int i 0 i lists i linked list message item list int l i round robin counter 1 lists int list num 1 if items noid null if l 0 list items noid else list num l 1 list items withid get list num else list num l list items withid get l while true if list is empty break message item item list get first if is urgent item submitted packet sender max coalescing delay now break int this size item get length if size 2 this size max size if size min size send it anyway nothing else to send size 2 this size list remove first if list is empty if list items noid items noid null lists else long id itemsi ds get list num items withid remove list num itemsi ds remove list num items byid remove id lists messages add item round robin counter i return size return size size 2 this size list remove first if list is empty if list items noid items noid null lists else long id itemsi ds get list num items withid remove list num itemsi ds remove list num items byid remove id lists messages add item round robin counter i return size addmessages minsize maxsize arraylist messageitem isurgent itemsnoid itemswithid itemswithid linkedlist messageitem roundrobincounter listnum itemsnoid itemsnoid listnum itemswithid listnum listnum itemswithid isempty messageitem getfirst isurgent packetsender max_coalescing_delay thissize getlength thissize maxsize minsize thissize removefirst isempty itemsnoid itemsnoid itemsids listnum itemswithid listnum itemsids listnum itemsbyid roundrobincounter thissize removefirst isempty itemsnoid itemsnoid itemsids listnum itemswithid listnum itemsids listnum itemsbyid roundrobincounter param size param min size param max size param now param messages return the new size of the packet multiplied by 1 iff there are more messages but they don t fit public int add urgent messages int size int min size int max size long now array list message item messages return add messages size min size max size now messages true minsize maxsize addurgentmessages minsize maxsize arraylist messageitem addmessages minsize maxsize param size param min size param max size param now param messages return the new size of the packet multiplied by 1 iff there are more messages but they don t fit public int add messages int size int min size int max size long now array list message item messages return add messages size min size max size now messages false minsize maxsize addmessages minsize maxsize arraylist messageitem addmessages minsize maxsize public void clear items noid null items withid null itemsi ds null items byid null itemsnoid itemswithid itemsids itemsbyid peer message queue queues by priority new prio queue dmt num priorities for int i 0 i queues by priority length i queues by priority i new prio queue peermessagequeue queuesbypriority prioqueue num_priorities queuesbypriority queuesbypriority prioqueue public synchronized int queue and estimate size message item item enqueue prioritized message item item int x 0 for prio queue pq queues by priority if pq items noid null for message item it pq items noid x it get length 2 if x 1024 break if pq items withid null for linked list message item q pq items withid for message item it q x it get length 2 if x 1024 break return x queueandestimatesize messageitem enqueueprioritizedmessageitem prioqueue queuesbypriority itemsnoid messageitem itemsnoid getlength itemswithid linkedlist messageitem itemswithid messageitem getlength public synchronized long get message queue length bytes long x 0 for prio queue pq queues by priority if pq items noid null for message item it pq items noid x it get length 2 if pq items withid null for linked list message item q pq items withid for message item it q x it get length 2 return x getmessagequeuelengthbytes prioqueue queuesbypriority itemsnoid messageitem itemsnoid getlength itemswithid linkedlist messageitem itemswithid messageitem getlength private synchronized void enqueue prioritized message item message item add me assume it goes on the end both the common case short prio add me get priority queues by priority prio add last add me enqueueprioritizedmessageitem messageitem addme addme getpriority queuesbypriority addlast addme like enqueue prioritized message item but adds it to the front of those in the same priority synchronized void pushfront prioritized message item message item add me assume it goes on the front short prio add me get priority queues by priority prio add first add me enqueueprioritizedmessageitem pushfrontprioritizedmessageitem messageitem addme addme getpriority queuesbypriority addfirst addme public synchronized message item grab queued message items int size 0 for int i 0 i queues by priority length i size queues by priority i size message item output new message item size int ptr 0 for prio queue queue queues by priority ptr queue add to output ptr queue clear return output messageitem grabqueuedmessageitems queuesbypriority queuesbypriority messageitem messageitem prioqueue queuesbypriority addto get the time at which the next message must be sent if any message is overdue we will return a value less than now which may not be completely accurate param t param now return public synchronized long get next urgent time long t long now for prio queue queue queues by priority t math min t queue get next urgent time t now if t now return t how much in the past doesn t matter as long as it s in the past return t getnexturgenttime prioqueue queuesbypriority getnexturgenttime public boolean must send now long now return get next urgent time long max value now now mustsendnow getnexturgenttime max_value public synchronized boolean must send size int min size int max size int length min size for prio queue items queues by priority length items add size length max size if length max size return true return false mustsendsize minsize maxsize minsize prioqueue queuesbypriority addsize maxsize maxsize add urgent messages to the queue param size param now param min size param max size param messages return the new size of the packet multiplied by 1 iff there are more messages but they don t fit public synchronized int add urgent messages int size long now int min size int max size array list message item messages boolean got enough false for prio queue queue queues by priority size queue add urgent messages size min size max size now messages if size 0 size size got enough true if got enough return size else return size minsize maxsize addurgentmessages minsize maxsize arraylist messageitem gotenough prioqueue queuesbypriority addurgentmessages minsize maxsize gotenough gotenough add non urgent messages to the queue param size param now param min size param max size param messages return the new size of the packet multiplied by 1 iff there are more messages but they don t fit public synchronized int add non urgent messages int size long now int min size int max size array list message item messages boolean got enough false for prio queue queue queues by priority size queue add messages size min size max size now messages if size 0 size size got enough true if got enough return size else return size minsize maxsize addnonurgentmessages minsize maxsize arraylist messageitem gotenough prioqueue queuesbypriority addmessages minsize maxsize gotenough gotenough public static t extends object object set t query object container container class t clazz db4o 7 4 84 12673 throws a runtime exception not supported when we use this documented api to query all elements of a class isn t that great fixme file a bug with db4o object set has key listener results container query has key listener class query query container query query constrain clazz return query execute objectset objectcontainer runtimeexception objectset haskeylistener haskeylistener private final hash set sendable request set transient sendable request set set new hash set sendable request hashset sendablerequest transientsendablerequestset hashset sendablerequest public synchronized boolean add request sendable request req object container container return set add req addrequest sendablerequest objectcontainer public synchronized sendable request list requests object container container return set to array new sendable request set size sendablerequest listrequests objectcontainer toarray sendablerequest public synchronized boolean remove request sendable request req object container container return set remove req removerequest sendablerequest objectcontainer public void remove from object container container throw new unsupported operation exception removefrom objectcontainer unsupportedoperationexception public boolean object can new object container container logger error this not storing transient sendable request set in database new exception error return false objectcannew objectcontainer transientsendablerequestset public static void main string args throws fs parse exception peer parse exception interrupted exception reference signature verification exception node init exception invalid threshold exception random source random node starter global test init pingtest false logger error true create 2 nodes executor executor new pooled executor node node1 node starter create test node 5001 0 pingtest false false true node default max htl 0 random executor 1000 65536 true false false false false false true 0 false false null node node2 node starter create test node 5002 0 pingtest false false true node default max htl 0 random executor 1000 65536 true false false false false false true 0 false false null connect node1 connect node2 node2 connect node1 no swapping node1 start true node2 start true ping peer node pn node1 get peer nodes 0 int pingid 0 thread sleep 20000 node1 usm set drop probability 4 while true logger minor real node ping test class sending ping pingid boolean success try success pn ping pingid catch not connected exception e1 logger normal real node ping test class not connected continue if success logger normal real node ping test class ping pingid successful else logger normal real node ping test class ping failed pingid try thread sleep 2000 catch interrupted exception e shouldn t happen pingid fsparseexception peerparseexception interruptedexception referencesignatureverificationexception nodeinitexception invalidthresholdexception randomsource nodestarter globaltestinit pooledexecutor nodestarter createtestnode default_max_htl nodestarter createtestnode default_max_htl peernode getpeernodes setdropprobability realnodepingtest notconnectedexception realnodepingtest realnodepingtest realnodepingtest interruptedexception apply a bias to a number in the unit interval moving numbers towards 0 or 1 according to the bias parameter param a the number to bias param b the bias parameter 0 5 means no change smaller values bias towards 0 larger towards 1 return the output value public static float bias float a float b return float math pow a math log b math log 0 5 return a 1 0f b 2 1 0f a 1 a variant of the gamma function param a the number to apply gain to param b the gain parameter 0 5 means no change smaller values reduce gain larger values increase gain return the output value public static float gain float a float b float p float math log 1 0 b float math log 0 5 if a 001 return 0 0f else if a 999 return 1 0f if a 0 5 return float math pow 2 a p 2 else return 1 0f float math pow 2 1 a p 2 float c 1 0f b 2 0f 1 0f 2 0f a if a 0 5 return a c 1 0f else return c a c 1 0f the step function returns 0 below a threshold 1 above param a the threshold position param x the input parameter return the output value 0 or 1 public static float step float a float x return x a 0 0f 1 0f the pulse function returns 1 between two thresholds 0 outside param a the lower threshold position param b the upper threshold position param x the input parameter return the output value 0 or 1 public static float pulse float a float b float x return x a x b 0 0f 1 0f a smoothed pulse function a cubic function is used to smooth the step between two thresholds param a1 the lower threshold position for the start of the pulse param a2 the upper threshold position for the start of the pulse param b1 the lower threshold position for the end of the pulse param b2 the upper threshold position for the end of the pulse param x the input parameter return the output value public static float smooth pulse float a1 float a2 float b1 float b2 float x if x a1 x b2 return 0 if x a2 if x b1 return 1 0f x x b1 b2 b1 return 1 0f x x 3 0f 2 0f x x x a1 a2 a1 return x x 3 0f 2 0f x smoothpulse a smoothed step function a cubic function is used to smooth the step between two thresholds param a the lower threshold position param b the upper threshold position param x the input parameter return the output value public static float smooth step float a float b float x if x a return 0 if x b return 1 x x a b a return x x 3 2 x smoothstep a circle up function returns y on a unit circle given 1 x useful for forming bevels param x the input parameter in the range 0 1 return the output value public static float circle up float x x 1 x return float math sqrt 1 x x circleup a circle down function returns 1 y on a unit circle given x useful for forming bevels param x the input parameter in the range 0 1 return the output value public static float circle down float x return 1 0f float math sqrt 1 x x circledown clamp a value to an interval param a the lower clamp threshold param b the upper clamp threshold param x the input parameter return the clamped value public static float clamp float x float a float b return x a a x b b x clamp a value to an interval param a the lower clamp threshold param b the upper clamp threshold param x the input parameter return the clamped value public static int clamp int x int a int b return x a a x b b x return a mod b this differs from the operator with respect to negative numbers param a the dividend param b the divisor return a mod b public static double mod double a double b int n int a b a n b if a 0 return a b return a return a mod b this differs from the operator with respect to negative numbers param a the dividend param b the divisor return a mod b public static float mod float a float b int n int a b a n b if a 0 return a b return a return a mod b this differs from the operator with respect to negative numbers param a the dividend param b the divisor return a mod b public static int mod int a int b int n a b a n b if a 0 return a b return a the triangle function returns a repeating triangle shape in the range 0 1 with wavelength 1 0 param x the input parameter return the output value public static float triangle float x float r mod x 1 0f return 2 0f r 0 5 r 1 r linear interpolation param t the interpolation parameter param a the lower interpolation range param b the upper interpolation range return the interpolated value public static float lerp float t float a float b return a t b a linear interpolation param t the interpolation parameter param a the lower interpolation range param b the upper interpolation range return the interpolated value public static int lerp float t int a int b return int a t b a linear interpolation of argb values param t the interpolation parameter param rgb1 the lower interpolation range param rgb2 the upper interpolation range return the interpolated value public static int mix colors float t int rgb1 int rgb2 int a1 rgb1 24 0xff int r1 rgb1 16 0xff int g1 rgb1 8 0xff int b1 rgb1 0xff int a2 rgb2 24 0xff int r2 rgb2 16 0xff int g2 rgb2 8 0xff int b2 rgb2 0xff a1 lerp t a1 a2 r1 lerp t r1 r2 g1 lerp t g1 g2 b1 lerp t b1 b2 return a1 24 r1 16 g1 8 b1 mixcolors bilinear interpolation of argb values param x the x interpolation parameter 0 1 param y the y interpolation parameter 0 1 param rgb array of four argb values in the order nw ne sw se return the interpolated value public static int bilinear interpolate float x float y int nw int ne int sw int se float m0 m1 int a0 nw 24 0xff int r0 nw 16 0xff int g0 nw 8 0xff int b0 nw 0xff int a1 ne 24 0xff int r1 ne 16 0xff int g1 ne 8 0xff int b1 ne 0xff int a2 sw 24 0xff int r2 sw 16 0xff int g2 sw 8 0xff int b2 sw 0xff int a3 se 24 0xff int r3 se 16 0xff int g3 se 8 0xff int b3 se 0xff float cx 1 0f x float cy 1 0f y m0 cx a0 x a1 m1 cx a2 x a3 int a int cy m0 y m1 m0 cx r0 x r1 m1 cx r2 x r3 int r int cy m0 y m1 m0 cx g0 x g1 m1 cx g2 x g3 int g int cy m0 y m1 m0 cx b0 x b1 m1 cx b2 x b3 int b int cy m0 y m1 return a 24 r 16 g 8 b bilinearinterpolate return the ntsc gray level of an rgb value param rgb1 the input pixel return the gray level 0 255 public static int brightnessntsc int rgb int r rgb 16 0xff int g rgb 8 0xff int b rgb 0xff return int r 0 299f g 0 587f b 0 114f compute a catmull rom spline param x the input parameter param num knots the number of knots in the spline param knots the array of knots return the spline value public static float spline float x int num knots float knots int span int num spans num knots 3 float k0 k1 k2 k3 float c0 c1 c2 c3 if num spans 1 throw new illegal argument exception too few knots in spline x clamp x 0 1 num spans span int x if span num knots 4 span num knots 4 x span k0 knots span k1 knots span 1 k2 knots span 2 k3 knots span 3 c3 m00 k0 m01 k1 m02 k2 m03 k3 c2 m10 k0 m11 k1 m12 k2 m13 k3 c1 m20 k0 m21 k1 m22 k2 m23 k3 c0 m30 k0 m31 k1 m32 k2 m33 k3 return c3 x c2 x c1 x c0 numknots numknots numspans numknots numspans illegalargumentexception numspans numknots numknots compute a catmull rom spline but with variable knot spacing param x the input parameter param num knots the number of knots in the spline param xknots the array of knot x values param yknots the array of knot y values return the spline value public static float spline float x int num knots int xknots int yknots int span int num spans num knots 3 float k0 k1 k2 k3 float c0 c1 c2 c3 if num spans 1 throw new illegal argument exception too few knots in spline for span 0 span num spans span if xknots span 1 x break if span num knots 3 span num knots 3 float t float x xknots span xknots span 1 xknots span span if span 0 span 0 t 0 k0 yknots span k1 yknots span 1 k2 yknots span 2 k3 yknots span 3 c3 m00 k0 m01 k1 m02 k2 m03 k3 c2 m10 k0 m11 k1 m12 k2 m13 k3 c1 m20 k0 m21 k1 m22 k2 m23 k3 c0 m30 k0 m31 k1 m32 k2 m33 k3 return c3 t c2 t c1 t c0 numknots numknots numspans numknots numspans illegalargumentexception numspans numknots numknots compute a catmull rom spline for rgb values param x the input parameter param num knots the number of knots in the spline param knots the array of knots return the spline value public static int color spline float x int num knots int knots int span int num spans num knots 3 float k0 k1 k2 k3 float c0 c1 c2 c3 if num spans 1 throw new illegal argument exception too few knots in spline x clamp x 0 1 num spans span int x if span num knots 4 span num knots 4 x span int v 0 for int i 0 i 4 i int shift i 8 k0 knots span shift 0xff k1 knots span 1 shift 0xff k2 knots span 2 shift 0xff k3 knots span 3 shift 0xff c3 m00 k0 m01 k1 m02 k2 m03 k3 c2 m10 k0 m11 k1 m12 k2 m13 k3 c1 m20 k0 m21 k1 m22 k2 m23 k3 c0 m30 k0 m31 k1 m32 k2 m33 k3 int n int c3 x c2 x c1 x c0 if n 0 n 0 else if n 255 n 255 v n shift return v numknots colorspline numknots numspans numknots numspans illegalargumentexception numspans numknots numknots compute a catmull rom spline for rgb values but with variable knot spacing param x the input parameter param num knots the number of knots in the spline param xknots the array of knot x values param yknots the array of knot y values return the spline value public static int color spline int x int num knots int xknots int yknots int span int num spans num knots 3 float k0 k1 k2 k3 float c0 c1 c2 c3 if num spans 1 throw new illegal argument exception too few knots in spline for span 0 span num spans span if xknots span 1 x break if span num knots 3 span num knots 3 float t float x xknots span xknots span 1 xknots span span if span 0 span 0 t 0 int v 0 for int i 0 i 4 i int shift i 8 k0 yknots span shift 0xff k1 yknots span 1 shift 0xff k2 yknots span 2 shift 0xff k3 yknots span 3 shift 0xff c3 m00 k0 m01 k1 m02 k2 m03 k3 c2 m10 k0 m11 k1 m12 k2 m13 k3 c1 m20 k0 m21 k1 m22 k2 m23 k3 c0 m30 k0 m31 k1 m32 k2 m33 k3 int n int c3 t c2 t c1 t c0 if n 0 n 0 else if n 255 n 255 v n shift return v numknots colorspline numknots numspans numknots numspans illegalargumentexception numspans numknots numknots an implementation of fant s resampling algorithm param source the source pixels param dest the destination pixels param length the length of the scanline to resample param offset the start offset into the arrays param stride the offset between pixels in consecutive rows param out an array of output positions for each pixel public static void resample int source int dest int length int offset int stride float out int i j float sizfac float in segment float out segment int a r g b nexta nextr nextg nextb float a sum r sum g sum b sum float in int src index offset int dest index offset int last index source length int rgb in new float length 2 i 0 for j 0 j length j while out i 1 j i in j i float j out i out i 1 out i in j image math clamp in j 0 length 1 in length length in length 1 length in segment 1 0f out segment in 1 sizfac out segment a sum r sum g sum b sum 0 0f rgb source src index a rgb 24 0xff r rgb 16 0xff g rgb 8 0xff b rgb 0xff src index stride rgb source src index nexta rgb 24 0xff nextr rgb 16 0xff nextg rgb 8 0xff nextb rgb 0xff src index stride i 1 while i length float a intensity in segment a 1 0f in segment nexta float r intensity in segment r 1 0f in segment nextr float g intensity in segment g 1 0f in segment nextg float b intensity in segment b 1 0f in segment nextb if in segment out segment a sum a intensity in segment r sum r intensity in segment g sum g intensity in segment b sum b intensity in segment out segment in segment in segment 1 0f a nexta r nextr g nextg b nextb if src index last index rgb source src index nexta rgb 24 0xff nextr rgb 16 0xff nextg rgb 8 0xff nextb rgb 0xff src index stride else a sum a intensity out segment r sum r intensity out segment g sum g intensity out segment b sum b intensity out segment dest dest index int math min a sum sizfac 255 24 int math min r sum sizfac 255 16 int math min g sum sizfac 255 8 int math min b sum sizfac 255 dest index stride a sum r sum g sum b sum 0 0f in segment out segment out segment in i 1 in i sizfac out segment i insegment outsegment asum rsum gsum bsum srcindex destindex lastindex imagemath insegment outsegment outsegment asum rsum gsum bsum srcindex srcindex srcindex srcindex aintensity insegment insegment rintensity insegment insegment gintensity insegment insegment bintensity insegment insegment insegment outsegment asum aintensity insegment rsum rintensity insegment gsum gintensity insegment bsum bintensity insegment outsegment insegment insegment srcindex lastindex srcindex srcindex asum aintensity outsegment rsum rintensity outsegment gsum gintensity outsegment bsum bintensity outsegment destindex asum rsum gsum bsum destindex asum rsum gsum bsum insegment outsegment outsegment outsegment premultiply a block of pixels public static void premultiply int p int offset int length length offset for int i offset i length i int rgb p i int a rgb 24 0xff int r rgb 16 0xff int g rgb 8 0xff int b rgb 0xff float f a 1 0f 255 0f r f g f b f p i a 24 r 16 g 8 b premultiply a block of pixels public static void unpremultiply int p int offset int length length offset for int i offset i length i int rgb p i int a rgb 24 0xff int r rgb 16 0xff int g rgb 8 0xff int b rgb 0xff if a 0 a 255 float f 255 0f a r f g f b f if r 255 r 255 if g 255 g 255 if b 255 b 255 p i a 24 r 16 g 8 b creates an introduction server public introduction server wot my wot identity fetcher my fetcher super my wot get plugin respirator get node my wot get plugin respirator gethl simple client wot introduction server m wot my wot m puzzle store m wot get introduction puzzle store m random m wot get plugin respirator get node fast weak random start introductionserver introductionserver mywot identityfetcher myfetcher mywot getpluginrespirator getnode mywot getpluginrespirator gethlsimpleclient mwot mywot mpuzzlestore mwot getintroductionpuzzlestore mrandom mwot getpluginrespirator getnode fastweakrandom public static int get identity puzzle count identity i try return math max integer parse int i get property introduction server puzzle count property 0 catch invalid parameter exception e return 0 getidentitypuzzlecount parseint getproperty introductionserver puzzle_count_property invalidparameterexception override protected collection client getter create fetch storage return new array list client getter default puzzle count 5 1 just assume that there are 5 identities clientgetter createfetchstorage arraylist clientgetter default_puzzle_count override protected collection base client putter create insert storage return new array list base client putter default puzzle count 5 1 just assume that there are 5 identities baseclientputter createinsertstorage arraylist baseclientputter default_puzzle_count public int get priority return native thread low priority getpriority nativethread low_priority override protected long get startup delay return startup delay 2 m random next int startup delay getstartupdelay startup_delay mrandom nextint startup_delay override protected long get sleep time return thread period 2 m random next int thread period getsleeptime thread_period mrandom nextint thread_period called by the superclass transfer thread after get startup delay milliseconds and then after each get sleep time milliseconds deletes old puzzles downloads solutions of existing ones and inserts new ones override protected void iterate m puzzle store delete expired puzzles synchronized m wot todo we might want to not lock all the time during captcha creation figure out how long this takes for own identity identity m wot get all own identities if identity has context introduction puzzle introduction context try logger debug this managing puzzles of identity get nickname download solutions identity generate new puzzles identity insert puzzles identity logger debug this managing puzzles finished catch exception e logger error this puzzle management failed for identity get nickname e transferthread getstartupdelay getsleeptime mpuzzlestore deleteexpiredpuzzles mwot ownidentity mwot getallownidentities hascontext introductionpuzzle introduction_context getnickname downloadsolutions generatenewpuzzles insertpuzzles getnickname private void download solutions own identity inserter throws fetch exception todo we restart all requests in every iteration decide whether this makes sense or not if not add code to re use requests for puzzles which still exist i think it makes sense to restart them because there are not many puzzles and therefore not many requests abort fetches synchronized m puzzle store object set own introduction puzzle puzzles m puzzle store get unsolved by inserter inserter logger debug this identity inserter get nickname has puzzles size unsolved puzzles stored trying to fetch solutions for own introduction puzzle p puzzles fetch context fetch context m client get fetch context fixme toad are these parameters correct fetch context max splitfile block retries 1 retry forever fetch context max non splitfile retries 1 retry forever client getter g m client fetch p get solutionuri xml transformer max introduction byte size m wot get request client this fetch context fixme set to a reasonable value before release plugin manager default is interactive priority g set priority class request starter update priority class m wot get plugin respirator get node client core client context null add fetch g logger debug this trying to fetch captcha solution for p get requesturi at p get solutionuri to string downloadsolutions ownidentity fetchexception abortfetches mpuzzlestore objectset ownintroductionpuzzle mpuzzlestore getunsolvedbyinserter getnickname ownintroductionpuzzle fetchcontext fetchcontext mclient getfetchcontext fetchcontext maxsplitfileblockretries fetchcontext maxnonsplitfileretries clientgetter mclient getsolutionuri xmltransformer max_introduction_byte_size mwot getrequestclient fetchcontext pluginmanager setpriorityclass requeststarter update_priority_class mwot getpluginrespirator getnode clientcore clientcontext addfetch getrequesturi getsolutionuri tostring private void generate new puzzles own identity identity throws io exception synchronized m puzzle store int puzzles to generate get identity puzzle count identity m puzzle store get of today by inserter identity size logger debug this trying to generate puzzles to generate new puzzles from identity get nickname while puzzles to generate 0 m puzzle factories m random next int m puzzle factories length generate puzzle m puzzle store identity puzzles to generate logger debug this finished generating puzzles from identity get nickname generatenewpuzzles ownidentity ioexception mpuzzlestore puzzlestogenerate getidentitypuzzlecount mpuzzlestore getoftodaybyinserter puzzlestogenerate getnickname puzzlestogenerate mpuzzlefactories mrandom nextint mpuzzlefactories generatepuzzle mpuzzlestore puzzlestogenerate getnickname private void insert puzzles own identity identity throws io exception insert exception synchronized m puzzle store object set own introduction puzzle puzzles m puzzle store get uninserted own puzzles by inserter identity logger debug this trying to insert puzzles size puzzles from identity get nickname for own introduction puzzle p puzzles try insert puzzle p catch exception e logger error this puzzle insert failed e logger debug this finished inserting puzzles from identity get nickname insertpuzzles ownidentity ioexception insertexception mpuzzlestore objectset ownintroductionpuzzle mpuzzlestore getuninsertedownpuzzlesbyinserter getnickname ownintroductionpuzzle insertpuzzle getnickname not synchronized because it s caller is synchronized already private void insert puzzle own introduction puzzle puzzle throws io exception insert exception transformer exception parser configuration exception assert puzzle was inserted bucket tempb mtbf make bucket xml transformer max introductionpuzzle byte size output stream os null try os tempb get output stream m wot getxml transformer export introduction puzzle puzzle os provides synchronization on the puzzle os close os null tempb set read only fixme toad are these parameters correct insert block ib new insert block tempb null puzzle get inserturi insert context ictx m client get insert context true client putter pu m client insert ib false null false ictx this fixme set to a reasonable value before release plugin manager default is interactive priority pu set priority class request starter update priority class m wot get plugin respirator get node client core client context null add insert pu tempb null logger debug this started insert of puzzle from puzzle get inserter get nickname finally if tempb null tempb free closer close os insertpuzzle ownintroductionpuzzle ioexception insertexception transformerexception parserconfigurationexception wasinserted makebucket xmltransformer max_introductionpuzzle_byte_size outputstream getoutputstream mwot getxmltransformer exportintroductionpuzzle setreadonly insertblock insertblock getinserturi insertcontext mclient getinsertcontext clientputter mclient pluginmanager setpriorityclass requeststarter update_priority_class mwot getpluginrespirator getnode clientcore clientcontext addinsert getinserter getnickname called when a puzzle was successfully inserted public void on success base client putter state object container container logger debug this successful insert of puzzle state geturi try synchronized m wot synchronized m puzzle store own introduction puzzle puzzle m puzzle store get own puzzle by requesturi state geturi be careful this locks the wot puzzle set inserted m puzzle store store and commit puzzle catch exception e logger error this error e finally remove insert state onsuccess baseclientputter objectcontainer mwot mpuzzlestore ownintroductionpuzzle mpuzzlestore getownpuzzlebyrequesturi setinserted mpuzzlestore storeandcommit removeinsert called when the insertion of a puzzle failed public void on failure insert exception e base client putter state object container container if e get mode insert exception cancelled logger debug this insert cancelled state geturi return try logger error this insert of puzzle failed state geturi e finally remove insert state onfailure insertexception baseclientputter objectcontainer getmode insertexception removeinsert called when a puzzle solution is successfully fetched we then add the identity which solved the puzzle public void on success fetch result result client getter state object container container logger debug this fetched puzzle solution state geturi try import introduction locks the wot so we need to do that here first to keep the locking order the same everywhere to prevent deadlocks synchronized m wot synchronized m puzzle store own introduction puzzle p m puzzle store get own puzzle by solutionuri state geturi synchronized p own identity puzzle owner own identity p get inserter identity new identity m wot getxml transformer import introduction puzzle owner result as bucket get input stream logger debug this imported identity introduction for identity new identity get requesturi to the own identity puzzle owner p set solved m puzzle store store and commit p catch exception e logger error this parsing failed for state geturi e finally remove fetch state onsuccess fetchresult clientgetter objectcontainer importintroduction mwot mpuzzlestore ownintroductionpuzzle mpuzzlestore getownpuzzlebysolutionuri ownidentity puzzleowner ownidentity getinserter newidentity mwot getxmltransformer importintroduction puzzleowner asbucket getinputstream newidentity getrequesturi ownidentity puzzleowner setsolved mpuzzlestore storeandcommit removefetch called when the node can t fetch a file or when there is a newer edition in our case called when there is no solution to a puzzle in the network public void on failure fetch exception e client getter state object container container if e get mode fetch exception cancelled logger debug this fetch cancelled state geturi return try if e get mode fetch exception data not found this is the normal case the puzzle was not solved else logger error this downloading puzzle solution state geturi failed e finally remove fetch state onfailure fetchexception clientgetter objectcontainer getmode fetchexception getmode fetchexception data_not_found removefetch not needed functions from the client callback interface only called by inserts public void on fetchable base client putter state object container container clientcallback onfetchable baseclientputter objectcontainer public void on fetchable base client putter state object container container only called by inserts public void on generateduri freeneturi uri base client putter state object container container onfetchable baseclientputter objectcontainer ongenerateduri baseclientputter objectcontainer public void on generateduri freeneturi uri base client putter state object container container called when freenet async thinks that the request should be serialized to disk if it is a persistent request public void on major progress object container container ongenerateduri baseclientputter objectcontainer onmajorprogress objectcontainer public web interface freetalk my freetalk m freetalk my freetalk m page maker m freetalk get plugin respirator get page maker m own identity null webinterface myfreetalk mfreetalk myfreetalk mpagemaker mfreetalk getpluginrespirator getpagemaker mownidentity private void set up menu m page maker remove all navigation links if m own identity null m page maker add navigation link back to freenet back to nodes home false null return m page maker add navigation link freetalk plugin uri home freetalk plugin home false null m page maker add navigation link freetalk plugin uri messages boards view all boards false null m page maker add navigation link freetalk plugin uri identities identities manage your own and known identities false null m page maker add navigation link freetalk plugin uri log out log out log out false null m page maker add navigation link back to freenet back to your freenet node false null setupmenu mpagemaker removeallnavigationlinks mownidentity mpagemaker addnavigationlink mpagemaker addnavigationlink plugin_uri mpagemaker addnavigationlink plugin_uri mpagemaker addnavigationlink plugin_uri mpagemaker addnavigationlink plugin_uri logout mpagemaker addnavigationlink private void set logged in own identity ft own identity user m own identity user setloggedinownidentity ftownidentity mownidentity private ft own identity get logged in own identity return m own identity ftownidentity getloggedinownidentity mownidentity todo this function is ugly clean it up public string handlehttp get http request request throws pluginhttp exception fixme string pass request get param form password if pass null fixme is this correct what if the client just does not specify the password so that its null if pass length 0 pass equals pr get node client core form password return errors make error page this buh invalid form password fixme ugly hack remove string page request get path substring freetalk plugin uri length int end index request get path index of if end index 0 page page substring 0 end index if page equals log out set logged in own identity null set up menu if page equals create identity return new create identity wizard this request tohtml if page equals log in try set logged in own identity m freetalk get identity manager get own identity request get param own identityid set up menu return new welcome this get logged in own identity request tohtml catch no such identity exception e ignore and continue as if the user did not specify an identity he will end up with a log in page if get logged in own identity null return new log in page this null request tohtml anything below this line assumes that we have a logged in own identity if page length 1 equals page return new welcome this get logged in own identity request tohtml if identities equals page return new identity editor this get logged in own identity request tohtml if messages equals page return new boards page this get logged in own identity request tohtml try fixme also use get logged in own identity here if page equals show board return new board page this get logged in own identity request tohtml if page equals show thread return new thread page this get logged in own identity request tohtml todo make this exceptions store the specified non existant element theirselves catch no such board exception e throw new not found pluginhttp exception unknown board request get param name page catch no such message exception e throw new not found pluginhttp exception unknown message request get param id page throw new not found pluginhttp exception resource not found in freetalk plugin page handlehttpget httprequest pluginhttpexception getparam formpassword getnode clientcore formpassword makeerrorpage getpath plugin_uri endindex getpath indexof endindex endindex logout setloggedinownidentity setupmenu createidentity createidentitywizard login setloggedinownidentity mfreetalk getidentitymanager getownidentity getparam ownidentityid setupmenu getloggedinownidentity nosuchidentityexception loginpage getloggedinownidentity loginpage getloggedinownidentity identityeditor getloggedinownidentity boardspage getloggedinownidentity getloggedinownidentity showboard boardpage getloggedinownidentity showthread threadpage getloggedinownidentity nosuchboardexception notfoundpluginhttpexception getparam nosuchmessageexception notfoundpluginhttpexception getparam notfoundpluginhttpexception todo this function is ugly clean it up public string handlehttp post http request request throws pluginhttp exception string pass request get part as string form password 32 if pass null pass length 0 pass equals m freetalk get plugin respirator get node client core form password return new error page this null request error invalid form password tohtml string page request get path substring freetalk plugin uri length if page length 1 throw new not found pluginhttp exception resource not found page try if page equals create identity set up menu return new create identity wizard this request tohtml anything below this line requires the user to be logged in with a certain own identity ft own identity own id m freetalk get identity manager get own identity request get part as string own identityid 64 if page equals log in set logged in own identity own id set up menu return new welcome this own id request tohtml set up menu if page equals new board return new new board page this own id request tohtml if page equals new thread return new new thread page this own id request tohtml if page equals new reply return new new reply page this own id request tohtml catch no such identity exception e throw new not found pluginhttp exception e get message page catch no such board exception e throw new not found pluginhttp exception e get message page catch no such message exception e throw new not found pluginhttp exception e get message page if page equals exportdb string writer sw new string writer try backup export config db db sw catch io exception e logger error this error while exporting database e return errors make error page this server buh buh e get message throw new download pluginhttp exception sw to string get bytes utf 8 fms kidding xml fms clone db backup if page equals importdb http uploaded file file request get uploaded file filename if file null file get filename trim length 0 return errors make error page this no file to import selected try backup import config db db file get data get input stream catch exception e logger error this error while importing db from file get filename e return errors make error page this error while importing db from file get filename e get message throw new redirect pluginhttp exception m freetalk plugin uri if page equals createownidentity list string err new array list string string nick request get part as string nick 1024 trim string request uri request get part as string requesturi 1024 string insert uri request get part as string inserturi 1024 boolean publish true equals request get part as string publish trust list 24 identity editor check nick err nick if request uri length 0 insert uri length 0 freeneturi kp m client generate key pair fms insert uri kp 0 to string request uri kp 1 to string err add uri was empty i generated one for you return identity editor make new own identity page this nick request uri insert uri publish err identity editor check inserturi err insert uri identity editor check requesturi err request uri if err size 0 fixme use identity manager to implement this throw new unsupported operation exception ft own identity oi new ft own identity nick request uri insert uri publish identity editor add new own identity db config oi err if err size 0 throw new redirect pluginhttp exception m freetalk plugin uri ownidentities return identity editor make new own identity page this nick request uri insert uri publish err if page equals addknownidentity list string err new array list string string request uri request get part as string requesturi 1024 if request uri length 0 err add are you jokingly uri was empty return identity editor make new known identity page this request uri err identity editor check requesturi err request uri if err size 0 fixme use identity manager to implement this throw new unsupported operation exception ft identity i new ft identity request uri identity editor add new known identity db config i err if err size 0 throw new redirect pluginhttp exception m freetalk plugin uri knownidentities return identity editor make new known identity page this request uri err if page equals delete own identity list string err new array list string string request uri request get part as string identity 1024 if request uri length 0 err add are you jokingly uri was empty return identity editor make delete own identity page this request uri err if request is part set confirmed identity editor delete identity this request uri err else err add please confirm if err size 0 return identity editor make delete own identity page this request uri err throw new redirect pluginhttp exception m freetalk plugin uri ownidentities return identity editor make delete own identity page fms request uri err if page equals delete identity list string err new array list string string request uri request get part as string identity 1024 if request uri length 0 err add are you jokingly uri was empty return identity editor make delete known identity page this request uri err if request is part set confirmed identity editor delete identity this request uri err else err add please confirm if err size 0 return identity editor make delete known identity page this request uri err throw new redirect pluginhttp exception m freetalk plugin uri knownidentities throw new not found pluginhttp exception resource not found page handlehttppost httprequest pluginhttpexception getpartasstring formpassword mfreetalk getpluginrespirator getnode clientcore formpassword errorpage getpath plugin_uri notfoundpluginhttpexception createidentity setupmenu createidentitywizard ftownidentity ownid mfreetalk getidentitymanager getownidentity getpartasstring ownidentityid login setloggedinownidentity ownid setupmenu ownid setupmenu newboard newboardpage ownid newthread newthreadpage ownid newreply newreplypage ownid nosuchidentityexception notfoundpluginhttpexception getmessage nosuchboardexception notfoundpluginhttpexception getmessage nosuchmessageexception notfoundpluginhttpexception getmessage stringwriter stringwriter exportconfigdb ioexception makeerrorpage buhbuh getmessage downloadpluginhttpexception tostring getbytes httpuploadedfile getuploadedfile getfilename makeerrorpage importconfigdb getdata getinputstream getfilename makeerrorpage getfilename getmessage redirectpluginhttpexception mfreetalk plugin_uri arraylist getpartasstring requesturi getpartasstring inserturi getpartasstring getpartasstring publishtrustlist identityeditor checknick requesturi inserturi mclient generatekeypair inserturi tostring requesturi tostring identityeditor makenewownidentitypage requesturi inserturi identityeditor checkinserturi inserturi identityeditor checkrequesturi requesturi unsupportedoperationexception ftownidentity ftownidentity requesturi inserturi identityeditor addnewownidentity db_config redirectpluginhttpexception mfreetalk plugin_uri identityeditor makenewownidentitypage requesturi inserturi arraylist requesturi getpartasstring requesturi identityeditor makenewknownidentitypage requesturi identityeditor checkrequesturi requesturi unsupportedoperationexception ftidentity ftidentity requesturi identityeditor addnewknownidentity db_config redirectpluginhttpexception mfreetalk plugin_uri identityeditor makenewknownidentitypage requesturi deleteownidentity arraylist requesturi getpartasstring requesturi identityeditor makedeleteownidentitypage requesturi ispartset identityeditor deleteidentity requesturi identityeditor makedeleteownidentitypage requesturi redirectpluginhttpexception mfreetalk plugin_uri identityeditor makedeleteownidentitypage requesturi deleteidentity arraylist requesturi getpartasstring requesturi identityeditor makedeleteknownidentitypage requesturi ispartset identityeditor deleteidentity requesturi identityeditor makedeleteknownidentitypage requesturi redirectpluginhttpexception mfreetalk plugin_uri notfoundpluginhttpexception public final freetalk get freetalk return m freetalk getfreetalk mfreetalk public final page maker get page maker return m page maker pagemaker getpagemaker mpagemaker return the code ft own identity code which is currently logged in public final ft own identity get own identity iterator ft own identity iter m freetalk get identity manager own identity iterator return iter has next iter next null ftownidentity ftownidentity getownidentity ftownidentity mfreetalk getidentitymanager ownidentityiterator hasnext private static final long serial versionuid 1 public not trusted exception string message super message serialversionuid nottrustedexception public class median filter extends whole image filter public median filter medianfilter wholeimagefilter medianfilter private int median int array int max max index for int i 0 i 4 i max 0 max index 0 for int j 0 j 9 j if array j max max array j max index j array max index 0 max 0 for int i 0 i 9 i if array i max max array i return max maxindex maxindex maxindex maxindex private int rgb median int r int g int b int sum index 0 min integer max value for int i 0 i 9 i sum 0 for int j 0 j 9 j sum math abs r i r j sum math abs g i g j sum math abs b i b j if sum min min sum index i return index rgbmedian max_value override protected int filter pixels int width int height int in pixels rectangle transformed space int index 0 int argb new int 9 int r new int 9 int g new int 9 int b new int 9 int out pixels new int width height for int y 0 y height y for int x 0 x width x int k 0 for int dy 1 dy 1 dy int iy y dy if 0 iy iy height int ioffset iy width for int dx 1 dx 1 dx int ix x dx if 0 ix ix width int rgb in pixels ioffset ix argb k rgb r k rgb 16 0xff g k rgb 8 0xff b k rgb 0xff k while k 9 argb k 0xff000000 r k g k b k 0 k out pixels index argb rgb median r g b return out pixels filterpixels inpixels transformedspace outpixels inpixels outpixels rgbmedian outpixels override public string to string return blur median tostring public read only file slice bucket file f long start at long length this file new file f get path copy so we can delete it this start at start at this length length readonlyfileslicebucket startat getpath startat startat public read only file slice bucket simple field set fs throws cannot create from field set exception string tmp fs get filename if tmp null throw new cannot create from field set exception no filename this file new file tmp tmp fs get length if tmp null throw new cannot create from field set exception no length try length long parse long tmp catch number format exception e throw new cannot create from field set exception corrupt length tmp e tmp fs get offset if tmp null throw new cannot create from field set exception no offset try start at long parse long tmp catch number format exception e throw new cannot create from field set exception corrupt offset tmp e readonlyfileslicebucket simplefieldset cannotcreatefromfieldsetexception cannotcreatefromfieldsetexception cannotcreatefromfieldsetexception parselong numberformatexception cannotcreatefromfieldsetexception cannotcreatefromfieldsetexception startat parselong numberformatexception cannotcreatefromfieldsetexception public output stream get output stream throws io exception throw new io exception bucket is read only outputstream getoutputstream ioexception ioexception public input stream get input stream throws io exception return new my input stream inputstream getinputstream ioexception myinputstream public string get name return rofs file get absolute path start at length getname getabsolutepath startat public long size return length public boolean is read only return true isreadonly public void set read only do nothing setreadonly my input stream throws io exception try this f new random access file file r f seek start at if f length start at length throw new read only file slice bucket exception file truncated length f length but start at start at for length bytes ptr 0 catch file not found exception e throw new read only file slice bucket exception e myinputstream ioexception randomaccessfile startat startat readonlyfileslicebucketexception startat filenotfoundexception readonlyfileslicebucketexception override public int read throws io exception if ptr length return 1 int x f read if x 1 ptr return x ioexception override public int read byte buf int offset int len throws io exception if ptr length return 1 len int math min len length ptr int x f read buf offset len ptr x return x ioexception override public int read byte buf throws io exception return read buf 0 buf length ioexception override public void close throws io exception f close ioexception private static final long serial versionuid 1 public read only file slice bucket exception file not found exception e super file not found e get message init cause e serialversionuid readonlyfileslicebucketexception filenotfoundexception getmessage initcause public read only file slice bucket exception string string super string readonlyfileslicebucketexception public void free public simple field set to field set simple field set fs new simple field set false fs put single type read only file slice bucket fs put single filename file to string fs put offset start at fs put length length return fs simplefieldset tofieldset simplefieldset simplefieldset putsingle readonlyfileslicebucket putsingle tostring startat public void store to object container container container store this storeto objectcontainer public void remove from object container container container delete file container delete this removefrom objectcontainer public void object on activate object container container cascading activation of dependancies container activate file 5 objectonactivate objectcontainer public bucket create shadow throws io exception string fnam new string file get path file new file new file fnam return new read only file slice bucket new file start at length createshadow ioexception getpath newfile readonlyfileslicebucket newfile startat public void make noise buffered image image float factor one float factor two float factor three float factor four do nothing makenoise bufferedimage factorone factortwo factorthree factorfour private float high output level 1 public levels filter highoutputlevel levelsfilter public void set low level float low level this low level low level setlowlevel lowlevel lowlevel lowlevel public float get low level return low level getlowlevel lowlevel public void set high level float high level this high level high level sethighlevel highlevel highlevel highlevel public float get high level return high level gethighlevel highlevel public void set low output level float low output level this low output level low output level setlowoutputlevel lowoutputlevel lowoutputlevel lowoutputlevel public float get low output level return low output level getlowoutputlevel lowoutputlevel public void set high output level float high output level this high output level high output level sethighoutputlevel highoutputlevel highoutputlevel highoutputlevel public float get high output level return high output level gethighoutputlevel highoutputlevel override protected int filter pixels int width int height int in pixels rectangle transformed space histogram histogram new histogram in pixels width height 0 width int i j if histogram get num samples 0 float scale 255 0f histogram get num samples lut new int 3 256 float low low level 255 float high high level 255 if low high high for i 0 i 3 i for j 0 j 256 j lut i j pixel utils clamp int 255 low output level high output level low output level j low high low else lut null i 0 for int y 0 y height y for int x 0 x width x in pixels i filterrgb x y in pixels i i lut null return in pixels filterpixels inpixels transformedspace inpixels getnumsamples getnumsamples lowlevel highlevel pixelutils lowoutputlevel highoutputlevel lowoutputlevel inpixels inpixels inpixels public int filterrgb int x int y int rgb if lut null int a rgb 0xff000000 int r lut histogram red rgb 16 0xff int g lut histogram green rgb 8 0xff int b lut histogram blue rgb 0xff return a r 16 g 8 b return rgb override public string to string return colors levels tostring get list head element return list head element or null if list is empty public synchronized l2 list elem head return next this next null l2listelem get list tail element return list tail element or null if list is empty public synchronized l2 list elem tail return prev this prev null l2listelem make list empty public synchronized void clear modify next prev this n elems 0 update counter 1 nelems updatecounter insert element at the beginning of the list public synchronized void prepend l2 list elem elem modify next modify elem modify elem next next elem prev this next prev elem next elem n elems 1 update counter 1 l2listelem nelems updatecounter insert element at the end of the list public synchronized void append l2 list elem elem modify prev modify elem modify elem next this elem prev prev prev next elem prev elem n elems 1 update counter 1 l2listelem nelems updatecounter remove element from the list public synchronized void remove l2 list elem elem modify elem prev modify elem next modify elem next prev elem prev elem prev next elem next n elems 1 update counter 1 l2listelem nelems updatecounter check if list is empty return code true code if list is empty public synchronized boolean is empty return next this isempty add object to the list param obj object added to the list return always returns code true code public synchronized boolean add object obj append l2 list elem obj return true l2listelem remove object from the list param o object to be removed from the list return always returns code true code public synchronized boolean remove object o remove l2 list elem o return true l2listelem get size of the list return number of elements in the list public int size return n elems nelems check if object is in collection param o object to be searched in the collection return code true code if there is an object in the collection which is equals to the specified object public synchronized boolean contains object o for l2 list elem e next e this e e next if e equals o return true return false l2listelem private int counter l2 list iterator curr l2 list this counter update counter l2listiterator l2list updatecounter public object next if has next throw new no such element exception curr curr next return curr hasnext nosuchelementexception public int next oid return i persistent next get oid nextoid ipersistent getoid public boolean has next if counter update counter throw new illegal state exception return curr next l2 list this hasnext updatecounter illegalstateexception l2list public void remove if counter update counter curr l2 list this throw new illegal state exception l2 list this remove curr counter update counter curr curr prev updatecounter l2list illegalstateexception l2list updatecounter get list iterator this iterator supports remove method put concurrent modifications of thje list during iteration are not possible return list iterator public synchronized iterator iterator return new l2 list iterator l2listiterator get array of the list elements return array with list elements public synchronized object to array l2 list elem arr new l2 list elem n elems l2 list elem e this for int i 0 i arr length i arr i e e next return arr toarray l2listelem l2listelem nelems l2listelem returns an array containing all of the elements in this list in the correct order the runtime type of the returned array is that of the specified array if the list fits in the specified array it is returned therein otherwise a new array is allocated with the runtime type of the specified array and the size of this list p if the list fits in the specified array with room to spare i e the array has more elements than the list the element in the array immediately following the end of the collection is set to tt null tt this is useful in determining the length of the list i only i if the caller knows that the list does not contain any tt null tt elements param a the array into which the elements of the list are to be stored if it is big enough otherwise a new array of the same runtime type is allocated for this purpose return an array containing the elements of the list throws array store exception if the runtime type of a is not a supertype of the runtime type of every element in this list public synchronized object to array object a int size n elems if a length size a object java lang reflect array new instance a get class get component type size l2 list elem e this for int i 0 i size i a i e e next if a length size a size null return a arraystoreexception toarray nelems newinstance getclass getcomponenttype l2listelem returns tt true tt if this collection contains all of the elements in the specified collection p this implementation iterates over the specified collection checking each element returned by the iterator in turn to see if it s contained in this collection if all elements are so contained tt true tt is returned otherwise tt false tt param c collection to be checked for containment in this collection return tt true tt if this collection contains all of the elements in the specified collection throws null pointer exception if the specified collection is null see contains object public synchronized boolean contains all collection c iterator e c iterator while e has next if contains e next return false return true nullpointerexception containsall hasnext adds all of the elements in the specified collection to this collection optional operation the behavior of this operation is undefined if the specified collection is modified while the operation is in progress this implies that the behavior of this call is undefined if the specified collection is this collection and this collection is nonempty p this implementation iterates over the specified collection and adds each object returned by the iterator to this collection in turn p note that this implementation will throw an tt unsupported operation exception tt unless tt add tt is overridden assuming the specified collection is non empty param c collection whose elements are to be added to this collection return tt true tt if this collection changed as a result of the call throws unsupported operation exception if this collection does not support the tt add all tt method throws null pointer exception if the specified collection is null see add object public synchronized boolean add all collection c iterator e c iterator while e has next add e next return true unsupportedoperationexception unsupportedoperationexception addall nullpointerexception addall hasnext removes from this collection all of its elements that are contained in the specified collection optional operation p this implementation iterates over this collection checking each element returned by the iterator in turn to see if it s contained in the specified collection if it s so contained it s removed from this collection with the iterator s tt remove tt method p note that this implementation will throw an tt unsupported operation exception tt if the iterator returned by the tt iterator tt method does not implement the tt remove tt method and this collection contains one or more elements in common with the specified collection param c elements to be removed from this collection return tt true tt if this collection changed as a result of the call throws unsupported operation exception if the tt remove all tt method is not supported by this collection throws null pointer exception if the specified collection is null see remove object see contains object public synchronized boolean remove all collection c boolean modified false iterator e iterator while e has next if c contains e next e remove modified true return modified unsupportedoperationexception unsupportedoperationexception removeall nullpointerexception removeall hasnext retains only the elements in this collection that are contained in the specified collection optional operation in other words removes from this collection all of its elements that are not contained in the specified collection p this implementation iterates over this collection checking each element returned by the iterator in turn to see if it s contained in the specified collection if it s not so contained it s removed from this collection with the iterator s tt remove tt method p note that this implementation will throw an tt unsupported operation exception tt if the iterator returned by the tt iterator tt method does not implement the tt remove tt method and this collection contains one or more elements not present in the specified collection param c elements to be retained in this collection return tt true tt if this collection changed as a result of the call throws unsupported operation exception if the tt retain all tt method is not supported by this collection throws null pointer exception if the specified collection is null see remove object see contains object public synchronized boolean retain all collection c boolean modified false iterator e iterator while e has next if c contains e next e remove modified true return modified unsupportedoperationexception unsupportedoperationexception retainall nullpointerexception retainall hasnext select members of the collection using search predicate this iterator doesn t support remove method it is not possible to update list during iteration param cls class of index members param predicate jsql condition return iterator through members of the collection matching search condition public iterable iterator select class cls string predicate query query new query impl get storage return query select cls iterator predicate iterableiterator queryimpl getstorage public ssdp notify request set method http notify seturi ssdpnotifyrequest setmethod param random param wipe files param dir if code null code then use the default temporary directory param prefix throws io exception public filename generator random random boolean wipe files file dir string prefix throws io exception this random random this prefix prefix if dir null tmp dir file util get canonical file new file system get property java io tmpdir else tmp dir file util get canonical file dir if tmp dir exists tmp dir mkdir if tmp dir is directory tmp dir can read tmp dir can write throw new io exception not a directory or cannot read write tmp dir if wipe files long wiped files 0 long wipeable files 0 long start wipe system current time millis file filenames tmp dir list files if filenames null for int i 0 i filenames length i wrapper manager signal starting 5 60 1000 if i 1024 0 i 0 user may want some feedback during startup system err println deleted wiped files temp files i wipeable files non temp files in temp dir file f filenames i string name f get name if file separator char name to lower case starts with prefix to lower case name starts with prefix wipeable files if f delete f exists system err println unable to delete temporary file f permissions problem else wiped files long end wipe system current time millis system err println deleted wiped files of wipeable files temporary files filenames length wipeable files non temp files in temp directory in time util format time end wipe start wipe wipefiles ioexception filenamegenerator wipefiles ioexception tmpdir fileutil getcanonicalfile getproperty tmpdir fileutil getcanonicalfile tmpdir tmpdir tmpdir isdirectory tmpdir canread tmpdir canwrite ioexception tmpdir wipefiles wipedfiles wipeablefiles startwipe currenttimemillis tmpdir listfiles wrappermanager signalstarting wipedfiles wipeablefiles getname separatorchar tolowercase startswith tolowercase startswith wipeablefiles wipedfiles endwipe currenttimemillis wipedfiles wipeablefiles wipeablefiles timeutil formattime endwipe startwipe public long make random filename long random filename should be plenty while true random filename random next long if random filename 1 continue disallowed as used for error reporting string filename prefix long to hex string random filename file ret new file tmp dir filename if ret exists if logger should log logger minor this logger minor this made random filename ret new exception debug return random filename makerandomfilename randomfilename randomfilename nextlong randomfilename tohexstring randomfilename tmpdir shouldlog randomfilename public file get filename long id return new file tmp dir prefix long to hex string id getfilename tmpdir tohexstring public file make random file throws io exception while true file file get filename make random filename if file create new file return file makerandomfile ioexception getfilename makerandomfilename createnewfile public boolean matches file file return getid file 1 public long getid file file if file util get canonical file file get parent file equals tmp dir logger error this not the same dir parent file util get canonical file file get parent file but tmp dir tmp dir return 1 string name file get name if name starts with prefix logger error this does not start with prefix name prefix prefix return 1 try return fields hex to long name substring prefix length catch number format exception e logger error this cannot getid e from name substring prefix length e return 1 fileutil getcanonicalfile getparentfile tmpdir fileutil getcanonicalfile getparentfile tmpdir tmpdir getname startswith hextolong numberformatexception public file get dir return tmp dir getdir tmpdir set up the dir and prefix note that while we can change the dir and prefix we cannot do so online at least not on windows param dir param prefix public void init file dir string prefix random random throws io exception this random random there is a problem with putting file s into db4o iirc i think we workaround this somewhere else symptoms are it trying to move even though the two dirs are blatantly identical file old dir file util get canonical file new file tmp dir get path file new dir file util get canonical file dir system err println old old dir prefix this prefix from tmp dir old path tmp dir get path old parent tmp dir get parent system err println new new dir prefix prefix from dir if old dir equals new dir this prefix equals prefix logger normal this initialised filename generator successfully no change in dir and prefix dir dir prefix prefix else if old dir equals new dir this prefix equals prefix if dir exists old dir rename to dir tmp dir dir this will interest the user since they changed it string msg successfully renamed persistent temporary directory from tmp dir to dir logger error this msg system err println msg else if dir exists if dir mkdir fixme localise these errors somehow system err println unable to create new temporary directory dir throw new io exception unable to create new temporary directory dir if dir can read dir can write fixme localise these errors somehow system err println unable to read and write new temporary directory dir throw new io exception unable to read and write new temporary directory dir int moved 0 int failed 0 move each file file list tmp dir list files for int i 0 i list length i file f list i string name f get name if name starts with prefix continue if file util move to f new file dir name true moved else failed if failed 0 fixme maybe a useralert system err println warning not all files successfully moved changing temp dir failed failed system err println warning some persistent downloads etc may fail else if dir exists if dir mkdir fixme localise these errors somehow system err println unable to create new temporary directory dir throw new io exception unable to create new temporary directory dir if dir can read dir can write fixme localise these errors somehow system err println unable to read and write new temporary directory dir throw new io exception unable to read and write new temporary directory dir int moved 0 int failed 0 move each file file list tmp dir list files for int i 0 i list length i file f list i string name f get name if name starts with this prefix continue string new name prefix name substring this prefix length if file util move to f new file dir new name true moved if failed 0 fixme maybe a useralert system err println warning not all files successfully moved changing temp dir failed failed system err println warning some persistent downloads etc may fail ioexception olddir fileutil getcanonicalfile tmpdir getpath newdir fileutil getcanonicalfile olddir tmpdir tmpdir getpath tmpdir getparent newdir olddir newdir filenamegenerator olddir newdir olddir renameto tmpdir tmpdir ioexception canread canwrite ioexception tmpdir listfiles getname startswith fileutil moveto ioexception canread canwrite ioexception tmpdir listfiles getname startswith newname fileutil moveto newname param bucket size param bf param db job runner if not null use this to store buckets to disk progressively to avoid a big transaction at the end caller then must call store to at some point public bucket chain bucket long bucket size bucket factory bf this bucket size bucket size this buckets new vector bucket this bf bf size 0 freed false read only false bucketsize dbjobrunner storeto bucketchainbucket bucketsize bucketfactory bucketsize bucketsize readonly private bucket chain bucket vector bucket new buckets long bucket size2 long size2 boolean read only bucket factory bf2 this buckets new buckets this bucket size bucket size2 this size size2 this read only read only this bf bf2 bucketchainbucket newbuckets bucketsize2 readonly bucketfactory newbuckets bucketsize bucketsize2 readonly readonly public void free bucket list synchronized this list get buckets freed true buckets clear for int i 0 i list length i list i free getbuckets equivalent to free but don t free the underlying buckets void clear synchronized this size 0 buckets clear public synchronized bucket get buckets return buckets to array new bucket buckets size getbuckets toarray public input stream get input stream throws io exception synchronized this if freed throw new io exception freed if buckets size 0 return new null input stream return new input stream private int bucket no 0 private input stream cur bucket stream get bucket input stream 0 private long read bytes override public int read throws io exception synchronized bucket chain bucket this if freed cur bucket stream close cur bucket stream null throw new io exception freed while true if cur bucket stream null cur bucket stream get bucket input stream 0 if cur bucket stream null return 1 try int x cur bucket stream read if x 0 read bytes return x catch eof exception e handle the same synchronized bucket chain bucket this no more data to read at the moment if read bytes size return 1 bucket no cur bucket stream close cur bucket stream get bucket input stream bucket no override public int read byte buf throws io exception synchronized bucket chain bucket this if freed cur bucket stream close cur bucket stream null throw new io exception freed return read buf 0 buf length override public int read byte buf int offset int length throws io exception synchronized bucket chain bucket this if freed cur bucket stream close cur bucket stream null throw new io exception freed if length 0 return 0 while true if cur bucket stream null cur bucket stream get bucket input stream 0 if cur bucket stream null return 1 try int x cur bucket stream read buf offset length if x 0 read bytes x return x catch eof exception e handle the same synchronized bucket chain bucket this no more data to read at the moment if read bytes size return 1 bucket no cur bucket stream close cur bucket stream get bucket input stream bucket no override public int available throws io exception synchronized bucket chain bucket this if freed cur bucket stream close cur bucket stream null throw new io exception freed return int math min integer max value size read bytes override public void close throws io exception if cur bucket stream null cur bucket stream close inputstream getinputstream ioexception ioexception nullinputstream inputstream bucketno inputstream curbucketstream getbucketinputstream readbytes ioexception bucketchainbucket curbucketstream curbucketstream ioexception curbucketstream curbucketstream getbucketinputstream curbucketstream curbucketstream readbytes eofexception bucketchainbucket readbytes bucketno curbucketstream curbucketstream getbucketinputstream bucketno ioexception bucketchainbucket curbucketstream curbucketstream ioexception ioexception bucketchainbucket curbucketstream curbucketstream ioexception curbucketstream curbucketstream getbucketinputstream curbucketstream curbucketstream readbytes eofexception bucketchainbucket readbytes bucketno curbucketstream curbucketstream getbucketinputstream bucketno ioexception bucketchainbucket curbucketstream curbucketstream ioexception max_value readbytes ioexception curbucketstream curbucketstream override public int read throws io exception synchronized bucket chain bucket this if freed cur bucket stream close cur bucket stream null throw new io exception freed while true if cur bucket stream null cur bucket stream get bucket input stream 0 if cur bucket stream null return 1 try int x cur bucket stream read if x 0 read bytes return x catch eof exception e handle the same synchronized bucket chain bucket this no more data to read at the moment if read bytes size return 1 bucket no cur bucket stream close cur bucket stream get bucket input stream bucket no ioexception bucketchainbucket curbucketstream curbucketstream ioexception curbucketstream curbucketstream getbucketinputstream curbucketstream curbucketstream readbytes eofexception bucketchainbucket readbytes bucketno curbucketstream curbucketstream getbucketinputstream bucketno override public int read byte buf throws io exception synchronized bucket chain bucket this if freed cur bucket stream close cur bucket stream null throw new io exception freed return read buf 0 buf length ioexception bucketchainbucket curbucketstream curbucketstream ioexception override public int read byte buf int offset int length throws io exception synchronized bucket chain bucket this if freed cur bucket stream close cur bucket stream null throw new io exception freed if length 0 return 0 while true if cur bucket stream null cur bucket stream get bucket input stream 0 if cur bucket stream null return 1 try int x cur bucket stream read buf offset length if x 0 read bytes x return x catch eof exception e handle the same synchronized bucket chain bucket this no more data to read at the moment if read bytes size return 1 bucket no cur bucket stream close cur bucket stream get bucket input stream bucket no ioexception bucketchainbucket curbucketstream curbucketstream ioexception curbucketstream curbucketstream getbucketinputstream curbucketstream curbucketstream readbytes eofexception bucketchainbucket readbytes bucketno curbucketstream curbucketstream getbucketinputstream bucketno override public int available throws io exception synchronized bucket chain bucket this if freed cur bucket stream close cur bucket stream null throw new io exception freed return int math min integer max value size read bytes ioexception bucketchainbucket curbucketstream curbucketstream ioexception max_value readbytes override public void close throws io exception if cur bucket stream null cur bucket stream close ioexception curbucketstream curbucketstream protected synchronized input stream get bucket input stream int i throws io exception bucket bucket buckets get i if bucket null return null return bucket get input stream inputstream getbucketinputstream ioexception getinputstream public string get name return bucket chain bucket getname bucketchainbucket public output stream get output stream throws io exception bucket list synchronized this if read only throw new io exception read only if freed throw new io exception freed size 0 list get buckets buckets clear for int i 0 i list length i list i free return new output stream private int bucket no 0 private output stream cur bucket stream make bucket output stream 0 private long bucket length 0 override public void write int c throws io exception synchronized bucket chain bucket this if freed cur bucket stream close cur bucket stream null throw new io exception freed if read only cur bucket stream close cur bucket stream null throw new io exception read only if bucket length bucket size cur bucket stream close cur bucket stream make bucket output stream bucket no bucket length 0 cur bucket stream write c bucket length synchronized bucket chain bucket this size override public void write byte buf throws io exception write buf 0 buf length override public void write byte buf int offset int length throws io exception synchronized bucket chain bucket this if freed cur bucket stream close cur bucket stream null throw new io exception freed if read only cur bucket stream close cur bucket stream null throw new io exception read only if length 0 return if bucket length bucket size cur bucket stream close cur bucket stream make bucket output stream bucket no bucket length 0 if bucket length length bucket size int split int bucket size bucket length write buf offset split write buf offset split length split return cur bucket stream write buf offset length bucket length length synchronized bucket chain bucket this size length override public void close throws io exception if cur bucket stream null cur bucket stream close outputstream getoutputstream ioexception readonly ioexception ioexception getbuckets outputstream bucketno outputstream curbucketstream makebucketoutputstream bucketlength ioexception bucketchainbucket curbucketstream curbucketstream ioexception readonly curbucketstream curbucketstream ioexception bucketlength bucketsize curbucketstream curbucketstream makebucketoutputstream bucketno bucketlength curbucketstream bucketlength bucketchainbucket ioexception ioexception bucketchainbucket curbucketstream curbucketstream ioexception readonly curbucketstream curbucketstream ioexception bucketlength bucketsize curbucketstream curbucketstream makebucketoutputstream bucketno bucketlength bucketlength bucketsize bucketsize bucketlength curbucketstream bucketlength bucketchainbucket ioexception curbucketstream curbucketstream override public void write int c throws io exception synchronized bucket chain bucket this if freed cur bucket stream close cur bucket stream null throw new io exception freed if read only cur bucket stream close cur bucket stream null throw new io exception read only if bucket length bucket size cur bucket stream close cur bucket stream make bucket output stream bucket no bucket length 0 cur bucket stream write c bucket length synchronized bucket chain bucket this size ioexception bucketchainbucket curbucketstream curbucketstream ioexception readonly curbucketstream curbucketstream ioexception bucketlength bucketsize curbucketstream curbucketstream makebucketoutputstream bucketno bucketlength curbucketstream bucketlength bucketchainbucket override public void write byte buf throws io exception write buf 0 buf length ioexception override public void write byte buf int offset int length throws io exception synchronized bucket chain bucket this if freed cur bucket stream close cur bucket stream null throw new io exception freed if read only cur bucket stream close cur bucket stream null throw new io exception read only if length 0 return if bucket length bucket size cur bucket stream close cur bucket stream make bucket output stream bucket no bucket length 0 if bucket length length bucket size int split int bucket size bucket length write buf offset split write buf offset split length split return cur bucket stream write buf offset length bucket length length synchronized bucket chain bucket this size length ioexception bucketchainbucket curbucketstream curbucketstream ioexception readonly curbucketstream curbucketstream ioexception bucketlength bucketsize curbucketstream curbucketstream makebucketoutputstream bucketno bucketlength bucketlength bucketsize bucketsize bucketlength curbucketstream bucketlength bucketchainbucket override public void close throws io exception if cur bucket stream null cur bucket stream close ioexception curbucketstream curbucketstream protected output stream make bucket output stream int i throws io exception bucket bucket synchronized this bucket bf make bucket bucket size buckets add bucket if buckets size i 1 throw new illegal state exception added bucket size should be i 1 but is buckets size if buckets get i bucket throw new illegal state exception bucket got replaced race condition return bucket get output stream outputstream makebucketoutputstream ioexception makebucket bucketsize illegalstateexception illegalstateexception getoutputstream public boolean is read only return read only isreadonly readonly public void set read only read only true setreadonly readonly public long size return size public void store to object container container throw new unsupported operation exception storeto objectcontainer unsupportedoperationexception public void remove from object container container throw new unsupported operation exception removefrom objectcontainer unsupportedoperationexception public bucket create shadow throws io exception vector bucket new buckets new vector bucket for int i 0 i buckets size i bucket data buckets get i bucket shadow data create shadow if shadow null for bucket bucket new buckets bucket free return null new buckets add shadow return new bucket chain bucket new buckets bucket size size true bf createshadow ioexception newbuckets createshadow newbuckets newbuckets bucketchainbucket newbuckets bucketsize public class bytes public static short unpack2 byte arr int offs return short arr offs 8 arr offs 1 0xff return short arr offs 8 arr offs 1 0xff public static int unpack4 byte arr int offs return arr offs 24 arr offs 1 0xff 16 arr offs 2 0xff 8 arr offs 3 0xff arr offs 2 0xff 8 arr offs 3 0xff public static long unpack8 byte arr int offs return long unpack4 arr offs 32 unpack4 arr offs 4 0xffffffffl unpack4 arr offs 4 0xffffffffl public static float unpackf4 byte arr int offs return float int bits to float bytes unpack4 arr offs intbitstofloat return float int bits to float bytes unpack4 arr offs public static double unpackf8 byte arr int offs return double long bits to double bytes unpack8 arr offs intbitstofloat longbitstodouble public static string unpack str byte arr int offs string encoding int len unpack4 arr offs offs 4 if len 0 char chars new char len for int i 0 i len i chars i char unpack2 arr offs offs 2 return new string chars else if len 1 if encoding null try return new string arr offs len 2 encoding catch unsupported encoding exception x throw new storage error storage error unsupported encoding else return new string arr offs len 2 return null unpackstr unsupportedencodingexception storageerror storageerror unsupported_encoding public static void pack2 byte arr int offs short val arr offs byte val 8 arr offs 1 byte val public static void pack4 byte arr int offs int val arr offs byte val 24 arr offs 1 byte val 16 arr offs 2 byte val 8 arr offs 3 byte val arr offs 3 byte val public static void pack8 byte arr int offs long val pack4 arr offs int val 32 pack4 arr offs 4 int val pack4 arr offs 4 int val public static void packf4 byte arr int offs float val pack4 arr offs float float to int bits val floattointbits pack4 arr offs float float to int bits val public static void packf8 byte arr int offs double val pack8 arr offs double double to long bits val floattointbits doubletolongbits public static int pack str byte arr int offs string str string encoding if str null bytes pack4 arr offs 1 offs 4 else if encoding null int n str length bytes pack4 arr offs n offs 4 for int i 0 i n i bytes pack2 arr offs short str char at i offs 2 else try byte bytes str get bytes encoding pack4 arr offs 2 bytes length system arraycopy bytes 0 arr offs 4 bytes length offs 4 bytes length catch unsupported encoding exception x throw new storage error storage error unsupported encoding return offs packstr charat getbytes unsupportedencodingexception storageerror storageerror unsupported_encoding public static int sizeof string str string encoding try return str null 4 encoding null 4 str length 2 4 new string str get bytes encoding length catch unsupported encoding exception x throw new storage error storage error unsupported encoding getbytes unsupportedencodingexception storageerror storageerror unsupported_encoding public static int sizeof byte arr int offs int len unpack4 arr offs if len 0 return 4 len 2 else if len 1 return 4 2 len else return 4 public http server thread http server http server socket sock this http server http server this sock sock this set daemon true httpserverthread httpserver httpserver httpserver httpserver setdaemon public void run http socket http sock new http socket sock if http sock open false return http request http req new http request http req set socket http sock while http req read true http server perform request listener http req if http req is keep alive false break http sock close httpsocket httpsock httpsocket httpsock httprequest httpreq httprequest httpreq setsocket httpsock httpreq httpserver performrequestlistener httpreq httpreq iskeepalive httpsock construct a perspective filter public perspective filter this 0 0 100 0 100 100 0 100 perspectivefilter perspectivefilter construct a perspective filter param x0 the new position of the top left corner param y0 the new position of the top left corner param x1 the new position of the top right corner param y1 the new position of the top right corner param x2 the new position of the bottom right corner param y2 the new position of the bottom right corner param x3 the new position of the bottom left corner param y3 the new position of the bottom left corner public perspective filter float x0 float y0 float x1 float y1 float x2 float y2 float x3 float y3 set corners x0 y0 x1 y1 x2 y2 x3 y3 perspectivefilter perspectivefilter setcorners set the new positions of the image corners param x0 the new position of the top left corner param y0 the new position of the top left corner param x1 the new position of the top right corner param y1 the new position of the top right corner param x2 the new position of the bottom right corner param y2 the new position of the bottom right corner param x3 the new position of the bottom left corner param y3 the new position of the bottom left corner public void set corners float x0 float y0 float x1 float y1 float x2 float y2 float x3 float y3 this x0 x0 this y0 y0 this x1 x1 this y1 y1 this x2 x2 this y2 y2 this x3 x3 this y3 y3 dx1 x1 x2 dy1 y1 y2 dx2 x3 x2 dy2 y3 y2 dx3 x0 x1 x2 x3 dy3 y0 y1 y2 y3 float a11 a12 a13 a21 a22 a23 a31 a32 if dx3 0 dy3 0 a11 x1 x0 a21 x2 x1 a31 x0 a12 y1 y0 a22 y2 y1 a32 y0 a13 a23 0 else a13 dx3 dy2 dx2 dy3 dx1 dy2 dy1 dx2 a23 dx1 dy3 dy1 dx3 dx1 dy2 dy1 dx2 a11 x1 x0 a13 x1 a21 x3 x0 a23 x3 a31 x0 a12 y1 y0 a13 y1 a22 y3 y0 a23 y3 a32 y0 a a22 a32 a23 b a31 a23 a21 c a21 a32 a31 a22 d a32 a13 a12 e a11 a31 a13 f a31 a12 a11 a32 g a12 a23 a22 a13 h a21 a13 a11 a23 i a11 a22 a21 a12 setcorners override protected void transform space rectangle rect rect x int math min math min x0 x1 math min x2 x3 rect y int math min math min y0 y1 math min y2 y3 rect width int math max math max x0 x1 math max x2 x3 rect x rect height int math max math max y0 y1 math max y2 y3 rect y transformspace get the origin of the output image use this for working out where to draw your new image return the x origin public float get originx return x0 int math min math min x0 x1 math min x2 x3 getoriginx get the origin of the output image use this for working out where to draw your new image return the y origin public float get originy return y0 int math min math min y0 y1 math min y2 y3 getoriginy override protected void transform inverse int x int y float out out 0 original space width a x b y c g x h y i out 1 original space height d x e y f g x h y i transforminverse originalspace originalspace override public string to string return distort perspective tostring private final own identity m identity public delete own identity page web interface my web interface http request my request throws unknown identity exception super my web interface my request m identity wot get own identity byid request get part as string id 128 ownidentity midentity deleteownidentitypage webinterface mywebinterface httprequest myrequest unknownidentityexception mywebinterface myrequest midentity getownidentitybyid getpartasstring public void make if request is part set confirm wot delete identity m identity fixme show the own identities page instead use the trick which freetalk does for inlining pages html node box add content box success box add child the identity was deleted else make confirmation ispartset deleteidentity midentity ownidentities htmlnode addcontentbox addchild makeconfirmation private void make confirmation html node box add content box confirm identity deletion box add child new html node p you are about to delete identity m identity get nickname are you sure box add child new html node p you might want to backup its keys for later use html node confirm form pr add form child box uri delete identity confirm form add child input new string type name value new string hidden page delete identity confirm form add child input new string type name value new string hidden id m identity getid confirm form add child input new string type name value new string submit confirm i am sure delete it makeconfirmation htmlnode addcontentbox addchild htmlnode midentity getnickname addchild htmlnode htmlnode confirmform addformchild deleteidentity confirmform addchild deleteidentity confirmform addchild midentity confirmform addchild public message manager ext object container mydb executor my executor identity manager my identity manager assert mydb null assert my identity manager null db mydb m executor my executor m identity manager my identity manager messagemanager extobjectcontainer myexecutor identitymanager myidentitymanager myidentitymanager mexecutor myexecutor midentitymanager myidentitymanager for being used in j unit tests to run without a node public message manager ext object container mydb identity manager my identity manager db mydb m executor null m identity manager my identity manager junit messagemanager extobjectcontainer identitymanager myidentitymanager mexecutor midentitymanager myidentitymanager this is the primary function for posting messages param my parent message the message to which the new message is a reply null if the message should be a thread param my boards the boards to which the new message should be posted has to contain at least one board param my reply to board the board to which replies to this message should be sent this is just a recommendation notice that it should be contained in my boards can be null param my author the author of the new message cannot be null param my title the subject of the new message cannot be null or empty param my date the utc time of the message null to use the current time param my text the body of the new message cannot be null param my attachments the attachments of the new message see code message attachment code set to null if the message has none return the new message throws invalid parameter exception invalid board names invalid title invalid body throws exception public abstract own message post message message my parent message set board my boards board my reply to board ft own identity my author myparentmessage myboards myreplytoboard myboards myauthor mytitle mydate mytext myattachments invalidparameterexception ownmessage postmessage myparentmessage myboards myreplytoboard ftownidentity myauthor public synchronized own message post message message my parent message set string my boards string my reply to board ft own identity my author string my title date my date string my text list attachment my attachments throws exception fixme instead of always creating the boards notify the user that they do not exist and ask if he made a typo hash set board board set new hash set board for iterator string i my boards iterator i has next string board name i next board board get or create board board name board set add board board reply to board null if my reply to board null reply to board get or create board my reply to board return post message my parent message board set reply to board my author my title my date my text my attachments ownmessage postmessage myparentmessage myboards myreplytoboard ftownidentity myauthor mytitle mydate mytext myattachments hashset boardset hashset myboards hasnext boardname getorcreateboard boardname boardset replytoboard myreplytoboard replytoboard getorcreateboard myreplytoboard postmessage myparentmessage boardset replytoboard myauthor mytitle mydate mytext myattachments suppress warnings unchecked public synchronized int count unsent messages fixme this is not fully synchronized message inserter calls own message was inserted to mark a message as inserted and that function synchronizes on the own message object query q db query q constrain own message class q descend m realuri constrain null identity int unsent count q execute size q db query q constrain own message list class q descend i was inserted constrain false object set own message list not inserted lists q execute for own message list list not inserted lists unsent count list get message count return unsent count suppresswarnings countunsentmessages messageinserter ownmessage wasinserted ownmessage ownmessage mrealuri unsentcount ownmessagelist iwasinserted objectset ownmessagelist notinsertedlists ownmessagelist notinsertedlists unsentcount getmessagecount unsentcount public synchronized void on message received message message try get message getid logger debug this downloaded a message which we already have message geturi catch no such message exception e try message initialize transient db this message store for board board message get boards board add message message for message reference ref get all references to message message getid ref set message was downloaded flag catch exception ex fixme delete the message if this happens logger error this exception while storing a downloaded message ex onmessagereceived nosuchmessageexception initializetransient getboards addmessage messagereference getallreferencestomessage setmessagewasdownloadedflag public synchronized void on message list received message list list try get message list list getid logger debug this downloaded a message list which we already have list geturi catch no such message list exception e list initialize transient db this list store onmessagelistreceived messagelist getmessagelist messagelist nosuchmessagelistexception initializetransient abstract because we need to store an object of a child class of message list which is chosen dependent on which implementation of the messging system we are using messagelist public synchronized void on message fetch failed message reference message reference message list message fetch failed reference reason reason if reason message list message fetch failed reference reason data not found todo handle dnf in some reasonable way mark the messages as unavailable after a certain amount of retries maybe return try get message reference get messageid logger debug this trying to mark a message as downlod failed which we actually have message reference geturi catch no such message exception e try message list message fetch failed reference failed marker new message list message fetch failed reference message reference reason failed marker initialize transient db failed marker store for message reference r get all references to message message reference get messageid r set message was downloaded flag logger debug this marked message as download failed with reason reason message reference geturi catch exception ex logger error this exception while marking a not downloadable messge ex onmessagefetchfailed messagereference messagereference messagelist messagefetchfailedreference messagelist messagefetchfailedreference datanotfound messagereference getmessageid messagereference nosuchmessageexception messagelist messagefetchfailedreference failedmarker messagelist messagefetchfailedreference messagereference failedmarker initializetransient failedmarker messagereference getallreferencestomessage messagereference getmessageid setmessagewasdownloadedflag messagereference get a list of all message reference objects to the given message id references to own message are not returned used to mark the references to a message which was downloaded as downloaded private iterable message list message reference get all references to message final string id return new iterable message list message reference suppress warnings unchecked public iterator message list message reference iterator return new iterator message list message reference private iterator message list message reference iter query query db query query constrain message list message reference class query constrain own message list own message reference class not query descend m messageid constrain id fixme this function should only return message references which are for a board which an own identity wants to read and from as specified above this has to be implemented yet fixme order the message references randomly with some trick iter query execute iterator public boolean has next return iter has next public message list message reference next message list message reference next iter next next initialize transient db return next public void remove throw new unsupported operation exception messagereference ownmessage messagelist messagereference getallreferencestomessage messagelist messagereference suppresswarnings messagelist messagereference messagelist messagereference messagelist messagereference messagelist messagereference ownmessagelist ownmessagereference mmessageid messagereferences ownidentity hasnext hasnext messagelist messagereference messagelist messagereference initializetransient unsupportedoperationexception return new iterable message list message reference suppress warnings unchecked public iterator message list message reference iterator return new iterator message list message reference private iterator message list message reference iter query query db query query constrain message list message reference class query constrain own message list own message reference class not query descend m messageid constrain id fixme this function should only return message references which are for a board which an own identity wants to read and from as specified above this has to be implemented yet fixme order the message references randomly with some trick iter query execute iterator public boolean has next return iter has next public message list message reference next message list message reference next iter next next initialize transient db return next public void remove throw new unsupported operation exception messagelist messagereference suppresswarnings messagelist messagereference messagelist messagereference messagelist messagereference messagelist messagereference ownmessagelist ownmessagereference mmessageid messagereferences ownidentity hasnext hasnext messagelist messagereference messagelist messagereference initializetransient unsupportedoperationexception public boolean has next return iter has next hasnext hasnext public message list message reference next message list message reference next iter next next initialize transient db return next messagelist messagereference messagelist messagereference initializetransient public void remove throw new unsupported operation exception unsupportedoperationexception get a message by its uri the transient fields of the returned message will be initialized already this will not return own message objects your own messages will be returned by this function as soon as they have been downloaded throws no such message exception public message get freeneturi uri throws no such message exception return get message getid fromuri uri throw new unsupported operation exception getting a message by it s uri is inefficient compared to getting by id please only repair this function if absolutely unavoidable ownmessage nosuchmessageexception nosuchmessageexception getidfromuri unsupportedoperationexception get a message by its id the transient fields of the returned message will be initialized already this will not return own message objects your own messages will be returned by this function as soon as they have been downloaded as if they were normal messages of someone else throws no such message exception suppress warnings unchecked public synchronized message get string id throws no such message exception query query db query query constrain message class query constrain own message class not query descend mid constrain id object set message result query execute if result size 1 throw new duplicate message exception if result size 0 throw new no such message exception id message m result next m initialize transient db this return m ownmessage nosuchmessageexception suppresswarnings nosuchmessageexception ownmessage objectset duplicatemessageexception nosuchmessageexception initializetransient get a code message list code by its id the transient fields of the returned code message list code will be initialized already this will not return code own message list code objects your own message lists will be returned by this function as soon as they have been downloaded as if they were normal message lists of someone else throws no such message list exception suppress warnings unchecked public synchronized message list get message list string id throws no such message list exception query query db query query constrain message list class query constrain own message list class not query descend mid constrain id object set message list result query execute if result size 1 throw new duplicate message list exception if result size 0 throw new no such message list exception id message list list result next list initialize transient db this return list messagelist messagelist ownmessagelist nosuchmessagelistexception suppresswarnings messagelist getmessagelist nosuchmessagelistexception messagelist ownmessagelist objectset messagelist duplicatemessagelistexception nosuchmessagelistexception messagelist initializetransient suppress warnings unchecked public synchronized own message list get own message list string id throws no such message list exception query query db query query constrain own message list class query descend mid constrain id object set own message list result query execute if result size 1 throw new duplicate message list exception if result size 0 throw new no such message list exception id own message list list result next list initialize transient db this return list suppresswarnings ownmessagelist getownmessagelist nosuchmessagelistexception ownmessagelist objectset ownmessagelist duplicatemessagelistexception nosuchmessagelistexception ownmessagelist initializetransient public own message get own message freeneturi uri throws no such message exception return get own message message getid fromuri uri throw new unsupported operation exception getting a message by it s uri is inefficient compared to getting by id please only repair this function if absolutely unavoidable ownmessage getownmessage nosuchmessageexception getownmessage getidfromuri unsupportedoperationexception suppress warnings unchecked public synchronized own message get own message string id throws no such message exception query query db query query constrain own message class query descend mid constrain id object set own message result query execute if result size 1 throw new duplicate message exception if result size 0 throw new no such message exception id own message m result next m initialize transient db this return m suppresswarnings ownmessage getownmessage nosuchmessageexception ownmessage objectset ownmessage duplicatemessageexception nosuchmessageexception ownmessage initializetransient get a board by its name the transient fields of the returned board will be initialized already throws no such board exception suppress warnings unchecked public synchronized board get board by name string name throws no such board exception name name to lower case query query db query query constrain board class query descend m name constrain name object set board result query execute if result size 1 throw new duplicate board exception if result size 0 throw new no such board exception name board b result next b initialize transient db this return b nosuchboardexception suppresswarnings getboardbyname nosuchboardexception tolowercase mname objectset duplicateboardexception nosuchboardexception initializetransient public synchronized board get or create board string name throws invalid parameter exception name name to lower case board board try board get board by name name catch no such board exception e board new board name board initialize transient db this board store return board getorcreateboard invalidparameterexception tolowercase getboardbyname nosuchboardexception initializetransient for a database query of result type code object set board code this function provides an iterator the iterator of the object set cannot be used instead because it will not call initialize transient on the boards the iterator which is returned by this function takes care of that please synchronize on the code message manager code when using this function it is not synchronized itself suppress warnings unchecked protected iterator board general board iterator final query q return new iterator board private iterator board iter q execute iterator public boolean has next return iter has next public board next board next iter next next initialize transient db self return next public void remove throw new unsupported operation exception boards cannot be deleted yet objectset objectset initializetransient messagemanager suppresswarnings generalboarditerator hasnext hasnext initializetransient unsupportedoperationexception get an iterator of all boards the transient fields of the returned boards will be initialized already public synchronized iterator board board iterator fixme accelerate this query db4o should be configured to keep an alphabetic index of boards query query db query query constrain board class query descend m name order descending return general board iterator query boarditerator mname orderdescending generalboarditerator get an iterator of boards which were first seen after the given date sorted ascending by the date they were first seen at public synchronized iterator board board iterator sorted by date final date seen after query query db query query constrain board class query descend m first seen date constrain seen after greater query descend m first seen date order ascending return general board iterator query boarditeratorsortedbydate seenafter mfirstseendate seenafter mfirstseendate orderascending generalboarditerator get the next index of which a message from the selected identity is not stored public int get unavailable message index ft identity message author query q db query q constrain message class q constrain own message class not we also download our own message this helps the user to spot problems if he does not see his own messages we can hope that he reports a bug q descend m author constrain message author q descend m index order descending fixme write a native db4o query which just looks for the maximum object set message result q execute return result size 0 result next get index 1 0 suppress warnings unchecked public synchronized iterator own message not inserted message iterator return new iterator own message private iterator own message iter query query db query query constrain own message class query descend m realuri constrain null identity iter query execute iterator public boolean has next return iter has next public own message next own message next iter next next initialize transient db self return next public void remove throw new unsupported operation exception getunavailablemessageindex ftidentity messageauthor ownmessage mauthor messageauthor mindex orderdescending objectset getindex suppresswarnings ownmessage notinsertedmessageiterator ownmessage ownmessage ownmessage mrealuri hasnext hasnext ownmessage ownmessage initializetransient unsupportedoperationexception public boolean has next return iter has next hasnext hasnext public own message next own message next iter next next initialize transient db self return next ownmessage ownmessage initializetransient public void remove throw new unsupported operation exception unsupportedoperationexception get a list of not downloaded messages this function only returns messages which are posted to a board which an own identity wants to receive messages from however it might also return messages which are from an author which nobody wants to receive messages from filtering out unwanted authors is done at message list level message lists are only downloaded from identities which we want to read messages from suppress warnings unchecked public synchronized iterator message list message reference not downloaded message iterator return new iterator message list message reference private iterator message list message reference iter query query db query query constrain message list message reference class query constrain own message list own message reference class not query descend i was downloaded constrain false fixme this function should only return message references which are for a board which an own identity wants to read and from as specified above this has to be implemented yet fixme order the message references randomly with some trick iter query execute iterator public boolean has next return iter has next public message list message reference next message list message reference next iter next next initialize transient db return next public void remove throw new unsupported operation exception ownidentity messagelist messagelists suppresswarnings messagelist messagereference notdownloadedmessageiterator messagelist messagereference messagelist messagereference messagelist messagereference ownmessagelist ownmessagereference iwasdownloaded messagereferences ownidentity hasnext hasnext messagelist messagereference messagelist messagereference initializetransient unsupportedoperationexception public boolean has next return iter has next hasnext hasnext public message list message reference next message list message reference next iter next next initialize transient db return next messagelist messagereference messagelist messagereference initializetransient public void remove throw new unsupported operation exception unsupportedoperationexception returns true if the message was not downloaded yet and any of the ft own identity wants the message protected synchronized boolean should download message freeneturi uri ft identity author try get uri return false catch no such message exception e return m identity manager any own identity wants messages from author ftownidentity shoulddownloadmessage ftidentity nosuchmessageexception midentitymanager anyownidentitywantsmessagesfrom public abstract void terminate public identity manager get identity manager return m identity manager identitymanager getidentitymanager midentitymanager private boolean logminor logger should log logger minor this index writer shouldlog indexwriter public synchronized void make index perst root perst root throws exception logminor logger should log logger minor this try time taken system current time millis config config perst root get config file index dir new file config get index dir if index dir exists index dir mkdirs index dir exists index dir is directory logger error this cannot create index directory index dir return if logminor logger minor this spider regenerating index max size config get index subindex max size max entries config get index max entries make sub indices perst root make main index config time taken system current time millis time taken if logminor logger minor this spider indexes regenerated t produced index system current time millis t produced index ms ago time taken time taken ms t produced index system current time millis finally makeindex perstroot perstroot shouldlog time_taken currenttimemillis perstroot getconfig indexdir getindexdir indexdir indexdir indexdir indexdir isdirectory indexdir max_size getindexsubindexmaxsize max_entries getindexmaxentries makesubindices perstroot makemainindex time_taken currenttimemillis time_taken tproducedindex currenttimemillis tproducedindex time_taken tproducedindex currenttimemillis generates the main index file that can be used by librarian for searching in the list of subindices param void author swati throws io exception throws no such algorithm exception private void make main index config config throws io exception no such algorithm exception produce the main index file if logminor logger minor this producing top index the main index file file output file new file config get index dir index xml use a stream so we can explicitly close minimise number of filehandles used buffered output stream fos new buffered output stream new file output stream output file stream result result stream result stream new stream result fos try initialize xml builder document xml doc null document builder factory xml factory null document builder xml builder null dom implementation impl null element root element null xml factory document builder factory new instance try xml builder xml factory new document builder catch javax xml parsers parser configuration exception e logger error this spider error while initializing xml generator e to string e return impl xml builder getdom implementation starting to generate index xml doc impl create document null main index null root element xml doc get document element adding header to the index element header element xml doc create elementns null header title element sub header element xml doc create elementns null title text sub header text xml doc create text node config get index title sub header element append child sub header text header element append child sub header element owner sub header element xml doc create elementns null owner sub header text xml doc create text node config get index owner sub header element append child sub header text header element append child sub header element owner email if config get index owner email null sub header element xml doc create elementns null email sub header text xml doc create text node config get index owner email sub header element append child sub header text header element append child sub header element the max number of digits in md5 to be used for matching with the search query is stored in the xml element prefix element xml doc create elementns null prefix adding word index element keywords element xml doc create elementns null keywords for int i 0 i indices size i element sub index element xml doc create elementns null sub index sub index element set attributens null key indices element at i the subindex element key will contain the bits used for matching in that subindex keywords element append child sub index element prefix element set attributens null value match root element append child prefix element root element append child header element root element append child keywords element serialization dom source dom source new dom source xml doc transformer factory transform factory transformer factory new instance transformer serializer try serializer transform factory new transformer catch javax xml transform transformer configuration exception e logger error this spider error while serializing xml transform factory new transformer e to string e return serializer set output property output keys encoding utf 8 serializer set output property output keys indent yes final step try serializer transform dom source result stream catch javax xml transform transformer exception e logger error this spider error while serializing xml transform e to string e return finally fos close the main xml file is generated as each word is generated enter it into the respective subindex the parsing will start and nodes will be added as needed ioexception nosuchalgorithmexception makemainindex ioexception nosuchalgorithmexception outputfile getindexdir bufferedoutputstream bufferedoutputstream fileoutputstream outputfile streamresult resultstream resultstream streamresult xmldoc documentbuilderfactory xmlfactory documentbuilder xmlbuilder domimplementation rootelement xmlfactory documentbuilderfactory newinstance xmlbuilder xmlfactory newdocumentbuilder parserconfigurationexception tostring xmlbuilder getdomimplementation xmldoc createdocument main_index rootelement xmldoc getdocumentelement headerelement xmldoc createelementns subheaderelement xmldoc createelementns subheadertext xmldoc createtextnode getindextitle subheaderelement appendchild subheadertext headerelement appendchild subheaderelement subheaderelement xmldoc createelementns subheadertext xmldoc createtextnode getindexowner subheaderelement appendchild subheadertext headerelement appendchild subheaderelement getindexowneremail subheaderelement xmldoc createelementns subheadertext xmldoc createtextnode getindexowneremail subheaderelement appendchild subheadertext headerelement appendchild subheaderelement prefixelement xmldoc createelementns keywordselement xmldoc createelementns subindexelement xmldoc createelementns subindex subindexelement setattributens elementat keywordselement appendchild subindexelement prefixelement setattributens rootelement appendchild prefixelement rootelement appendchild headerelement rootelement appendchild keywordselement domsource domsource domsource xmldoc transformerfactory transformfactory transformerfactory newinstance transformfactory newtransformer transformerconfigurationexception transformfactory newtransformer tostring setoutputproperty outputkeys setoutputproperty outputkeys domsource resultstream transformerexception tostring generates the subindices each index has less than code max entries words the original treemap is split into several sublists indexed by the common substring of the hash code of the words throws exception private void make sub indices perst root perst root throws exception logger normal this generating index indices new vector string match 1 for string hex hex generate sub index perst root hex max_entries makesubindices perstroot perstroot generatesubindex perstroot private void generate sub index perst root perst root string prefix throws exception if logminor logger minor this generating subindex for prefix if prefix length match match prefix length if generatexml perst root prefix return if logminor logger minor this too big subindex for prefix for string hex hex generate sub index perst root prefix hex generatesubindex perstroot perstroot perstroot generatesubindex perstroot generates the xml index with the given list of words with prefix number of matching bits in md5 param prefix prefix string return successful throws io exception private boolean generatexml perst root perst root string prefix throws io exception final config config perst root get config final long max size config get index subindex max size final int max entries config get index max entries file output file new file config get index dir index prefix xml buffered output stream fos null int count 0 int estimate size 0 try document builder factory xml factory document builder factory new instance document builder xml builder try xml builder xml factory new document builder catch javax xml parsers parser configuration exception e throw new runtime exception spider error while initializing xml generator e dom implementation impl xml builder getdom implementation starting to generate index document xml doc impl create document sub index null element root element xml doc get document element if config is debug root element set attributens http www w3 org 2000 xmlns xmlns debug urn freenet xmlspider debug root element append child xml doc create comment new date togmt string adding header to the index element header element xml doc create elementns null header title element sub header element xml doc create elementns null title text sub header text xml doc create text node config get index title sub header element append child sub header text header element append child sub header element list of files referenced in this subindex element files element xml doc create elementns null files files element file element set long fileid new hash set long adding word index element keywords element xml doc create elementns null keywords iterable iterator term term iterator perst root get term iterator prefix prefix g for term term term iterator element word element xml doc create elementns null word word element set attributens null v term get word if config is debug word element set attributens urn freenet xmlspider debug debug md5 term getmd5 count estimate size 12 estimate size term get word length set page pages term get pages if count 1 estimate size pages size 13 max size count max entries return false for page page pages term position term pos page get term position term false if term pos null continue synchronized term pos synchronized page adding file information uri element lists the id of the file containing a particular word file element lists the id key title of the files mentioned in the entire subindex element uri element xml doc create elementns null file uri element set attributens null id long to string page get id position by position int positions term pos positions string builder position list new string builder for int k 0 k positions length k if k 0 position list append position list append positions k uri element append child xml doc create text node position list to string word element append child uri element estimate size 13 estimate size position list length if fileid contains page get id fileid add page get id element file element xml doc create elementns null file file element set attributens null id long to string page get id file element set attributens null key page geturi file element set attributens null title page get page title null page get page title page geturi files element append child file element estimate size 15 estimate size files element get attributens null id length estimate size files element get attributens null key length estimate size files element get attributens null title length keywords element append child word element element entries element xml doc create elementns null entries entries element set attributens null value count root element append child entries element root element append child header element root element append child files element root element append child keywords element serialization dom source dom source new dom source xml doc transformer factory transform factory transformer factory new instance transformer serializer try serializer transform factory new transformer catch javax xml transform transformer configuration exception e throw new runtime exception spider error while serializing xml transform factory new transformer e serializer set output property output keys encoding utf 8 serializer set output property output keys indent yes fos new buffered output stream new file output stream output file stream result result stream new stream result fos final step try serializer transform dom source result stream catch javax xml transform transformer exception e throw new runtime exception spider error while serializing xml transform e finally closer close fos if output file length max size count 1 output file delete return false if logminor logger minor this spider indexes regenerated indices add prefix return true ioexception perstroot perstroot ioexception perstroot getconfig max_size getindexsubindexmaxsize max_entries getindexmaxentries outputfile getindexdir index_ bufferedoutputstream estimatesize documentbuilderfactory xmlfactory documentbuilderfactory newinstance documentbuilder xmlbuilder xmlbuilder xmlfactory newdocumentbuilder parserconfigurationexception runtimeexception domimplementation xmlbuilder getdomimplementation xmldoc createdocument sub_index rootelement xmldoc getdocumentelement isdebug rootelement setattributens rootelement appendchild xmldoc createcomment togmtstring headerelement xmldoc createelementns subheaderelement xmldoc createelementns subheadertext xmldoc createtextnode getindextitle subheaderelement appendchild subheadertext headerelement appendchild subheaderelement fileselement xmldoc createelementns fileselement fileelement hashset keywordselement xmldoc createelementns iterableiterator termiterator perstroot gettermiterator termiterator wordelement xmldoc createelementns wordelement setattributens getword isdebug wordelement setattributens estimatesize estimatesize getword getpages estimatesize max_size max_entries termposition termpos gettermposition termpos termpos urielement fileelement urielement xmldoc createelementns urielement setattributens tostring getid termpos stringbuilder positionlist stringbuilder positionlist positionlist urielement appendchild xmldoc createtextnode positionlist tostring wordelement appendchild urielement estimatesize estimatesize positionlist getid getid fileelement xmldoc createelementns fileelement setattributens tostring getid fileelement setattributens fileelement setattributens getpagetitle getpagetitle fileselement appendchild fileelement estimatesize estimatesize fileselement getattributens estimatesize fileselement getattributens estimatesize fileselement getattributens keywordselement appendchild wordelement entrieselement xmldoc createelementns entrieselement setattributens rootelement appendchild entrieselement rootelement appendchild headerelement rootelement appendchild fileselement rootelement appendchild keywordselement domsource domsource domsource xmldoc transformerfactory transformfactory transformerfactory newinstance transformfactory newtransformer transformerconfigurationexception runtimeexception transformfactory newtransformer setoutputproperty outputkeys setoutputproperty outputkeys bufferedoutputstream fileoutputstream outputfile streamresult resultstream streamresult domsource resultstream transformerexception runtimeexception outputfile max_size outputfile public static void main string arg throws exception storage db storage factory get instance create storage db set property perst object cache kind pinned db set property perst object cache init size 8192 db set property perst alternative btree true db set property perst string encoding utf 8 db set property perst concurrent iterator true db set property perst file readonly true db open arg 0 perst root root perst root db get root index writer writer new index writer int benchmark 0 long time taken null if arg 1 null benchmark integer parse int arg 1 time taken new long benchmark for int i 0 i benchmark i long start time system current time millis writer make index root long end time system current time millis long mem free runtime get runtime free memory long mem total runtime get runtime total memory system out println index generated in end time start time ms used memory mem total mem free if benchmark 0 time taken i end time start time system out println cooling down for int j 0 j 3 j system gc system run finalization thread sleep 3000 if benchmark 0 long total time 0 long total sq time 0 for long t time taken total time t total sq time t t double mean time total time benchmark double mean sq time total sq time benchmark system out println mean time long mean time ms system out println sd long math sqrt mean sq time mean time mean time ms storagefactory getinstance createstorage setproperty setproperty setproperty setproperty setproperty setproperty perstroot perstroot getroot indexwriter indexwriter timetaken parseint timetaken starttime currenttimemillis makeindex endtime currenttimemillis memfree getruntime freememory memtotal getruntime totalmemory endtime starttime memtotal memfree timetaken endtime starttime runfinalization totaltime totalsqtime timetaken totaltime totalsqtime meantime totaltime meansqtime totalsqtime meantime meansqtime meantime meantime public action list actionlist public action get action int n return action get n getaction private static final long serial versionuid 1 url encoded format exception serialversionuid urlencodedformatexception url encoded format exception url encoded format exception string s super s urlencodedformatexception urlencodedformatexception private static final long serial versionuid 1 public http range exception throwable cause super cause serialversionuid httprangeexception public http range exception string msg super msg httprangeexception override public final synchronized throwable fill in stack trace return null fillinstacktrace public class snmp integer32 extends snmp type wrapper num public snmp integer32 super snmpinteger32 snmptypewrappernum snmpinteger32 public class snmp integer32 extends snmp type wrapper num public snmp integer32 super public snmp integer32 long value super value snmpinteger32 snmptypewrappernum snmpinteger32 snmpinteger32 public void set value long value todo make it prettier this value new long value int value system err println value cut from value to this value setvalue intvalue protected void init this typeid 0x02 private final exception m error public error page web interface my web interface http request my request exception my error super my web interface my request m error my error merror errorpage webinterface mywebinterface httprequest myrequest myerror mywebinterface myrequest merror myerror public void make html node error box add error box internal error please report this string message m error get localized message if message null message equals message m error get message html node p error box add child p message p error box add child p stack trace for stack trace element element m error get stack trace p add child br p add child element to string htmlnode errorbox adderrorbox merror getlocalizedmessage merror getmessage htmlnode errorbox addchild errorbox addchild stacktraceelement merror getstacktrace addchild addchild tostring suppress warnings unchecked public node restart jobs queue long nodedb handle2 nodedb handle nodedb handle2 db jobs new set native thread java priority range db jobs early new set native thread java priority range for int i 0 i db jobs length i db jobs i new hash set db job db jobs early i new hash set db job suppresswarnings noderestartjobsqueue nodedbhandle2 nodedbhandle nodedbhandle2 dbjobs nativethread java_priority_range dbjobsearly nativethread java_priority_range dbjobs dbjobs hashset dbjob dbjobsearly hashset dbjob public static node restart jobs queue init final long nodedb handle object container container suppress warnings serial object set node restart jobs queue results container query new predicate node restart jobs queue override public boolean match node restart jobs queue arg0 return arg0 nodedb handle nodedb handle if results has next system err println found old restart jobs queue node restart jobs queue queue results next container activate queue 1 queue on init container return queue node restart jobs queue queue new node restart jobs queue nodedb handle container store queue system err println created new restart jobs queue return queue noderestartjobsqueue nodedbhandle objectcontainer suppresswarnings objectset noderestartjobsqueue noderestartjobsqueue noderestartjobsqueue nodedbhandle nodedbhandle hasnext noderestartjobsqueue oninit noderestartjobsqueue noderestartjobsqueue nodedbhandle object set node restart jobs queue results container query new predicate node restart jobs queue override public boolean match node restart jobs queue arg0 return arg0 nodedb handle nodedb handle objectset noderestartjobsqueue noderestartjobsqueue noderestartjobsqueue nodedbhandle nodedbhandle private void on init object container container oninit objectcontainer public synchronized void queue restart job db job job int priority object container container boolean early if logger should log logger minor this logger minor this queueing restart job job at priority priority early early set db job jobs early db jobs early priority db jobs priority container store job container activate jobs 1 if jobs add job store to 1 hop only otherwise db4o will update all the jobs on the queue to a depth of 3 which in practice means all the buckets inside the bucket chain bucket s linked by the bucket chain bucket kill tag s adding new ones this will take ages and is in any case not what we want see http tracker db4o com browse cor 1436 container ext store jobs 1 container deactivate jobs 1 queuerestartjob dbjob objectcontainer shouldlog dbjob dbjobsearly dbjobs bucketchainbucket bucketchainbucketkilltag public synchronized void remove restart job db job job int priority object container container boolean job was active container ext is active job if job was active container activate job 1 container activate db jobs priority 1 container activate db jobs early priority 1 if db jobs priority remove job db jobs early priority remove job int found 0 for int i 0 i db jobs length i container activate db jobs priority 1 if db jobs priority remove job store to 1 hop only otherwise db4o will update all the jobs on the queue to a depth of 3 which in practice means all the buckets inside the bucket chain bucket s linked by the bucket chain bucket kill tag s adding new ones this will take ages and is in any case not what we want see http tracker db4o com browse cor 1436 container ext store db jobs priority 1 found if db jobs early priority remove job store to 1 hop only otherwise db4o will update all the jobs on the queue to a depth of 3 which in practice means all the buckets inside the bucket chain bucket s linked by the bucket chain bucket kill tag s adding new ones this will take ages and is in any case not what we want see http tracker db4o com browse cor 1436 container ext store db jobs early priority 1 found container deactivate db jobs priority 1 container deactivate db jobs early priority 1 if found 0 logger error this job job not in specified priority priority found in found other priorities when removing else logger error this job job not found when removing it else store to 1 hop only otherwise db4o will update all the jobs on the queue to a depth of 3 which in practice means all the buckets inside the bucket chain bucket s linked by the bucket chain bucket kill tag s adding new ones this will take ages and is in any case not what we want see http tracker db4o com browse cor 1436 container ext store db jobs priority 1 container deactivate db jobs priority 1 container ext store db jobs early priority 1 container deactivate db jobs early priority 1 if job was active container deactivate job 1 removerestartjob dbjob objectcontainer jobwasactive isactive jobwasactive dbjobs dbjobsearly dbjobs dbjobsearly dbjobs dbjobs dbjobs bucketchainbucket bucketchainbucketkilltag dbjobs dbjobsearly bucketchainbucket bucketchainbucketkilltag dbjobsearly dbjobs dbjobsearly bucketchainbucket bucketchainbucketkilltag dbjobs dbjobs dbjobsearly dbjobsearly jobwasactive static class restartdb job public restartdb job db job job2 int i job job2 prio i restartdbjob restartdbjob dbjob synchronized restartdb job get early restart database jobs object container container array list restartdb job list new array list restartdb job for int i db jobs early length 1 i 0 i container activate db jobs early i 1 if db jobs early i is empty system err println adding db jobs early i size early restart jobs at priority i for db job job db jobs early i list add new restartdb job job i container deactivate db jobs early i 1 return list to array new restartdb job list size restartdbjob getearlyrestartdatabasejobs objectcontainer arraylist restartdbjob arraylist restartdbjob dbjobsearly dbjobsearly dbjobsearly isempty dbjobsearly dbjob dbjobsearly restartdbjob dbjobsearly toarray restartdbjob void add late restart database jobs db job runner runner object container container for int i db jobs early length 1 i 0 i container activate db jobs i 1 if db jobs i is empty system err println adding db jobs i size restart jobs at priority i for iterator db job it db jobs i iterator it has next db job job it next if job null logger error this late restart job removed without telling the node restart jobs queue on priority i it remove container ext store db jobs i 2 continue container activate job 1 runner queue job i false addlaterestartdatabasejobs dbjobrunner objectcontainer dbjobsearly dbjobs dbjobs isempty dbjobs dbjob dbjobs hasnext dbjob noderestartjobsqueue dbjobs static final string get message int reason switch reason case internal error return internal error probably a bug case route not found return could not store the data on enough nodes case rejected overload return a node downstream either timed out or was overloaded retry case route really not found return the insert could not get off the node at all case collision return the insert collided with different data of the same key already on the network default return unknown error code reason getmessage internal_error route_not_found rejected_overload route_really_not_found public low level put exception int code string message throwable t super message t this code code lowlevelputexception low level put exception int reason super get message reason this code reason lowlevelputexception getmessage public client put dir message simple field set fs throws message invalid exception identifier fs get identifier global fields string to bool fs get global false default name fs get default name if identifier null throw new message invalid exception protocol error message missing field no identifier null global try string u fs get uri if u null throw new message invalid exception protocol error message missing field no uri identifier global freeneturi uu new freeneturi fs get uri client is allowed to put a slash at the end if it wants to but this is discouraged string meta uu get all meta strings if meta null meta length 1 meta 0 length 0 uu uu set meta string null uri uu catch malformedurl exception e throw new message invalid exception protocol error message freenet uri parse error e get message identifier global string verbosity string fs get verbosity if verbosity string null verbosity 0 else try verbosity integer parse int verbosity string 10 catch number format exception e throw new message invalid exception protocol error message error parsing number error parsing verbosity field e get message identifier global string max retries string fs get max retries if max retries string null default to 0 max retries 0 else try max retries integer parse int max retries string 10 catch number format exception e throw new message invalid exception protocol error message error parsing number error parsing max size field e get message identifier global getchk only fields string to bool fs get getchk only false string priority string fs get priority class if priority string null defaults to the one just below f proxy priority class request starter immediate splitfile priority class else try priority class short parse short priority string 10 if priority class request starter maximum priority class priority class request starter minimum priority class throw new message invalid exception protocol error message invalid field valid priorities are from request starter maximum priority class to request starter minimum priority class identifier global catch number format exception e throw new message invalid exception protocol error message error parsing number error parsing priority class field e get message identifier global dont compress fields string to bool fs get dont compress false string persistence string fs get persistence if persistence string null persistence string equals ignore case connection default persists until connection loss persistence type client request persist connection else if persistence string equals ignore case reboot reports to client by name persists over connection loss not saved to disk so dies on reboot persistence type client request persist reboot else if persistence string equals ignore case forever same as reboot but saved to disk persists forever persistence type client request persist forever else throw new message invalid exception protocol error message error parsing number error parsing persistence field persistence string identifier global client token fs get client token early encode fields string to bool fs get early encode false clientputdirmessage simplefieldset messageinvalidexception stringtobool defaultname defaultname messageinvalidexception protocolerrormessage missing_field messageinvalidexception protocolerrormessage missing_field getallmetastrings setmetastring malformedurlexception messageinvalidexception protocolerrormessage freenet_uri_parse_error getmessage verbositystring verbositystring parseint verbositystring numberformatexception messageinvalidexception protocolerrormessage error_parsing_number getmessage maxretriesstring maxretries maxretriesstring maxretries maxretries parseint maxretriesstring numberformatexception messageinvalidexception protocolerrormessage error_parsing_number maxsize getmessage getchkonly stringtobool getchkonly prioritystring priorityclass prioritystring fproxy priorityclass requeststarter immediate_splitfile_priority_class priorityclass parseshort prioritystring priorityclass requeststarter maximum_priority_class priorityclass requeststarter minimum_priority_class messageinvalidexception protocolerrormessage invalid_field requeststarter maximum_priority_class requeststarter minimum_priority_class numberformatexception messageinvalidexception protocolerrormessage error_parsing_number priorityclass getmessage dontcompress stringtobool dontcompress persistencestring persistencestring persistencestring equalsignorecase persistencetype clientrequest persist_connection persistencestring equalsignorecase persistencetype clientrequest persist_reboot persistencestring equalsignorecase persistencetype clientrequest persist_forever messageinvalidexception protocolerrormessage error_parsing_number persistencestring clienttoken clienttoken earlyencode stringtobool earlyencode override public simple field set get field set simple field set sfs new simple field set true sfs put single uri uri to string sfs put single identifier identifier sfs put single verbosity integer to string verbosity sfs put single max retries integer to string max retries sfs put single client token client token sfs put single getchk only boolean to string getchk only sfs put single priority class short to string priority class sfs put single persistence type client request persistence type string persistence type sfs put single dont compress boolean to string dont compress sfs put single global boolean to string global sfs put single default name default name return sfs simplefieldset getfieldset simplefieldset simplefieldset putsingle tostring putsingle putsingle tostring putsingle maxretries tostring maxretries putsingle clienttoken clienttoken putsingle getchkonly tostring getchkonly putsingle priorityclass tostring priorityclass putsingle persistencetype clientrequest persistencetypestring persistencetype putsingle dontcompress tostring dontcompress putsingle tostring putsingle defaultname defaultname public final class color composite extends rgb composite public color composite float alpha super alpha colorcomposite rgbcomposite colorcomposite public composite context create context color model src color model color model dst color model rendering hints hints return new context extra alpha src color model dst color model compositecontext createcontext colormodel srccolormodel colormodel dstcolormodel renderinghints extraalpha srccolormodel dstcolormodel private float dhsb new float 3 public context float alpha color model src color model color model dst color model super alpha src color model dst color model colormodel srccolormodel colormodel dstcolormodel srccolormodel dstcolormodel override public void composergb int src int dst float alpha int w src length for int i 0 i w i 4 int sr src i int dir dst i int sg src i 1 int dig dst i 1 int sb src i 2 int dib dst i 2 int sa src i 3 int dia dst i 3 int dor dog dob color rg btohsb sr sg sb shsb color rg btohsb dir dig dib dhsb dhsb 0 shsb 0 dhsb 1 shsb 1 int dorgb color hs btorgb dhsb 0 dhsb 1 dhsb 2 dor dorgb 0xff0000 16 dog dorgb 0xff00 8 dob dorgb 0xff float a alpha sa 255f float ac 1 a dst i int a dor ac dir dst i 1 int a dog ac dig dst i 2 int a dob ac dib dst i 3 int sa alpha dia ac rgbtohsb rgbtohsb hsbtorgb private t prev public t get next return next getnext suppress warnings unchecked public t set next item i t old next next t i return old suppresswarnings setnext public t get prev return prev getprev suppress warnings unchecked public t set prev item i t old prev prev t i return old suppresswarnings setprev private doubly linked list super t parent list public doubly linked list super t get parent return parent list doublylinkedlist parentlist doublylinkedlist getparent parentlist public doubly linked list super t set parent doubly linked list super t l doubly linked list super t old parent parent list parent list l return old parent doublylinkedlist setparent doublylinkedlist doublylinkedlist oldparent parentlist parentlist oldparent public introduction puzzle store wot my wot m wot my wot mdb my wot getdb delete corrupted puzzles introductionpuzzlestore mywot mwot mywot mywot deletecorruptedpuzzles private synchronized void delete corrupted puzzles synchronized mdb lock object set introduction puzzle puzzles mdb query by example introduction puzzle class for introduction puzzle p puzzles mdb activate p 3 fixme is this the correct depth if p check consistency false logger error this deleting corrupted puzzle mdb delete p mdb commit our goal is to delete the puzzles so we do not rollback here if an exception occurs that would restore the deleted puzzles deletecorruptedpuzzles objectset introductionpuzzle querybyexample introductionpuzzle introductionpuzzle checkconsistency delete puzzles which can no longer be solved because they have expired suppress warnings unchecked protected synchronized void delete expired puzzles synchronized mdb lock query q mdb query q constrain introduction puzzle class q descend m valid until time constrain current timeutc get in millis smaller object set introduction puzzle result q execute for introduction puzzle p result mdb delete p todo minor but interesting optimization result size should take about o n time before the for and o 1 after it if db4o is smart enough verify if it really calculates and stores the size during the iteration if not the log line should be prefixed with if loglevel is debug logger debug introduction puzzle class deleted result size expired puzzles mdb commit our goal is to delete the puzzles so we do not rollback here if an exception occurs that would restore the deleted puzzles suppresswarnings deleteexpiredpuzzles introductionpuzzle mvaliduntiltime currenttimeutc getinmillis objectset introductionpuzzle introductionpuzzle introductionpuzzle delete the oldest puzzles so that only an amount of code puzzle pool size code is left used by the introduction client to delete old puzzles and replace them with new ones param puzzle pool size the amount of puzzles which should not be deleted suppress warnings unchecked protected synchronized void delete oldest unsolved puzzles int puzzle pool size synchronized mdb lock query q mdb query q constrain introduction puzzle class q constrain own introduction puzzle class not q descend m valid until time order ascending object set introduction puzzle result q execute int delete count result size puzzle pool size logger debug introduction puzzle class deleting delete count old puzzles keeping puzzle pool size while delete count 0 result has next introduction puzzle puzzle result next we do not handle the following check in the query so that db4o can use the index on m valid until time to run the query and size in o 1 instead of o amount of puzzles in the database unfortunately toad said that it does not really do that even though it is logically possible todo tell it to do so if puzzle was solved false mdb delete puzzle delete count mdb commit our goal is to delete the puzzles so we do not rollback here if an exception occurs that would restore the deleted puzzles puzzlepoolsize puzzlepoolsize suppresswarnings deleteoldestunsolvedpuzzles puzzlepoolsize introductionpuzzle ownintroductionpuzzle mvaliduntiltime orderascending objectset introductionpuzzle deletecount puzzlepoolsize introductionpuzzle deletecount puzzlepoolsize deletecount hasnext introductionpuzzle mvaliduntiltime toad_ wassolved deletecount public synchronized void store and commit introduction puzzle puzzle todo convert to assert maybe when we are sure that this does not happen duplicate puzzles will be deleted after they expire anyway further isn t there a db4o option which ensures that mid is a primary key and therefore no duplicates can exist synchronized puzzle synchronized mdb lock introduction puzzle existing puzzle get byid puzzle getid if existing puzzle null existing puzzle puzzle throw new illegal argument exception puzzle with id puzzle getid already exists if mdb is stored puzzle mdb is active puzzle throw new runtime exception trying to store an inactive introduction puzzle object try mdb store puzzle get type mdb store puzzle get date of insertion not stored because it is a primitive for db4o mdb store puzzle mdb commit logger debug puzzle commited catch runtime exception e mdb rollback throw e storeandcommit introductionpuzzle introductionpuzzle existingpuzzle getbyid existingpuzzle existingpuzzle illegalargumentexception isstored isactive runtimeexception introductionpuzzle gettype getdateofinsertion runtimeexception get an introduction puzzle or own introduction puzzle by it s id suppress warnings unchecked public synchronized introduction puzzle get byid string id query q mdb query q constrain introduction puzzle class q descend mid constrain id object set introduction puzzle result q execute todo decide whether we maybe should throw to get bug reports if this happens otoh puzzles are not so important assert result size 1 return result has next result next null introductionpuzzle ownintroductionpuzzle suppresswarnings introductionpuzzle getbyid introductionpuzzle objectset introductionpuzzle hasnext get a puzzle by it s request uri if you synchronize on the puzzle store while calling this function you have to synchronize on the wot before synchronizing on the puzzle store because this function locks the wot if you did not lock it before dead locks might occur used by the introduction client to obtain the corresponding puzzle object when an insert succeeded or failed protected introduction puzzle get puzzle by requesturi freeneturi uri throws parse exception unknown identity exception identity inserter m wot get identity byuri uri date date introduction puzzle get date from requesturi uri int index introduction puzzle get index from requesturi uri return introduction puzzle get by inserter date index inserter date index introductionclient introductionpuzzle getpuzzlebyrequesturi parseexception unknownidentityexception mwot getidentitybyuri introductionpuzzle getdatefromrequesturi introductionpuzzle getindexfromrequesturi introductionpuzzle getbyinserterdateindex protected introduction puzzle get puzzle by solutionuri freeneturi uri throws parse exception unknown identity exception return get byid introduction puzzle getid from solutionuri uri introductionpuzzle getpuzzlebysolutionuri parseexception unknownidentityexception getbyid introductionpuzzle getidfromsolutionuri get an own puzzle by it s request uri if you synchronize on the puzzle store while calling this function you have to synchronize on the wot before synchronizing on the puzzle store because this function locks the wot if you did not lock it before dead locks might occur used by the introduction server to obtain the corresponding puzzle object when an insert succeeded or failed protected own introduction puzzle get own puzzle by requesturi freeneturi uri throws parse exception unknown identity exception own identity inserter m wot get own identity byuri uri date date introduction puzzle get date from requesturi uri int index introduction puzzle get index from requesturi uri return own introduction puzzle get by inserter date index inserter date index introductionserver ownintroductionpuzzle getownpuzzlebyrequesturi parseexception unknownidentityexception ownidentity mwot getownidentitybyuri introductionpuzzle getdatefromrequesturi introductionpuzzle getindexfromrequesturi ownintroductionpuzzle getbyinserterdateindex get a puzzle by it s solution uri used by the introduction server when a solution was downloaded from the given uri to retrieve the introduction puzzle object which belongs to the uri param db param uri return throws parse exception protected own introduction puzzle get own puzzle by solutionuri freeneturi uri throws parse exception return own introduction puzzle get byid own introduction puzzle getid from solutionuri uri introductionserver introductionpuzzle parseexception ownintroductionpuzzle getownpuzzlebysolutionuri parseexception ownintroductionpuzzle getbyid ownintroductionpuzzle getidfromsolutionuri used by the introduction puzzle factories for creating new puzzles suppress warnings deprecation unchecked public synchronized int get free index own identity inserter date date query q mdb query q constrain own introduction puzzle class q descend m inserter constrain inserter identity q descend m date of insertion constrain new date date get year date get month date get date q descend m index order descending object set introduction puzzle result q execute return result size 0 result next get index 1 0 introductionpuzzlefactories suppresswarnings getfreeindex ownidentity ownintroductionpuzzle minserter mdateofinsertion getyear getmonth getdate mindex orderdescending objectset introductionpuzzle getindex get all not inserted puzzles of the given identity you have to put a synchronized this introduction puzzle store statement around the call to this function and the processing of the list which was returned by it used by the introduction server for inserting puzzles suppress warnings unchecked public object set own introduction puzzle get uninserted own puzzles by inserter own identity identity query q mdb query q constrain own introduction puzzle class q descend m was inserted constrain false return q execute introductionpuzzlestore introductionserver suppresswarnings objectset ownintroductionpuzzle getuninsertedownpuzzlesbyinserter ownidentity ownintroductionpuzzle mwasinserted get all not solved puzzles which where inserted by the given identity you have to put a synchronized this introduction puzzle store statement around the call to this function and the processing of the list which was returned by it used by the introduction server for downloading solutions suppress warnings unchecked protected synchronized object set own introduction puzzle get unsolved by inserter own identity inserter query q mdb query q constrain own introduction puzzle class q descend m inserter constrain inserter identity q descend m was solved constrain false return q execute introductionpuzzlestore introductionserver suppresswarnings objectset ownintroductionpuzzle getunsolvedbyinserter ownidentity ownintroductionpuzzle minserter mwassolved get a list of puzzles which are from today you have to put a synchronized this introduction puzzle store statement around the call to this function and the processing of the list which was returned by it used by for checking whether new puzzles have to be inserted for a given own identity or can be downloaded from a given identity suppress warnings deprecation unchecked protected synchronized object set introduction puzzle get of today by inserter identity inserter date max age new date current timeutc get year 1900 current timeutc get month current timeutc get day of month query q mdb query q constrain introduction puzzle class q descend m inserter constrain inserter identity q descend m date of insertion constrain max age smaller not return q execute introductionpuzzlestore ownidentity suppresswarnings objectset introductionpuzzle getoftodaybyinserter maxage currenttimeutc getyear currenttimeutc getmonth currenttimeutc getdayofmonth introductionpuzzle minserter mdateofinsertion maxage get a puzzle of a given identity from a given date with a given index used by the introduction client to check whether we already have a puzzle from the given date and index if yes then we do not need to download that one suppress warnings unchecked protected synchronized introduction puzzle get by inserter date index identity inserter date date int index query q mdb query q constrain introduction puzzle class q descend m inserter constrain inserter identity q descend m date of insertion constrain date q descend m index constrain index object set introduction puzzle result q execute todo decide whether we maybe should throw to get bug reports if this happens otoh puzzles are not so important assert result size 1 return result has next result next null introductionclient suppresswarnings introductionpuzzle getbyinserterdateindex introductionpuzzle minserter mdateofinsertion mindex objectset introductionpuzzle hasnext get a list of non own puzzles which were downloaded and not solved yet of a given type you have to put a synchronized this introduction puzzle store statement around the call to this function and the processing of the list which was returned by it suppress warnings unchecked protected synchronized object set introduction puzzle get unsolved puzzles puzzle type puzzle type query q mdb query q constrain introduction puzzle class q constrain own introduction puzzle class not q descend m valid until time order descending q descend m was solved constrain false q descend m type constrain puzzle type object set introduction puzzle puzzles q execute return puzzles introductionpuzzlestore suppresswarnings objectset introductionpuzzle getunsolvedpuzzles puzzletype puzzletype introductionpuzzle ownintroductionpuzzle mvaliduntiltime orderdescending mwassolved mtype puzzletype objectset introductionpuzzle get a list of all solved non own puzzles you have to put a synchronized this introduction puzzle store statement around the call to this function and the processing of the list which was returned by it used by the introduction client for inserting solutions of solved puzzles suppress warnings unchecked public synchronized object set introduction puzzle get uninserted solved puzzles query q mdb query q constrain introduction puzzle class q constrain own introduction puzzle class not q descend m was inserted constrain false q descend m was solved constrain true return q execute introductionpuzzlestore introductionclient suppresswarnings objectset introductionpuzzle getuninsertedsolvedpuzzles introductionpuzzle ownintroductionpuzzle mwasinserted mwassolved public synchronized int get own catpcha amount boolean solved query q mdb query q constrain own introduction puzzle class q descend m was solved constrain solved return q execute size getowncatpchaamount ownintroductionpuzzle mwassolved public synchronized int get non own captcha amount boolean solved query q mdb query q constrain introduction puzzle class q constrain own introduction puzzle class not q descend m was solved constrain solved return q execute size getnonowncaptchaamount introductionpuzzle ownintroductionpuzzle mwassolved memory usage constructor public memory usage class cls this cls cls memoryusage memoryusage protected function2d basis public fbm float h float lacunarity float octaves this h lacunarity octaves new noise public fbm float h float lacunarity float octaves function2d basis this h h this lacunarity lacunarity this octaves octaves this basis basis exponents new float int octaves 1 float frequency 1 0f for int i 0 i int octaves i exponents i float math pow frequency h frequency lacunarity public void set basis function2d basis this basis basis setbasis public function2d get basis type return basis getbasistype public float evaluate float x float y float value 0 0f float remainder int i to prevent cascading effects x 371 y 529 for i 0 i int octaves i value basis evaluate x y exponents i x lacunarity y lacunarity remainder octaves int octaves if remainder 0 value remainder basis evaluate x y exponents i return value public persistent put dir string identifier freeneturi uri int verbosity short priority class short persistence type boolean global string default name hash map string object manifest elements string token boolean started int max retries boolean was disk put object container container this identifier identifier this uri uri this verbosity verbosity this priority class priority class this persistence type persistence type this global global this default name default name this manifest elements manifest elements this token token this started started this max retries max retries this was disk put was disk put cached generate field set container persistentputdir priorityclass persistencetype defaultname hashmap manifestelements maxretries wasdiskput objectcontainer priorityclass priorityclass persistencetype persistencetype defaultname defaultname manifestelements manifestelements maxretries maxretries wasdiskput wasdiskput generatefieldset private simple field set generate field set object container container simple field set fs new simple field set false false because this can get huge fs put single identifier identifier fs put single uri uri to string false false fs put verbosity verbosity fs put single persistence client request persistence type string persistence type fs put priority class priority class fs put single global boolean to string global fs put single put dir type was disk put disk complex simple field set files new simple field set false flatten the hierarchy it can be reconstructed on restarting storing it directly would be a pita fixme resolve the new base manifest putter s container mode does not hold the origin data after composing the put handlers done in base manifest putter they are lost a resumed half done container put can not get the complete file list from base manifest putter is it really necessary to include the file list here manifest element elements simple manifest putter flatten manifest elements fs put single default name default name for int i 0 i elements length i string num integer to string i manifest element e elements i string mime override e get mime type override simple field set subset new simple field set false freeneturi tempuri e get targeturi subset put single name e get name if tempuri null subset put single upload from redirect subset put single targeturi tempuri to string else bucket data e get data if persistence type client request persist forever container activate data 1 if data instanceof delayed free bucket data delayed free bucket data get underlying subset put data length e get size if mime override null subset put single metadata content type mime override what to do with the bucket it is either a persistent encrypted bucket or a file bucket if data null logger error this bucket already freed e get data for e for e get name for identifier else if data instanceof file bucket subset put single upload from disk subset put single filename file bucket data get file get path else if data instanceof padded ephemerally encrypted bucket data instanceof null bucket subset put single upload from direct else throw new illegal state exception don t know what to do with bucket data if persistence type client request persist forever container deactivate data 1 files put num subset files put count elements length fs put files files if token null fs put single client token token fs put started started fs put max retries max retries return fs simplefieldset generatefieldset objectcontainer simplefieldset simplefieldset putsingle putsingle tostring putsingle clientrequest persistencetypestring persistencetype priorityclass priorityclass putsingle tostring putsingle putdirtype wasdiskput simplefieldset simplefieldset basemanifestputter puthandlers basemanifestputter basemanifestputter manifestelement simplemanifestputter manifestelements putsingle defaultname defaultname tostring manifestelement mimeoverride getmimetypeoverride simplefieldset simplefieldset gettargeturi putsingle getname putsingle uploadfrom putsingle tostring getdata persistencetype clientrequest persist_forever delayedfreebucket delayedfreebucket getunderlying datalength getsize mimeoverride putsingle contenttype mimeoverride getdata getname filebucket putsingle uploadfrom putsingle filebucket getfile getpath paddedephemerallyencryptedbucket nullbucket putsingle uploadfrom illegalstateexception persistencetype clientrequest persist_forever putsingle clienttoken maxretries maxretries override public simple field set get field set return cached simplefieldset getfieldset override public string get name return name getname override public void run fcp connection handler handler node node throws message invalid exception throw new message invalid exception protocol error message invalid message persistent put goes from server to client not the other way around identifier global fcpconnectionhandler messageinvalidexception messageinvalidexception protocolerrormessage invalid_message persistentput override public void remove from object container container container activate uri 5 uri remove from container manifest elements will be removed by client put dir free data not our problem container activate cached integer max value cached remove from container container delete this removefrom objectcontainer removefrom manifestelements clientputdir freedata max_value removefrom private final array list thread late jobs public semi ordered shutdown hook early jobs new array list thread late jobs new array list thread arraylist latejobs semiorderedshutdownhook earlyjobs arraylist latejobs arraylist public synchronized void add early job thread r early jobs add r addearlyjob earlyjobs public synchronized void add late job thread r late jobs add r addlatejob latejobs override public void run system err println shutting down first run early jobs all at once and wait for them to all complete for thread r early jobs r start for thread r early jobs try r join timeout catch interrupted exception e may as well move on then run late jobs all at once and wait for them to all complete jvm will exit when we return for thread r late jobs r start for thread r late jobs try r join timeout catch interrupted exception e may as well move on earlyjobs earlyjobs interruptedexception latejobs latejobs interruptedexception void discard int flags if used 0 flags enable segment caching 0 invalidate next null enable_segment_caching protected int flags public int read byte b new byte 1 return read b 0 1 1 b 0 0xff 1 public int read byte b int off int len if pos first size return 1 int rest first size pos if len rest len rest int rc len while len 0 if blob offs curr body length blob impl prev curr curr prev next curr load curr used 1 if prev first prev discard flags blob offs 0 int n len curr body length blob offs curr body length blob offs len system arraycopy curr body blob offs b off n blob offs n off n len n pos n return rc bloboffs blobimpl bloboffs bloboffs bloboffs bloboffs bloboffs public long set position long new pos if new pos pos if new pos pos blob offs blob offs pos new pos return pos int new pos if first curr curr discard flags curr first pos 0 blob offs 0 skip new pos pos return pos setposition newpos newpos newpos bloboffs bloboffs newpos newpos bloboffs newpos public long get position return pos getposition public long size return first size public long skip long offs int rest first size pos if offs rest offs rest int len int offs while len 0 if blob offs curr body length blob impl prev curr curr prev next curr load curr used 1 if prev first prev discard flags blob offs 0 int n len curr body length blob offs curr body length blob offs len pos n len n blob offs n return offs bloboffs blobimpl bloboffs bloboffs bloboffs bloboffs public int available return first size pos public void close curr discard flags if first curr first discard flags curr first null protected blob input stream blob impl first int flags this flags flags this first first first load curr first first used 1 blobinputstream blobimpl public void write int b byte buf new byte 1 buf 0 byte b write buf 0 1 public void write byte b int off int len while len 0 if blob offs curr body length blob impl prev curr if prev next null int length curr body length if flags double segment size 0 length 1 length length length header size 1 header size blob impl next new blob impl curr get storage length curr prev next next modified true else curr prev next curr load curr used 1 if prev first if modified prev store prev discard flags blob offs 0 int n len curr body length blob offs curr body length blob offs len system arraycopy b off curr body blob offs n modified true blob offs n off n len n pos n if pos first size first size pos bloboffs blobimpl double_segment_size headersize headersize blobimpl blobimpl getstorage bloboffs bloboffs bloboffs bloboffs bloboffs public void close if flags truncate last segment 0 blob offs curr body length curr next null byte tmp new byte blob offs system arraycopy curr body 0 tmp 0 blob offs curr body tmp curr store curr discard flags if curr first first store first discard flags first curr null truncate_last_segment bloboffs bloboffs bloboffs public long set position long new pos if new pos pos if new pos pos blob offs blob offs pos new pos return pos int new pos if first curr if modified curr store modified false curr discard flags curr first pos 0 blob offs 0 skip new pos pos return pos setposition newpos newpos newpos bloboffs bloboffs newpos newpos bloboffs newpos public long get position return pos getposition public long size return first size public long skip long offs int rest first size pos if offs rest offs rest int len int offs while len 0 if blob offs curr body length blob impl prev curr curr prev next curr load curr used 1 if prev first if modified prev store modified false prev discard flags blob offs 0 int n len curr body length blob offs curr body length blob offs len pos n len n blob offs n return offs bloboffs blobimpl bloboffs bloboffs bloboffs bloboffs blob output stream blob impl first int flags this flags flags this first first first load first used 1 curr first if flags append 0 skip first size bloboutputstream blobimpl public boolean recursive loading return false recursiveloading public random access input stream get input stream return get input stream 0 randomaccessinputstream getinputstream getinputstream public random access input stream get input stream int flags return new blob input stream this flags randomaccessinputstream getinputstream blobinputstream public random access output stream get output stream return get output stream append randomaccessoutputstream getoutputstream getoutputstream public random access output stream get output stream boolean multisession return get output stream multisession append truncate last segment append randomaccessoutputstream getoutputstream getoutputstream truncate_last_segment public random access output stream get output stream long position boolean multisession random access output stream stream get output stream multisession stream set position position return stream randomaccessoutputstream getoutputstream randomaccessoutputstream getoutputstream setposition public random access output stream get output stream int flags return new blob output stream this flags randomaccessoutputstream getoutputstream bloboutputstream public void deallocate load if size 0 blob impl curr next while curr null curr load blob impl tail curr next curr deallocate curr tail super deallocate blobimpl blobimpl blob impl storage storage int size super storage body new byte size blobimpl blob impl blobimpl public watch global simple field set fs throws message invalid exception enabled fields string to bool fs get enabled true string s fs get verbosity mask if s null try verbosity mask integer parse int s catch number format exception e throw new message invalid exception protocol error message error parsing number e to string null false else verbosity mask integer max value watchglobal simplefieldset messageinvalidexception stringtobool verbositymask verbositymask parseint numberformatexception messageinvalidexception protocolerrormessage error_parsing_number tostring verbositymask max_value override public simple field set get field set simple field set fs new simple field set true fs put enabled enabled fs put verbosity mask verbosity mask return fs simplefieldset getfieldset simplefieldset simplefieldset verbositymask verbositymask override public string get name return name getname override public void run final fcp connection handler handler node node throws message invalid exception handler get reboot client set watch global enabled verbosity mask node client core getfcp server null handler server core client context job runner queue new db job public void run object container container client context context fcp client client handler get forever client container container activate client 1 client set watch global enabled verbosity mask handler server container container deactivate client 1 native thread high priority false fcpconnectionhandler messageinvalidexception getrebootclient setwatchglobal verbositymask clientcore getfcpserver clientcontext jobrunner dbjob objectcontainer clientcontext fcpclient getforeverclient setwatchglobal verbositymask nativethread high_priority public void run object container container client context context fcp client client handler get forever client container container activate client 1 client set watch global enabled verbosity mask handler server container container deactivate client 1 objectcontainer clientcontext fcpclient getforeverclient setwatchglobal verbositymask override public void remove from object container container container delete this removefrom objectcontainer public class null client callback implements client callback public void on failure fetch exception e client getter state object container container ignore nullclientcallback clientcallback onfailure fetchexception clientgetter objectcontainer public void on failure insert exception e base client putter state object container container impossible onfailure insertexception baseclientputter objectcontainer public void on fetchable base client putter state object container container impossible onfetchable baseclientputter objectcontainer public void on generateduri freeneturi uri base client putter state object container container impossible ongenerateduri baseclientputter objectcontainer public void on major progress object container container ignore onmajorprogress objectcontainer public void on success fetch result result client getter state object container container result data free onsuccess fetchresult clientgetter objectcontainer public void on success base client putter state object container container impossible onsuccess baseclientputter objectcontainer protected final linked hash map string sub config configs by prefix public config configs by prefix new linked hash map string sub config linkedhashmap subconfig configsbyprefix configsbyprefix linkedhashmap subconfig public void register sub config sc synchronized this if configs by prefix contains key sc prefix throw new illegal argument exception already registered sc prefix sc configs by prefix put sc prefix sc subconfig configsbyprefix containskey illegalargumentexception configsbyprefix write current config to disk throws io exception public void store do nothing ioexception finished initialization public void finished init do nothing finishedinit public void on register sub config config option o do nothing onregister subconfig fetch all the sub config s used by user facing config thingies public synchronized sub config get configs return configs by prefix values to array new sub config configs by prefix size subconfig subconfig getconfigs configsbyprefix toarray subconfig configsbyprefix public synchronized sub config get string sub config return configs by prefix get sub config subconfig subconfig configsbyprefix subconfig create an image which will have written a distorted text param text the distorted characters return image with the text public buffered image create image string text word renderer word renderer get config get word renderer impl gimpy engine gimpy engine get config get obscurificator impl background producer background producer get config get background impl boolean is border drawn get config is border drawn this width get config get width this height get config get height buffered image bi word renderer render word text width height bi gimpy engine get distorted image bi bi background producer add background bi graphics2d graphics bi create graphics if is border drawn draw box graphics return bi bufferedimage createimage wordrenderer wordrenderer getconfig getwordrendererimpl gimpyengine gimpyengine getconfig getobscurificatorimpl backgroundproducer backgroundproducer getconfig getbackgroundimpl isborderdrawn getconfig isborderdrawn getconfig getwidth getconfig getheight bufferedimage wordrenderer renderword gimpyengine getdistortedimage backgroundproducer addbackground creategraphics isborderdrawn drawbox private void draw box graphics2d graphics color border color get config get border color int border thickness get config get border thickness graphics set color border color if border thickness 1 basic stroke stroke new basic stroke float border thickness graphics set stroke stroke line2d line1 new line2d double 0 0 0 width graphics draw line1 line2d line2 new line2d double 0 0 width 0 graphics draw line2 line2 new line2d double 0 height 1 width height 1 graphics draw line2 line2 new line2d double width 1 height 1 width 1 0 graphics draw line2 drawbox bordercolor getconfig getbordercolor borderthickness getconfig getborderthickness setcolor bordercolor borderthickness basicstroke basicstroke borderthickness setstroke return the text to be drawn public string create text return get config get text producer impl get text createtext getconfig gettextproducerimpl gettext construct a threshold filter public threshold filter this 127 thresholdfilter thresholdfilter construct a threshold filter param t the threshold value public threshold filter int t set lower threshold t set upper threshold t thresholdfilter thresholdfilter setlowerthreshold setupperthreshold set the lower threshold value param lower threshold the threshold value see get lower threshold public void set lower threshold int lower threshold this lower threshold lower threshold lower threshold3 lower threshold 3 lowerthreshold getlowerthreshold setlowerthreshold lowerthreshold lowerthreshold lowerthreshold lowerthreshold3 lowerthreshold get the lower threshold value return the threshold value see set lower threshold public int get lower threshold return lower threshold setlowerthreshold getlowerthreshold lowerthreshold set the upper threshold value param upper threshold the threshold value see get upper threshold public void set upper threshold int upper threshold this upper threshold upper threshold upper threshold3 upper threshold 3 upperthreshold getupperthreshold setupperthreshold upperthreshold upperthreshold upperthreshold upperthreshold3 upperthreshold get the upper threshold value return the threshold value see set upper threshold public int get upper threshold return upper threshold setupperthreshold getupperthreshold upperthreshold set the color to be used for pixels above the upper threshold param white the color see get white public void set white int white this white white getwhite setwhite get the color to be used for pixels above the upper threshold return the color see set white public int get white return white setwhite getwhite set the color to be used for pixels below the lower threshold param black the color see get black public void set black int black this black black getblack setblack set the color to be used for pixels below the lower threshold return the color see set black public int get black return black setblack getblack override public int filterrgb int x int y int rgb int a rgb 0xff000000 int r rgb 16 0xff int g rgb 8 0xff int b rgb 0xff int l r g b if l lower threshold3 return a black else if l upper threshold3 return a white return rgb lowerthreshold3 upperthreshold3 override public string to string return stylize threshold tostring private int tile public shatter filter shatterfilter public void set transition float transition this transition transition settransition public float get transition return transition gettransition public void set distance float distance this distance distance setdistance public float get distance return distance getdistance public void set rotation float rotation this rotation rotation setrotation public float get rotation return rotation getrotation public void set zoom float zoom this zoom zoom setzoom public float get zoom return zoom getzoom public void set start alpha float start alpha this start alpha start alpha setstartalpha startalpha startalpha startalpha public float get start alpha return start alpha getstartalpha startalpha public void set end alpha float end alpha this end alpha end alpha setendalpha endalpha endalpha endalpha public float get end alpha return end alpha getendalpha endalpha public void set centrex float centrex this centrex centrex setcentrex public float get centrex return centrex getcentrex public void set centrey float centrey this centrey centrey setcentrey public float get centrey return centrey getcentrey public void set centre point2d centre this centrex float centre getx this centrey float centre gety setcentre public point2d get centre return new point2d float centrex centrey getcentre public void set iterations int iterations this iterations iterations setiterations public int get iterations return iterations getiterations public void set tile int tile this tile tile settile public int get tile return tile gettile public buffered image filter buffered image src buffered image dst if dst null dst create compatible dest image src null float width float src get width float height float src get height float cx float src get width centrex float cy float src get height centrey float image radius float math sqrt cx cx cy cy buffered image tiles new buffered image iterations int num tiles iterations iterations tile shapes new tile num tiles float rx new float num tiles float ry new float num tiles float rz new float num tiles graphics2d g dst create graphics g draw image src null null random random new random 0 float lastx 0 lasty 0 for int i 0 i num tiles i double angle double i 2 math pi num tiles float x cx width float math cos angle float y cy height float math sin angle g set color color black g set color color gethsb color float angle 1 1 if i 0 rz i 1 tile 2 random next float 1 ry i 1 tile random next float rz i 1 tile random next float general path p new general path p move to cx cy p line to lastx lasty p line to x y p close path shapes i 1 p rectangle r p get bounds r intersect r new rectangle int width int height r lastx x lasty y for int y 0 y iterations y int y1 int height y iterations int y2 int height y 1 iterations for int x 0 x iterations x int i y iterations x int x1 int width x iterations int x2 int width x 1 iterations rx i tile random next float ry i tile random next float rx i 0 ry i 0 rz i tile 2 random next float 1 shape p new rectangle x1 y1 x2 x1 y2 y1 shapes i new tile shapes i shape p shapes i x x1 x2 0 5f shapes i y y1 y2 0 5f shapes i vx width cx x shapes i vy height cy y shapes i w x2 x1 shapes i h y2 y1 for int i 0 i num tiles i float h float i num tiles double angle h 2 math pi float x transition width float math cos angle float y transition height float math sin angle tile tile shapes i rectangle r tile shape get bounds affine transform t g get transform x tile x transition tile vx y tile y transition tile vy g translate x y g translate tile w 0 5f tile h 0 5f g rotate transition rz i g scale float math cos transition rx i float math cos transition ry i g translate tile w 0 5f tile h 0 5f g set color color gethsb color h 1 1 shape clip g get clip g clip tile shape g draw image src 0 0 null g set clip clip g set transform t g dispose return dst bufferedimage bufferedimage bufferedimage createcompatibledestimage getwidth getheight getwidth getheight imageradius bufferedimage bufferedimage numtiles numtiles numtiles numtiles numtiles creategraphics drawimage numtiles numtiles setcolor setcolor gethsbcolor nextfloat nextfloat nextfloat generalpath generalpath moveto lineto lineto closepath getbounds nextfloat nextfloat nextfloat numtiles numtiles getbounds affinetransform gettransform setcolor gethsbcolor getclip drawimage setclip settransform override public string to string return transition shatter tostring public class null long callback extends long callback override public long get return 0l nulllongcallback longcallback override public void set long val throws invalid config value exception ignore invalidconfigvalueexception protected own message messageuri newuri freeneturi new realuri string newid message list new message list messageuri new threaduri messageuri new parenturi set board new boards board new reply to board ft identity new author string new title date new date string new text list attachment new attachments throws invalid parameter exception super newuri new realuri newid new message list new threaduri new parenturi new boards new reply to board new author new title new date new text new attachments ownmessage newrealuri messagelist newmessagelist newthreaduri newparenturi newboards newreplytoboard ftidentity newauthor newtitle newdate newtext newattachments invalidparameterexception newrealuri newmessagelist newthreaduri newparenturi newboards newreplytoboard newauthor newtitle newdate newtext newattachments override for synchronization override public synchronized messageuri geturi return muri generate the insert uri for a message public abstract freeneturi get inserturi getinserturi throws runtime exception if the message was not inserted yet and therefore the real uri is unknown return the chk uri of the message public synchronized freeneturi get realuri if m realuri null throw new runtime exception get realuri called on the not inserted message this return m realuri runtimeexception getrealuri mrealuri runtimeexception getrealuri mrealuri public synchronized void set message list own message list new message list m message list new message list store setmessagelist ownmessagelist newmessagelist mmessagelist newmessagelist public synchronized boolean was inserted return m realuri null wasinserted mrealuri public synchronized void mark as inserted freeneturi my realuri m realuri my realuri store markasinserted myrealuri mrealuri myrealuri static final int segment length 128 1024 public void write long pos byte buf throw new unsupported operation exception zip file write segment_length unsupportedoperationexception zipfile public int read long pos byte buf try int seg int pos segment length zip entry e entries seg int size int e get size if e curr entry input stream in file get input stream e int rc offs 0 while offs size rc in read segment offs size offs 0 offs rc if offs size throw new storage error storage error file access error curr entry e int offs int pos long seg segment length if offs size int len buf length size offs buf length size offs system arraycopy segment offs buf 0 len return len return 0 catch io exception x throw new storage error storage error file access error segment_length zipentry getsize currentry inputstream getinputstream storageerror storageerror file_access_error currentry segment_length ioexception storageerror storageerror file_access_error public void sync public boolean try lock boolean shared return true trylock public void lock boolean shared public void unlock public void close try file close catch io exception x throw new storage error storage error file access error ioexception storageerror storageerror file_access_error public long length return long entries length 1 segment length entries entries length 1 get size segment_length getsize constructor of comressed file param path path to the archieve previously prepared by compress database utility public compressed file string path try file new zip file path int n entries file size entries new zip entry n entries enumeration ee file entries for int i 0 ee has more elements i entries i zip entry ee next element segment new byte segment length curr entry null catch io exception x throw new storage error storage error file access error compressdatabase compressedfile zipfile nentries zipentry nentries hasmoreelements zipentry nextelement segment_length currentry ioexception storageerror storageerror file_access_error public bucket compress bucket data bucket factory bf long max read length long max write length throws io exception compression output size exception if max read length 0 throw new illegal argument exception bucket output bf make bucket max write length input stream is null output stream os null gzip output stream gos null try is data get input stream os new buffered output stream output get output stream counted output stream cos new counted output stream os gos new gzip output stream cos long read 0 bigger input buffer so can compress all at once won t hurt on i o either although most o ss will only return a page at a time byte buffer new byte 32768 while true int l int math min buffer length max read length read int x l 0 1 is read buffer 0 l if x 1 break if x 0 throw new io exception returned zero from read gos write buffer 0 x read x if cos written max write length throw new compression output size exception gos flush finally if is null is close if gos null gos close else if os null os close return output bucketfactory maxreadlength maxwritelength ioexception compressionoutputsizeexception maxreadlength illegalargumentexception makebucket maxwritelength inputstream outputstream gzipoutputstream getinputstream bufferedoutputstream getoutputstream countedoutputstream countedoutputstream gzipoutputstream oss maxreadlength ioexception maxwritelength compressionoutputsizeexception public bucket decompress bucket data bucket factory bf long max length long max check size length bucket preferred throws io exception compression output size exception bucket output if preferred null output preferred else output bf make bucket max length input stream is null output stream os null try is data get input stream os output get output stream decompress is os max length max check size length os close os null is close is null return output finally if is null closer close is if os null closer close os bucketfactory maxlength maxchecksizelength ioexception compressionoutputsizeexception makebucket maxlength inputstream outputstream getinputstream getoutputstream maxlength maxchecksizelength private long decompress input stream is output stream os long max length long max check size bytes throws io exception compression output size exception gzip input stream gis new gzip input stream is long written 0 byte buffer new byte 4096 while true int l int math min buffer length max length written we can over read to determine whether we have over read we enforce maximum size this way fixme there is probably a better way to do this int x gis read buffer 0 buffer length if l x logger normal this l l x x written written max length max length throwing a compression output size exception if max check size bytes 0 written x while true l int math min buffer length max length max check size bytes written x gis read buffer 0 l if x 1 throw new compression output size exception written if x 0 throw new io exception returned zero from read written x throw new compression output size exception if x 1 return written if x 0 throw new io exception returned zero from read os write buffer 0 x written x inputstream outputstream maxlength maxchecksizebytes ioexception compressionoutputsizeexception gzipinputstream gzipinputstream maxlength maxlength maxlength compressionoutputsizeexception maxchecksizebytes maxlength maxchecksizebytes compressionoutputsizeexception ioexception compressionoutputsizeexception ioexception public int decompress byte dbuf int i int j byte output throws compression output size exception didn t work with inflater fixme fix sometimes to use inflater format issue byte array input stream bais new byte array input stream dbuf i j byte array output stream baos new byte array output stream output length int bytes 0 try bytes int decompress bais baos output length 1 catch io exception e impossible throw new error got io exception e get message e byte buf baos to byte array system arraycopy buf 0 output 0 bytes return bytes compressionoutputsizeexception bytearrayinputstream bytearrayinputstream bytearrayoutputstream bytearrayoutputstream ioexception ioexception getmessage tobytearray public static final semaphore compressor semaphore new semaphore get max running compression threads public real compressor executor e this exec e compressorsemaphore getmaxrunningcompressionthreads realcompressor public void set client context client context context this context context setclientcontext clientcontext public int get priority return native thread high priority getpriority nativethread high_priority public synchronized void enqueue new job compress job j awaitingjobs add j if logger should log logger minor this logger minor this enqueueing compression job j notify all enqueuenewjob compressjob _awaitingjobs shouldlog notifyall public void run logger normal this starting real compressor while true compress job current job null try synchronized this current job awaitingjobs poll if current job null wait continue compressor semaphore acquire catch interrupted exception e logger error this caught e get message e continue final compress job final job current job exec execute new prio runnable public void run freenet support logger os thread logpid this try try final job try compress context catch insert exception e final job on failure e null context catch out of memory error e oom handler handleoom e system err println off thread compressor thread above failed might not be heap so try anyway final job on failure new insert exception insert exception internal error e null null context catch throwable t logger error this caught in off thread compressor t t system err println caught in off thread compressor t t print stack trace try to fail gracefully final job on failure new insert exception insert exception internal error t null null context catch throwable t logger error this caught t in this t finally compressor semaphore release public int get priority return native thread min priority compressor thread for current job realcompressor compressjob currentjob currentjob _awaitingjobs currentjob compressorsemaphore interruptedexception getmessage compressjob finaljob currentjob priorunnable osthread finaljob trycompress insertexception finaljob onfailure outofmemoryerror oomhandler offthreadcompressor finaljob onfailure insertexception insertexception internal_error offthreadcompressor offthreadcompressor printstacktrace finaljob onfailure insertexception insertexception internal_error compressorsemaphore getpriority nativethread min_priority currentjob exec execute new prio runnable public void run freenet support logger os thread logpid this try try final job try compress context catch insert exception e final job on failure e null context catch out of memory error e oom handler handleoom e system err println off thread compressor thread above failed might not be heap so try anyway final job on failure new insert exception insert exception internal error e null null context catch throwable t logger error this caught in off thread compressor t t system err println caught in off thread compressor t t print stack trace try to fail gracefully final job on failure new insert exception insert exception internal error t null null context catch throwable t logger error this caught t in this t finally compressor semaphore release priorunnable osthread finaljob trycompress insertexception finaljob onfailure outofmemoryerror oomhandler offthreadcompressor finaljob onfailure insertexception insertexception internal_error offthreadcompressor offthreadcompressor printstacktrace finaljob onfailure insertexception insertexception internal_error compressorsemaphore public int get priority return native thread min priority getpriority nativethread min_priority public boolean object can new object container container logger error this not storing real compressor in database new exception error return false objectcannew objectcontainer realcompressor private static int get max running compression threads int max running threads 1 string os name system get property os name if os name index of windows 1 os name to lower case index of mac os x 0 native thread using native code os x niceness is really weak so we don t want any more background cpu load than necessary also on non windows we need the native threads library to be working max running threads 1 else most other o ss will have reasonable niceness so go by ram runtime r runtime get runtime int max r available processors fixme this may change in a vm poll it long max memory r max memory if max memory 128 1024 1024 max 1 else one compressor thread per 128mb of ram available core max math min max int math min integer max value max memory 128 1024 1024 max running threads max logger minor real compressor class maximum compressor threads max running threads return max running threads getmaxrunningcompressionthreads maxrunningthreads osname getproperty osname indexof osname tolowercase indexof nativethread usingnativecode maxrunningthreads oss getruntime availableprocessors maxmemory maxmemory maxmemory max_value maxmemory maxrunningthreads realcompressor maxrunningthreads maxrunningthreads public final class exclusion composite extends rgb composite public exclusion composite float alpha super alpha exclusioncomposite rgbcomposite exclusioncomposite public composite context create context color model src color model color model dst color model rendering hints hints return new context extra alpha src color model dst color model compositecontext createcontext colormodel srccolormodel colormodel dstcolormodel renderinghints extraalpha srccolormodel dstcolormodel static class context extends rgb composite context public context float alpha color model src color model color model dst color model super alpha src color model dst color model rgbcompositecontext colormodel srccolormodel colormodel dstcolormodel srccolormodel dstcolormodel override public void composergb int src int dst float alpha int w src length for int i 0 i w i 4 int sr src i int dir dst i int sg src i 1 int dig dst i 1 int sb src i 2 int dib dst i 2 int sa src i 3 int dia dst i 3 int dor dog dob dor dir multiply255 sr 255 dir dir dog dig multiply255 sg 255 dig dig dob dib multiply255 sb 255 dib dib float a alpha sa 255f float ac 1 a dst i int a dor ac dir dst i 1 int a dog ac dig dst i 2 int a dob ac dib dst i 3 int sa alpha dia ac public warp grid int rows int cols int w int h this rows rows this cols cols x grid new float rows cols y grid new float rows cols int index 0 for int row 0 row rows row for int col 0 col cols col x grid index float col w 1 cols 1 y grid index float row h 1 rows 1 index warpgrid xgrid ygrid xgrid ygrid add a new row to the grid before must be in the range 1 rows 1 i e you can only add rows inside the grid public void add row int before int size rows 1 cols float x new float size float y new float size rows int i 0 int j 0 for int row 0 row rows row for int col 0 col cols col int k j col int l i col if row before x k x grid l x grid k 2 y k y grid l y grid k 2 else x k x grid l y k y grid l if row before 1 i cols j cols x grid x y grid y addrow xgrid xgrid ygrid ygrid xgrid ygrid xgrid ygrid add a new column to the grid before must be in the range 1 cols 1 i e you can only add columns inside the grid public void add col int before int size rows cols 1 float x new float size float y new float size cols int i 0 int j 0 for int row 0 row rows row int i row cols 1 int j row cols for int col 0 col cols col if col before x j x grid i x grid i 1 2 y j y grid i y grid i 1 2 else x j x grid i y j y grid i i j x grid x y grid y addcol xgrid xgrid ygrid ygrid xgrid ygrid xgrid ygrid remove a row from the grid public void remove row int r int size rows 1 cols float x new float size float y new float size rows int i 0 int j 0 for int row 0 row rows row for int col 0 col cols col int k j col int l i col x k x grid l y k y grid l if row r 1 i cols i cols j cols x grid x y grid y removerow xgrid ygrid xgrid ygrid remove a column from the grid public void remove col int r int size rows cols 1 float x new float size float y new float size cols for int row 0 row rows row int i row cols 1 int j row cols for int col 0 col cols col x j x grid i y j y grid i if col r 1 i i j x grid x y grid y removecol xgrid ygrid xgrid ygrid public void lerp float t warp grid destination warp grid intermediate if rows destination rows cols destination cols throw new illegal argument exception source and destination are different sizes if rows intermediate rows cols intermediate cols throw new illegal argument exception source and intermediate are different sizes int index 0 for int row 0 row rows row for int col 0 col cols col intermediate x grid index float image math lerp t x grid index destination x grid index intermediate y grid index float image math lerp t y grid index destination y grid index index warpgrid warpgrid illegalargumentexception illegalargumentexception xgrid imagemath xgrid xgrid ygrid imagemath ygrid ygrid public void warp int in pixels int cols int rows warp grid source grid warp grid dest grid int out pixels try int x y int u v int intermediate warp grid splines if source grid rows dest grid rows source grid cols dest grid cols throw new illegal argument exception source and destination grids are different sizes int size math max cols rows float xrow new float size float yrow new float size float scale new float size 1 float interpolated new float size 1 int grid cols source grid cols int grid rows source grid rows splines new warp grid rows grid cols 1 1 for u 0 u grid cols u int i u for v 0 v grid rows v xrow v source grid x grid i yrow v source grid y grid i i grid cols interpolate spline yrow xrow 0 grid rows interpolated 0 rows i u for y 0 y rows y splines x grid i interpolated y i grid cols for u 0 u grid cols u int i u for v 0 v grid rows v xrow v dest grid x grid i yrow v dest grid y grid i i grid cols interpolate spline yrow xrow 0 grid rows interpolated 0 rows i u for y 0 y rows y splines y grid i interpolated y i grid cols first pass warp x using splines intermediate new int rows cols int offset 0 for y 0 y rows y fit spline to x intercepts resample over all cols interpolate spline splines x grid splines y grid offset grid cols scale 0 cols scale cols cols image math resample in pixels intermediate cols y cols 1 scale offset grid cols create table of y intercepts for intermediate mesh s hor splines splines new warp grid grid rows cols 1 1 offset 0 int offset2 0 for v 0 v grid rows v interpolate spline source grid x grid source grid y grid offset grid cols splines x grid offset2 cols offset grid cols offset2 cols offset 0 offset2 0 for v 0 v grid rows v interpolate spline dest grid x grid dest grid y grid offset grid cols splines y grid offset2 cols offset grid cols offset2 cols second pass warp y for x 0 x cols x int i x for v 0 v grid rows v xrow v splines x grid i yrow v splines y grid i i cols interpolate spline xrow yrow 0 grid rows scale 0 rows scale rows rows image math resample intermediate out pixels rows x cols scale catch exception e e print stack trace inpixels warpgrid sourcegrid warpgrid destgrid outpixels warpgrid sourcegrid destgrid sourcegrid destgrid illegalargumentexception gridcols sourcegrid gridrows sourcegrid warpgrid gridcols gridcols gridrows sourcegrid xgrid sourcegrid ygrid gridcols interpolatespline gridrows xgrid gridcols gridcols gridrows destgrid xgrid destgrid ygrid gridcols interpolatespline gridrows ygrid gridcols interpolatespline xgrid ygrid gridcols imagemath inpixels gridcols warpgrid gridrows gridrows interpolatespline sourcegrid xgrid sourcegrid ygrid gridcols xgrid gridcols gridrows interpolatespline destgrid xgrid destgrid ygrid gridcols ygrid gridcols gridrows xgrid ygrid interpolatespline gridrows imagemath outpixels printstacktrace protected void interpolate spline float x knots float y knots int offset int length float spliney int spline offset int spline length int index offset int end offset length 1 float x0 x1 float k0 k1 k2 k3 float c0 c1 c2 c3 x0 x knots index k0 k1 k2 y knots index x1 x knots index 1 k3 y knots index 1 for int i 0 i spline length i if index end i x knots index k0 k1 k1 k2 k2 k3 x0 x knots index index if index end x1 x knots index if index end k3 y knots index 1 else k3 k2 float t i x0 x1 x0 c3 m00 k0 m01 k1 m02 k2 m03 k3 c2 m10 k0 m11 k1 m12 k2 m13 k3 c1 m20 k0 m22 k2 c0 m31 k1 spliney spline offset i c3 t c2 t c1 t c0 interpolatespline xknots yknots splineoffset splinelength xknots yknots xknots yknots splinelength xknots xknots xknots yknots splineoffset protected void interpolate spline2 float x knots float y knots int offset float spliney int spline offset int spline length int index offset float leftx rightx float lefty righty leftx x knots index lefty y knots index rightx x knots index 1 righty y knots index 1 for int i 0 i spline length i if i x knots index leftx x knots index lefty y knots index index rightx x knots index righty y knots index float f i leftx rightx leftx spliney spline offset i lefty f righty lefty interpolatespline2 xknots yknots splineoffset splinelength xknots yknots xknots yknots splinelength xknots xknots yknots xknots yknots splineoffset suppress warnings deprecation public void set up throws exception super set up hash set board my boards1 new hash set board my boards1 add new board en board1 my boards1 add new board en board2 hash set board my boards2 new hash set board my boards2 add new board en board3 my boards2 add new board en board4 hash set board my boards3 new hash set board my boards3 add new board en board5 my boards3 add new board en board6 freeneturi author requestssk new freeneturi ssk nu16tncs7 isp ta9gw6nf8c3l qpjgfha2 kwt tom ju nk fj cioug sl6ipoe9gl nai9w cp1vpm8k181 gjw62 hhy so aqacaae freeneturi author insertssk new freeneturi ssk ykhv0x0k8jtrg olqwvs4s2 jvmnm64zv5vo nj mfz1nyi fj cioug sl6ipoe9gl nai9w cp1vpm8k181 gjw62 hhy so aqecaae string authorid wot identity getuid fromuri author requestssk wot own identity my author new wot own identity authorid author requestssk author insertssk nickname m message manager new wot message manager db null m messages new wot own message m message manager post message null my boards1 null my author title1 new date 2009 1900 06 1 01 text1 null m message manager post message null my boards2 null my author title2 new date 2008 1900 05 1 02 text2 null m message manager post message null my boards3 null my author title3 new date 2007 1900 04 1 03 text3 null freeneturi messageur is new freeneturi new freeneturi chk 7qms7 lkly ihbz88i0 u97lxrlks2ux nwzwq oj pd xn jw ila f sjww2mp wlz wx7 fgp zbb er yd lkqie1u srcn lbm aaia 8 new freeneturi chk 0yut4b eorqjcet qrl sgh bcw5rl7kq nm6 fbpo3 thz ty4 6 rzuh23 twpq0id qcg poxeyx7yb tgt nydd uj0i9dtq aaia 8 new freeneturi chk h4nfd tqgquq0 ckd pzvrs2f i ikjo cnf en s042j uxuw wk cr ktmvmy qzuo3f4v2 jlb87w jkk0dspmgj ivztyp8 aaia 8 m message list new wot own message list my author 123 m message list initialize transient db m message manager for int i 0 i m messages length i m messages i mark as inserted messageur is i m message list add message m messages i m hardcoded encoded message list new string xml version 1 0 encoding utf 8 standalone no freetalk testing message list version 1 message date 2009 06 01 id m messages 0 getid uri chk 7qms7 lkly ihbz88i0 u97lxrlks2ux nwzwq oj pd xn jw ila f sjww2mp wlz wx7 fgp zbb er yd lkqie1u srcn lbm aaia 8 board name en board1 board name en board2 message message date 2008 05 02 id m messages 1 getid uri chk 0yut4b eorqjcet qrl sgh bcw5rl7kq nm6 fbpo3 thz ty4 6 rzuh23 twpq0id qcg poxeyx7yb tgt nydd uj0i9dtq aaia 8 board name en board3 board name en board4 message message date 2007 04 03 id m messages 2 getid uri chk h4nfd tqgquq0 ckd pzvrs2f i ikjo cnf en s042j uxuw wk cr ktmvmy qzuo3f4v2 jlb87w jkk0dspmgj ivztyp8 aaia 8 board name en board5 board name en board6 message message list freetalk testing suppresswarnings setup setup hashset myboards1 hashset myboards1 myboards1 hashset myboards2 hashset myboards2 myboards2 hashset myboards3 hashset myboards3 myboards3 authorrequestssk ispta9gw6nf8c3lqpjgfha2kwttomjunk fjciougsl6ipoe9glnai9wcp1vpm8k181gjw62hhyso authorinsertssk ykhv0x0k8jtrgolqwvs4s2jvmnm64zv5vonjmfz1nyi fjciougsl6ipoe9glnai9wcp1vpm8k181gjw62hhyso wotidentity getuidfromuri authorrequestssk wotownidentity myauthor wotownidentity authorrequestssk authorinsertssk mmessagemanager wotmessagemanager mmessages wotownmessage mmessagemanager postmessage myboards1 myauthor mmessagemanager postmessage myboards2 myauthor mmessagemanager postmessage myboards3 myauthor messageuris 7qms7lklyihbz88i0 u97lxrlks2uxnwzwqojpdxnjw fsjww2mpwlzwx7fgpzbberydlkqie1usrcn 0yut4beorqjcetqrlsghbcw5rl7kqnm6fbpo3thzty4 6rzuh23 twpq0idqcgpoxeyx7ybtgtnydd h4nfdtqgquq0ckdpzvrs2f iikjocnfen s042juxuw wkcrktmvmyqzuo3f4v2jlb87wjkk0dspmgj mmessagelist wotownmessagelist myauthor mmessagelist initializetransient mmessagemanager mmessages mmessages markasinserted messageuris mmessagelist addmessage mmessages mhardcodedencodedmessagelist messagelist mmessages 7qms7lklyihbz88i0 u97lxrlks2uxnwzwqojpdxnjw fsjww2mpwlzwx7fgpzbberydlkqie1usrcn mmessages 0yut4beorqjcetqrlsghbcw5rl7kqnm6fbpo3thzty4 6rzuh23 twpq0idqcgpoxeyx7ybtgtnydd mmessages h4nfdtqgquq0ckdpzvrs2f iikjocnfen s042juxuw wkcrktmvmyqzuo3f4v2jlb87wjkk0dspmgj messagelist public void test encode throws transformer exception parser configuration exception no such message exception byte array output stream encoded message list new byte array output stream 4096 wot message listxml encode m message manager m message list encoded message list assert equals m hardcoded encoded message list encoded message list to string replace all r n testencode transformerexception parserconfigurationexception nosuchmessageexception bytearrayoutputstream encodedmessagelist bytearrayoutputstream wotmessagelistxml mmessagemanager mmessagelist encodedmessagelist assertequals mhardcodedencodedmessagelist encodedmessagelist tostring replaceall public void test decode throws exception byte array input stream is new byte array input stream m hardcoded encoded message list get bytes wot message list decoded list wot message listxml decode m message manager m message list get author m message list geturi is store the list of boards for each test message multi value table wot own message string message boards new multi value table wot own message string 2 m messages length for wot own message m m messages for board b m get boards message boards put m b get name now we check every message reference we receive from the decoded xml for each seen message board pair we remove that pair from the message boards table if the table is empty at the end the xml decoding has not dropped any of the pairs for message list message reference ref decoded list wot own message message wot own message m message manager get own message ref get messageid assert true a board was listed in the message list multiple times ref get board get name message boards contains element message ref get board get name message boards remove element message ref get board get name assert true not all boards or messages were specified in the message list message boards is empty testdecode bytearrayinputstream bytearrayinputstream mhardcodedencodedmessagelist getbytes wotmessagelist decodedlist wotmessagelistxml mmessagemanager mmessagelist getauthor mmessagelist multivaluetable wotownmessage messageboards multivaluetable wotownmessage mmessages wotownmessage mmessages getboards messageboards getname messageboards messagelist messagereference decodedlist wotownmessage wotownmessage mmessagemanager getownmessage getmessageid asserttrue getboard getname messageboards containselement getboard getname messageboards removeelement getboard getname asserttrue messageboards isempty public class jsql null pointer exception extends jsql runtime exception constructor of exception param target class of the target object in which field was not found param field name name of the locate field public jsql null pointer exception class target string field name super dereferencing null reference target field name jsqlnullpointerexception jsqlruntimeexception fieldname jsqlnullpointerexception fieldname fieldname public boolean has next boolean result if next null collection shared lock if iterator has next next iterator next result true else result false collection unlock else result true return result hasnext sharedlock hasnext public t next t obj next if obj null collection shared lock obj iterator next collection unlock else next null return obj sharedlock public thread safe iterator i resource collection iterator t iterator this collection collection this iterator iterator threadsafeiterator iresource public void remove collection exclusive lock iterator remove collection unlock next null exclusivelock override protected float transfer function float f f image math gain f gain f image math bias f bias return f transferfunction imagemath imagemath set the gain param gain the gain min value 0 max value 1 see get gain public void set gain float gain this gain gain initialized false getgain setgain get the gain return the gain see set gain public float get gain return gain setgain getgain set the bias param bias the bias min value 0 max value 1 see get bias public void set bias float bias this bias bias initialized false getbias setbias get the bias return the bias see set bias public float get bias return bias setbias getbias override public string to string return colors gain tostring private short compression algorithm 1 public clientssk block byte data byte headers clientssk key boolean dont verify throws ssk verify exception super data headers nodessk key get node key dont verify this key key compressionalgorithm clientsskblock dontverify sskverifyexception getnodekey dontverify public static clientssk block construct ssk block block clientssk key throws ssk verify exception constructor expects clientkey to have the pubkey in the case of binary blobs the block may have it instead if key get pub key null key set public key block get pub key return new clientssk block block data block headers key false clientsskblock sskblock sskverifyexception getpubkey setpublickey getpubkey clientsskblock decode the data public bucket decode bucket factory factory int max length boolean dont decompress throws key decode exception io exception we know the signature is valid because it is checked in the constructor we also know e h docname is valid byte decrypted headers new byte encrypted headers length system arraycopy headers headers offset decrypted headers 0 encrypted headers length rijndael aes try logger minor this crypto algorithm key crypto algorithm for get client key geturi aes new rijndael 256 256 catch unsupported cipher exception e throw new error e aes initialize key crypto key pcfb mode pcfb pcfb mode create aes ecb encrypted e h docname serves as iv pcfb reset key eh docname pcfb block decipher decrypted headers 0 decrypted headers length first 32 bytes are the key byte data decrypt key new byte data decrypt key length system arraycopy decrypted headers 0 data decrypt key 0 data decrypt key length aes initialize data decrypt key byte data output new byte data length system arraycopy data 0 data output 0 data length data decrypt key should be unique so use it as iv pcfb reset data decrypt key pcfb block decipher data output 0 data output length 2 bytes data length int data length decrypted headers data decrypt key length 0xff 8 decrypted headers data decrypt key length 1 0xff metadata flag is top bit if data length 32768 0 data length data length 32768 is metadata true if data length data length throw new ssk decode exception data length data length but data length data length compression algorithm short decrypted headers data decrypt key length 2 0xff 8 decrypted headers data decrypt key length 3 0xff decoded true if dont decompress return bucket tools make immutable bucket factory data output data length bucket b key decompress compression algorithm 0 data output data length factory math min max decompressed data length max length compression algorithm true return b bucketfactory maxlength dontdecompress keydecodeexception ioexception decryptedheaders encrypted_headers_length headersoffset decryptedheaders encrypted_headers_length cryptoalgorithm cryptoalgorithm getclientkey unsupportedcipherexception cryptokey pcfbmode pcfbmode ehdocname blockdecipher decryptedheaders decryptedheaders datadecryptkey data_decrypt_key_length decryptedheaders datadecryptkey data_decrypt_key_length datadecryptkey dataoutput dataoutput datadecryptkey blockdecipher dataoutput dataoutput datalength decryptedheaders data_decrypt_key_length decryptedheaders data_decrypt_key_length datalength datalength datalength ismetadata datalength sskdecodeexception datalength compressionalgorithm decryptedheaders data_decrypt_key_length decryptedheaders data_decrypt_key_length dontdecompress buckettools makeimmutablebucket dataoutput datalength compressionalgorithm dataoutput datalength max_decompressed_data_length maxlength compressionalgorithm public boolean is metadata if decoded throw new illegal state exception cannot read is metadata before decoded return is metadata ismetadata illegalstateexception ismetadata ismetadata public client key get client key return key clientkey getclientkey public short get compression codec return compression algorithm getcompressioncodec compressionalgorithm public byte memory decode throws key decode exception return memory decode false memorydecode keydecodeexception memorydecode decode into ram if short throws key decode exception public byte memory decode boolean dont decompress throws key decode exception try array bucket a array bucket decode new array bucket factory 32 1024 dont decompress return bucket tools to byte array a fixme catch io exception e throw new error e keydecodeexception memorydecode dontdecompress keydecodeexception arraybucket arraybucket arraybucketfactory dontdecompress buckettools tobytearray ioexception override public int hash code return super hash code key hash code hashcode hashcode hashcode override public boolean equals object o if o instanceof clientssk block return false clientssk block block clientssk block o if key equals block key return false return super equals o clientsskblock clientsskblock clientsskblock param base image the base image return an image with a gradient background added to the base image public buffered image add background buffered image base image color color from get config get background color from color color to get config get background color to int width base image get width int height base image get height create an opaque image buffered image image with background new buffered image width height buffered image type int rgb graphics2d graph graphics2d image with background get graphics rendering hints hints new rendering hints rendering hints key antialiasing rendering hints value antialias off hints add new rendering hints rendering hints key color rendering rendering hints value color render quality hints add new rendering hints rendering hints key alpha interpolation rendering hints value alpha interpolation quality hints add new rendering hints rendering hints key rendering rendering hints value render quality graph set rendering hints hints gradient paint paint new gradient paint 0 0 color from width height color to graph set paint paint graph fill new rectangle2d double 0 0 width height draw the transparent image over the background graph draw image base image 0 0 null return image with background baseimage bufferedimage addbackground bufferedimage baseimage colorfrom getconfig getbackgroundcolorfrom colorto getconfig getbackgroundcolorto baseimage getwidth baseimage getheight bufferedimage imagewithbackground bufferedimage bufferedimage type_int_rgb imagewithbackground getgraphics renderinghints renderinghints renderinghints key_antialiasing renderinghints value_antialias_off renderinghints renderinghints key_color_rendering renderinghints value_color_render_quality renderinghints renderinghints key_alpha_interpolation renderinghints value_alpha_interpolation_quality renderinghints renderinghints key_rendering renderinghints value_render_quality setrenderinghints gradientpaint gradientpaint colorfrom colorto setpaint drawimage baseimage imagewithbackground long created public info system created system current time millis 10 infosystem currenttimemillis public string getsnmpoid int index switch index case 0 ucd snmp mib mem total real 0 return 1 3 6 1 4 1 2021 4 5 0 case 1 ucd snmp mib mem avail real 0 return 1 3 6 1 4 1 2021 4 6 0 case 2 snm pv2 mib sys name 0 return 1 3 6 1 2 1 1 5 0 case 3 snm pv2 mib sys up time 0 return 1 3 6 1 2 1 1 3 0 case 4 ucd snmp mib mem total real 0 return 1 3 6 1 4 1 2021 4 5 case 5 ucd snmp mib mem avail real 0 return 1 3 6 1 4 1 2021 4 6 default return null memtotalreal memavailreal snmpv2 sysname snmpv2 sysuptime memtotalreal memavailreal public object getsnmp data string oid runtime r runtime get runtime system err println requesting oid if oid equals 1 3 6 1 2 1 1 3 0 snm pv2 mib sys up time 0 return new snmp time ticks system current time millis 10 created if oid equals 1 3 6 1 4 1 2021 4 5 0 ucd snmp mib mem total real 0 return new snmp integer32 r total memory if oid equals 1 3 6 1 4 1 2021 4 6 0 ucd snmp mib mem avail real 0 return new snmp integer32 r free memory if oid equals 1 3 6 1 2 1 1 5 0 snm pv2 mib sys name 0 return version node name version node version version build number if oid equals 1 3 6 1 4 1 2021 4 5 ucd snmp mib mem total real 0 return new snmp integer32 r total memory if oid equals 1 3 6 1 4 1 2021 4 6 ucd snmp mib mem avail real 0 return new snmp integer32 r free memory return null getsnmpdata getruntime snmpv2 sysuptime snmptimeticks currenttimemillis memtotalreal snmpinteger32 totalmemory memavailreal snmpinteger32 freememory snmpv2 sysname nodename nodeversion buildnumber memtotalreal snmpinteger32 totalmemory memavailreal snmpinteger32 freememory renders a word to an image param word the word to be rendered param width the width of the image to be created param height the height of the image to be created return the buffered image created from the word public buffered image render word string word int width int height int font size get config get text producer font size font fonts get config get text producer fonts font size color color get config get text producer font color buffered image image new buffered image width height buffered image type int argb graphics2d g2d image create graphics g2d set color color rendering hints hints new rendering hints rendering hints key antialiasing rendering hints value antialias on hints add new rendering hints rendering hints key rendering rendering hints value render quality g2d set rendering hints hints font render context frc g2d get font render context random random new random int start posx width 2 word length int start posy height font size 5 font size char word chars word to char array for int i 0 i word chars length i font chosen font fonts random next int fonts length g2d set font chosen font char char to draw new char word chars i glyph vector gv chosen font create glyph vector frc char to draw double char width gv get visual bounds get width g2d draw chars char to draw 0 char to draw length start posx start posy start posx start posx int char width 2 return image bufferedimage bufferedimage renderword fontsize getconfig gettextproducerfontsize getconfig gettextproducerfonts fontsize getconfig gettextproducerfontcolor bufferedimage bufferedimage bufferedimage type_int_argb creategraphics setcolor renderinghints renderinghints renderinghints key_antialiasing renderinghints value_antialias_on renderinghints renderinghints key_rendering renderinghints value_render_quality setrenderinghints fontrendercontext getfontrendercontext startposx startposy fontsize fontsize wordchars tochararray wordchars chosenfont nextint setfont chosenfont chartodraw wordchars glyphvector chosenfont createglyphvector chartodraw charwidth getvisualbounds getwidth drawchars chartodraw chartodraw startposx startposy startposx startposx charwidth public modify peer note simple field set fs this fs fs identifier fs get identifier fs remove value identifier modifypeernote simplefieldset removevalue override public simple field set get field set return new simple field set true simplefieldset getfieldset simplefieldset override public string get name return name getname override public void run fcp connection handler handler node node throws message invalid exception if handler has full access throw new message invalid exception protocol error message access denied modify peer note requires full access identifier false string node identifier fs get node identifier if node identifier null throw new message invalid exception protocol error message missing field error node identifier field missing identifier false peer node pn node get peer node node identifier if pn null fcp message msg new unknown node identifier message node identifier identifier handler output handler queue msg return if pn instanceof darknet peer node throw new message invalid exception protocol error message darknet only modify peer note only available for darknet peers identifier false darknet peer node dpn darknet peer node pn int peer note type try peer note type fs get int peer note type catch fs parse exception e throw new message invalid exception protocol error message invalid field error parsing peer note type field e get message identifier false string encoded note text fs get note text if encoded note text null throw new message invalid exception protocol error message missing field error note text field missing identifier false string note text fixme this should be generalized for multiple peer notes per peer after peer node is similarly generalized try note text new string base64 decode encoded note text catch illegal base64 exception e logger error this bad base64 encoding when decoding a fcp received private darknet comment simple field set e return if peer note type node peer note type private darknet comment dpn set private darknet comment note note text else fcp message msg new unknown peer note type message peer note type identifier handler output handler queue msg return handler output handler queue new peer note node identifier note text peer note type identifier fcpconnectionhandler messageinvalidexception hasfullaccess messageinvalidexception protocolerrormessage access_denied modifypeernote nodeidentifier nodeidentifier nodeidentifier messageinvalidexception protocolerrormessage missing_field nodeidentifier peernode getpeernode nodeidentifier fcpmessage unknownnodeidentifiermessage nodeidentifier outputhandler darknetpeernode messageinvalidexception protocolerrormessage darknet_only modifypeernote darknetpeernode darknetpeernode peernotetype peernotetype getint peernotetype fsparseexception messageinvalidexception protocolerrormessage invalid_field peernotetype getmessage encodednotetext notetext encodednotetext messageinvalidexception protocolerrormessage missing_field notetext notetext peernode notetext encodednotetext illegalbase64exception simplefieldset peernotetype peer_note_type_private_darknet_comment setprivatedarknetcommentnote notetext fcpmessage unknownpeernotetypemessage peernotetype outputhandler outputhandler peernote nodeidentifier notetext peernotetype override public void remove from object container container throw new unsupported operation exception removefrom objectcontainer unsupportedoperationexception private static final string svn revision custom static string get svn revision return svn revision svnrevision getsvnrevision svnrevision get a list of fields which the database should create an index on public static string get indexed fields return new string m name getindexedfields mname public static string get board message link indexed fields todo ugly find a better way return new string m board m message m message index getboardmessagelinkindexedfields mboard mmessage mmessageindex public static string get allowed language codes return locale getiso languages getallowedlanguagecodes getisolanguages create a board you have to store it yourself after creation param new name the name of the board for restrictions see code is name valid code throws invalid parameter exception if none or an invalid name is given public board string new name throws invalid parameter exception if new name null new name length 0 throw new illegal argument exception empty board name if is name valid new name throw new invalid parameter exception board names have to be either in english or have an iso language code at the beginning followed by a dot fixme validate name and description m name new name to lower case m first seen date current timeutc get m latest message date null newname isnamevalid invalidparameterexception newname invalidparameterexception newname newname illegalargumentexception isnamevalid newname invalidparameterexception mname newname tolowercase mfirstseendate currenttimeutc mlatestmessagedate has to be used after loading a ft board object from the database to initialize the transient fields public void initialize transient ext object container mydb message manager my message manager assert mydb null assert my message manager null db mydb m message manager my message manager ftboard initializetransient extobjectcontainer messagemanager mymessagemanager mymessagemanager mmessagemanager mymessagemanager store this object in the database you have to initialize transient before public synchronized void store fixme check for duplicates synchronized db lock if db ext is stored this db ext is active this throw new runtime exception trying to store a non active board object db store this db commit initializetransient isstored isactive runtimeexception check if a board name is valid board names are required to begin with a known language code and may not contain any blacklisted characters formatting characters must be properly paired within each part of the name special formatting characters may be needed e g for some arabic or hebrew group names to be displayed properly public static boolean is name valid string name paranoia checks if name null name length 0 return false check maximum length if name length max boardname text length return false check for illegal characters if string validity checker contains no linebreaks name string validity checker contains no invalid characters name string validity checker contains no control characters name string validity checker contains noidn blacklist characters name return false for character c name to char array if disallowed name characters index of c 1 return false check for invalid formatting characters each dot separated part of the input string must be valid on its own string parts name split if parts length 2 return false for int i 0 i parts length i if parts i length 0 string validity checker contains no invalid formatting parts i return false first part of name must be a recognized language code return iso languages contains parts 0 isnamevalid max_boardname_text_length stringvaliditychecker containsnolinebreaks stringvaliditychecker containsnoinvalidcharacters stringvaliditychecker containsnocontrolcharacters stringvaliditychecker containsnoidnblacklistcharacters tochararray disallowed_name_characters indexof stringvaliditychecker containsnoinvalidformatting isolanguages return the name public string get name return m name getname mname public date get first seen date return m first seen date getfirstseendate mfirstseendate public synchronized date get latest message date return m latest message date getlatestmessagedate mlatestmessagedate public synchronized string get description ft own identity viewer fixme implement return getdescription ftownidentity compare boards by comparing their names provided so we can sort an array of boards public int compare to board b return get name compare to b get name compareto getname compareto getname called by the code ft message manager code to add a just received message to the board the job for this function is to find the right place in the thread tree for the new message and to move around older messages if a parent message of them is received public synchronized void add message message new message synchronized m message manager if new message instanceof own message we do not add the message to the boards it is posted to because the user should only see the message if it has been downloaded successfully this helps the user to spot problems if he does not see his own messages we can hope that he reports a bug throw new illegal argument exception adding own messages to a board is not allowed new message initialize transient db m message manager new message store synchronized board message link class new board message link this new message get free message index store db if new message is thread message parent thread null try parent thread find parent thread new message get message new message set thread parent thread catch no such message exception e try new message set parent m message manager get new message get parentid todo this allows crossposting figure out whether we need to handle it specially catch no such message exception e the message is an orphan if parent thread null the message is an absolute orphan fixme the message manager should try to download the parent message if it s poster has enough trust if it is programmed to do that it will check its hashtable whether the parent message already exists we also do that here therefore when implementing parent message downloading please do the hashtable checking only once link orphans to new parent new message if m latest message date null new message get date after m latest message date m latest message date new message get date ftmessagemanager addmessage newmessage mmessagemanager newmessage ownmessage illegalargumentexception ownmessages newmessage initializetransient mmessagemanager newmessage boardmessagelink boardmessagelink newmessage getfreemessageindex newmessage isthread parentthread parentthread findparentthread newmessage getmessage newmessage setthread parentthread nosuchmessageexception newmessage setparent mmessagemanager newmessage getparentid nosuchmessageexception parentthread messagemanager linkorphanstonewparent newmessage mlatestmessagedate newmessage getdate mlatestmessagedate mlatestmessagedate newmessage getdate assumes that the transient fields of the new message are initialized already private synchronized void link orphans to new parent message new message if new message is thread iterator message absolute orphans absolute orphan iterator new message getid while absolute orphans has next search in the absolute orphans for messages which belong to this thread message orphan absolute orphans next orphan set thread new message try if orphan get parenturi equals new message geturi orphan set parent new message catch no such message exception e logger error this message is reply to thread but parenturi null orphan geturi else try message parent thread new message get thread search in its parent thread for its children for message parent thread child parent thread get children this try if parent thread child get parenturi equals new message geturi we found its parent yeah parent thread child set parent new message it s a child of the new message not of the parent thread catch no such message exception e logger error this message is reply to thread but parenturi null parent thread child geturi catch no such message exception e the new message is an absolute orphan find its children amongst the other absolute orphans iterator message absolute orphans absolute orphan iterator new message getid while absolute orphans has next search in the orphans for messages which belong to this message message orphan absolute orphans next the following if could be joined into the db4o query in absolute orphan iterator i did not do it because we could cache the list of absolute orphans locally try if orphan get parenturi equals new message geturi orphan set parent new message catch no such message exception error logger error this should not happen error newmessage linkorphanstonewparent newmessage newmessage isthread absoluteorphans absoluteorphaniterator newmessage absoluteorphans hasnext absoluteorphans setthread newmessage getparenturi newmessage setparent newmessage nosuchmessageexception parentthread newmessage getthread parentthreadchild parentthread getchildren parentthreadchild getparenturi newmessage parentthreadchild setparent newmessage newmessage parentthread nosuchmessageexception parentthreadchild nosuchmessageexception absoluteorphans absoluteorphaniterator newmessage absoluteorphans hasnext absoluteorphans absoluteorphaniterator getparenturi newmessage setparent newmessage nosuchmessageexception finds the parent thread of a message in the database the transient fields of the returned message will be initialized already throws no such message exception suppress warnings unchecked private synchronized message reference find parent thread message m throws no such message exception query q db query q constrain board message link class fixme this query has to be optimized maybe we should store the thread id in the board message link or we could first just query for message objects with the given id ignoring board message links and then query for a board message link which links the resulting message to the target board this could be sufficiently fast as the number of messages which are posted to multiple boards will be very small q descend m board constrain this identity q descend m message descend mid constrain m get threadid object set message reference parents q execute assert parents size 1 if parents size 0 throw new no such message exception m get threadid else message reference parent thread parents next assert parent thread get message getid equals m get threadid the query works important it is possible that we receive a message which has a parent thread uri specified but the message at that uri is not really a thread but just a reply to a thread we must not return the thread which is specified as thread in the referred uri instead because the thread id of that one is different to the thread id which is calculated from the false thread uri to explain it in other words the given message has a wrong thread uri stored caused by a malfunction in the client which inserted the message and the thread id which is stored in that message is calculated from the uri therefore it is also wrong if this function did return the real thread for the given message then it would return false information because the id of the returned thread would not match the id which is stored in the given message further we also cannot return the message which is referred by the false uri because it is not a thread other functions in freetalk rely on the fact that messages which are said to be threads are really threads so that is the reason why the following if statement is necessary notice that this comment was written after i figured out that messages are not being displayed if the if is left out so please do not remove it in the future if parent thread get message is thread false throw new no such message exception return parent thread nosuchmessageexception suppresswarnings messagereference findparentthread nosuchmessageexception boardmessagelink boardmessagelink boardmessagelinks boardmessagelink mboard mmessage getthreadid objectset messagereference nosuchmessageexception getthreadid messagereference parentthread parentthread getmessage getthreadid parentthread getmessage isthread nosuchmessageexception parentthread get all threads in the board the view is specified to the ft own identity displaying it therefore you have to pass one as parameter the transient fields of the returned messages will be initialized already param identity the identity viewing the board return an iterator of the message which the identity will see based on its trust levels suppress warnings unchecked public synchronized iterator message reference thread iterator final ft own identity identity return new iterator message reference private final ft own identity m identity identity private final iterator board message link iter private message reference next fixme if db4o supports precompiled queries this one should be stored precompiled reason we sort the threads by date maybe we can just keep the query object and call q execute as many times as we like to or somehow tell db4o to keep a per board thread index which is sorted by date this would be the best solution query q db query q constrain board message link class q descend m board constrain board this q descend m message descend m thread constrain null identity we require m parent to be null because this allows discussions where only the head message is missing to be displayed as a single thread instead of displaying a bunch of single messages where each would appear to be a thread q descend m message descend m parent constrain null identity q descend m message descend m date order descending iter q execute iterator next iter has next iter next null public boolean has next for next null next iter has next iter next null if m identity wants messages from next get message get author return true return false public message reference next message reference result has next next null next iter has next iter next null return result public void remove throw new unsupported operation exception ftownidentity suppresswarnings messagereference threaditerator ftownidentity messagereference ftownidentity midentity boardmessagelink messagereference boardmessagelink mboard mmessage mthread mparent mmessage mparent mmessage mdate orderdescending hasnext hasnext hasnext midentity wantsmessagesfrom getmessage getauthor messagereference messagereference hasnext hasnext unsupportedoperationexception public boolean has next for next null next iter has next iter next null if m identity wants messages from next get message get author return true return false hasnext hasnext midentity wantsmessagesfrom getmessage getauthor public message reference next message reference result has next next null next iter has next iter next null return result messagereference messagereference hasnext hasnext public void remove throw new unsupported operation exception unsupportedoperationexception get an iterator over messages for which the parent thread with the given id was not known the transient fields of the returned messages will be initialized already suppress warnings unchecked private synchronized iterator message absolute orphan iterator final string threadid return new iterator message private final iterator board message link iter fixme this query should be accelerated the amount of absolute orphans is very small usually so we should configure db4o to keep a separate list of those query q db query q constrain board message link class q descend m board constrain board this identity q descend m message descend m threadid constrain threadid q descend m message descend m thread constrain null identity iter q execute iterator public boolean has next return iter has next public message next return iter next get message public void remove throw new unsupported operation exception suppresswarnings absoluteorphaniterator boardmessagelink boardmessagelink mboard mmessage mthreadid mmessage mthread hasnext hasnext getmessage unsupportedoperationexception public boolean has next return iter has next hasnext hasnext public message next return iter next get message getmessage public void remove throw new unsupported operation exception unsupportedoperationexception which picks threads chosen by the viewer see thread iterator for how to do this suppress warnings unchecked public synchronized list message reference get all messages final boolean sort by message index ascending query q db query q constrain board message link class q descend m board constrain this identity if sort by message index ascending q descend m message index order ascending needed for nntp return q execute threaditerator suppresswarnings messagereference getallmessages sortbymessageindexascending boardmessagelink mboard sortbymessageindexascending mmessageindex orderascending suppress warnings unchecked public synchronized int get message index message message throws no such message exception query q db query q constrain board message link class q descend m message constrain message identity object set board message link result q execute if result size 0 throw new no such message exception message getid return result next get index suppresswarnings getmessageindex nosuchmessageexception boardmessagelink mmessage objectset boardmessagelink nosuchmessageexception getindex fixme this function counts all messages not only the ones which the viewer wants to see public synchronized int get last message index return get free message index 1 getlastmessageindex getfreemessageindex suppress warnings unchecked public synchronized message get message by index int index throws no such message exception query q db query q constrain board message link class q descend m board constrain this identity q descend m message index constrain index object set message reference result q execute if result size 0 throw new no such message exception return result next get message suppresswarnings getmessagebyindex nosuchmessageexception boardmessagelink mboard mmessageindex objectset messagereference nosuchmessageexception getmessage suppress warnings unchecked public synchronized list message reference get messages by minimum index int minimum index final boolean sort by message index ascending final boolean sort by message date ascending final query q db query q constrain board message link class q descend m board constrain this identity if minimum index 0 minimum index db4o provides no greater equal so we do it this way q descend m message index constrain minimum index greater if sort by message index ascending q descend m message index order ascending if sort by message date ascending q descend m message descend m date order ascending return q execute suppresswarnings messagereference getmessagesbyminimumindex minimumindex sortbymessageindexascending sortbymessagedateascending boardmessagelink mboard minimumindex minimumindex greaterequal mmessageindex minimumindex sortbymessageindexascending mmessageindex orderascending sortbymessagedateascending mmessage mdate orderascending suppress warnings unchecked public synchronized list message reference get messages by minimum date long minimum date final boolean sort by message index ascending final boolean sort by message date ascending final query q db query q constrain board message link class q descend m board constrain this identity if minimum date 0 minimum date db4o provides no greater equal so we do it this way q descend m message descend m date constrain minimum date greater if sort by message index ascending q descend m message index order ascending if sort by message date ascending q descend m message descend m date order ascending return q execute suppresswarnings messagereference getmessagesbyminimumdate minimumdate sortbymessageindexascending sortbymessagedateascending boardmessagelink mboard minimumdate minimumdate greaterequal mmessage mdate minimumdate sortbymessageindexascending mmessageindex orderascending sortbymessagedateascending mmessage mdate orderascending get the next free nntp index for a message please synchronize on board message link class when creating a message this method does not and cannot provide synchronization as creating a message is no atomic operation suppress warnings unchecked private int get free message index query q db query q constrain board message link class q descend m board constrain this identity q descend m message index order descending fixme use a db4o native query to find the maximum instead of sorting o n vs o n log n object set message reference result q execute return result size 0 1 result next get index 1 boardmessagelink suppresswarnings getfreemessageindex boardmessagelink mboard mmessageindex orderdescending objectset messagereference getindex get the number of messages in this board fixme this function counts all messages not only the ones which the viewer wants to see public synchronized int message count query q db query q constrain board message link class q descend m board constrain this identity return q execute size messagecount boardmessagelink mboard get the number of replies to the given thread fixme this function counts all replies not only the ones which the viewer wants to see public synchronized int thread reply count ft own identity viewer message thread return get all thread replies thread false size threadreplycount ftownidentity getallthreadreplies get all replies to the given thread sorted ascending by date if requested fixme this function returns all replies not only the ones which the viewer wants to see convert the function to an iterator which picks threads chosen by the viewer see thread iterator for how to do this suppress warnings unchecked public synchronized list message reference get all thread replies message thread final boolean sort by date ascending query q db query fixme this query is inefficient it should rather first query for objects of message class which have m threadid thread getid and then check whether a board message link to this board exists q constrain board message link class q descend m board constrain this identity q descend m message constrain thread identity not try q descend m message descend m threadid constrain thread is thread thread getid thread get threadid fixme for some reason m parent seems to stay null on some thread replies even though their parent is present in the database q descend m message descend m parent constrain null identity not catch no such message exception e throw new runtime exception message is no thread but parent threaduri null thread geturi if sort by date ascending q descend m message descend m date order ascending return q execute threaditerator suppresswarnings messagereference getallthreadreplies sortbydateascending mthreadid boardmessagelink boardmessagelink mboard mmessage mmessage mthreadid isthread getthreadid mparent mmessage mparent nosuchmessageexception runtimeexception parentthreaduri sortbydateascending mmessage mdate orderascending public interface message reference get the message to which this reference points public message get message messagereference getmessage public message get message get an unique index number of this message in the board where which the query for the message was executed this index number is needed for nntp public int get index getmessage getindex public board message link board my board message my message int my index assert my board null my message null m board my board m message my message m message index my index boardmessagelink myboard mymessage myindex myboard mymessage mboard myboard mmessage mymessage mmessageindex myindex public void store ext object container local db synchronized db lock if local db ext is stored this local db ext is active this throw new runtime exception trying to store a non active board message link object local db store this local db commit extobjectcontainer localdb localdb isstored localdb isactive runtimeexception boardmessagelink localdb localdb public int get index return m message index getindex mmessageindex public message get message we do not have to initialize m board and can assume that it is initialized because a board message link will only be loaded by the board it belongs to m message initialize transient m board db m board m message manager db activate m message 2 fixme figure out a reasonable depth return m message getmessage mboard boardmessagelink mmessage initializetransient mboard mboard mmessagemanager mmessage mmessage private static final long serial versionuid 1 public key verify exception string message super message serialversionuid keyverifyexception public key verify exception string message throwable cause super message cause keyverifyexception public key verify exception super keyverifyexception public key verify exception throwable cause super cause keyverifyexception public class snmp counter32 extends snmp type wrapper num public snmp counter32 super snmpcounter32 snmptypewrappernum snmpcounter32 public class snmp counter32 extends snmp type wrapper num public snmp counter32 super public snmp counter32 long value super value snmpcounter32 snmptypewrappernum snmpcounter32 snmpcounter32 public void set value long value todo make it prettier this value new long value int value system err println value cut from value to this value setvalue intvalue protected void init this typeid 0x41 session key peer node parent packet tracker tracker block cipher cipher byte session key this pn parent this packets tracker this session cipher cipher this session key session key sessionkey peernode packettracker blockcipher sessionkey sessioncipher sessionkey sessionkey override public string to string return super to string packets to string tostring tostring tostring public static final string code2 string int code switch code case continue return continue case ok return ok case partial content return partial content case bad request return bad request case not found return not found case precondition failed return precondition failed case invalid range return invalid range case internal server error return internal server error return code2string partial_content bad_request not_found precondition_failed invalid_range internal_server_error public http status set version set status code 0 set reason phrase httpstatus setversion setstatuscode setreasonphrase public http status string ver int code string reason set version ver set status code code set reason phrase reason httpstatus setversion setstatuscode setreasonphrase public http status string line str set line str httpstatus linestr linestr private string reason phrase public void set version string value version value reasonphrase setversion public void set status code int value status code value setstatuscode statuscode public void set reason phrase string value reason phrase value setreasonphrase reasonphrase public string get version return version getversion public int get status code return status code getstatuscode statuscode public string get reason phrase return reason phrase getreasonphrase reasonphrase final public static boolean is successful int stat code if 200 stat code stat code 300 return true return false issuccessful statcode statcode statcode public boolean is successful return is successful get status code issuccessful issuccessful getstatuscode public void set string line str if line str null set version http version set status code internal server error set reason phrase code2 string internal server error return try string tokenizer st new string tokenizer line str http status line delim if st has more tokens false return string ver st next token set version ver trim if st has more tokens false return string code str st next token int code 0 try code integer parse int code str catch exception e1 set status code code string reason while st has more tokens true if 0 reason length reason reason st next token set reason phrase reason trim catch exception e debug warning e linestr linestr setversion setstatuscode internal_server_error setreasonphrase code2string internal_server_error stringtokenizer stringtokenizer linestr status_line_delim hasmoretokens nexttoken setversion hasmoretokens codestr nexttoken parseint codestr setstatuscode hasmoretokens nexttoken setreasonphrase cretae a buffered image from an image producer param producer the image producer return a new type int argb buffered image public static buffered image create image image producer producer pixel grabber pg new pixel grabber producer 0 0 1 1 null 0 0 try pg grab pixels catch interrupted exception e throw new runtime exception image fetch interrupted if pg status image observer abort 0 throw new runtime exception image fetch aborted if pg status image observer error 0 throw new runtime exception image fetch error buffered image p new buffered image pg get width pg get height buffered image type int argb p setrgb 0 0 pg get width pg get height int pg get pixels 0 pg get width return p bufferedimage imageproducer imageproducer type_int_argb bufferedimage bufferedimage createimage imageproducer pixelgrabber pixelgrabber grabpixels interruptedexception runtimeexception imageobserver runtimeexception imageobserver runtimeexception bufferedimage bufferedimage getwidth getheight bufferedimage type_int_argb getwidth getheight getpixels getwidth convert an image into a type int argb buffered image if the image is already of this type the original image is returned unchanged param image the image to convert return the converted image public static buffered image convert image toargb image image if image instanceof buffered image buffered image image get type buffered image type int argb return buffered image image buffered image p new buffered image image get width null image get height null buffered image type int argb graphics2d g p create graphics g draw image image 0 0 null g dispose return p type_int_argb bufferedimage bufferedimage convertimagetoargb bufferedimage bufferedimage gettype bufferedimage type_int_argb bufferedimage bufferedimage bufferedimage getwidth getheight bufferedimage type_int_argb creategraphics drawimage returns a copy of a subimage of image this avoids the performance problems associated with buffered image get subimage param image the image param x the x position param y the y position param w the width param h the height return the subimage public static buffered image get subimage buffered image image int x int y int w int h buffered image new image new buffered image w h buffered image type int argb graphics2d g new image create graphics g draw rendered image image affine transform get translate instance x y g dispose return new image bufferedimage getsubimage bufferedimage getsubimage bufferedimage bufferedimage newimage bufferedimage bufferedimage type_int_argb newimage creategraphics drawrenderedimage affinetransform gettranslateinstance newimage clones a buffered image param image the image to clone return the cloned image public static buffered image clone image buffered image image buffered image new image new buffered image image get width image get height buffered image type int argb graphics2d g new image create graphics g draw rendered image image null g dispose return new image bufferedimage bufferedimage cloneimage bufferedimage bufferedimage newimage bufferedimage getwidth getheight bufferedimage type_int_argb newimage creategraphics drawrenderedimage newimage paint a check pattern used for a background to indicate image transparency param c the component to draw into param g the graphics objects param x the x position param y the y position param width the width param height the height public static void paint checked background component c graphics g int x int y int width int height if background image null background image new buffered image 64 64 buffered image type int argb graphics bg background image create graphics for int by 0 by 64 by 8 for int bx 0 bx 64 bx 8 bg set color bx by 8 0 color light gray color white bg fill rect bx by 8 8 bg dispose if background image null shape save clip g get clip rectangle r g get clip bounds if r null r new rectangle c get size r r intersection new rectangle x y width height g set clip r int w background image get width int h background image get height if w 1 h 1 int x1 r x w w int y1 r y h h int x2 r x r width w 1 w w int y2 r y r height h 1 h h for y y1 y y2 y h for x x1 x x2 x w g draw image background image x y c g set clip save clip paintcheckedbackground backgroundimage backgroundimage bufferedimage bufferedimage type_int_argb backgroundimage creategraphics setcolor lightgray fillrect backgroundimage saveclip getclip getclipbounds getsize setclip backgroundimage getwidth backgroundimage getheight drawimage backgroundimage setclip saveclip calculates the bounds of the non transparent parts of the given image param p the image return the bounds of the non transparent area public static rectangle get selected bounds buffered image p int width p get width int height p get height int maxx 0 maxy 0 minx width miny height boolean any selected false int y1 int pixels null for y1 height 1 y1 0 y1 pixels getrgb p 0 y1 width 1 pixels for int x 0 x minx x if pixels x 0xff000000 0 minx x maxy y1 any selected true break for int x width 1 x maxx x if pixels x 0xff000000 0 maxx x maxy y1 any selected true break if any selected break pixels null for int y 0 y y1 y pixels getrgb p 0 y width 1 pixels for int x 0 x minx x if pixels x 0xff000000 0 minx x if y miny miny y any selected true break for int x width 1 x maxx x if pixels x 0xff000000 0 maxx x if y miny miny y any selected true break if any selected return new rectangle minx miny maxx minx 1 maxy miny 1 return null getselectedbounds bufferedimage getwidth getheight anyselected anyselected anyselected anyselected anyselected anyselected anyselected compose src onto dst using the alpha of sel to interpolate between the two i can t think of a way to do this using alpha composite param src the source raster param dst the destination raster param sel the mask raster public static void compose through mask raster src writable raster dst raster sel int x src get minx int y src get miny int w src get width int h src get height int srcrgb null int selrgb null int dstrgb null for int i 0 i h i srcrgb src get pixels x y w 1 srcrgb selrgb sel get pixels x y w 1 selrgb dstrgb dst get pixels x y w 1 dstrgb int k x for int j 0 j w j int sr srcrgb k int dir dstrgb k int sg srcrgb k 1 int dig dstrgb k 1 int sb srcrgb k 2 int dib dstrgb k 2 int sa srcrgb k 3 int dia dstrgb k 3 float a selrgb k 3 255f float ac 1 a dstrgb k int a sr ac dir dstrgb k 1 int a sg ac dig dstrgb k 2 int a sb ac dib dstrgb k 3 int a sa ac dia k 4 dst set pixels x y w 1 dstrgb y alphacomposite composethroughmask writableraster getminx getminy getwidth getheight getpixels getpixels getpixels setpixels a convenience method for getting argb pixels from an image this tries to avoid the performance penalty of buffered image getrgb unmanaging the image param image a buffered image object param x the left edge of the pixel block param y the right edge of the pixel block param width the width of the pixel arry param height the height of the pixel arry param pixels the array to hold the returned pixels may be null return the pixels see setrgb public static int getrgb buffered image image int x int y int width int height int pixels int type image get type if type buffered image type int argb type buffered image type int rgb return int image get raster get data elements x y width height pixels return image getrgb x y width height pixels 0 width bufferedimage bufferedimage bufferedimage gettype bufferedimage type_int_argb bufferedimage type_int_rgb getraster getdataelements a convenience method for setting argb pixels in an image this tries to avoid the performance penalty of buffered image setrgb unmanaging the image param image a buffered image object param x the left edge of the pixel block param y the right edge of the pixel block param width the width of the pixel arry param height the height of the pixel arry param pixels the array of pixels to set see getrgb public static void setrgb buffered image image int x int y int width int height int pixels int type image get type if type buffered image type int argb type buffered image type int rgb image get raster set data elements x y width height pixels else image setrgb x y width height pixels 0 width bufferedimage bufferedimage bufferedimage gettype bufferedimage type_int_argb bufferedimage type_int_rgb getraster setdataelements construct a gamma filter public gamma filter this 1 0f gammafilter gammafilter construct a gamma filter param gamma the gamma level for all rgb channels public gamma filter float gamma this gamma gamma gamma gammafilter gammafilter construct a gamma filter param r gamma the gamma level for the red channel param g gamma the gamma level for the blue channel param b gamma the gamma level for the green channel public gamma filter float r gamma float g gamma float b gamma set gamma r gamma g gamma b gamma gammafilter rgamma ggamma bgamma gammafilter rgamma ggamma bgamma setgamma rgamma ggamma bgamma set the gamma levels param r gamma the gamma level for the red channel param g gamma the gamma level for the blue channel param b gamma the gamma level for the green channel see get gamma public void set gamma float r gamma float g gamma float b gamma this r gamma r gamma this g gamma g gamma this b gamma b gamma initialized false rgamma ggamma bgamma getgamma setgamma rgamma ggamma bgamma rgamma rgamma ggamma ggamma bgamma bgamma set the gamma level param gamma the gamma level for all rgb channels see get gamma public void set gamma float gamma set gamma gamma gamma gamma getgamma setgamma setgamma get the gamma level return the gamma level for all rgb channels see set gamma public float get gamma return r gamma setgamma getgamma rgamma override protected void initialize r table make table r gamma if g gamma r gamma g table r table else g table make table g gamma if b gamma r gamma b table r table else if b gamma g gamma b table g table else b table make table b gamma rtable maketable rgamma ggamma rgamma gtable rtable gtable maketable ggamma bgamma rgamma btable rtable bgamma ggamma btable gtable btable maketable bgamma private int make table float gamma int table new int 256 for int i 0 i 256 i int v int 255 0 math pow i 255 0 1 0 gamma 0 5 if v 255 v 255 table i v return table maketable override public string to string return colors gamma tostring public class invert filter extends point filter public invert filter can filter index color model true invertfilter pointfilter invertfilter canfilterindexcolormodel override public int filterrgb int x int y int rgb int a rgb 0xff000000 return a rgb 0x00ffffff override public string to string return colors invert tostring create one for a global queued request not made by fcp throws identifier collision exception throws not allowed exception throws io exception public client get fcp client global client freeneturi uri boolean ds only boolean ignoreds int max splitfile retries int max non splitfile retries long max output length short return type boolean persist reboot only string identifier int verbosity short prio class file return filename file return temp filename fcp server server object container container throws identifier collision exception not allowed exception io exception super uri identifier verbosity null global client prio class persist reboot only client request persist reboot client request persist forever null true container fctx new fetch context server default fetch context fetch context identical mask false null fctx event producer add event listener this fctx local request only ds only fctx ignore store ignoreds fctx max non splitfile retries max non splitfile retries fctx max splitfile block retries max splitfile retries fctx max output length max output length fctx max temp length max output length bucket ret null this return type return type binary blob false if return type client get message return type disk this target file return filename this temp file return temp filename if server core allow download to return temp filename server core allow download to return filename throw new not allowed exception ret new file bucket return temp filename false true false false false else if return type client get message return type none target file null temp file null ret new null bucket else target file null temp file null if persistence type persist forever ret server core persistent temp bucket factory make bucket max output length else ret server core temp bucket factory make bucket max output length return bucket ret getter new client getter this uri fctx priority class low level client return bucket null identifiercollisionexception notallowedexception ioexception clientget fcpclient globalclient dsonly maxsplitfileretries maxnonsplitfileretries maxoutputlength returntype persistrebootonly prioclass returnfilename returntempfilename fcpserver objectcontainer identifiercollisionexception notallowedexception ioexception globalclient prioclass persistrebootonly clientrequest persist_reboot clientrequest persist_forever fetchcontext defaultfetchcontext fetchcontext identical_mask eventproducer addeventlistener localrequestonly dsonly ignorestore maxnonsplitfileretries maxnonsplitfileretries maxsplitfileblockretries maxsplitfileretries maxoutputlength maxoutputlength maxtemplength maxoutputlength returntype returntype binaryblob returntype clientgetmessage return_type_disk targetfile returnfilename tempfile returntempfilename allowdownloadto returntempfilename allowdownloadto returnfilename notallowedexception filebucket returntempfilename returntype clientgetmessage return_type_none targetfile tempfile nullbucket targetfile tempfile persistencetype persist_forever persistenttempbucketfactory makebucket maxoutputlength tempbucketfactory makebucket maxoutputlength returnbucket clientgetter priorityclass lowlevelclient returnbucket public client get fcp connection handler handler client get message message fcp server server object container container throws identifier collision exception message invalid exception super message uri message identifier message verbosity handler message priority class message persistence type message client token message global container create a fetcher directly in order to get more fine grained control since the client may override a few context elements fctx new fetch context server default fetch context fetch context identical mask false null fctx event producer add event listener this ignoreds fctx local request only message ds only fctx ignore store message ignoreds fctx max non splitfile retries message max retries fctx max splitfile block retries message max retries fixme do something with verbosity has already been checked fctx max output length message max size fctx max temp length message max temp size if message allowedmime types null fctx allowedmime types new hash set string for string mime message allowedmime types fctx allowedmime types add mime this return type message return type this binary blob message binary blob bucket ret null if return type client get message return type disk this target file message disk file this temp file message temp file if server core allow download to temp file server core allow download to target file throw new message invalid exception protocol error message access denied not allowed to download to temp file or target file identifier global else if handler allowdda from temp file true handler allowdda from target file true throw new message invalid exception protocol error message direct disk access denied not allowed to download to temp file or target file you might need to do a testdda request message name first identifier global ret new file bucket message temp file false true false false false else if return type client get message return type none target file null temp file null ret new null bucket else target file null temp file null try if persistence type persist forever ret server core persistent temp bucket factory make bucket fctx max output length else ret server core temp bucket factory make bucket fctx max output length catch io exception e logger error this cannot create bucket for temp storage e e getter null return bucket null this is not a fetch exception since we don t register it it s a protocol error throw new message invalid exception protocol error message internal error cannot create bucket for temporary storage out of disk space e identifier global if ret null logger error this impossible ret null in fcp constructor for this new exception debug return bucket ret getter new client getter this uri fctx priority class low level client binary blob new null bucket return bucket binary blob return bucket null clientget fcpconnectionhandler clientgetmessage fcpserver objectcontainer identifiercollisionexception messageinvalidexception priorityclass persistencetype clienttoken fetchcontext defaultfetchcontext fetchcontext identical_mask eventproducer addeventlistener localrequestonly dsonly ignorestore maxnonsplitfileretries maxretries maxsplitfileblockretries maxretries maxoutputlength maxsize maxtemplength maxtempsize allowedmimetypes allowedmimetypes hashset allowedmimetypes allowedmimetypes returntype returntype binaryblob binaryblob returntype clientgetmessage return_type_disk targetfile diskfile tempfile tempfile allowdownloadto tempfile allowdownloadto targetfile messageinvalidexception protocolerrormessage access_denied tempfile targetfile allowddafrom tempfile allowddafrom targetfile messageinvalidexception protocolerrormessage direct_disk_access_denied tempfile targetfile testddarequestmessage filebucket tempfile returntype clientgetmessage return_type_none targetfile tempfile nullbucket targetfile tempfile persistencetype persist_forever persistenttempbucketfactory makebucket maxoutputlength tempbucketfactory makebucket maxoutputlength ioexception returnbucket fetchexception messageinvalidexception protocolerrormessage internal_error returnbucket clientgetter priorityclass lowlevelclient binaryblob nullbucket returnbucket binaryblob returnbucket create a client get from a request serialized to a simple field set can throw and does minimal verification as is dealing with data supposedly serialized out by the node throws io exception throws fetch exception public client get simple field set fs fcp client client2 fcp server server throws io exception fetch exception super fs client2 return type client get message parse valid return type fs get return type string f fs get filename if f null target file new file f else target file null f fs get temp filename if f null temp file new file f else temp file null boolean ignoreds fields string to bool fs get ignoreds false boolean ds only fields string to bool fs get ds only false int max retries integer parse int fs get max retries fctx new fetch context server default fetch context fetch context identical mask false null fctx event producer add event listener this ignoreds fctx local request only ds only fctx ignore store ignoreds fctx max non splitfile retries max retries fctx max splitfile block retries max retries binary blob fields string to bool fs get binary blob false succeeded fields string to bool fs get succeeded false if finished if succeeded found data length long parse long fs get found data length found data mime type fs get found data mime type simple field set fs1 fs subset post fetch protocol error if fs1 null post fetch protocol error message new protocol error message fs1 else get failed message new get failed message fs subset get failed false bucket ret null if return type client get message return type disk if succeeded ret new file bucket target file false true false false false else ret new file bucket temp file false true false false false else if return type client get message return type none ret new null bucket else if return type client get message return type direct try ret serializable to field set bucket util create fs subset return bucket server core random server core persistent temp bucket factory if ret null throw new cannot create from field set exception ret null catch cannot create from field set exception e logger error this cannot read this e e try create a new temp bucket if persistence type persist forever ret server core persistent temp bucket factory make bucket fctx max output length else ret server core temp bucket factory make bucket fctx max output length catch io exception e1 logger error this cannot create bucket for temp storage e e getter null return bucket null throw new fetch exception fetch exception bucket error e else throw new illegal argument exception if succeeded if found data length ret size logger error this failing identifier because lost data succeeded false if ret null logger error this impossible ret null in sfs constructor for this new exception debug return bucket ret string allowed fs get all allowedmime types if allowed null fctx allowedmime types new hash set string for string a allowed fctx allowedmime types add a getter new client getter this uri fctx priority class low level client binary blob new null bucket return bucket binary blob return bucket null if finished succeeded all data pending new all data message return bucket identifier global startup time completion time this found data mime type clientget simplefieldset ioexception fetchexception clientget simplefieldset fcpclient fcpserver ioexception fetchexception returntype clientgetmessage parsevalidreturntype returntype targetfile targetfile tempfilename tempfile tempfile stringtobool dsonly stringtobool dsonly maxretries parseint maxretries fetchcontext defaultfetchcontext fetchcontext identical_mask eventproducer addeventlistener localrequestonly dsonly ignorestore maxnonsplitfileretries maxretries maxsplitfileblockretries maxretries binaryblob stringtobool binaryblob stringtobool founddatalength parselong founddatalength founddatamimetype founddatamimetype simplefieldset postfetchprotocolerror postfetchprotocolerrormessage protocolerrormessage getfailedmessage getfailedmessage getfailed returntype clientgetmessage return_type_disk filebucket targetfile filebucket tempfile returntype clientgetmessage return_type_none nullbucket returntype clientgetmessage return_type_direct serializabletofieldsetbucketutil returnbucket persistenttempbucketfactory cannotcreatefromfieldsetexception cannotcreatefromfieldsetexception persistencetype persist_forever persistenttempbucketfactory makebucket maxoutputlength tempbucketfactory makebucket maxoutputlength ioexception returnbucket fetchexception fetchexception bucket_error illegalargumentexception founddatalength returnbucket getall allowedmimetypes allowedmimetypes hashset allowedmimetypes clientgetter priorityclass lowlevelclient binaryblob nullbucket returnbucket binaryblob returnbucket alldatapending alldatamessage returnbucket startuptime completiontime founddatamimetype must be called just after construction but within a transaction throws identifier collision exception if the identifier is already in use override void register object container container boolean lazy resume boolean no tags throws identifier collision exception if client null assert this persistence type client persistence type if persistence type persist connection try client register this lazy resume container catch identifier collision exception e return bucket free if persistence type persist forever return bucket remove from container throw e if persistence type persist connection no tags fcp message msg persistent tag message container client queue client request message msg 0 container identifiercollisionexception objectcontainer lazyresume notags identifiercollisionexception persistencetype persistencetype persistencetype persist_connection lazyresume identifiercollisionexception returnbucket persistencetype persist_forever returnbucket removefrom persistencetype persist_connection notags fcpmessage persistenttagmessage queueclientrequestmessage override public void start object container container client context context try synchronized this if finished return getter start container context if persistence type persist connection finished fcp message msg persistent tag message container client queue client request message msg 0 container synchronized this started true catch fetch exception e synchronized this started true before the failure handler on failure e null container catch throwable t synchronized this started true on failure new fetch exception fetch exception internal error t null container if persistence type persist forever container store this update objectcontainer clientcontext persistencetype persist_connection fcpmessage persistenttagmessage queueclientrequestmessage fetchexception onfailure onfailure fetchexception fetchexception internal_error persistencetype persist_forever override public void on lost connection object container container client context context if persistence type persist connection cancel container context otherwise ignore onlostconnection objectcontainer clientcontext persistencetype persist_connection public void on success fetch result result client getter state object container container logger minor this succeeded identifier bucket data result as bucket if persistence type persist forever if data null container activate data 5 if return bucket null container activate return bucket 5 container activate client 1 if temp file null container activate temp file 5 if target file null container activate target file 5 if return bucket data binary blob boolean failed true synchronized this if finished logger error this already finished but on success for this data data new exception debug data free if persistence type persist forever data remove from container return already failed bucket error maybe if return type client get message return type direct return bucket null lost bucket for some reason e g bucket error caused by io exception on previous try recover return bucket data failed false if failed persistence type persist forever if container ext getid return bucket container ext getid data logger error this db4o bug detected without array handling evil horrible bug uid return bucket container ext getid return bucket for return bucket active container ext is active return bucket stored container ext is stored return bucket but uid data container ext getid data for data active container ext is active data stored container ext is stored data succeed anyway hope that the returned bucket is consistent return bucket data failed false if failed logger error this return bucket return bucket but on success data data new exception debug caller guarantees that data return bucket on failure new fetch exception fetch exception internal error data return bucket null container return boolean dont free false fixme i don t think this is a problem in this case disk write while locked all data message adm null synchronized this if succeeded logger error this on success called twice for this identifier return we might be called twice ignore it if so started true if binary blob this found data mime type result get mime type else this found data mime type binary blob mime type if return type client get message return type direct send all the data at once fixme there should be other options fixme completion time is set on finish we need to give it current time here but it means we won t always return the same value to clients does it matter adm new all data message return bucket identifier global startup time system current time millis this found data mime type if persistence type persist connection adm set free on sent dont free true else if return type client get message return type none do nothing else if return type client get message return type disk write to temp file then rename over filename if file util rename to temp file target file post fetch protocol error message new protocol error message protocol error message could not rename file false null identifier global don t delete temp file user might want it return bucket new file bucket target file false true false false false if persistence type persist forever progress pending null container activate progress pending 1 progress pending remove from container progress pending null this found data length return bucket size this succeeded true finished true try send data found or get failed null container if adm null try send all data message adm null container if dont free data free if persistence type persist forever return bucket store to container container store this finish container if client null client notify success this container onsuccess fetchresult clientgetter objectcontainer asbucket persistencetype persist_forever returnbucket returnbucket tempfile tempfile targetfile targetfile returnbucket binaryblob onsuccess persistencetype persist_forever removefrom returntype clientgetmessage return_type_direct returnbucket ioexception returnbucket persistencetype persist_forever returnbucket returnbucket returnbucket returnbucket isactive returnbucket isstored returnbucket isactive isstored returnbucket returnbucket returnbucket onsuccess returnbucket onfailure fetchexception fetchexception internal_error returnbucket dontfree alldatamessage onsuccess binaryblob founddatamimetype getmimetype founddatamimetype binaryblob mime_type returntype clientgetmessage return_type_direct completiontime alldatamessage returnbucket startuptime currenttimemillis founddatamimetype persistencetype persist_connection setfreeonsent dontfree returntype clientgetmessage return_type_none returntype clientgetmessage return_type_disk fileutil renameto tempfile targetfile postfetchprotocolerrormessage protocolerrormessage protocolerrormessage could_not_rename_file returnbucket filebucket targetfile persistencetype persist_forever progresspending progresspending progresspending removefrom progresspending founddatalength returnbucket trysenddatafoundorgetfailed trysendalldatamessage dontfree persistencetype persist_forever returnbucket storeto notifysuccess private void try send data found or get failed fcp connection output handler handler object container container fcp message msg don t need to lock succeeded is only ever set never unset and succeeded and get failed message are both atomic if succeeded msg new data found message found data length found data mime type identifier global else msg get failed message if persistence type persist forever container activate msg 5 if handler null persistence type persist connection handler orig handler output handler if handler null handler queue msg else client queue client request message msg 0 container if post fetch protocol error message null if persistence type persist forever container activate post fetch protocol error message 5 if handler null handler queue post fetch protocol error message else if persistence type persist forever container activate client 1 client queue client request message post fetch protocol error message 0 container trysenddatafoundorgetfailed fcpconnectionoutputhandler objectcontainer fcpmessage getfailedmessage datafoundmessage founddatalength founddatamimetype getfailedmessage persistencetype persist_forever persistencetype persist_connection orighandler outputhandler queueclientrequestmessage postfetchprotocolerrormessage persistencetype persist_forever postfetchprotocolerrormessage postfetchprotocolerrormessage persistencetype persist_forever queueclientrequestmessage postfetchprotocolerrormessage private void try send all data message all data message msg fcp connection output handler handler object container container if persistence type client request persist connection all data pending msg if persistence type client request persist forever container store this return if handler null handler orig handler output handler handler queue msg trysendalldatamessage alldatamessage fcpconnectionoutputhandler objectcontainer persistencetype clientrequest persist_connection alldatapending persistencetype clientrequest persist_forever orighandler outputhandler private void try send progress fcp message msg fcp connection output handler handler object container container if persistence type client request persist connection fcp message old progress progress pending if msg instanceof simple progress message progress pending simple progress message msg else if msg instanceof sending to network message sent to network true if persistence type client request persist forever container store this if old progress null container activate old progress 1 old progress remove from container if persistence type persist forever container activate client 1 if persistence type persist connection handler null handler orig handler output handler if handler null handler queue msg else client queue client request message msg verbosity splitfile progress container if persistence type persist forever client is global queue container deactivate client 1 trysendprogress fcpmessage fcpconnectionoutputhandler objectcontainer persistencetype clientrequest persist_connection fcpmessage oldprogress progresspending simpleprogressmessage progresspending simpleprogressmessage sendingtonetworkmessage senttonetwork persistencetype clientrequest persist_forever oldprogress oldprogress oldprogress removefrom persistencetype persist_forever persistencetype persist_connection orighandler outputhandler queueclientrequestmessage verbosity_splitfile_progress persistencetype persist_forever isglobalqueue override public void send pending messages fcp connection output handler handler boolean include persistent request boolean include data boolean only data object container container if persistence type client request persist connection logger error this wtf persistence type persistence type new exception error return if only data if include persistent request fcp message msg persistent tag message container handler queue msg if progress pending null if persistence type persist forever container activate progress pending 5 handler queue progress pending if sent to network handler queue new sending to network message identifier global if finished try send data found or get failed handler container if only data all data pending null logger error this no data pending if include data all data pending null if persistence type persist forever container activate all data pending 5 handler queue all data pending sendpendingmessages fcpconnectionoutputhandler includepersistentrequest includedata onlydata objectcontainer persistencetype clientrequest persist_connection persistencetype persistencetype onlydata includepersistentrequest fcpmessage persistenttagmessage progresspending persistencetype persist_forever progresspending progresspending senttonetwork sendingtonetworkmessage trysenddatafoundorgetfailed onlydata alldatapending includedata alldatapending persistencetype persist_forever alldatapending alldatapending override protected fcp message persistent tag message object container container if persistence type persist forever container activate uri 5 container activate fctx 1 container activate client 1 container activate target file 5 container activate temp file 5 return new persistent get identifier uri verbosity priority class return type persistence type target file temp file client token client is global queue started fctx max non splitfile retries binary blob fctx max output length fcpmessage persistenttagmessage objectcontainer persistencetype persist_forever targetfile tempfile persistentget priorityclass returntype persistencetype targetfile tempfile clienttoken isglobalqueue maxnonsplitfileretries binaryblob maxoutputlength public void on failure fetch exception e client getter state object container container if finished return synchronized this succeeded false get failed message new get failed message e identifier global finished true started true if logger should log logger minor this logger minor this caught e e try send data found or get failed null container if persistence type persist forever container activate client 1 we do not want the data to be removed on failure because the request may be restarted and the bucket persists on the getter even if we get rid of it here free data container finish container if client null client notify failure this container if persistence type persist forever container store this onfailure fetchexception clientgetter objectcontainer getfailedmessage getfailedmessage shouldlog trysenddatafoundorgetfailed persistencetype persist_forever freedata notifyfailure persistencetype persist_forever public void on success base client putter state object container container ignore onsuccess baseclientputter objectcontainer public void on failure insert exception e base client putter state object container container ignore onfailure insertexception baseclientputter objectcontainer public void on generateduri freeneturi uri base client putter state object container container ignore ongenerateduri baseclientputter objectcontainer override public void request was removed object container container client context context if request is still running send a get failed with code cancelled if finished synchronized this succeeded false finished true fetch exception cancelled new fetch exception fetch exception cancelled get failed message new get failed message cancelled identifier global try send data found or get failed null container notify client that request was removed fcp message msg new persistent request removed message get identifier global if persistence type persist connection if persistence type persist forever container activate client 1 client queue client request message msg 0 container free data container if persistence type persist forever container activate fctx 1 if fctx allowedmime types null container activate fctx allowedmime types 5 container delete fctx allowedmime types fctx remove from container getter remove from container context if target file null container delete target file if temp file null container delete temp file if get failed message null container activate get failed message 5 get failed message remove from container if post fetch protocol error message null container activate post fetch protocol error message 5 post fetch protocol error message remove from container if all data pending null container activate all data pending 5 all data pending remove from container if progress pending null container activate progress pending 5 progress pending remove from container super request was removed container context requestwasremoved objectcontainer clientcontext getfailed fetchexception fetchexception fetchexception getfailedmessage getfailedmessage trysenddatafoundorgetfailed fcpmessage persistentrequestremovedmessage getidentifier persistencetype persist_connection persistencetype persist_forever queueclientrequestmessage freedata persistencetype persist_forever allowedmimetypes allowedmimetypes allowedmimetypes removefrom removefrom targetfile targetfile tempfile tempfile getfailedmessage getfailedmessage getfailedmessage removefrom postfetchprotocolerrormessage postfetchprotocolerrormessage postfetchprotocolerrormessage removefrom alldatapending alldatapending alldatapending removefrom progresspending progresspending progresspending removefrom requestwasremoved public void receive client event ce object container container client context context don t need to lock verbosity is final and finished is never unset if finished return final fcp message progress if ce instanceof splitfile progress event if verbosity verbosity splitfile progress verbosity splitfile progress return progress new simple progress message identifier global splitfile progress event ce else if ce instanceof sending to network event if verbosity verbosity sent to network verbosity sent to network return progress new sending to network message identifier global else return don t know what to do with event container may be null if persistence type persist forever container null context job runner queue new db job public void run object container container client context context try send progress progress null container native thread high priority false else try send progress progress null container clientevent objectcontainer clientcontext fcpmessage splitfileprogressevent verbosity_splitfile_progress verbosity_splitfile_progress simpleprogressmessage splitfileprogressevent sendingtonetworkevent verbosity_sent_to_network verbosity_sent_to_network sendingtonetworkmessage persistencetype persist_forever jobrunner dbjob objectcontainer clientcontext trysendprogress nativethread high_priority trysendprogress context job runner queue new db job public void run object container container client context context try send progress progress null container jobrunner dbjob objectcontainer clientcontext trysendprogress different it can store detailed state override public synchronized simple field set get field set simple field set fs new simple field set false we will need multi level later fs put single type get fs put single uri uri to string false false fs put single identifier identifier fs put single verbosity integer to string verbosity fs put single priority class short to string priority class fs put single return type client get message return type string return type fs put single persistence persistence type string persistence type fs put single client name client name if target file null fs put single filename target file get path if temp file null fs put single temp filename temp file get path if client token null fs put single client token client token fs put single ignoreds boolean to string fctx ignore store fs put single ds only boolean to string fctx local request only fs put single max retries integer to string fctx max non splitfile retries fs put single finished boolean to string finished fs put single succeeded boolean to string succeeded if fctx allowedmime types null fs put overwrite allowedmime types string fctx allowedmime types to array new string fctx allowedmime types size if finished if succeeded fs put single found data length long to string found data length fs put single found data mime type found data mime type if post fetch protocol error message null fs put post fetch protocol error post fetch protocol error message get field set else if get failed message null fs put get failed get failed message get field set false return bucket if return type client get message return type direct succeeded false return bucket null bucket tofs fs return bucket false return bucket fs put single global boolean to string client is global queue fs put binary blob binary blob fs put startup time startup time if finished fs put completion time completion time return fs simplefieldset getfieldset simplefieldset simplefieldset putsingle putsingle tostring putsingle putsingle tostring putsingle priorityclass tostring priorityclass putsingle returntype clientgetmessage returntypestring returntype putsingle persistencetypestring persistencetype putsingle clientname targetfile putsingle targetfile getpath tempfile putsingle tempfilename tempfile getpath clienttoken putsingle clienttoken clienttoken putsingle tostring ignorestore putsingle dsonly tostring localrequestonly putsingle maxretries tostring maxnonsplitfileretries putsingle tostring putsingle tostring allowedmimetypes putoverwrite allowedmimetypes allowedmimetypes toarray allowedmimetypes putsingle founddatalength tostring founddatalength putsingle founddatamimetype founddatamimetype postfetchprotocolerrormessage postfetchprotocolerror postfetchprotocolerrormessage getfieldset getfailedmessage getfailed getfailedmessage getfieldset returntype clientgetmessage return_type_direct returnbucket buckettofs returnbucket returnbucket putsingle tostring isglobalqueue binaryblob binaryblob startuptime startuptime completiontime completiontime override protected client requester get client request return getter clientrequester getclientrequest override protected void free data object container container bucket data synchronized this data return bucket return bucket null if data null if persistence type persist forever container activate data 5 data free if persistence type persist forever data remove from container if persistence type persist forever container store this freedata objectcontainer returnbucket returnbucket persistencetype persist_forever persistencetype persist_forever removefrom persistencetype persist_forever override public boolean has succeeded return succeeded hassucceeded public boolean is direct return this return type client get message return type direct isdirect returntype clientgetmessage return_type_direct public boolean is to disk return this return type client get message return type disk istodisk returntype clientgetmessage return_type_disk public freeneturi geturi object container container if persistence type persist forever container activate uri 5 return uri objectcontainer persistencetype persist_forever public long get data size object container container if found data length 0 return found data length if getter null if persistence type persist forever container activate getter 1 return getter expected size return 1 getdatasize objectcontainer founddatalength founddatalength persistencetype persist_forever expectedsize public string getmime type object container container if found data mime type null return found data mime type if getter null if persistence type persist forever container activate getter 1 return getter expectedmime return null getmimetype objectcontainer founddatamimetype founddatamimetype persistencetype persist_forever public file get dest filename object container container if persistence type persist forever container activate target file 5 return target file getdestfilename objectcontainer persistencetype persist_forever targetfile targetfile override public double get success fraction object container container if persistence type persist forever progress pending null container activate progress pending 2 if progress pending null return progress pending get fraction else return 1 getsuccessfraction objectcontainer persistencetype persist_forever progresspending progresspending progresspending progresspending getfraction override public double get total blocks object container container if persistence type persist forever progress pending null container activate progress pending 2 if progress pending null return progress pending get total blocks else return 1 gettotalblocks objectcontainer persistencetype persist_forever progresspending progresspending progresspending progresspending gettotalblocks override public double get min blocks object container container if persistence type persist forever progress pending null container activate progress pending 2 if progress pending null return progress pending get min blocks else return 1 getminblocks objectcontainer persistencetype persist_forever progresspending progresspending progresspending progresspending getminblocks override public double get failed blocks object container container if persistence type persist forever progress pending null container activate progress pending 2 if progress pending null return progress pending get failed blocks else return 0 getfailedblocks objectcontainer persistencetype persist_forever progresspending progresspending progresspending progresspending getfailedblocks override public double get fataly failed blocks object container container if persistence type persist forever progress pending null container activate progress pending 2 if progress pending null return progress pending get fataly failed blocks else return 0 getfatalyfailedblocks objectcontainer persistencetype persist_forever progresspending progresspending progresspending progresspending getfatalyfailedblocks override public double get fetched blocks object container container if persistence type persist forever progress pending null container activate progress pending 2 if progress pending null return progress pending get fetched blocks else return 0 getfetchedblocks objectcontainer persistencetype persist_forever progresspending progresspending progresspending progresspending getfetchedblocks override public string get failure reason object container container if get failed message null return null if persistence type persist forever container activate get failed message 5 string s get failed message short code description if get failed message extra description null s get failed message extra description return s getfailurereason objectcontainer getfailedmessage persistencetype persist_forever getfailedmessage getfailedmessage shortcodedescription getfailedmessage extradescription getfailedmessage extradescription override public boolean is total finalized object container container if finished succeeded return true if progress pending null return false else if persistence type persist forever container activate progress pending 1 return progress pending is total finalized istotalfinalized objectcontainer progresspending persistencetype persist_forever progresspending progresspending istotalfinalized returns the link bucket that contains the downloaded data return the data in a link bucket or code null code if this isn rsquo t applicable public bucket get bucket object container container synchronized this if target file null if succeeded temp file null if persistence type persist forever container activate target file 5 return new file bucket target file false true false false false else if persistence type persist forever container activate temp file 5 return new file bucket temp file false true false false false else return return bucket getbucket objectcontainer targetfile tempfile persistencetype persist_forever targetfile filebucket targetfile persistencetype persist_forever tempfile filebucket tempfile returnbucket public void on fetchable base client putter state object container container ignore we don t insert onfetchable baseclientputter objectcontainer override public boolean can restart if finished logger minor this cannot restart because not finished for identifier return false if succeeded logger minor this cannot restart because succeeded for identifier return false return getter can restart canrestart canrestart override public boolean restart object container container client context context if can restart return false freeneturi redirect synchronized this finished false redirect get failed message null null get failed message redirecturi if persistence type persist forever get failed message null get failed message remove from container this get failed message null if persistence type persist forever all data pending null all data pending remove from container this all data pending null if persistence type persist forever post fetch protocol error message null post fetch protocol error message remove from container this post fetch protocol error message null if persistence type persist forever progress pending null progress pending remove from container this progress pending null started false if persistence type persist forever container store this try if getter restart redirect container context synchronized this if redirect null if persistence type persist forever uri remove from container this uri redirect started true if persistence type persist forever container store this return true catch fetch exception e on failure e null container return false objectcontainer clientcontext canrestart getfailedmessage getfailedmessage persistencetype persist_forever getfailedmessage getfailedmessage removefrom getfailedmessage persistencetype persist_forever alldatapending alldatapending removefrom alldatapending persistencetype persist_forever postfetchprotocolerrormessage postfetchprotocolerrormessage removefrom postfetchprotocolerrormessage persistencetype persist_forever progresspending progresspending removefrom progresspending persistencetype persist_forever persistencetype persist_forever removefrom persistencetype persist_forever fetchexception onfailure public synchronized boolean has perm redirect return get failed message null get failed message redirecturi null haspermredirect getfailedmessage getfailedmessage public void on remove event producer object container container do nothing we called the remove from onremoveeventproducer objectcontainer removefrom private boolean shadow override public int hash code return hash code hashcode hashcode public persistent blob temp bucket persistent blob temp bucket factory factory2 long block size2 long slot persistent blob temp bucket tag tag boolean shadow factory factory2 block size block size2 index slot hash code super hash code if tag null shadow throw new null pointer exception this tag tag this shadow shadow this read only shadow persistentblobtempbucket persistentblobtempbucketfactory blocksize2 persistentblobtempbuckettag blocksize blocksize2 hashcode hashcode nullpointerexception readonly public bucket create shadow throws io exception return factory create shadow this createshadow ioexception createshadow public void free if shadow factory free shadow index this else factory free bucket index this will call on free always take the outer lock first freeshadow freebucket onfree public boolean freed return freed synchronized void on free freed true onfree boolean persisted return persisted public input stream get input stream throws io exception if freed throw new io exception already freed final file channel channel factory channel synchronized persistent blob temp bucket this input streams return new input stream private int offset private boolean closed override public int read throws io exception if closed throw new io exception closed byte buf new byte 1 int res read buf if res 1 return 1 return buf 0 override public int read byte buffer int buf offset int length throws io exception if closed throw new io exception closed long max synchronized persistent blob temp bucket this if freed throw new io exception bucket freed during read max math min block size size if length 0 return 0 if buf offset 0 return 1 throw new eof exception if offset length max length int math min max offset integer max value if length 0 return 1 if length 0 throw new illegal state exception offset buf offset length length buf len buffer length my offset is offset my size is max for this for persistent blob temp bucket this byte buffer buf byte buffer wrap buffer buf offset length int read channel read buf block size index offset if read 0 offset read return read override public int read byte buffer throws io exception if closed throw new io exception closed return read buffer 0 buffer length override public int available return int math min block size offset integer max value override public void close if closed return closed true synchronized persistent blob temp bucket this input streams do nothing inputstream getinputstream ioexception ioexception filechannel persistentblobtempbucket inputstreams inputstream ioexception ioexception bufoffset ioexception ioexception persistentblobtempbucket ioexception blocksize bufoffset eofexception max_value illegalstateexception bufoffset persistentblobtempbucket bytebuffer bytebuffer bufoffset blocksize ioexception ioexception blocksize max_value persistentblobtempbucket inputstreams override public int read throws io exception if closed throw new io exception closed byte buf new byte 1 int res read buf if res 1 return 1 return buf 0 ioexception ioexception override public int read byte buffer int buf offset int length throws io exception if closed throw new io exception closed long max synchronized persistent blob temp bucket this if freed throw new io exception bucket freed during read max math min block size size if length 0 return 0 if buf offset 0 return 1 throw new eof exception if offset length max length int math min max offset integer max value if length 0 return 1 if length 0 throw new illegal state exception offset buf offset length length buf len buffer length my offset is offset my size is max for this for persistent blob temp bucket this byte buffer buf byte buffer wrap buffer buf offset length int read channel read buf block size index offset if read 0 offset read return read bufoffset ioexception ioexception persistentblobtempbucket ioexception blocksize bufoffset eofexception max_value illegalstateexception bufoffset persistentblobtempbucket bytebuffer bytebuffer bufoffset blocksize override public int read byte buffer throws io exception if closed throw new io exception closed return read buffer 0 buffer length ioexception ioexception override public int available return int math min block size offset integer max value blocksize max_value override public void close if closed return closed true synchronized persistent blob temp bucket this input streams do nothing persistentblobtempbucket inputstreams public string get name return factory get name index getname getname public output stream get output stream throws io exception if freed throw new io exception already freed if shadow throw new io exception shadow if read only throw new io exception read only final file channel channel factory channel return new output stream private int offset override public void write int arg throws io exception byte buf new byte byte arg write buf 0 1 override public void write byte buffer int buf offset int length throws io exception synchronized persistent blob temp bucket this if freed throw new io exception bucket freed during write if read only throw new io exception bucket made read only during write long remaining block size offset if remaining 0 throw new io exception too big if length remaining throw new io exception writing too many bytes written offset of block size and now want to write length byte buffer buf byte buffer wrap buffer buf offset length int written 0 while written length int w channel write buf block size index offset offset w synchronized persistent blob temp bucket this size w written w override public void write byte buffer throws io exception write buffer 0 buffer length outputstream getoutputstream ioexception ioexception ioexception readonly ioexception filechannel outputstream ioexception bufoffset ioexception persistentblobtempbucket ioexception readonly ioexception blocksize ioexception ioexception blocksize bytebuffer bytebuffer bufoffset blocksize persistentblobtempbucket ioexception override public void write int arg throws io exception byte buf new byte byte arg write buf 0 1 ioexception override public void write byte buffer int buf offset int length throws io exception synchronized persistent blob temp bucket this if freed throw new io exception bucket freed during write if read only throw new io exception bucket made read only during write long remaining block size offset if remaining 0 throw new io exception too big if length remaining throw new io exception writing too many bytes written offset of block size and now want to write length byte buffer buf byte buffer wrap buffer buf offset length int written 0 while written length int w channel write buf block size index offset offset w synchronized persistent blob temp bucket this size w written w bufoffset ioexception persistentblobtempbucket ioexception readonly ioexception blocksize ioexception ioexception blocksize bytebuffer bytebuffer bufoffset blocksize persistentblobtempbucket override public void write byte buffer throws io exception write buffer 0 buffer length ioexception public synchronized boolean is read only return read only isreadonly readonly public synchronized void set read only read only true setreadonly readonly public synchronized long size return size public void store to object container container if shadow throw new unsupported operation exception can t store a shadow boolean p synchronized this if tag null throw new null pointer exception p persisted persisted true if p factory store this container calls on store take the outer lock first storeto objectcontainer unsupportedoperationexception nullpointerexception onstore public boolean object can new object container container if shadow throw new unsupported operation exception can t store a shadow synchronized this if persisted return true logger error this object on new called but we haven t been stored yet for this for factory index index new exception error return true objectcannew objectcontainer unsupportedoperationexception objectonnew public boolean object can deactivate object container container if input streams 0 logger error this deactivating when have active input streams new exception error return false return true objectcandeactivate objectcontainer inputstreams public void remove from object container container if shadow throw new unsupported operation exception can t store a shadow boolean p synchronized this p persisted if p factory remove this container calls on remove container delete this removefrom objectcontainer unsupportedoperationexception onremove synchronized void on remove persisted false onremove private static final long serial versionuid 4509857798038125744l public ssdp search response socket list serialversionuid ssdpsearchresponsesocketlist public void set control point control point ctrl point int n sockets size for int n 0 n n sockets n ssdp search response socket sock getssdp search response socket n sock set control point ctrl point setcontrolpoint controlpoint ctrlpoint nsockets nsockets ssdpsearchresponsesocket getssdpsearchresponsesocket setcontrolpoint ctrlpoint public ssdp search response socket getssdp search response socket int n return ssdp search response socket get n ssdpsearchresponsesocket getssdpsearchresponsesocket ssdpsearchresponsesocket public boolean open int port try int n host addrs host interface getn host addresses for int n 0 n n host addrs n string bind addr host interface get host address n ssdp search response socket socket new ssdp search response socket bind addr port add socket catch exception e stop close clear return false return true nhostaddrs hostinterface getnhostaddresses nhostaddrs bindaddr hostinterface gethostaddress ssdpsearchresponsesocket ssdpsearchresponsesocket bindaddr public boolean open return open ssdp port public void close int n sockets size for int n 0 n n sockets n ssdp search response socket sock getssdp search response socket n sock close clear nsockets nsockets ssdpsearchresponsesocket getssdpsearchresponsesocket public void start int n sockets size for int n 0 n n sockets n ssdp search response socket sock getssdp search response socket n sock start nsockets nsockets ssdpsearchresponsesocket getssdpsearchresponsesocket public void stop int n sockets size for int n 0 n n sockets n ssdp search response socket sock getssdp search response socket n sock stop nsockets nsockets ssdpsearchresponsesocket getssdpsearchresponsesocket public boolean post ssdp search request req boolean ret true int n sockets size for int n 0 n n sockets n ssdp search response socket sock getssdp search response socket n string bind addr sock get local address req set local address bind addr string ssdp addr ssdp address if host interface isi pv6 address bind addr true ssdp addr ssdp geti pv6 address sock join group ssdp addr ssdp port bind addr if sock post ssdp addr ssdp port req false ret false sock leave group ssdp addr ssdp port bind addr return ret ssdpsearchrequest nsockets nsockets ssdpsearchresponsesocket getssdpsearchresponsesocket bindaddr getlocaladdress setlocaladdress bindaddr ssdpaddr hostinterface isipv6address bindaddr ssdpaddr getipv6address joingroup ssdpaddr bindaddr ssdpaddr leavegroup ssdpaddr bindaddr public final subscribeusk message message subscribedusk message subscribeusk message m this message m subscribeuskmessage subscribeduskmessage subscribeuskmessage override public simple field set get field set simple field set sfs new simple field set true sfs put single identifier message identifier sfs put single uri message key geturi to string sfs put dont poll message dont poll return sfs simplefieldset getfieldset simplefieldset simplefieldset putsingle putsingle tostring dontpoll dontpoll override public string get name return name getname override public void run fcp connection handler handler node node throws message invalid exception throw new message invalid exception protocol error message invalid message name goes from server to client not the other way around name false fcpconnectionhandler messageinvalidexception messageinvalidexception protocolerrormessage invalid_message override public void remove from object container container container activate message 1 message remove from container fixme this is throwing unsupported operation exception container delete this removefrom objectcontainer removefrom unsupportedoperationexception private int hash code public byte array wrapper byte data buf data hash code fields hash code buf hashcode bytearraywrapper hashcode hashcode override public boolean equals object o if o instanceof byte array wrapper byte array wrapper b byte array wrapper o if b buf buf return true return arrays equals b buf buf return false bytearraywrapper bytearraywrapper bytearraywrapper override public int hash code return hash code hashcode hashcode private int lut public equalize filter equalizefilter override protected int filter pixels int width int height int in pixels rectangle transformed space histogram histogram new histogram in pixels width height 0 width int i j if histogram get num samples 0 float scale 255 0f histogram get num samples lut new int 3 256 for i 0 i 3 i lut i 0 histogram get frequency i 0 for j 1 j 256 j lut i j lut i j 1 histogram get frequency i j for j 0 j 256 j lut i j int math round lut i j scale else lut null i 0 for int y 0 y height y for int x 0 x width x in pixels i filterrgb x y in pixels i i lut null return in pixels filterpixels inpixels transformedspace inpixels getnumsamples getnumsamples getfrequency getfrequency inpixels inpixels inpixels private int filterrgb int x int y int rgb if lut null int a rgb 0xff000000 int r lut histogram red rgb 16 0xff int g lut histogram green rgb 8 0xff int b lut histogram blue rgb 0xff return a r 16 g 8 b return rgb override public string to string return colors equalize tostring public advertiser device dev set device dev setdevice private device device public void set device device dev device dev setdevice public device get device return device getdevice public void run device dev get device long lease time dev get lease time long notify interval while is runnable true notify interval lease time 4 long float lease time math random 0 25f notify interval 1000 try thread sleep notify interval catch interrupted exception e dev announce getdevice leasetime getleasetime notifyinterval isrunnable notifyinterval leasetime leasetime notifyinterval notifyinterval interruptedexception public term string word storage storage this word word md5 md5 word page set storage page create scalable set storage make persistent this pageset createscalableset makepersistent public term public boolean add page page page return page set add page addpage pageset public boolean remove page page page return page set remove page removepage pageset public set page get pages return page set getpages pageset public string get word return word getword public string getmd5 return md5 override public boolean equals object o if o null return false if get class o get class return false term t term o return md5 equals t md5 word equals t word getclass getclass override public int hash code return md5 hash code word hash code hashcode hashcode hashcode public static string md5 string text try message digest md message digest get instance md5 byte md5hash new byte 32 byte b text get bytes utf 8 md update b 0 b length md5hash md digest return convert to hex md5hash catch unsupported encoding exception e throw new runtime exception utf 8 not supported e catch no such algorithm exception e throw new runtime exception md5 not supported e messagedigest messagedigest getinstance getbytes converttohex unsupportedencodingexception runtimeexception nosuchalgorithmexception runtimeexception public static string convert to hex byte data string builder buf new string builder for int i 0 i data length i int halfbyte data i 4 0x0f int two halfs 0 do if 0 halfbyte halfbyte 9 buf append char 0 halfbyte else buf append char a halfbyte 10 halfbyte data i 0x0f while two halfs 1 return buf to string converttohex stringbuilder stringbuilder two_halfs two_halfs tostring private static final long serial versionuid 1 too long exception string s super s serialversionuid toolongexception public identity manager ext object container mydb executor my executor logger debug this creating identity manager db mydb m executor my executor identitymanager extobjectcontainer myexecutor mexecutor myexecutor for being used in j unit tests to run without a node public identity manager ext object container mydb db mydb m executor null junit identitymanager extobjectcontainer mexecutor public abstract ft own identity create own identity string new nickname boolean publishes trust list boolean publishes introduction puzzles throws exception ftownidentity createownidentity newnickname publishestrustlist publishesintroductionpuzzles public abstract ft own identity create own identity string new nickname boolean publishes trust list boolean publishes introduction puzzles throws exception public abstract ft own identity create own identity string new nickname boolean publishes trust list boolean publishes introduction puzzles freeneturi requesturi freeneturi inserturi throws exception ftownidentity createownidentity newnickname publishestrustlist publishesintroductionpuzzles ftownidentity createownidentity newnickname publishestrustlist publishesintroductionpuzzles freeneturi requesturi freeneturi inserturi throws exception public abstract iterable extends ft identity get all identities ftidentity getallidentities public synchronized int count known identities fixme this should probably take an ft own identity as param and count the identities seen by it query q db query q constrain ft identity class q constrain ft own identity class not return q execute size countknownidentities ftownidentity ftidentity ftownidentity suppress warnings unchecked public synchronized iterator ft own identity own identity iterator return new iterator ft own identity iterator ft own identity iter query q db query q constrain ft own identity class iter q execute iterator public boolean has next return iter has next public ft own identity next ft own identity oi iter next oi initialize transient db identity manager this return oi public void remove throw new unsupported operation exception cannot delete own identities via own identity iterator suppresswarnings ftownidentity ownidentityiterator ftownidentity ftownidentity ftownidentity hasnext hasnext ftownidentity ftownidentity initializetransient identitymanager unsupportedoperationexception ownidentityiterator public boolean has next return iter has next hasnext hasnext public ft own identity next ft own identity oi iter next oi initialize transient db identity manager this return oi ftownidentity ftownidentity initializetransient identitymanager public void remove throw new unsupported operation exception cannot delete own identities via own identity iterator unsupportedoperationexception ownidentityiterator public abstract ft identity get identity string uid throws no such identity exception ftidentity getidentity nosuchidentityexception public abstract ft identity get identity string uid throws no such identity exception public abstract ft own identity get own identity string uid throws no such identity exception ftidentity getidentity nosuchidentityexception ftownidentity getownidentity nosuchidentityexception public synchronized boolean any own identity wants messages from ft identity identity iterator ft own identity iter own identity iterator boolean no own identities true while iter has next no own identities false ft own identity oid iter next if oid wants messages from identity return true return no own identities true false anyownidentitywantsmessagesfrom ftidentity ftownidentity ownidentityiterator noownidentities hasnext noownidentities ftownidentity wantsmessagesfrom noownidentities public abstract void terminate param spider public web interface xml spider spider xml spider spider page maker xml spider get page maker page maker add navigation link plugins plugins xml spider xml spider home home page false null page maker add navigation link plugins plugins xml spider xml spider config page config configuration false null page maker add navigation link plugins plugins page back to plugins page false null webinterface xmlspider xmlspider pagemaker xmlspider getpagemaker pagemaker addnavigationlink xmlspider xmlspider pagemaker addnavigationlink xmlspider xmlspider configpage pagemaker addnavigationlink interface to the spider data public string handlehttp get http request request throws pluginhttp exception html node page node page maker get page node xml spider plugin name null html node content node page maker get content node page node web page page get page object request page write content request content node return page node generate handlehttpget httprequest pluginhttpexception htmlnode pagenode pagemaker getpagenode xmlspider pluginname htmlnode contentnode pagemaker getcontentnode pagenode webpage getpageobject writecontent contentnode pagenode public string handlehttp post http request request throws pluginhttp exception html node page node page maker get page node xml spider plugin name null html node content node page maker get content node page node web page page get page object request page process post request request content node page write content request content node return page node generate handlehttppost httprequest pluginhttpexception htmlnode pagenode pagemaker getpagenode xmlspider pluginname htmlnode contentnode pagemaker getcontentnode pagenode webpage getpageobject processpostrequest contentnode writecontent contentnode pagenode public web page get page object http request request if request is parameter set config page return new config page xml spider return new main page xml spider webpage getpageobject httprequest isparameterset configpage configpage xmlspider mainpage xmlspider public class state variable data extends node data public state variable data statevariabledata nodedata statevariabledata private string value public string get value return value getvalue public void set value string value this value value setvalue private query listener query listener null public query listener get query listener return query listener querylistener querylistener querylistener getquerylistener querylistener public void set query listener query listener query listener this query listener query listener setquerylistener querylistener querylistener querylistener querylistener private query response query res null public query response get query response return query res queryresponse queryres queryresponse getqueryresponse queryres public void set query response query response res query res res setqueryresponse queryresponse queryres public class compile error extends runtime exception public compile error string msg int pos super msg in position pos compileerror runtimeexception compileerror public progress string initialmsg retrieved false complete false msg initialmsg public void set string msg msg msg retrieved false _msg _msg public void done string msg done msg null public void done string msg string result retrieved false complete true this msg msg this result result null result todo better status format public string get boolean pushonupdate probably best to do this with a lock if pushonupdate look for a progress update while retrieved whilst theres no new msg try thread sleep 500 catch java lang interrupted exception e retrieved true if complete return msg br event description else return msg br event description interruptedexception eventdescription eventdescription public string getresult return result hears an event param container the database context the event was generated in note that it may not have been generated in a database context at all in this case container will be null and you should use context to schedule a db job public void receive client event ce object container maybe container client context context event description ce get description retrieved false dbjob clientevent objectcontainer maybecontainer clientcontext eventdescription getdescription called when the event producer gets remove from object container if the listener is the main listener which probably called remove from it should do nothing if it s a tag along but request specific listener it may need to remove itself public void on remove event producer object container container eventproducer removefrom objectcontainer removefrom onremoveeventproducer objectcontainer private static final long serial versionuid 1 public illegal base64 exception string descr super descr serialversionuid illegalbase64exception public abstract class persistent collection t extends persistent resource implements i table t public iterable iterator t select class cls string predicate query t query new query impl t get storage return query select cls iterator predicate persistentcollection persistentresource itable iterableiterator queryimpl getstorage returns tt true tt if this collection contains all of the elements in the specified collection p this implementation iterates over the specified collection checking each element returned by the iterator in turn to see if it s contained in this collection if all elements are so contained tt true tt is returned otherwise tt false tt param c collection to be checked for containment in this collection return tt true tt if this collection contains all of the elements in the specified collection throws null pointer exception if the specified collection is null see contains object public boolean contains all collection c iterator e c iterator while e has next if contains e next return false return true nullpointerexception containsall hasnext adds all of the elements in the specified collection to this collection optional operation the behavior of this operation is undefined if the specified collection is modified while the operation is in progress this implies that the behavior of this call is undefined if the specified collection is this collection and this collection is nonempty p this implementation iterates over the specified collection and adds each object returned by the iterator to this collection in turn p note that this implementation will throw an tt unsupported operation exception tt unless tt add tt is overridden assuming the specified collection is non empty param c collection whose elements are to be added to this collection return tt true tt if this collection changed as a result of the call throws unsupported operation exception if this collection does not support the tt add all tt method throws null pointer exception if the specified collection is null see add object public boolean add all collection extends t c boolean modified false iterator extends t e c iterator while e has next if add e next modified true return modified unsupportedoperationexception unsupportedoperationexception addall nullpointerexception addall hasnext removes from this collection all of its elements that are contained in the specified collection optional operation p this implementation iterates over this collection checking each element returned by the iterator in turn to see if it s contained in the specified collection if it s so contained it s removed from this collection with the iterator s tt remove tt method p note that this implementation will throw an tt unsupported operation exception tt if the iterator returned by the tt iterator tt method does not implement the tt remove tt method and this collection contains one or more elements in common with the specified collection param c elements to be removed from this collection return tt true tt if this collection changed as a result of the call throws unsupported operation exception if the tt remove all tt method is not supported by this collection throws null pointer exception if the specified collection is null see remove object see contains object public boolean remove all collection c boolean modified false iterator i c iterator while i has next modified remove i next return modified unsupportedoperationexception unsupportedoperationexception removeall nullpointerexception removeall hasnext retains only the elements in this collection that are contained in the specified collection optional operation in other words removes from this collection all of its elements that are not contained in the specified collection p this implementation iterates over this collection checking each element returned by the iterator in turn to see if it s contained in the specified collection if it s not so contained it s removed from this collection with the iterator s tt remove tt method p note that this implementation will throw an tt unsupported operation exception tt if the iterator returned by the tt iterator tt method does not implement the tt remove tt method and this collection contains one or more elements not present in the specified collection param c elements to be retained in this collection return tt true tt if this collection changed as a result of the call throws unsupported operation exception if the tt retain all tt method is not supported by this collection throws null pointer exception if the specified collection is null see remove object see contains object public boolean retain all collection c array list t to be removed new array list t iterator t i iterator while i has next t o i next if c contains o to be removed add o int n to be removed size for int j 0 j n j remove to be removed get j return n 0 unsupportedoperationexception unsupportedoperationexception retainall nullpointerexception retainall arraylist toberemoved arraylist hasnext toberemoved toberemoved toberemoved returns tt true tt if this collection contains the specified element more formally returns tt true tt if and only if this collection contains at least one element tt e tt such that tt o null e null o equals e tt p this implementation iterates over the elements in the collection checking each element in turn for equality with the specified element param o object to be checked for containment in this collection return tt true tt if this collection contains the specified element public boolean contains object o iterator t e iterator if o null while e has next if e next null return true else while e has next if o equals e next return true return false hasnext hasnext removes a single instance of the specified element from this collection if it is present optional operation more formally removes an element tt e tt such that tt o null e null o equals e tt if the collection contains one or more such elements returns tt true tt if the collection contained the specified element or equivalently if the collection changed as a result of the call p this implementation iterates over the collection looking for the specified element if it finds the element it removes the element from the collection using the iterator s remove method p note that this implementation throws an tt unsupported operation exception tt if the iterator returned by this collection s iterator method does not implement the tt remove tt method and this collection contains the specified object param o element to be removed from this collection if present return tt true tt if the collection contained the specified element throws unsupported operation exception if the tt remove tt method is not supported by this collection public boolean remove object o iterator t e iterator if o null while e has next if e next null e remove return true else while e has next if o equals e next e remove return true return false unsupportedoperationexception unsupportedoperationexception hasnext hasnext ensures that this collection contains the specified element optional operation returns tt true tt if the collection changed as a result of the call returns tt false tt if this collection does not permit duplicates and already contains the specified element collections that support this operation may place limitations on what elements may be added to the collection in particular some collections will refuse to add tt null tt elements and others will impose restrictions on the type of elements that may be added collection classes should clearly specify in their documentation any restrictions on what elements may be added p this implementation always throws an tt unsupported operation exception tt param o element whose presence in this collection is to be ensured return tt true tt if the collection changed as a result of the call throws unsupported operation exception if the tt add tt method is not supported by this collection throws null pointer exception if this collection does not permit tt null tt elements and the specified element is tt null tt throws class cast exception if the class of the specified element prevents it from being added to this collection throws illegal argument exception if some aspect of this element prevents it from being added to this collection public boolean add t o throw new unsupported operation exception unsupportedoperationexception unsupportedoperationexception nullpointerexception classcastexception illegalargumentexception unsupportedoperationexception returns tt true tt if this collection contains no elements p this implementation returns tt size 0 tt return tt true tt if this collection contains no elements public boolean is empty return size 0 isempty default constructor public persistent collection persistentcollection constructor of the collection associated with the specified storage param storage storage associated with the collection public persistent collection storage storage super storage persistentcollection private static final long serial versionuid 1l public no such board exception super serialversionuid nosuchboardexception public no such board exception string name super unknown board name nosuchboardexception public edit own identity page web interface my web interface http request my request throws unknown identity exception super my web interface my request m identity wot get own identity byid request get part as string id 128 editownidentitypage webinterface mywebinterface httprequest myrequest unknownidentityexception mywebinterface myrequest midentity getownidentitybyid getpartasstring public void make synchronized wot synchronized m identity if request is part set edit try m identity set publish trust list request is part set publish trust list request get part as string publish trust list 6 equals true if request is part set publish puzzles request get part as string publish puzzles 6 equals true m identity add context introduction puzzle introduction context m identity set property introduction server puzzle count property integer to string introduction server default puzzle count else m identity remove context introduction puzzle introduction context m identity remove property introduction server puzzle count property wot store and commit m identity catch exception e add error box saving the changes failed e get message html node box add content box edit identity m identity get nickname html node create form pr add form child box uri edit identity create form add child input new string type name value new string hidden id m identity getid create form add child input new string type name value new string hidden page edit identity create form add child p new string style new string font size x small request uri m identity get requesturi to string create form add child p new string style new string font size x small insert uri keep this secret m identity get inserturi to string todo give the user the ability to edit these create form add child p contexts m identity get contexts create form add child p properties m identity get properties html node p create form add child p publish trust list if m identity does publish trust list p add child input new string type name value checked new string checkbox publish trust list true checked else p add child input new string type name value new string checkbox publish trust list true p create form add child p publish introduction puzzles if m identity has context introduction puzzle introduction context p add child input new string type name value checked new string checkbox publish puzzles true checked else p add child input new string type name value new string checkbox publish puzzles true create form add child input new string type name value new string submit edit save changes midentity ispartset midentity setpublishtrustlist ispartset publishtrustlist getpartasstring publishtrustlist ispartset publishpuzzles getpartasstring publishpuzzles midentity addcontext introductionpuzzle introduction_context midentity setproperty introductionserver puzzle_count_property tostring introductionserver default_puzzle_count midentity removecontext introductionpuzzle introduction_context midentity removeproperty introductionserver puzzle_count_property storeandcommit midentity adderrorbox getmessage htmlnode addcontentbox midentity getnickname htmlnode createform addformchild editidentity createform addchild midentity createform addchild editidentity createform addchild midentity getrequesturi tostring createform addchild midentity getinserturi tostring createform addchild midentity getcontexts createform addchild midentity getproperties htmlnode createform addchild midentity doespublishtrustlist addchild publishtrustlist addchild publishtrustlist createform addchild midentity hascontext introductionpuzzle introduction_context addchild publishpuzzles addchild publishpuzzles createform addchild public http socket socket socket set socket socket open httpsocket setsocket public http socket http socket socket set socket socket get socket set input stream socket get input stream set output stream socket get output stream httpsocket httpsocket setsocket getsocket setinputstream getinputstream setoutputstream getoutputstream public void finalize close private socket socket null private void set socket socket socket this socket socket setsocket public socket get socket return socket getsocket public string get local address return get socket get local address get host address getlocaladdress getsocket getlocaladdress gethostaddress public int get local port return get socket get local port getlocalport getsocket getlocalport private output stream sock out null private void set input stream input stream in sock in in outputstream sockout setinputstream inputstream sockin public input stream get input stream return sock in inputstream getinputstream sockin private void set output stream output stream out sock out out setoutputstream outputstream sockout private output stream get output stream return sock out outputstream getoutputstream sockout public boolean open socket sock get socket try sock in sock get input stream sock out sock get output stream catch exception e return false return true getsocket sockin getinputstream sockout getoutputstream public boolean close try if sock in null sock in close if sock out null sock out close get socket close catch exception e debug warning e return false return true sockin sockin sockout sockout getsocket private boolean post http response http res byte content long content offset long content length boolean is only header http res set date calendar get instance output stream out get output stream try http res set content length content length out write http res get header get bytes out write http crlf get bytes if is only header true out flush return true boolean is chunked response http res is chunked if is chunked response true string chun size buf long to string content length out write chun size buf get bytes out write http crlf get bytes out write content int content offset int content length if is chunked response true out write http crlf get bytes out write 0 get bytes out write http crlf get bytes out flush catch exception e debug warning e return false return true httpresponse httpres contentoffset contentlength isonlyheader httpres setdate getinstance outputstream getoutputstream httpres setcontentlength contentlength httpres getheader getbytes getbytes isonlyheader ischunkedresponse httpres ischunked ischunkedresponse chunsizebuf tostring contentlength chunsizebuf getbytes getbytes contentoffset contentlength ischunkedresponse getbytes getbytes getbytes private boolean post http response http res input stream in long content offset long content length boolean is only header http res set date calendar get instance output stream out get output stream try http res set content length content length out write http res get header get bytes out write http crlf get bytes if is only header true out flush return true boolean is chunked response http res is chunked if 0 content offset in skip content offset int chunk size http get chunk size byte read buf new byte chunk size long read cnt 0 long read size chunk size content length chunk size content length int read len in read read buf 0 int read size while 0 read len read cnt content length if is chunked response true string chun size buf long to string read len out write chun size buf get bytes out write http crlf get bytes out write read buf 0 read len if is chunked response true out write http crlf get bytes read cnt read len read size chunk size content length read cnt chunk size content length read cnt read len in read read buf 0 int read size if is chunked response true out write 0 get bytes out write http crlf get bytes out flush catch exception e debug warning e return false return true httpresponse httpres inputstream contentoffset contentlength isonlyheader httpres setdate getinstance outputstream getoutputstream httpres setcontentlength contentlength httpres getheader getbytes getbytes isonlyheader ischunkedresponse httpres ischunked contentoffset contentoffset chunksize getchunksize readbuf chunksize readcnt readsize chunksize contentlength chunksize contentlength readlen readbuf readsize readlen readcnt contentlength ischunkedresponse chunsizebuf tostring readlen chunsizebuf getbytes getbytes readbuf readlen ischunkedresponse getbytes readcnt readlen readsize chunksize contentlength readcnt chunksize contentlength readcnt readlen readbuf readsize ischunkedresponse getbytes getbytes public boolean post http response http res long content offset long content length boolean is only header if http res has content input stream true return post http res http res get content input stream content offset content length is only header return post http res http res get content content offset content length is only header httpresponse httpres contentoffset contentlength isonlyheader httpres hascontentinputstream httpres httpres getcontentinputstream contentoffset contentlength isonlyheader httpres httpres getcontent contentoffset contentlength isonlyheader public canceler jmdns impl jmdns impl service info impl info object lock this jmdns impl jmdns impl this infos new service info impl info this lock lock this jmdns impl add listener info new dns question info get qualified name dns constants type any dns constants class in jmdnsimpl jmdnsimpl serviceinfoimpl jmdnsimpl jmdnsimpl serviceinfoimpl jmdnsimpl addlistener dnsquestion getqualifiedname dnsconstants type_any dnsconstants class_in public canceler jmdns impl jmdns impl service info impl infos object lock this jmdns impl jmdns impl this infos infos this lock lock jmdnsimpl jmdnsimpl serviceinfoimpl jmdnsimpl jmdnsimpl public canceler jmdns impl jmdns impl collection infos object lock this jmdns impl jmdns impl this infos service info impl infos to array new service info impl infos size this lock lock jmdnsimpl jmdnsimpl jmdnsimpl jmdnsimpl serviceinfoimpl toarray serviceinfoimpl public void start timer timer timer schedule this 0 dns constants announce wait interval dnsconstants announce_wait_interval public void run try if count 3 logger finer run jmdns canceling service announce the service long now system current time millis dns outgoing out new dns outgoing dns constants flags qr response dns constants flags aa for int i 0 i infos length i service info impl info infos i info add answers out ttl this jmdns impl get local host this jmdns impl get local host add address records out false this jmdns impl send out else after three successful announcements we are finished synchronized lock this jmdns impl set closed true lock notify all this cancel catch throwable e logger log level warning run exception e this jmdns impl recover currenttimemillis dnsoutgoing dnsoutgoing dnsconstants flags_qr_response dnsconstants flags_aa serviceinfoimpl addanswers jmdnsimpl getlocalhost jmdnsimpl getlocalhost addaddressrecords jmdnsimpl jmdnsimpl setclosed notifyall jmdnsimpl public remove peer simple field set fs this fs fs identifier fs get identifier fs remove value identifier removepeer simplefieldset removevalue override public simple field set get field set return new simple field set true simplefieldset getfieldset simplefieldset override public string get name return name getname override public void run fcp connection handler handler node node throws message invalid exception if handler has full access throw new message invalid exception protocol error message access denied name requires full access identifier false string node identifier fs get node identifier if node identifier null throw new message invalid exception protocol error message missing field error node identifier field missing identifier false peer node pn node get peer node node identifier if pn null fcp message msg new unknown node identifier message node identifier identifier handler output handler queue msg return string identity pn get identity string node remove peer connection pn handler output handler queue new peer removed identity node identifier identifier fcpconnectionhandler messageinvalidexception hasfullaccess messageinvalidexception protocolerrormessage access_denied nodeidentifier nodeidentifier nodeidentifier messageinvalidexception protocolerrormessage missing_field nodeidentifier peernode getpeernode nodeidentifier fcpmessage unknownnodeidentifiermessage nodeidentifier outputhandler getidentitystring removepeerconnection outputhandler peerremoved nodeidentifier override public void remove from object container container throw new unsupported operation exception removefrom objectcontainer unsupportedoperationexception int old oid btree key key key int oid this key key this oid oid oldoid btreekey final void get str page pg int i int len btree page get key str size pg i int offs btree page first key offs btree page get key str offs pg i char sval new char len for int j 0 j len j sval j char bytes unpack2 pg data offs offs 2 key new key sval getstr btreepage getkeystrsize btreepage firstkeyoffs btreepage getkeystroffs final void get byte array page pg int i int len btree page get key str size pg i int offs btree page first key offs btree page get key str offs pg i byte bval new byte len system arraycopy pg data offs bval 0 len key new key bval getbytearray btreepage getkeystrsize btreepage firstkeyoffs btreepage getkeystroffs final void extract page pg int offs int type byte data pg data switch type case class descriptor tp boolean key new key data offs 0 break case class descriptor tp byte key new key data offs break case class descriptor tp short key new key bytes unpack2 data offs break case class descriptor tp char key new key char bytes unpack2 data offs break case class descriptor tp int case class descriptor tp object case class descriptor tp enum key new key bytes unpack4 data offs break case class descriptor tp long case class descriptor tp date key new key bytes unpack8 data offs break case class descriptor tp float key new key float int bits to float bytes unpack4 data offs break case class descriptor tp double key new key double long bits to double bytes unpack8 data offs break default assert failed invalid type classdescriptor tpboolean classdescriptor tpbyte classdescriptor tpshort classdescriptor tpchar classdescriptor tpint classdescriptor tpobject classdescriptor tpenum classdescriptor tplong classdescriptor tpdate classdescriptor tpfloat intbitstofloat classdescriptor tpdouble longbitstodouble final void pack page pg int i byte dst pg data switch key type case class descriptor tp boolean case class descriptor tp byte dst btree page first key offs i byte key ival break case class descriptor tp short case class descriptor tp char bytes pack2 dst btree page first key offs i 2 short key ival break case class descriptor tp int case class descriptor tp object case class descriptor tp enum bytes pack4 dst btree page first key offs i 4 key ival break case class descriptor tp long case class descriptor tp date bytes pack8 dst btree page first key offs i 8 key lval break case class descriptor tp float bytes pack4 dst btree page first key offs i 4 float float to int bits float key dval break case class descriptor tp double bytes pack8 dst btree page first key offs i 8 double double to long bits key dval break default assert failed invalid type bytes pack4 dst btree page first key offs btree page max items i 1 4 oid classdescriptor tpboolean classdescriptor tpbyte btreepage firstkeyoffs classdescriptor tpshort classdescriptor tpchar btreepage firstkeyoffs classdescriptor tpint classdescriptor tpobject classdescriptor tpenum btreepage firstkeyoffs classdescriptor tplong classdescriptor tpdate btreepage firstkeyoffs classdescriptor tpfloat btreepage firstkeyoffs floattointbits classdescriptor tpdouble btreepage firstkeyoffs doubletolongbits btreepage firstkeyoffs btreepage maxitems peer node status peer node peer node boolean no heavy peer p peer node get peer if p null peer address null peer port 1 else peer address p get freenet address to string peer port p get port this selection rate peer node selection rate this status value peer node get peer node status this status name peer node get peer node status string this statuscss name peer node get peer node statuscss class name this location peer node get location this peers location peer node get peers location this version peer node get version this simple version peer node get simple version this routing backoff length peer node get routing backoff length this routing backed off until peer node get routing backed off until this connected peer node is connected this routable peer node is routable this is fetchingark peer node is fetchingark this is opennet peer node is opennet this average ping time peer node average ping time this public invalid version peer node public invalid version this public reverse invalid version peer node public reverse invalid version this backed off percent peer node backed off percent current value this last backoff reason peer node get last backoff reason this time last routable peer node time last routable this time last connection completed peer node time last connection completed this peer added time peer node get peer added time if no heavy this local messages received peer node get local node received messages from statistic this local messages sent peer node get local node sent messages to statistic else this local messages received null this local messages sent null this hash code peer node hash code this p reject peer node getp rejected this total bytes in peer node get total input bytes this total bytes out peer node get total output bytes this total bytes in since startup peer node get total input since startup this total bytes out since startup peer node get total output since startup this percent time routable connection peer node get percent time routable connection this throttle peer node get throttle this clock delta peer node get clock delta this record status peer node record status this is seed client peer node instanceof seed client peer node this is seed server peer node instanceof seed server peer node this is searchable peer node is real connection this resend bytes sent peer node get resend bytes sent this reported uptime percentage peer node get uptime peernodestatus peernode peernode noheavy peernode getpeer peeraddress peerport peeraddress getfreenetaddress tostring peerport getport selectionrate peernode selectionrate statusvalue peernode getpeernodestatus statusname peernode getpeernodestatusstring statuscssname peernode getpeernodestatuscssclassname peernode getlocation peerslocation peernode getpeerslocation peernode getversion simpleversion peernode getsimpleversion routingbackofflength peernode getroutingbackofflength routingbackedoffuntil peernode getroutingbackedoffuntil peernode isconnected peernode isroutable isfetchingark peernode isfetchingark isopennet peernode isopennet averagepingtime peernode averagepingtime publicinvalidversion peernode publicinvalidversion publicreverseinvalidversion peernode publicreverseinvalidversion backedoffpercent peernode backedoffpercent currentvalue lastbackoffreason peernode getlastbackoffreason timelastroutable peernode timelastroutable timelastconnectioncompleted peernode timelastconnectioncompleted peeraddedtime peernode getpeeraddedtime noheavy localmessagesreceived peernode getlocalnodereceivedmessagesfromstatistic localmessagessent peernode getlocalnodesentmessagestostatistic localmessagesreceived localmessagessent hashcode peernode hashcode preject peernode getprejected totalbytesin peernode gettotalinputbytes totalbytesout peernode gettotaloutputbytes totalbytesinsincestartup peernode gettotalinputsincestartup totalbytesoutsincestartup peernode gettotaloutputsincestartup percenttimeroutableconnection peernode getpercenttimeroutableconnection peernode getthrottle clockdelta peernode getclockdelta recordstatus peernode recordstatus isseedclient peernode seedclientpeernode isseedserver peernode seedserverpeernode issearchable peernode isrealconnection resendbytessent peernode getresendbytessent reporteduptimepercentage peernode getuptime return the local messages received public map string long get local messages received return local messages received localmessagesreceived getlocalmessagesreceived localmessagesreceived return the local messages sent public map string long get local messages sent return local messages sent localmessagessent getlocalmessagessent localmessagessent return the peer added time public long get peer added time return peer added time peeraddedtime getpeeraddedtime peeraddedtime counts the peers in code peer nodes code that have the specified status param peer node statuses the peer nodes statuses param status the status to count return the number of peers that have the specified status public static int get peer status count peer node status peer node statuses int status int count 0 for int peer index 0 peer count peer node statuses length peer index peer count peer index if peer node statuses peer index get status value status count return count peernodes peernodestatuses getpeerstatuscount peernodestatus peernodestatuses peerindex peercount peernodestatuses peerindex peercount peerindex peernodestatuses peerindex getstatusvalue return the time last connection completed public long get time last connection completed return time last connection completed timelastconnectioncompleted gettimelastconnectioncompleted timelastconnectioncompleted return the backed off percent public double get backed off percent return backed off percent backedoffpercent getbackedoffpercent backedoffpercent return the last backoff reason public string get last backoff reason return last backoff reason lastbackoffreason getlastbackoffreason lastbackoffreason return the time last routable public long get time last routable return time last routable timelastroutable gettimelastroutable timelastroutable return the public invalid version public boolean is public invalid version return public invalid version publicinvalidversion ispublicinvalidversion publicinvalidversion return the public reverse invalid version public boolean is public reverse invalid version return public reverse invalid version publicreverseinvalidversion ispublicreverseinvalidversion publicreverseinvalidversion return the average ping time public double get average ping time return average ping time averagepingtime getaveragepingtime averagepingtime return the get routing backed off until public long get routing backed off until return routing backed off until getroutingbackedoffuntil getroutingbackedoffuntil routingbackedoffuntil return the location public double get location return location getlocation public double get peers location return peers location getpeerslocation peerslocation return the peer address public string get peer address return peer address peeraddress getpeeraddress peeraddress return the peer port public int get peer port return peer port peerport getpeerport peerport return the routing backoff length public int get routing backoff length return routing backoff length routingbackofflength getroutingbackofflength routingbackofflength return the statuscss name public string get statuscss name return statuscss name statuscssname getstatuscssname statuscssname return the status name public string get status name return status name statusname getstatusname statusname return the status value public int get status value return status value statusvalue getstatusvalue statusvalue return the version public string get version return version getversion return the connected public boolean is connected return connected isconnected return the routable public boolean is routable return routable isroutable return the is fetchingark public boolean is fetchingark return is fetchingark isfetchingark isfetchingark isfetchingark return the is opennet public boolean is opennet return is opennet isopennet isopennet isopennet return the simple version public int get simple version return simple version simpleversion getsimpleversion simpleversion override public string to string return status name peer address peer port location version backoff routing backoff length math max routing backed off until system current time millis 0 tostring statusname peeraddress peerport routingbackofflength routingbackedoffuntil currenttimemillis override public int hash code return hash code hashcode hashcode public double getp reject return p reject getpreject preject public long get total input bytes return total bytes in gettotalinputbytes totalbytesin public long get total output bytes return total bytes out gettotaloutputbytes totalbytesout public long get total input since startup return total bytes in since startup gettotalinputsincestartup totalbytesinsincestartup public long get total output since startup return total bytes out since startup gettotaloutputsincestartup totalbytesoutsincestartup public double get percent time routable connection return percent time routable connection getpercenttimeroutableconnection percenttimeroutableconnection public packet throttle get throttle return throttle packetthrottle getthrottle public long get clock delta return clock delta getclockdelta clockdelta public boolean record status return record status recordstatus recordstatus public boolean is seed server return is seed server isseedserver isseedserver public boolean is seed client return is seed client isseedclient isseedclient public boolean is searchable return is searchable issearchable issearchable public long get resend bytes sent return resend bytes sent getresendbytessent resendbytessent public int get reported uptime percentage return reported uptime percentage getreporteduptimepercentage reporteduptimepercentage public double get selection rate return selection rate getselectionrate selectionrate logger register log threshold callback new log threshold callback override public void should update logminor logger should log logger minor this registerlogthresholdcallback logthresholdcallback shouldupdate shouldlog public boolean object can update object container container if logminor logger minor this object can update on debugging hash map this stored container ext is stored this active container ext is active this size size new exception debug return true objectcanupdate objectcontainer objectcanupdate debugginghashmap isstored isactive public boolean object can new object container container if logminor logger minor this object can new on debugging hash map this stored container ext is stored this active container ext is active this size size new exception debug return true objectcannew objectcontainer objectcannew debugginghashmap isstored isactive public void object on update object container container if logminor logger minor this object on update on debugging hash map this stored container ext is stored this active container ext is active this size size new exception debug objectonupdate objectcontainer objectonupdate debugginghashmap isstored isactive public void object on new object container container if logminor logger minor this object on new on debugging hash map this stored container ext is stored this active container ext is active this size size new exception debug objectonnew objectcontainer objectonnew debugginghashmap isstored isactive public boolean object can activate object container container if logminor logger minor this object can activate on debugging hash map stored container ext is stored this active container ext is active this size size new exception debug fixme this was an attempt to ensure we always activate to depth 2 it didn t work if activating activating false return true activating true container activate this 2 return false return true objectcanactivate objectcontainer objectcanactivate debugginghashmap isstored isactive boolean flushing public weak hash table int initial capacity threshold int initial capacity load factor table new entry initial capacity weakhashtable initialcapacity initialcapacity loadfactor initialcapacity public synchronized boolean remove int oid entry tab table int index oid 0x7fffffff tab length for entry e tab index prev null e null prev e e e next if e oid oid if prev null prev next e next else tab index e next e clear count 1 return true return false protected reference create reference object obj return new weak reference obj createreference weakreference public synchronized void put int oid i persistent obj reference ref create reference obj entry tab table int index oid 0x7fffffff tab length for entry e tab index e null e e next if e oid oid e ref ref return if count threshold flushing rehash the table if the threshold is exceeded rehash tab table index oid 0x7fffffff tab length creates the new entry tab index new entry oid ref tab index count 1 ipersistent createreference public i persistent get int oid while true cs synchronized this entry tab table int index oid 0x7fffffff tab length for entry e tab index e null e e next if e oid oid i persistent obj i persistent e ref get if obj null if e dirty 0 break cs else if obj is deleted e ref clear return null return obj return null system run finalization ipersistent ipersistent ipersistent isdeleted runfinalization public void flush while true cs synchronized this flushing true for int i 0 i table length i for entry e table i e null e e next i persistent obj i persistent e ref get if obj null if obj is modified obj store else if e dirty 0 break cs flushing false if count threshold rehash the table if the threshold is exceeded rehash return system run finalization ipersistent ipersistent ismodified runfinalization public void invalidate while true cs synchronized this for int i 0 i table length i for entry e table i e null e e next i persistent obj i persistent e ref get if obj null if obj is modified e dirty 0 obj invalidate else if e dirty 0 break cs table i null count 0 return system run finalization ipersistent ipersistent ismodified runfinalization public synchronized void clear entry tab table for int i 0 i tab length i tab i null count 0 void rehash int old capacity table length entry old map table int i for i old capacity i 0 entry e next prev for prev null e old map i e null e next next e next i persistent obj i persistent e ref get if obj null obj is deleted e dirty 0 count 1 e clear if prev null old map i next else prev next next else prev e if count threshold 1 return int new capacity old capacity 2 1 entry new map new entry new capacity threshold int new capacity load factor table new map for i old capacity i 0 for entry old old map i old null entry e old old old next int index e oid 0x7fffffff new capacity e next new map index new map index e oldcapacity oldmap oldcapacity oldmap ipersistent ipersistent isdeleted oldmap newcapacity oldcapacity newmap newcapacity newcapacity loadfactor newmap oldcapacity oldmap newcapacity newmap newmap public synchronized void set dirty i persistent obj int oid obj get oid entry tab table int index oid 0x7fffffff tab length for entry e tab index e null e e next if e oid oid e dirty 1 return setdirty ipersistent getoid public synchronized void clear dirty i persistent obj int oid obj get oid entry tab table int index oid 0x7fffffff tab length for entry e tab index e null e e next if e oid oid if e dirty 0 e dirty 1 return cleardirty ipersistent getoid public int size return count void clear ref clear ref null dirty 0 next null entry int oid reference ref entry chain next chain this oid oid this ref ref public final static string to timeout header string long time if time subscription infinite value return subscription infinite string return subscription timeout header long to string time totimeoutheaderstring infinite_value infinite_string timeout_header tostring public final static long get timeout string header value int minus idx header value index of long timeout subscription infinite value try string timeout str header value substring minus idx 1 header value length timeout long parse long timeout str catch exception e return timeout gettimeout headervalue minusidx headervalue indexof infinite_value timeoutstr headervalue minusidx headervalue parselong timeoutstr public static final string createsid return u pnp createuuid upnp public final static string tosid header string string id return subscription uuid id tosidheaderstring public final static string getsid string header value if header value null return return header value substring subscription uuid length header value length headervalue headervalue headervalue headervalue public web interface wot my wot string uri m wot my wot muri uri m plugin respirator m wot get plugin respirator m page maker m plugin respirator get page maker m page maker add navigation link muri home home page false null m page maker add navigation link muri own identities own identities manage your own identities false null m page maker add navigation link muri known identities known identities manage others identities false null m page maker add navigation link muri configuration configuration configure the wot plugin false null m page maker add navigation link plugins plugins page back to plugins page false null webinterface mywot mwot mywot mpluginrespirator mwot getpluginrespirator mpagemaker mpluginrespirator getpagemaker mpagemaker addnavigationlink mpagemaker addnavigationlink ownidentities mpagemaker addnavigationlink knownidentities mpagemaker addnavigationlink mpagemaker addnavigationlink public string geturi return muri public string handlehttp get final http request request throws pluginhttp exception web page page null try if request is parameter set own identities page new own identities page this request else if request is parameter set known identities page new known identities page this request else if request is parameter set configuration page new configuration page this request else if request is parameter set show identity page new identity page this request else if request is parameter set puzzle introduction puzzle p m wot get introduction puzzle store get byid request get param id if p null byte data p get data fixme the current plugin manager implementation allows plugins only to send html replies implement general replying with any mime type and return the jpeg return else page new home page this request page make return page tohtml catch exception e try page new error page this request e page make return page tohtml catch exception double fault return double fault to string handlehttpget httprequest pluginhttpexception webpage isparameterset ownidentities ownidentitiespage isparameterset knownidentities knownidentitiespage isparameterset configurationpage isparameterset showidentity identitypage isparameterset introductionpuzzle mwot getintroductionpuzzlestore getbyid getparam getdata pluginmanager homepage errorpage doublefault doublefault tostring public string handlehttp post final http request request throws pluginhttp exception web page page string pass request get part as string form password 32 if pass length 0 pass equals m plugin respirator get node client core form password return invalid form password try string page title request get part as string page 50 if page title equals create identity page new create identity page this request else if page title equals add identity page new known identities page this request else if page title equals view tree page new known identities page this request else if page title equals set trust page new known identities page this request else if page title equals edit identity page new edit own identity page this request else if page title equals introduce identity page title equals solve puzzles page new introduce identity page this request else if page title equals restore identity page new own identities page this request else if page title equals delete identity page new delete own identity page this request else page new home page this request page make return page tohtml catch exception e try page new error page this request e page make return page tohtml catch exception double fault return double fault to string handlehttppost httprequest pluginhttpexception webpage getpartasstring formpassword mpluginrespirator getnode clientcore formpassword pagetitle getpartasstring pagetitle createidentity createidentitypage pagetitle addidentity knownidentitiespage pagetitle viewtree knownidentitiespage pagetitle settrust knownidentitiespage pagetitle editidentity editownidentitypage pagetitle introduceidentity pagetitle solvepuzzles introduceidentitypage pagetitle restoreidentity ownidentitiespage pagetitle deleteidentity deleteownidentitypage homepage errorpage doublefault doublefault tostring public string handlehttp put http request request throws pluginhttp exception return go to hell handlehttpput httprequest pluginhttpexception public page maker get page maker return m page maker pagemaker getpagemaker mpagemaker public wot get wot return m wot getwot mwot private static final string l10n string string return l10n get string config toadlet string getstring configtoadlet private static boolean logminor override public string to string return super to string for uid tostring tostring request sender constructor param key the key to request its public key should have been looked up already request sender will not look it up public resettinghtl probe request sender double target short htl long uid node n double nearest loc boolean reset nearest loc peer node source double best this htl htl this uid uid this node n this source source this nearest loc nearest loc this target target this best best this counter 1 this linear counter 1 this unique counter 1 logminor logger should log logger minor this update best if target 0 0 target 1 0 throw new illegal argument exception requestsender requestsender resettinghtlproberequestsender nearestloc resetnearestloc peernode nearestloc nearestloc linearcounter uniquecounter shouldlog updatebest illegalargumentexception public void start node executor execute this resettinghtl probe request sender for uid uid resettinghtlproberequestsender public void run try real run catch throwable t logger error this caught t t fire timeout internal error finally if logminor logger minor this leaving request sender run for uid realrun firetimeout requestsender private void real run int route attempts 0 int reject overloads 0 hash set peer node nodes routed to new hash set peer node while true if logminor logger minor this htl htl if htl 0 fire completion return route attempts route it peer node next next node peers closer peer source nodes routed to target true node is advanced mode enabled 1 null null if next null if logminor reject overloads 0 logger minor this no more peers but overloads reject overloads route attempts overloaded backtrack firernf return if logminor logger minor this routing request to next nodes routed to add next htl node decrementhtl has forwarded next source htl message req create data request try this is the first contact to this node it is more likely to timeout using send sync could make accepted timeout more accurate as it is measured from the send time use a lot of our time that we have to fulfill this request simply waiting on the send queue or longer if the node just went down using send async could make accepted timeout much more likely leave many hanging requests unclaimedfifo items potentially make overloaded peers more overloaded we make a request and promptly forget about them don t use send async next send sync req this catch not connected exception e logger minor this not connected continue synchronized this has forwarded true message msg null while true what are we waiting for fnp accepted continue fnp rejected loop go to another node fnp rejected overload propagate back to source go to another node if local message filter mf accepted message filter create set source next set field dmt uid uid set timeout accepted timeout set type dmt fnp accepted message filter mf rejected loop message filter create set source next set field dmt uid uid set timeout accepted timeout set type dmt fnp rejected loop message filter mf rejected overload message filter create set source next set field dmt uid uid set timeout accepted timeout set type dmt fnp rejected overload mf rejected overload must be the last thing in the or so its or pointer remains null otherwise we need to recreate it below message filter mf mf accepted or mf rejected loop or mf rejected overload try msg node usm wait for mf this if logminor logger minor this first part got msg catch disconnected exception e logger normal this disconnected from next while waiting for accepted on uid break if msg null visited one node at least but maybe already been there counter if logminor logger minor this timeout waiting for accepted timeout waiting for accepted next local rejected overload accepted timeout forward rejected overload try next node break if msg get spec dmt fnp rejected loop visited one node already visited it counter if logminor logger minor this rejected loop find another node to route to break if msg get spec dmt fnp rejected overload visited one and only one node unique counter counter if logminor logger minor this rejected overload non fatal probably still have time left forward rejected overload if msg get boolean dmt is local if logminor logger minor this local rejected overload moving on to next peer give up on this one try another break could be a previous rejection the timeout to incur another accepted timeout is minimal continue if msg get spec dmt fnp accepted logger error this unrecognized message msg continue don t increment here we will let the node do it for us break if msg null msg get spec dmt fnp accepted try another node continue if logminor logger minor this got accepted otherwise must be accepted so wait int got messages 0 string last message null while true message filter mfdf make data found filter next message filter mf route not found message filter create set source next set field dmt uid uid set timeout fetch timeout set type dmt fnp route not found message filter mf rejected overload message filter create set source next set field dmt uid uid set timeout fetch timeout set type dmt fnp rejected overload message filter mf pub key message filter create set source next set field dmt uid uid set timeout fetch timeout set type dmt fnpssk pub key message filter mf trace message filter create set source next set field dmt uid uid set timeout fetch timeout set type dmt fnprh probe trace message filter mf mf route not found or mf rejected overload or mfdf or mf pub key or mf trace try msg node usm wait for mf this catch disconnected exception e logger normal this disconnected from next while waiting for data on uid break if logminor logger minor this second part got msg if msg null logger normal this request fatal timeout null after accept got messages messages last last message fatal timeout forward rejected overload fire timeout timeout return for debugging purposes remember the number of responses after the insert and the last message type we received got messages last message msg get spec get name if msg get spec dmt fnp route not found backtrack within available hops short new htl msg get short dmt htl if new htl htl htl new htl don t use the new nearest loc since we don t on requests and anyway it doesn t make any sense to do so it s only valid within that pocket message sub msg get sub message dmt fnprh return sub message if sub null double new best sub get double dmt best location if new best target new best best best new best counter math max 0 sub get short dmt counter unique counter math max 0 sub get short dmt unique counter linear counter is unchanged it s only valid on a reply fixme ideally we d return it here if we don t manage to reroute else counter unique counter htl break if msg get spec dmt fnp rejected overload non fatal probably still have time left forward rejected overload reject overloads count the nodes involved for results purposes don t use the htl or nearest loc message sub msg get sub message dmt fnprh return sub message if sub null double new best sub get double dmt best location if new best target new best best best new best counter math max 0 sub get short dmt counter unique counter math max 0 sub get short dmt unique counter if msg get boolean dmt is local nb is local means it s terminal not is local implies that the rejection message was forwarded from a downstream node local from our peers perspective this has nothing to do with local requests source null if logminor logger minor this local rejected overload moving on to next peer give up on this one try another break so long as the node does not send a is local message interestingly messages can often timeout having only received this message continue if msg get spec dmt fnprh probe reply double his nearest msg get double dmt nearest location if location distance his nearest target true location distance nearest loc target true nearest loc his nearest realrun routeattempts rejectoverloads hashset peernode nodesroutedto hashset peernode firecompletion routeattempts peernode closerpeer nodesroutedto isadvancedmodeenabled rejectoverloads rejectoverloads routeattempts nodesroutedto hasforwarded createdatarequest sendsync accepted_timeout sendasync accepted_timeout sendasync sendsync notconnectedexception hasforwarded fnpaccepted fnprejectedloop fnprejectedoverload messagefilter mfaccepted messagefilter setsource setfield settimeout accepted_timeout settype fnpaccepted messagefilter mfrejectedloop messagefilter setsource setfield settimeout accepted_timeout settype fnprejectedloop messagefilter mfrejectedoverload messagefilter setsource setfield settimeout accepted_timeout settype fnprejectedoverload mfrejectedoverload messagefilter mfaccepted mfrejectedloop mfrejectedoverload waitfor disconnectedexception localrejectedoverload acceptedtimeout forwardrejectedoverload getspec fnprejectedloop getspec fnprejectedoverload uniquecounter forwardrejectedoverload getboolean is_local rejectedoverload accepted_timeout getspec fnpaccepted getspec fnpaccepted gotmessages lastmessage messagefilter makedatafoundfilter messagefilter mfroutenotfound messagefilter setsource setfield settimeout fetch_timeout settype fnproutenotfound messagefilter mfrejectedoverload messagefilter setsource setfield settimeout fetch_timeout settype fnprejectedoverload messagefilter mfpubkey messagefilter setsource setfield settimeout fetch_timeout settype fnpsskpubkey messagefilter mftrace messagefilter setsource setfield settimeout fetch_timeout settype fnprhprobetrace messagefilter mfroutenotfound mfrejectedoverload mfpubkey mftrace waitfor disconnectedexception gotmessages lastmessage forwardrejectedoverload firetimeout gotmessages lastmessage getspec getname getspec fnproutenotfound newhtl getshort newhtl newhtl nearestloc getsubmessage fnprhreturnsubmessage newbest getdouble best_location newbest newbest newbest getshort uniquecounter getshort unique_counter linearcounter uniquecounter getspec fnprejectedoverload forwardrejectedoverload rejectoverloads nearestloc getsubmessage fnprhreturnsubmessage newbest getdouble best_location newbest newbest newbest getshort uniquecounter getshort unique_counter getboolean is_local is_local is_local rejectedoverload is_local getspec fnprhprobereply hisnearest getdouble nearest_location hisnearest nearestloc nearestloc hisnearest private void fire trace double nearest double best short htl short counter short unique counter double location long myuid short buffer peer locs short buffer peerui ds short linear counter string reason long prevuid if this best target this best best best this best if location distance nearest target true location distance this nearest loc target true nearest this nearest loc counter short counter this counter unique counter short unique counter this unique counter linear counter short linear counter this linear counter synchronized listeners for listener l listeners try l on trace uid nearest best htl counter unique counter location myuid peer locs peerui ds short 0 linear counter reason prevuid catch throwable t logger error this caught t t firetrace uniquecounter shortbuffer peerlocs shortbuffer peeruids linearcounter nearestloc nearestloc uniquecounter uniquecounter uniquecounter linearcounter linearcounter linearcounter ontrace uniquecounter peerlocs peeruids linearcounter note that this must be first on the list private message filter make data found filter peer node next return message filter create set source next set field dmt uid uid set timeout fetch timeout set type dmt fnprh probe reply messagefilter makedatafoundfilter peernode messagefilter setsource setfield settimeout fetch_timeout settype fnprhprobereply private message create data request return dmt createfnprh probe request uid target this nearest loc best htl createdatarequest createfnprhproberequest nearestloc forward rejected overload to the request originator private void forward rejected overload synchronized this if has forwarded rejected overload return has forwarded rejected overload true notify all fire received reject overload nearest loc best counter unique counter linear counter rejectedoverload forwardrejectedoverload hasforwardedrejectedoverload hasforwardedrejectedoverload notifyall firereceivedrejectoverload nearestloc uniquecounter linearcounter wait rejected overload wait finished public short gethtl return htl wait_rejected_overload wait_finished public void sent bytes int x synchronized total bytes sync total bytes sent x node node stats probe request ctr sent bytes x sentbytes totalbytessync totalbytessent nodestats proberequestctr sentbytes public int get total sent bytes synchronized total bytes sync return total bytes sent gettotalsentbytes totalbytessync totalbytessent public void received bytes int x synchronized total bytes sync total bytes received x node node stats probe request ctr received bytes x receivedbytes totalbytessync totalbytesreceived nodestats proberequestctr receivedbytes public int get total received bytes synchronized total bytes sync return total bytes received gettotalreceivedbytes totalbytessync totalbytesreceived synchronized boolean has forwarded return has forwarded hasforwarded hasforwarded public void sent payload int x logger error this sent payload x in resettinghtl probe request sender for this new exception error sentpayload sentpayload resettinghtlproberequestsender public boolean is local request search return source null islocalrequestsearch all these methods should return quickly interface listener should return quickly allocate a thread if it needs to block etc throws not connected exception void on received reject overload double nearest double best short counter short unique counter short linear counter string reason throws not connected exception notconnectedexception onreceivedrejectoverload uniquecounter linearcounter notconnectedexception throws not connected exception void on received reject overload double nearest double best short counter short unique counter short linear counter string reason throws not connected exception void on trace long uid double nearest double best short htl short counter short unique counter double location long myuid short buffer peer locs short buffer peerui ds short s short linear counter string reason long prevuid throws not connected exception notconnectedexception onreceivedrejectoverload uniquecounter linearcounter notconnectedexception ontrace uniquecounter shortbuffer peerlocs shortbuffer peeruids linearcounter notconnectedexception void on received reject overload double nearest double best short counter short unique counter short linear counter string reason throws not connected exception void on trace long uid double nearest double best short htl short counter short unique counter double location long myuid short buffer peer locs short buffer peerui ds short s short linear counter string reason long prevuid throws not connected exception on completion throws not connected exception void on completion double nearest double best short counter short unique counter short linear counter throws not connected exception onreceivedrejectoverload uniquecounter linearcounter notconnectedexception ontrace uniquecounter shortbuffer peerlocs shortbuffer peeruids linearcounter notconnectedexception notconnectedexception oncompletion uniquecounter linearcounter notconnectedexception throws not connected exception void on completion double nearest double best short counter short unique counter short linear counter throws not connected exception on rnf throws not connected exception void onrnf short htl double nearest double best short counter short unique counter short linear counter throws not connected exception notconnectedexception oncompletion uniquecounter linearcounter notconnectedexception notconnectedexception uniquecounter linearcounter notconnectedexception throws not connected exception void onrnf short htl double nearest double best short counter short unique counter short linear counter throws not connected exception on timeout param reason throws not connected exception void on timeout double nearest double best short counter short unique counter short linear counter string reason throws not connected exception notconnectedexception uniquecounter linearcounter notconnectedexception notconnectedexception ontimeout uniquecounter linearcounter notconnectedexception public void add listener listener l no request coalescing atm must be added before anything has happened synchronized this synchronized listeners listeners add l addlistener private void fire received reject overload double nearest double best short counter short unique counter short linear counter string reason synchronized listeners for listener l listeners try l on received reject overload nearest best counter unique counter linear counter reason catch throwable t logger error this caught t t firereceivedrejectoverload uniquecounter linearcounter onreceivedrejectoverload uniquecounter linearcounter private void fire completion synchronized listeners for listener l listeners try l on completion nearest loc best counter unique counter linear counter catch throwable t logger error this caught t t firecompletion oncompletion nearestloc uniquecounter linearcounter private void firernf synchronized listeners for listener l listeners try l onrnf htl nearest loc best counter unique counter linear counter catch throwable t logger error this caught t t nearestloc uniquecounter linearcounter private void fire timeout string reason synchronized listeners for listener l listeners try l on timeout nearest loc best counter unique counter linear counter reason catch throwable t logger error this caught t t firetimeout ontimeout nearestloc uniquecounter linearcounter private void update best peer node nodes node peers my peers for peer node node nodes if node is connected continue double loc node get location if loc target continue if loc target loc best best loc updatebest peernode mypeers peernode isconnected getlocation public int get priority return native thread high priority getpriority nativethread high_priority double get best return best getbest public double get nearest loc return nearest loc getnearestloc nearestloc public array bucket factory abf new array bucket factory override protected bucket make bucket long size throws io exception return abf make bucket size arraybucketfactory arraybucketfactory makebucket ioexception makebucket override protected void free bucket bucket bucket throws io exception bucket free freebucket ioexception public segmented bucket chain bucket int block size bucket factory factory db job runner runner int segment size2 bucket size block size bf factory db job runner runner segment size segment size2 segments new array list segmented chain bucket segment segmentedbucketchainbucket blocksize bucketfactory dbjobrunner segmentsize2 bucketsize blocksize dbjobrunner segmentsize segmentsize2 arraylist segmentedchainbucketsegment public bucket create shadow throws io exception return null createshadow ioexception public void free synchronized this freed true clearing false due to memory issues we cannot complete the cleanup before returning especially if we are already on the database thread db job free job new db job public void run object container container client context context segmented chain bucket segment segment null if container ext is stored segmented bucket chain bucket this logger error this bucket not stored in free job already deleted container delete this return synchronized this if segments is empty segment segments remove 0 if segment null container activate segment 1 if logger should log logger minor segmented bucket chain bucket this logger minor segmented bucket chain bucket this freeing segment segment segment activate buckets container segment free segment remove from container synchronized this if segments is empty db job runner queue this native thread high priority true db job runner queue restart job this native thread high priority container false container store this return container delete segments container delete segmented bucket chain bucket this container delete this synchronized segmented bucket chain bucket this if kill me null return db job runner remove restart job kill me native thread high priority container container delete kill me must be run blocking so that if we are on the database thread the job is added before committing if we are not on the database thread it doesn t matter db job runner run blocking free job native thread high priority dbjob freejob dbjob objectcontainer clientcontext segmentedchainbucketsegment isstored segmentedbucketchainbucket freejob isempty shouldlog segmentedbucketchainbucket segmentedbucketchainbucket activatebuckets removefrom isempty dbjobrunner nativethread high_priority dbjobrunner queuerestartjob nativethread high_priority segmentedbucketchainbucket segmentedbucketchainbucket killme dbjobrunner removerestartjob killme nativethread high_priority killme dbjobrunner runblocking freejob nativethread high_priority public void run object container container client context context segmented chain bucket segment segment null if container ext is stored segmented bucket chain bucket this logger error this bucket not stored in free job already deleted container delete this return synchronized this if segments is empty segment segments remove 0 if segment null container activate segment 1 if logger should log logger minor segmented bucket chain bucket this logger minor segmented bucket chain bucket this freeing segment segment segment activate buckets container segment free segment remove from container synchronized this if segments is empty db job runner queue this native thread high priority true db job runner queue restart job this native thread high priority container false container store this return container delete segments container delete segmented bucket chain bucket this container delete this synchronized segmented bucket chain bucket this if kill me null return db job runner remove restart job kill me native thread high priority container container delete kill me objectcontainer clientcontext segmentedchainbucketsegment isstored segmentedbucketchainbucket freejob isempty shouldlog segmentedbucketchainbucket segmentedbucketchainbucket activatebuckets removefrom isempty dbjobrunner nativethread high_priority dbjobrunner queuerestartjob nativethread high_priority segmentedbucketchainbucket segmentedbucketchainbucket killme dbjobrunner removerestartjob killme nativethread high_priority killme public input stream get input stream throws io exception synchronized this if freed clearing throw new io exception freed return new input stream int segment no 1 int bucket no segment size segmented chain bucket segment seg null bucket buckets null input stream is null private long bucket read 0 private boolean closed override public int read throws io exception byte b new byte 1 if read b 0 1 0 return 1 return b 0 override public int read byte buf throws io exception return read buf 0 buf length override public int read byte buf int offset int length throws io exception if closed throw new io exception already closed if bucket read bucket size is null if is null is close if buckets null buckets bucket no null bucket read 0 bucket no if bucket no segment size buckets null bucket no 0 segment no seg get segment segment no if seg null return 1 buckets get buckets seg if bucket no buckets length synchronized segmented bucket chain bucket this if segment no segments size no more data return 1 buckets get buckets seg if bucket no buckets length return 1 is buckets bucket no get input stream int r is read buf offset length if r 0 bucket read r return r override public void close throws io exception if closed return if is null is close closed true is null seg null buckets null inputstream getinputstream ioexception ioexception inputstream segmentno bucketno segmentsize segmentedchainbucketsegment inputstream bucketread ioexception ioexception ioexception ioexception bucketread bucketsize bucketno bucketread bucketno bucketno segmentsize bucketno segmentno getsegment segmentno getbuckets bucketno segmentedbucketchainbucket segmentno getbuckets bucketno bucketno getinputstream bucketread ioexception override public int read throws io exception byte b new byte 1 if read b 0 1 0 return 1 return b 0 ioexception override public int read byte buf throws io exception return read buf 0 buf length ioexception override public int read byte buf int offset int length throws io exception if closed throw new io exception already closed if bucket read bucket size is null if is null is close if buckets null buckets bucket no null bucket read 0 bucket no if bucket no segment size buckets null bucket no 0 segment no seg get segment segment no if seg null return 1 buckets get buckets seg if bucket no buckets length synchronized segmented bucket chain bucket this if segment no segments size no more data return 1 buckets get buckets seg if bucket no buckets length return 1 is buckets bucket no get input stream int r is read buf offset length if r 0 bucket read r return r ioexception ioexception bucketread bucketsize bucketno bucketread bucketno bucketno segmentsize bucketno segmentno getsegment segmentno getbuckets bucketno segmentedbucketchainbucket segmentno getbuckets bucketno bucketno getinputstream bucketread override public void close throws io exception if closed return if is null is close closed true is null seg null buckets null ioexception protected synchronized segmented chain bucket segment get segment int i return segments get i segmentedchainbucketsegment getsegment protected bucket get buckets final segmented chain bucket segment seg final bucket array wrapper baw new bucket array wrapper db job runner run blocking new db job public void run object container container client context context container activate seg 1 synchronized baw baw buckets seg shallow copy buckets container deactivate seg 1 native thread high priority synchronized baw return baw buckets getbuckets segmentedchainbucketsegment bucketarraywrapper bucketarraywrapper dbjobrunner runblocking dbjob objectcontainer clientcontext shallowcopybuckets nativethread high_priority public void run object container container client context context container activate seg 1 synchronized baw baw buckets seg shallow copy buckets container deactivate seg 1 objectcontainer clientcontext shallowcopybuckets public string get name return segmented bucket chain bucket getname segmentedbucketchainbucket public output stream get output stream throws io exception final segmented chain bucket segment segs synchronized this if read only throw new io exception read only if freed clearing throw new io exception freed size 0 segs segments to array new segmented chain bucket segment segments size segments clear for int i 0 i segs length i segs i free if segs length 0 db job runner run blocking new db job public void run object container container client context context for int i 0 i segs length i segs i remove from container native thread high priority return new output stream int segment no 0 int bucket no 0 segmented chain bucket segment seg make segment segment no null output stream cur seg make bucket stream bucket no private long bucket length private boolean closed override public void write int arg0 throws io exception write new byte byte arg0 override public void write byte buf throws io exception write buf 0 buf length override public void write byte buf int offset int length throws io exception boolean ro synchronized segmented bucket chain bucket this ro read only if ro if closed close throw new io exception read only if closed throw new io exception already closed while length 0 if bucket length bucket size bucket no cur close if bucket no segment size bucket no 0 segment no seg make segment segment no seg cur seg make bucket stream bucket no bucket length 0 int left int math min integer max value bucket size bucket length int write math min left length cur write buf offset write offset write length write bucket length write synchronized segmented bucket chain bucket class size write override public void close throws io exception if closed return if logger should log logger minor this logger minor this closing this for segmented bucket chain bucket this cur close closed true cur null final segmented chain bucket segment old seg seg seg null db job runner run blocking new db job public void run object container container client context context if container ext is stored old seg if container ext is active old seg logger error this old segment stored but not active old seg new exception error container activate old seg 1 old seg store to container container ext store segments 1 container ext store segmented bucket chain bucket this 1 container deactivate old seg 1 if there is only one segment we didn t add a kill me add one now synchronized segmented bucket chain bucket this if kill me null return kill me new segmented bucket chain bucket kill job segmented bucket chain bucket this kill me schedule restart container context native thread high priority outputstream getoutputstream ioexception segmentedchainbucketsegment readonly ioexception ioexception toarray segmentedchainbucketsegment dbjobrunner runblocking dbjob objectcontainer clientcontext removefrom nativethread high_priority outputstream segmentno bucketno segmentedchainbucketsegment makesegment segmentno outputstream makebucketstream bucketno bucketlength ioexception ioexception ioexception segmentedbucketchainbucket readonly ioexception ioexception bucketlength bucketsize bucketno bucketno segmentsize bucketno segmentno makesegment segmentno makebucketstream bucketno bucketlength max_value bucketsize bucketlength bucketlength segmentedbucketchainbucket ioexception shouldlog segmentedbucketchainbucket segmentedchainbucketsegment oldseg dbjobrunner runblocking dbjob objectcontainer clientcontext isstored oldseg isactive oldseg oldseg oldseg oldseg storeto segmentedbucketchainbucket oldseg killme segmentedbucketchainbucket killme killme segmentedbucketchainbucketkilljob segmentedbucketchainbucket killme schedulerestart nativethread high_priority public void run object container container client context context for int i 0 i segs length i segs i remove from container objectcontainer clientcontext removefrom private boolean closed override public void write int arg0 throws io exception write new byte byte arg0 ioexception override public void write byte buf throws io exception write buf 0 buf length ioexception override public void write byte buf int offset int length throws io exception boolean ro synchronized segmented bucket chain bucket this ro read only if ro if closed close throw new io exception read only if closed throw new io exception already closed while length 0 if bucket length bucket size bucket no cur close if bucket no segment size bucket no 0 segment no seg make segment segment no seg cur seg make bucket stream bucket no bucket length 0 int left int math min integer max value bucket size bucket length int write math min left length cur write buf offset write offset write length write bucket length write synchronized segmented bucket chain bucket class size write ioexception segmentedbucketchainbucket readonly ioexception ioexception bucketlength bucketsize bucketno bucketno segmentsize bucketno segmentno makesegment segmentno makebucketstream bucketno bucketlength max_value bucketsize bucketlength bucketlength segmentedbucketchainbucket override public void close throws io exception if closed return if logger should log logger minor this logger minor this closing this for segmented bucket chain bucket this cur close closed true cur null final segmented chain bucket segment old seg seg seg null db job runner run blocking new db job public void run object container container client context context if container ext is stored old seg if container ext is active old seg logger error this old segment stored but not active old seg new exception error container activate old seg 1 old seg store to container container ext store segments 1 container ext store segmented bucket chain bucket this 1 container deactivate old seg 1 if there is only one segment we didn t add a kill me add one now synchronized segmented bucket chain bucket this if kill me null return kill me new segmented bucket chain bucket kill job segmented bucket chain bucket this kill me schedule restart container context native thread high priority ioexception shouldlog segmentedbucketchainbucket segmentedchainbucketsegment oldseg dbjobrunner runblocking dbjob objectcontainer clientcontext isstored oldseg isactive oldseg oldseg oldseg oldseg storeto segmentedbucketchainbucket oldseg killme segmentedbucketchainbucket killme killme segmentedbucketchainbucketkilljob segmentedbucketchainbucket killme schedulerestart nativethread high_priority public void run object container container client context context if container ext is stored old seg if container ext is active old seg logger error this old segment stored but not active old seg new exception error container activate old seg 1 old seg store to container container ext store segments 1 container ext store segmented bucket chain bucket this 1 container deactivate old seg 1 if there is only one segment we didn t add a kill me add one now synchronized segmented bucket chain bucket this if kill me null return kill me new segmented bucket chain bucket kill job segmented bucket chain bucket this kill me schedule restart container context objectcontainer clientcontext isstored oldseg isactive oldseg oldseg oldseg oldseg storeto segmentedbucketchainbucket oldseg killme segmentedbucketchainbucket killme killme segmentedbucketchainbucketkilljob segmentedbucketchainbucket killme schedulerestart protected segmented chain bucket segment make segment int index final segmented chain bucket segment old seg if logger should log logger minor this logger minor this make a segment for this index index old old seg if old seg null synchronized this while running seg store logger normal this waiting for last segment store job to finish on this try wait catch interrupted exception e ignore running seg store true try db job runner run blocking new db job public void run object container container client context context try old seg store to container container ext store segments 1 container ext store segmented bucket chain bucket this 1 container deactivate old seg 1 synchronized segmented bucket chain bucket this if kill me null return kill me new segmented bucket chain bucket kill job segmented bucket chain bucket this kill me schedule restart container context finally synchronized segmented bucket chain bucket this running seg store false segmented bucket chain bucket this notify all native thread high priority 1 catch throwable t logger error this caught throwable t t running seg store false synchronized this segmented chain bucket segment seg new segmented chain bucket segment this if segments size index throw new illegal argument exception asked to add segment index but segments length is segments size segments add seg return seg segmentedchainbucketsegment makesegment segmentedchainbucketsegment oldseg shouldlog oldseg oldseg runningsegstore interruptedexception runningsegstore dbjobrunner runblocking dbjob objectcontainer clientcontext oldseg storeto segmentedbucketchainbucket oldseg segmentedbucketchainbucket killme killme segmentedbucketchainbucketkilljob segmentedbucketchainbucket killme schedulerestart segmentedbucketchainbucket runningsegstore segmentedbucketchainbucket notifyall nativethread high_priority runningsegstore segmentedchainbucketsegment segmentedchainbucketsegment illegalargumentexception public void run object container container client context context try old seg store to container container ext store segments 1 container ext store segmented bucket chain bucket this 1 container deactivate old seg 1 synchronized segmented bucket chain bucket this if kill me null return kill me new segmented bucket chain bucket kill job segmented bucket chain bucket this kill me schedule restart container context finally synchronized segmented bucket chain bucket this running seg store false segmented bucket chain bucket this notify all objectcontainer clientcontext oldseg storeto segmentedbucketchainbucket oldseg segmentedbucketchainbucket killme killme segmentedbucketchainbucketkilljob segmentedbucketchainbucket killme schedulerestart segmentedbucketchainbucket runningsegstore segmentedbucketchainbucket notifyall public boolean is read only return read only isreadonly readonly public void remove from object container container valid no op if we haven t been stored removefrom objectcontainer public void set read only read only true setreadonly readonly public synchronized long size return size note that we don t recurse inside the segments as it would produce a huge transaction so you will need to close the output stream to commit the progress of writing to a file and yes we can t append so you need to write everything before storing the bucket fixme enforce the rule that you must close any output stream s before calling store to public void store to object container container throw new unsupported operation exception outputstream outputstream storeto storeto objectcontainer unsupportedoperationexception public bucket get buckets final bucket array wrapper baw new bucket array wrapper db job runner run blocking new db job public void run object container container client context context baw buckets get buckets container native thread high priority return baw buckets getbuckets bucketarraywrapper bucketarraywrapper dbjobrunner runblocking dbjob objectcontainer clientcontext getbuckets nativethread high_priority db job runner run blocking new db job public void run object container container client context context baw buckets get buckets container dbjobrunner runblocking dbjob objectcontainer clientcontext getbuckets protected synchronized bucket get buckets object container container int segs segments size if segs 0 return new bucket 0 segmented chain bucket segment seg segments get segs 1 container activate seg 1 seg activate buckets container int size segs 1 segment size seg size bucket buckets new bucket size seg shallow copy buckets buckets segs 1 segment size container deactivate seg 1 int pos 0 for int i 0 i segs 1 i seg segments get i container activate seg 1 seg activate buckets container seg shallow copy buckets buckets pos container deactivate seg 1 pos segment size return buckets getbuckets objectcontainer segmentedchainbucketsegment activatebuckets segmentsize shallowcopybuckets segmentsize activatebuckets shallowcopybuckets segmentsize public synchronized void clear due to memory issues we cannot complete this before we return synchronized this clearing true db job clear job new db job public void run object container container client context context if container ext is stored segmented bucket chain bucket this logger error this bucket not stored in clear job already deleted container delete this return segmented chain bucket segment segment null synchronized this if segments is empty segment segments remove 0 if segment null container activate segment 1 if logger should log logger minor segmented bucket chain bucket this logger minor segmented bucket chain bucket this clearing segment segment segment clear container synchronized this if segments is empty db job runner queue this native thread high priority 1 true db job runner queue restart job this native thread high priority 1 container false container store segments container store segmented bucket chain bucket this return container delete segments container delete segmented bucket chain bucket this container delete this synchronized segmented bucket chain bucket this if kill me null return db job runner remove restart job kill me native thread high priority container container delete kill me must be run blocking so that if we are on the database thread the job is added before committing if we are not on the database thread it doesn t matter db job runner run blocking clear job native thread high priority 1 dbjob clearjob dbjob objectcontainer clientcontext isstored segmentedbucketchainbucket clearjob segmentedchainbucketsegment isempty shouldlog segmentedbucketchainbucket segmentedbucketchainbucket isempty dbjobrunner nativethread high_priority dbjobrunner queuerestartjob nativethread high_priority segmentedbucketchainbucket segmentedbucketchainbucket segmentedbucketchainbucket killme dbjobrunner removerestartjob killme nativethread high_priority killme dbjobrunner runblocking clearjob nativethread high_priority public void run object container container client context context if container ext is stored segmented bucket chain bucket this logger error this bucket not stored in clear job already deleted container delete this return segmented chain bucket segment segment null synchronized this if segments is empty segment segments remove 0 if segment null container activate segment 1 if logger should log logger minor segmented bucket chain bucket this logger minor segmented bucket chain bucket this clearing segment segment segment clear container synchronized this if segments is empty db job runner queue this native thread high priority 1 true db job runner queue restart job this native thread high priority 1 container false container store segments container store segmented bucket chain bucket this return container delete segments container delete segmented bucket chain bucket this container delete this synchronized segmented bucket chain bucket this if kill me null return db job runner remove restart job kill me native thread high priority container container delete kill me objectcontainer clientcontext isstored segmentedbucketchainbucket clearjob segmentedchainbucketsegment isempty shouldlog segmentedbucketchainbucket segmentedbucketchainbucket isempty dbjobrunner nativethread high_priority dbjobrunner queuerestartjob nativethread high_priority segmentedbucketchainbucket segmentedbucketchainbucket segmentedbucketchainbucket killme dbjobrunner removerestartjob killme nativethread high_priority killme param container return true if there is more work to do we don t want to do everything in one transaction because this bucket could be enormous synchronized boolean remove contents object container container boolean logminor logger should log logger minor this while segments size 0 logger normal this freeing unfinished unstored bucket this segments left segments size remove the first so the space is reused at the beginning not at the end removing from the end results in not shrinking segmented chain bucket segment seg segments remove 0 if seg null already removed continue container activate seg 1 if logminor logger minor this removing segment seg size seg size if clearing seg clear container else seg activate buckets container seg free seg remove from container if segments size 0 container store segments container store this return true do some more in the next transaction else break if logminor logger minor this removed segments for this container delete segments container delete this if logminor logger minor this removed this freed true just in case it wasn t already return false removecontents objectcontainer shouldlog segmentedchainbucketsegment activatebuckets removefrom create a warp filter public warp filter warpfilter warpfilter create a warp filter with two warp grids param source grid the source grid param dest grid the destination grid public warp filter warp grid source grid warp grid dest grid this source grid source grid this dest grid dest grid warpfilter sourcegrid destgrid warpfilter warpgrid sourcegrid warpgrid destgrid sourcegrid sourcegrid destgrid destgrid set the source warp grid param source grid the source grid see get source grid public void set source grid warp grid source grid this source grid source grid sourcegrid getsourcegrid setsourcegrid warpgrid sourcegrid sourcegrid sourcegrid get the source warp grid return the source grid see set source grid public warp grid get source grid return source grid setsourcegrid warpgrid getsourcegrid sourcegrid set the destination warp grid param dest grid the destination grid see get dest grid public void set dest grid warp grid dest grid this dest grid dest grid destgrid getdestgrid setdestgrid warpgrid destgrid destgrid destgrid get the destination warp grid return the destination grid see set dest grid public warp grid get dest grid return dest grid setdestgrid warpgrid getdestgrid destgrid public void set frames int frames this frames frames setframes public int get frames return frames getframes for morphing sets the image we re morphing to if not set then we re just warping public void set morph image buffered image morph image this morph image morph image setmorphimage bufferedimage morphimage morphimage morphimage public buffered image get morph image return morph image bufferedimage getmorphimage morphimage public void set time float time this time time settime public float get time return time gettime override protected void transform space rectangle r r width frames transformspace override protected int filter pixels int width int height int in pixels rectangle transformed space int out pixels new int width height if morph image null int morph pixels getrgb morph image 0 0 width height null morph in pixels morph pixels out pixels source grid dest grid width height time else if frames 1 source grid warp in pixels width height source grid dest grid out pixels else warp grid new grid new warp grid source grid rows source grid cols width height for int i 0 i frames i float t float i frames 1 source grid lerp t dest grid new grid source grid warp in pixels width height source grid new grid out pixels return out pixels filterpixels inpixels transformedspace outpixels morphimage morphpixels morphimage inpixels morphpixels outpixels sourcegrid destgrid sourcegrid inpixels sourcegrid destgrid outpixels warpgrid newgrid warpgrid sourcegrid sourcegrid sourcegrid destgrid newgrid sourcegrid inpixels sourcegrid newgrid outpixels outpixels public void morph int src pixels int dest pixels int out pixels warp grid src grid warp grid dest grid int width int height float t warp grid new grid new warp grid src grid rows src grid cols width height src grid lerp t dest grid new grid src grid warp src pixels width height src grid new grid out pixels int dest pixels2 new int width height dest grid warp dest pixels width height dest grid new grid dest pixels2 cross dissolve out pixels dest pixels2 width height t srcpixels destpixels outpixels warpgrid srcgrid warpgrid destgrid warpgrid newgrid warpgrid srcgrid srcgrid srcgrid destgrid newgrid srcgrid srcpixels srcgrid newgrid outpixels destpixels2 destgrid destpixels destgrid newgrid destpixels2 crossdissolve outpixels destpixels2 public void cross dissolve int pixels1 int pixels2 int width int height float t int index 0 for int y 0 y height y for int x 0 x width x pixels1 index image math mix colors t pixels1 index pixels2 index index crossdissolve imagemath mixcolors override public string to string return distort mesh warp tostring public jaxp parser super jaxpparser public plugins u pnp org cybergarage xml node parse plugins u pnp org cybergarage xml node parent node org w3c dom node dom node int rank int dom node type dom node get node type if dom node type node element node return string dom node name dom node get node name string dom node value dom node get node value debug message rank elem dom node name dom node value type dom node type attrs arrrs len if dom node type org w3c dom node text node parent node set value dom node value return parent node if dom node type org w3c dom node element node return parent node plugins u pnp org cybergarage xml node node new plugins u pnp org cybergarage xml node node set name dom node name node set value dom node value if parent node null parent node add node node named node map attr map dom node get attributes int attr len attr map get length debug message attr len attr len for int n 0 n attr len n org w3c dom node attr attr map item n string attr name attr get node name string attr value attr get node value node set attribute attr name attr value org w3c dom node child dom node get first child while child null parse node child rank 1 child child get next sibling return node upnp upnp parentnode domnode domnodetype domnode getnodetype domnodetype element_node domnodename domnode getnodename domnodevalue domnode getnodevalue domnodename domnodevalue domnodetype arrrslen domnodetype text_node parentnode setvalue domnodevalue parentnode domnodetype element_node parentnode upnp upnp setname domnodename setvalue domnodevalue parentnode parentnode addnode namednodemap attrmap domnode getattributes attrlen attrmap getlength attrlen attrlen attrlen attrmap attrname getnodename attrvalue getnodevalue setattribute attrname attrvalue domnode getfirstchild getnextsibling public plugins u pnp org cybergarage xml node parse plugins u pnp org cybergarage xml node parent node org w3c dom node dom node return parse parent node dom node 0 upnp upnp parentnode domnode parentnode domnode public node parse input stream in stream throws parser exception plugins u pnp org cybergarage xml node root null try document builder factory factory document builder factory new instance document builder builder factory new document builder input source in src new input source in stream document doc builder parse in src org w3c dom element doc elem doc get document element if doc elem null root parse root doc elem node list root list doc get elements by tag name root debug message root list root list get length if 0 root list get length root parse root root list item 0 catch exception e throw new parser exception e return root inputstream instream parserexception upnp documentbuilderfactory documentbuilderfactory newinstance documentbuilder newdocumentbuilder inputsource insrc inputsource instream insrc docelem getdocumentelement docelem docelem nodelist rootlist getelementsbytagname rootlist rootlist getlength rootlist getlength rootlist parserexception private map long condition lock map new hash map long condition lock manager logdebug logger should log logger debug this lockmap hashmap lockmanager shouldlog lock the entry this lock is strong not strong re entrance no threads except cleaner should hold more then one lock at a time or deadlock may occur condition lock entry long offset if logdebug logger debug this try locking offset new exception condition condition try entry lock lock try do if shutdown return null condition lock cond lock map get offset if lock cond null lock cond await 10 time unit seconds 10s for checking shutdown else break while true condition entry lock new condition lock map put offset condition finally entry lock unlock catch interrupted exception e logger error this lock interrupted e return null if logdebug logger debug this locked offset new exception return condition lockentry entrylock lockcond lockmap lockcond lockcond timeunit entrylock newcondition lockmap entrylock interruptedexception unlock the entry void unlock entry long offset condition condition if logdebug logger debug this unlocking offset new exception debug entry lock lock try condition cond lock map remove offset assert cond condition cond signal finally entry lock unlock unlockentry entrylock lockmap entrylock shutdown and wait for all entries unlocked void shutdown shutdown true entry lock lock try while lock map is empty condition cond lock map values iterator next cond await uninterruptibly finally entry lock unlock entrylock lockmap isempty lockmap awaituninterruptibly entrylock public sky filter if sky colors null sky colors image utils create image toolkit get default toolkit get image get class get resource sky colors png get source skyfilter skycolors skycolors imageutils createimage getdefaulttoolkit getimage getclass getresource skycolors getsource public void set amount float amount this amount amount setamount public float get amount return amount getamount public void set operation int operation this operation operation setoperation public int get operation return operation getoperation public void set scale float scale this scale scale setscale public float get scale return scale getscale public void set stretch float stretch this stretch stretch setstretch public float get stretch return stretch getstretch public void sett float t this t t public float gett return t public void setfov float fov this fov fov public float getfov return fov public void set cloud cover float cloud cover this cloud cover cloud cover setcloudcover cloudcover cloudcover cloudcover public float get cloud cover return cloud cover getcloudcover cloudcover public void set cloud sharpness float cloud sharpness this cloud sharpness cloud sharpness setcloudsharpness cloudsharpness cloudsharpness cloudsharpness public float get cloud sharpness return cloud sharpness getcloudsharpness cloudsharpness public void set time float time this time time settime public float get time return time gettime public void set glow float glow this glow glow setglow public float get glow return glow getglow public void set glow falloff float glow falloff this glow falloff glow falloff setglowfalloff glowfalloff glowfalloff glowfalloff public float get glow falloff return glow falloff getglowfalloff glowfalloff public void set angle float angle this angle angle setangle public float get angle return angle getangle public void set octaves float octaves this octaves octaves setoctaves public float get octaves return octaves getoctaves public void seth float h this h h public float geth return h public void set lacunarity float lacunarity this lacunarity lacunarity setlacunarity public float get lacunarity return lacunarity getlacunarity public void set gain float gain this gain gain setgain public float get gain return gain getgain public void set bias float bias this bias bias setbias public float get bias return bias getbias public void set haziness float haziness this haziness haziness sethaziness public float get haziness return haziness gethaziness public void set sun elevation float sun elevation this sun elevation sun elevation setsunelevation sunelevation sunelevation sunelevation public float get sun elevation return sun elevation getsunelevation sunelevation public void set sun azimuth float sun azimuth this sun azimuth sun azimuth setsunazimuth sunazimuth sunazimuth sunazimuth public float get sun azimuth return sun azimuth getsunazimuth sunazimuth public void set sun color int sun color this sun color sun color setsuncolor suncolor suncolor suncolor public int get sun color return sun color getsuncolor suncolor public void set camera elevation float camera elevation this camera elevation camera elevation setcameraelevation cameraelevation cameraelevation cameraelevation public float get camera elevation return camera elevation getcameraelevation cameraelevation public void set camera azimuth float camera azimuth this camera azimuth camera azimuth setcameraazimuth cameraazimuth cameraazimuth cameraazimuth public float get camera azimuth return camera azimuth getcameraazimuth cameraazimuth public void set wind speed float wind speed this wind speed wind speed setwindspeed windspeed windspeed windspeed public float get wind speed return wind speed getwindspeed windspeed float mn mx override public buffered image filter buffered image src buffered image dst long start system current time millis sunr float sun color 16 0xff r255 sung float sun color 8 0xff r255 sunb float sun color 0xff r255 mn 10000 mx 10000 exponents new float int octaves 1 float frequency 1 0f for int i 0 i int octaves i exponents i float math pow 2 i frequency lacunarity min 1 max 1 min 1 2f max 1 2f width src get width height src get height int h src get height tan new float h for int i 0 i h i tan i float math tan fov float i h math pi 0 5 if dst null dst create compatible dest image src null int t int 63 time sky pixels getrgb sky colors t 0 1 64 sky pixels graphics2d g dst create graphics g draw image sky colors 0 0 dst get width dst get height t 0 t 1 64 null g dispose buffered image clouds super filter dst dst g draw rendered image clouds null g dispose long finish system current time millis system out println mn mx finish start 0 001f exponents null tan null return dst bufferedimage bufferedimage bufferedimage currenttimemillis suncolor suncolor suncolor getwidth getheight getheight createcompatibledestimage skypixels skycolors skypixels creategraphics drawimage skycolors getwidth getheight bufferedimage drawrenderedimage currenttimemillis public float evaluate float x float y float value 0 0f float remainder int i to prevent cascading effects x 371 y 529 for i 0 i int octaves i value noise noise3 x y t exponents i x lacunarity y lacunarity remainder octaves int octaves if remainder 0 value remainder noise noise3 x y t exponents i return value override public int filterrgb int x int y int rgb curvature float fx float x width y 20 math sin fx math pi 0 5 float fy y height float haze float math pow haziness 100 fy fy int argb sky pixels int fy float r float rgb 16 0xff r255 float g float rgb 8 0xff r255 float b float rgb 0xff r255 float cx width 0 5f float nx x cx float ny y fov ny float math tan fov fy math pi 0 5 ny tan y nx fx 0 5f 1 ny ny t wind speed wind towards the camera float xscale scale 1 y bias 0 1f nx scale ny scale stretch float f evaluate nx ny float fg f fixme bump map normalize to 0 1 f f min max min f f 1 23f 2 46f f amount int a rgb 0xff000000 int v work out cloud cover float c f cloud cover if c 0 c 0 float cloud alpha 1 float math pow cloud sharpness c cloud alpha amount if cloud alpha 1 cloud alpha 1 mn math min mn cloud alpha mx math max mx cloud alpha sun glow float centrex width sun azimuth float centrey height sun elevation float dx x centrex float dy y centrey float distance2 dx dx dy dy float sun 0 distance2 float math sqrt distance2 distance2 float math pow distance2 glow falloff float sun amount 10 float math exp distance2 glow 0 1f sun glow 10 float math exp distance2 sun glow onto sky r sun sunr g sun sung b sun sunb float cloud color cloud alpha sun bump map float nnx x cx float nny y 1 nnx xscale nny xscale stretch float gf evaluate nnx nny float gradient fg gf if y 100 system out println fg gf gradient cloud color amount gradient r cloud color r cloud alpha g cloud color g cloud alpha b cloud color b cloud alpha clouds get darker as they get thicker float ca 1 cloud alpha cloud alpha cloud alpha cloud alpha 1 sun amount float cloudr sunr ca float cloudg sung ca float cloudb sunb ca apply the haziness as we move further away cloud alpha haze composite the clouds on the sky float i cloud alpha 1 cloud alpha r i cloud alpha r cloud alpha cloudr g i cloud alpha g cloud alpha cloudg b i cloud alpha b cloud alpha cloudb exposure float exposure gain r 1 float math exp r exposure g 1 float math exp g exposure b 1 float math exp b exposure int ir int 255 r 16 int ig int 255 g 8 int ib int 255 b v 0xff000000 ir ig ib return v skypixels windspeed cloudcover cloudalpha cloudsharpness cloudalpha cloudalpha cloudalpha cloudalpha cloudalpha sunazimuth sunelevation glowfalloff cloudcolor cloudalpha cloudcolor cloudcolor cloudalpha cloudcolor cloudalpha cloudcolor cloudalpha cloudalpha cloudalpha cloudalpha cloudalpha cloudalpha icloudalpha cloudalpha icloudalpha cloudalpha icloudalpha cloudalpha icloudalpha cloudalpha override public string to string return texture sky tostring private final object object public sectored random grab array with object object object boolean persistent object container container remove random parent parent super persistent container parent this object object sectoredrandomgrabarraywithobject objectcontainer removerandomparent public object get object return object getobject override public string to string return super to string object tostring tostring public class inet6 address matcher implements address matcher public address type get address type return address type i pv6 inet6addressmatcher addressmatcher addresstype getaddresstype addresstype ipv6 public inet6 address matcher string pattern if pattern index of 1 address convert to bytes pattern substring 0 pattern index of string netmask string pattern substring pattern index of 1 trim if netmask string index of 1 netmask convert to bytes netmask string else netmask new byte 16 int bits integer parse int netmask string for int index 0 index 16 index netmask index byte 255 8 math min bits 8 bits math max bits 8 0 if arrays equals netmask full mask netmask full mask else address convert to bytes pattern netmask full mask if address length 16 throw new illegal argument exception address is not i pv6 inet6addressmatcher indexof converttobytes indexof netmaskstring indexof netmaskstring indexof converttobytes netmaskstring parseint netmaskstring full_mask full_mask converttobytes full_mask illegalargumentexception ipv6 private byte convert to bytes string address string tokenizer address tokens new string tokenizer address if address tokens count tokens 8 throw new illegal argument exception address is not an i pv6 address byte address bytes new byte 16 int count 0 while address tokens has more tokens int address word integer parse int address tokens next token 16 address bytes count 2 byte address word 8 0xff address bytes count 2 1 byte address word 0xff count return address bytes converttobytes stringtokenizer addresstokens stringtokenizer addresstokens counttokens illegalargumentexception ipv6 addressbytes addresstokens hasmoretokens addressword parseint addresstokens nexttoken addressbytes addressword addressbytes addressword addressbytes public boolean matches inet address address if address instanceof inet6 address return false byte address bytes address get address for int index 0 index 16 index if address bytes index netmask index this address index netmask index return false return true inetaddress inet6address addressbytes getaddress addressbytes public static boolean matches string pattern inet address address return new inet6 address matcher pattern matches address inetaddress inet6addressmatcher public string get human representation if netmask full mask return convert to string address else return convert to string address convert to string netmask gethumanrepresentation full_mask converttostring converttostring converttostring private string convert to string byte addr string builder sb new string builder 4 8 7 for int i 0 i 8 i if i 0 sb append int token addr i 2 0xff 8 addr i 2 1 0xff sb append integer to hex string token return sb to string converttostring stringbuilder stringbuilder tohexstring tostring creates a new persistent insert param uri the uri to insert data to param identifier the identifier of the insert param verbosity the verbosity bitmask param handler the fcp connection handler param priority class the priority for this insert param persistence type the persistence type of this insert param client token the client token of this insert param global whether this insert appears on the global queue param getchk only whether only the resulting chk is requested param dont compress whether the file should not be compressed param max retries the maximum number of retries param upload from type where the file is uploaded from param orig filename the original filename param content type the content type of the data param data the data may be code null code if code upload from type code is upload from redirect param redirect target the uri to redirect to if code upload from type code is upload from redirect throws identifier collision exception throws not allowed exception throws file not found exception throws malformedurl exception throws metadata unresolved exception throws insert exception public client put fcp client global client freeneturi uri string identifier int verbosity short priority class short persistence type string client token boolean getchk only boolean dont compress int max retries short upload from type file orig filename string content type bucket data freeneturi redirect target string target filename boolean early encode fcp server server object container container throws identifier collision exception not allowed exception file not found exception malformedurl exception metadata unresolved exception super uri identifier verbosity null global client priority class persistence type null true getchk only dont compress max retries early encode server container if upload from type client put message upload from disk if server core allow upload from orig filename throw new not allowed exception if orig filename exists orig filename can read throw new file not found exception logminor logger should log logger minor this binary blob false this target filename target filename this upload from upload from type this orig filename orig filename now go through the fields one at a time string mime type content type this client token client token bucket temp data data client metadata cm new client metadata mime type boolean is metadata false logminor logger should log logger minor this if logminor logger minor this data temp data upload from client put message upload from string upload from if upload from client put message upload from redirect this targeturi redirect target metadata m new metadata metadata simple redirect null null targeturi cm byte d d m write to byte array temp data new simple read only array bucket d is metadata true else targeturi null this data temp data this client metadata cm putter new client putter this data uri cm ctx priority class getchk only is metadata low level client null target filename binary blob priorityclass persistencetype clienttoken getchkonly dontcompress maxretries uploadfromtype origfilename contenttype uploadfromtype upload_from_redirect redirecttarget uploadfromtype upload_from_redirect identifiercollisionexception notallowedexception filenotfoundexception malformedurlexception metadataunresolvedexception insertexception clientput fcpclient globalclient priorityclass persistencetype clienttoken getchkonly dontcompress maxretries uploadfromtype origfilename contenttype redirecttarget targetfilename earlyencode fcpserver objectcontainer identifiercollisionexception notallowedexception filenotfoundexception malformedurlexception metadataunresolvedexception globalclient priorityclass persistencetype getchkonly dontcompress maxretries earlyencode uploadfromtype clientputmessage upload_from_disk allowuploadfrom origfilename notallowedexception origfilename origfilename canread filenotfoundexception shouldlog binaryblob targetfilename targetfilename uploadfrom uploadfromtype origfilename origfilename mimetype contenttype clienttoken clienttoken tempdata clientmetadata clientmetadata mimetype ismetadata shouldlog tempdata uploadfrom clientputmessage uploadfromstring uploadfrom uploadfrom clientputmessage upload_from_redirect redirecttarget simple_redirect writetobytearray tempdata simplereadonlyarraybucket ismetadata tempdata clientmetadata clientputter priorityclass getchkonly ismetadata lowlevelclient targetfilename binaryblob public client put fcp connection handler handler client put message message fcp server server object container container throws identifier collision exception message invalid exception malformedurl exception super message uri message identifier message verbosity handler message priority class message persistence type message client token message global message getchk only message dont compress message max retries message early encode server container string salt null byte salted hash null binary blob message binary blob if message upload from type client put message upload from disk if handler server core allow upload from message orig filename throw new message invalid exception protocol error message access denied not allowed to upload from message orig filename identifier global if message file hash null try salt handler connection identifier message identifier salted hash base64 decode message file hash catch illegal base64 exception e throw new message invalid exception protocol error message invalid field can t base64 decode client put base file hash identifier global else if handler allowdda from message orig filename false throw new message invalid exception protocol error message direct disk access denied not allowed to upload from message orig filename have you done a testdda previously identifier global this target filename message target filename logminor logger should log logger minor this this upload from message upload from type this orig filename message orig filename now go through the fields one at a time string mime type message content type if binary blob if mime type null mime type equals binary blob mime type throw new message invalid exception protocol error message invalid field no mime type allowed when inserting a binary blob identifier global if mime type null orig filename null mime type defaultmime types guessmime type orig filename get name true if mime type null target filename null mime type defaultmime types guessmime type target filename true if mime type null mime type defaultmime types guessmime type identifier true client token message client token bucket temp data message bucket client metadata cm new client metadata mime type boolean is metadata false if logminor logger minor this data temp data upload from client put message upload from string upload from if upload from client put message upload from redirect this targeturi message redirect target metadata m new metadata metadata simple redirect null null targeturi cm byte d try d m write to byte array catch metadata unresolved exception e impossible logger error this impossible e e this data null client metadata cm putter null this is not an insert exception since we don t register it it s a protocol error throw new message invalid exception protocol error message internal error impossible metadata unresolved e identifier global temp data new simple read only array bucket d is metadata true else targeturi null this data temp data this client metadata cm check the hash allow it to be null for backward compatibility and if testdda is allowed if salt null message digest md sha256 get message digest byte found hash try try md update salt get bytes utf 8 catch unsupported encoding exception e throw new error impossible jvm doesn t support utf 8 e e try input stream is data get input stream sha256 hash is md is close catch io exception e sha256 return message digest md logger error this got ioe e get message e throw new message invalid exception protocol error message could not read file unable to access file e identifier global found hash md digest finally sha256 return message digest md if logminor logger minor this file hash result we found base64 encode found hash and were given base64 encode salted hash if arrays equals salted hash found hash throw new message invalid exception protocol error message direct disk access denied the hash doesn t match salt used salt identifier global if logminor logger minor this data data upload from client put message upload from string upload from putter new client putter this data uri cm ctx priority class getchk only is metadata low level client null target filename binary blob clientput fcpconnectionhandler clientputmessage fcpserver objectcontainer identifiercollisionexception messageinvalidexception malformedurlexception priorityclass persistencetype clienttoken getchkonly dontcompress maxretries earlyencode saltedhash binaryblob binaryblob uploadfromtype clientputmessage upload_from_disk allowuploadfrom origfilename messageinvalidexception protocolerrormessage access_denied origfilename filehash connectionidentifier saltedhash filehash illegalbase64exception messageinvalidexception protocolerrormessage invalid_field clientputbase file_hash allowddafrom origfilename messageinvalidexception protocolerrormessage direct_disk_access_denied origfilename targetfilename targetfilename shouldlog uploadfrom uploadfromtype origfilename origfilename mimetype contenttype binaryblob mimetype mimetype binaryblob mime_type messageinvalidexception protocolerrormessage invalid_field mimetype origfilename mimetype defaultmimetypes guessmimetype origfilename getname mimetype targetfilename mimetype defaultmimetypes guessmimetype targetfilename mimetype mimetype defaultmimetypes guessmimetype clienttoken clienttoken tempdata clientmetadata clientmetadata mimetype ismetadata tempdata uploadfrom clientputmessage uploadfromstring uploadfrom uploadfrom clientputmessage upload_from_redirect redirecttarget simple_redirect writetobytearray metadataunresolvedexception clientmetadata insertexception messageinvalidexception protocolerrormessage internal_error tempdata simplereadonlyarraybucket ismetadata tempdata clientmetadata messagedigest getmessagedigest foundhash getbytes unsupportedencodingexception inputstream getinputstream ioexception returnmessagedigest getmessage messageinvalidexception protocolerrormessage could_not_read_file foundhash returnmessagedigest filehash foundhash saltedhash saltedhash foundhash messageinvalidexception protocolerrormessage direct_disk_access_denied uploadfrom clientputmessage uploadfromstring uploadfrom clientputter priorityclass getchkonly ismetadata lowlevelclient targetfilename binaryblob create from a persisted simple field set not very tolerant of errors as the input was generated by the node throws persistence parse exception throws io exception throws insert exception public client put simple field set fs fcp client client2 fcp server server object container container throws persistence parse exception io exception insert exception super fs client2 server logminor logger should log logger minor this string mime type fs get metadata content type string from fs get upload from if from equals direct upload from client put message upload from direct else if from equals disk upload from client put message upload from disk else if from equals redirect upload from client put message upload from redirect else throw new persistence parse exception unknown upload from from client metadata cm new client metadata mime type boolean is metadata false binary blob fs get boolean binary blob false target filename fs get target filename if upload from client put message upload from disk orig filename new file fs get filename if logminor logger minor this uploading from disk orig filename for this data new file bucket orig filename true false false false false targeturi null else if upload from client put message upload from direct orig filename null if logminor logger minor this uploading from direct for this if finished try data serializable to field set bucket util create fs subset temp bucket server core random server core persistent temp bucket factory catch cannot create from field set exception e throw new persistence parse exception could not read old bucket for identifier e e else if logger should log logger minor this logger minor this finished already so not reading bucket for this data null targeturi null else if upload from client put message upload from redirect string target fs get targeturi targeturi new freeneturi target if logminor logger minor this uploading from redirect for this targeturi metadata m new metadata metadata simple redirect null null targeturi cm byte d try d m write to byte array catch metadata unresolved exception e impossible logger error this impossible e e this data null client metadata cm orig filename null putter null throw new insert exception insert exception internal error impossible e in client put null data new simple read only array bucket d orig filename null is metadata true else throw new persistence parse exception shouldn t happen if logminor logger minor this data data this client metadata cm simple field set old progress fs subset progress if finished old progress null not useful any more putter new client putter this data uri cm ctx priority class getchk only is metadata low level client old progress target filename binary blob if persistence type persist connection fcp message msg persistent tag message container client queue client request message msg 0 container simplefieldset persistenceparseexception ioexception insertexception clientput simplefieldset fcpclient fcpserver objectcontainer persistenceparseexception ioexception insertexception shouldlog mimetype contenttype uploadfrom uploadfrom clientputmessage upload_from_direct uploadfrom clientputmessage upload_from_disk uploadfrom clientputmessage upload_from_redirect persistenceparseexception uploadfrom clientmetadata clientmetadata mimetype ismetadata binaryblob getboolean binaryblob targetfilename targetfilename uploadfrom clientputmessage upload_from_disk origfilename origfilename filebucket origfilename uploadfrom clientputmessage upload_from_direct origfilename serializabletofieldsetbucketutil tempbucket persistenttempbucketfactory cannotcreatefromfieldsetexception persistenceparseexception shouldlog uploadfrom clientputmessage upload_from_redirect simple_redirect writetobytearray metadataunresolvedexception clientmetadata origfilename insertexception insertexception internal_error clientput simplereadonlyarraybucket origfilename ismetadata persistenceparseexception clientmetadata simplefieldset oldprogress oldprogress clientputter priorityclass getchkonly ismetadata lowlevelclient oldprogress targetfilename binaryblob persistencetype persist_connection fcpmessage persistenttagmessage queueclientrequestmessage override void register object container container boolean lazy resume boolean no tags throws identifier collision exception if persistence type persist connection client register this false container if persistence type persist connection no tags fcp message msg persistent tag message container client queue client request message msg 0 container objectcontainer lazyresume notags identifiercollisionexception persistencetype persist_connection persistencetype persist_connection notags fcpmessage persistenttagmessage queueclientrequestmessage override public void start object container container client context context if logger should log logger minor this logger minor this starting this identifier synchronized this if finished return try putter start early encode false container context if persistence type persist connection finished fcp message msg persistent tag message container client queue client request message msg 0 container synchronized this started true if persistence type persist forever container store this update catch insert exception e synchronized this started true on failure e null container catch throwable t synchronized this started true on failure new insert exception insert exception internal error t null null container objectcontainer clientcontext shouldlog earlyencode persistencetype persist_connection fcpmessage persistenttagmessage queueclientrequestmessage persistencetype persist_forever insertexception onfailure onfailure insertexception insertexception internal_error override protected void free data object container container bucket d synchronized this d data data null if d null return if persistence type persist forever container activate d 5 finished size d size d free if persistence type persist forever d remove from container freedata objectcontainer persistencetype persist_forever finishedsize persistencetype persist_forever removefrom override protected freenet client async client requester get client request return putter clientrequester getclientrequest override protected fcp message persistent tag message object container container if persistence type persist forever container activate publicuri 5 container activate client metadata 5 container activate orig filename 5 return new persistent put identifier publicuri verbosity priority class upload from targeturi persistence type orig filename client metadata getmime type client is global queue get data size container client token started ctx max insert retries target filename binary blob fcpmessage persistenttagmessage objectcontainer persistencetype persist_forever clientmetadata origfilename persistentput priorityclass uploadfrom persistencetype origfilename clientmetadata getmimetype isglobalqueue getdatasize clienttoken maxinsertretries targetfilename binaryblob override protected string get type name return put gettypename override public boolean has succeeded return succeeded hassucceeded public freeneturi get finaluri object container container if persistence type persist forever container activate generateduri 5 return generateduri getfinaluri objectcontainer persistencetype persist_forever public boolean is direct return upload from client put message upload from direct isdirect uploadfrom clientputmessage upload_from_direct public file get orig filename object container container if upload from client put message upload from disk return null if persistence type persist forever container activate orig filename 5 return orig filename getorigfilename objectcontainer uploadfrom clientputmessage upload_from_disk persistencetype persist_forever origfilename origfilename public long get data size object container container if data null return finished size else if persistence type persist forever container activate data 1 return data size getdatasize objectcontainer finishedsize persistencetype persist_forever public string getmime type return client metadata getmime type getmimetype clientmetadata getmimetype override public boolean can restart if finished logger minor this cannot restart because not finished for identifier return false if succeeded logger minor this cannot restart because succeeded for identifier return false return putter can restart canrestart canrestart override public boolean restart object container container client context context if can restart return false set vars restart container try if putter restart early encode container context synchronized this generateduri null started true if persistence type persist forever container store this return true catch insert exception e on failure e null container return false objectcontainer clientcontext canrestart setvarsrestart earlyencode persistencetype persist_forever insertexception onfailure public void on failure fetch exception e client getter state object container container onfailure fetchexception clientgetter objectcontainer public void on failure fetch exception e client getter state object container container public void on success fetch result result client getter state object container container onfailure fetchexception clientgetter objectcontainer onsuccess fetchresult clientgetter objectcontainer public void on success fetch result result client getter state object container container public void on remove event producer object container container do nothing we called the remove from onsuccess fetchresult clientgetter objectcontainer onremoveeventproducer objectcontainer removefrom override public void request was removed object container container client context context if persistence type persist forever container activate putter 1 putter remove from container context putter null if orig filename null container activate orig filename 5 container delete orig filename client metadata will be deleted by putter if targeturi null container activate targeturi 5 targeturi remove from container super request was removed container context requestwasremoved objectcontainer clientcontext persistencetype persist_forever removefrom origfilename origfilename origfilename clientmetadata removefrom requestwasremoved private final segmented bucket chain bucket bcb public segmented chain bucket segment segmented bucket chain bucket bucket this bcb bucket this buckets new array list bucket segmentedbucketchainbucket segmentedchainbucketsegment segmentedbucketchainbucket arraylist public void free for bucket bucket buckets if bucket null logger error this bucket is null on this continue bucket free public void store to object container container if logger should log logger minor this logger minor this storing segment this for bucket bucket buckets bucket store to container container ext store buckets 1 container ext store this 1 storeto objectcontainer shouldlog storeto public synchronized bucket shallow copy buckets int sz buckets size bucket out new bucket sz for int i 0 i sz i out i buckets get i return out shallowcopybuckets public synchronized void shallow copy buckets bucket out int index int sz buckets size for int i 0 i sz i out index buckets get i shallowcopybuckets public output stream make bucket stream int bucket no throws io exception if bucket no bcb segment size throw new illegal argument exception too many buckets in segment bucket b bcb bf make bucket bcb bucket size synchronized this if buckets size bucket no throw new illegal argument exception next bucket should be buckets size but is bucket no buckets add b return b get output stream outputstream makebucketstream bucketno ioexception bucketno segmentsize illegalargumentexception makebucket bucketsize bucketno illegalargumentexception bucketno getoutputstream public int size return buckets size void activate buckets object container container container activate buckets 1 for bucket bucket buckets container activate bucket 1 will cascade activatebuckets objectcontainer public void clear object container container buckets clear container delete buckets container delete this objectcontainer public void remove from object container container for bucket bucket buckets if bucket null probably not a problem continue container activate bucket 1 bucket remove from container container delete buckets container delete this removefrom objectcontainer removefrom construct a scale filter public scale filter this 32 32 scalefilter scalefilter construct a scale filter param width the width to scale to param height the height to scale to public scale filter int width int height this width width this height height scalefilter scalefilter public buffered image filter buffered image src buffered image dst int w src get width int h src get height if dst null color model dstcm src get color model dst new buffered image dstcm dstcm create compatible writable raster w h dstcm is alpha premultiplied null image scale image src get scaled instance w h image scale area averaging graphics2d g dst create graphics g draw image src 0 0 width height null g dispose return dst bufferedimage bufferedimage bufferedimage getwidth getheight colormodel getcolormodel bufferedimage createcompatiblewritableraster isalphapremultiplied scaleimage getscaledinstance scale_area_averaging creategraphics drawimage override public string to string return distort scale tostring public queue toadlet node client core core fcp server fcp high level simple client client super client this core core this fcp fcp if fcp null throw new null pointer exception fcp set completion callback this load completed identifiers queuetoadlet nodeclientcore fcpserver highlevelsimpleclient nullpointerexception setcompletioncallback loadcompletedidentifiers override public void handle post uri uri http request request final toadlet context ctx throws toadlet context closed exception io exception redirect exception if core has loaded queue write error l10n get string queue toadlet not loaded yet title l10n get string queue toadlet not loaded yet ctx false return if container public gateway mode ctx is allowed full access super send error page ctx 403 l10n get string toadlet unauthorized title l10n get string toadlet unauthorized return boolean logminor logger should log logger minor this try browse button if request get part as string insert local 128 length 0 preserve the key freeneturi inserturi string key type request get part as string keytype 3 if chk equals key type inserturi new freeneturi chk else try string u request get part as string key 128 inserturi new freeneturi u if logminor logger minor this inserting key inserturi u catch malformedurl exception mue1 write error l10n get string queue toadlet error invaliduri l10n get string queue toadlet error invaliduri tou ctx return multi value table string string response headers new multi value table string string response headers put location files key inserturi toascii string ctx send reply headers 302 found response headers null 0 return string pass request get part as string form password 32 if pass length 0 pass equals core form password multi value table string string headers new multi value table string string headers put location queue ctx send reply headers 302 found headers null 0 if logminor logger minor this no form password pass return if request is part set remove request request get part as string remove request 32 length 0 string identifier request get part as string identifier max identifier length if logminor logger minor this removing identifier try fcp remove global request blocking identifier catch message invalid exception e this send error page ctx 200 l10n get string queue toadlet failed to remove request l10n get string queue toadlet failed to remove new string id message new string identifier e get message return write permanent redirect ctx done queue return else if request is part set restart request request get part as string restart request 32 length 0 string identifier request get part as string identifier max identifier length if logminor logger minor this restarting identifier fcp restart blocking identifier write permanent redirect ctx done queue return else if request is part set remove allrequests request get part as string remove allrequests 32 length 0 fixme panic button should just dump the entire database fixme what about non global requests boolean success false try success fcp remove all global requests blocking catch exception e logger error this exception on remove all e if success this send error page ctx 200 l10n get string queue toadlet failed to remove request l10n get string queue toadlet failed to remove all else write permanent redirect ctx done queue return else if request is part set download queue a download if request is part set key write error l10n get string queue toadlet error no key l10n get string queue toadlet error no key tod ctx return string expectedmime type null if request is part set type expectedmime type request get part as string type max type length freeneturi fetchuri try fetchuri new freeneturi request get part as string key max key length catch malformedurl exception e write error l10n get string queue toadlet error invaliduri l10n get string queue toadlet error invaliduri tod ctx return string persistence request get part as string persistence 32 string return type request get part as string return type 32 try fcp make persistent global request blocking fetchuri expectedmime type persistence return type catch not allowed exception e this write error l10n get string queue toadlet errord to disk l10n get string queue toadlet errord to disk config ctx return write permanent redirect ctx done queue return else if request is part set bulk downloads string bulk downloads as string request get part as string bulk downloads integer max value string keys bulk downloads as string split n if equals bulk downloads as string keys length 1 write permanent redirect ctx done queue return linked list string success new linked list string failure new linked list string for int i 0 i keys length i string current key keys i try freeneturi fetchuri new freeneturi current key fcp make persistent global request blocking fetchuri null forever disk success add current key catch exception e failure add current key logger error this an error occured while attempting to download key i current key e get message boolean display failure box failure size 0 boolean display success box success size 0 html node page node ctx get page maker get page node l10n get string queue toadlet download files ctx html node content node ctx get page maker get content node page node html node alert node content node add child ctx get page maker get infobox display failure box infobox warning infobox info l10n get string queue toadlet download files html node alert content ctx get page maker get content node alert node iterator string it if display success box html node success div alert content add child ul success div add child l10n get string queue toadlet enqueued successfully number string value of success size it success iterator while it has next html node line success div add child li line add child it next success div add child br if display failure box html node failure div alert content add child ul if display failure box failure div add child l10n get string queue toadlet enqueued failure number string value of failure size it failure iterator while it has next html node line failure div add child li line add child it next failure div add child br alert content add child a href queue l10n get string toadlet return to queuepage writehtml reply ctx 200 ok page node generate return else if request is part set change priority string identifier request get part as string identifier max identifier length short new priority short parse short request get part as string priority 32 fcp modify global request blocking identifier null new priority write permanent redirect ctx done queue return fixme factor out the next 3 items they are very messy else if request get part as string insert 128 length 0 final freeneturi inserturi string key type request get part as string keytype 3 if chk equals key type inserturi new freeneturi chk else try string u request get part as string key 128 inserturi new freeneturi u if logminor logger minor this inserting key inserturi u catch malformedurl exception mue1 write error l10n get string queue toadlet error invaliduri l10n get string queue toadlet error invaliduri tou ctx return final http uploaded file file request get uploaded file filename if file null file get filename trim length 0 write error l10n get string queue toadlet error no file selected l10n get string queue toadlet error no file selectedu ctx return final boolean compress request get part as string compress 128 length 0 final string identifier file get filename fred system current time millis final string fnam if inserturi get key type equals chk fnam file get filename else fnam null copy bucket data final bucket copied bucket core persistent temp bucket factory make bucket file get data size bucket tools copy file get data copied bucket final mutable boolean done new mutable boolean core queue new db job public void run object container container client context context try final client put client put try client put new client put fcp get global forever client inserturi identifier integer max value request starter bulk splitfile priority class client request persist forever null false compress 1 client put message upload from direct null file get content type copied bucket null fnam false fcp container if client put null try fcp start blocking client put container context catch identifier collision exception e logger error this cannot put same file twice in same millisecond write permanent redirect ctx done queue return wri handlepost httprequest toadletcontext toadletcontextclosedexception ioexception redirectexception hasloadedqueue writeerror getstring queuetoadlet notloadedyettitle getstring queuetoadlet notloadedyet publicgatewaymode isallowedfullaccess senderrorpage getstring unauthorizedtitle getstring shouldlog getpartasstring keytype getpartasstring keytype getpartasstring malformedurlexception writeerror getstring queuetoadlet errorinvaliduri getstring queuetoadlet errorinvaliduritou multivaluetable responseheaders multivaluetable responseheaders toasciistring sendreplyheaders responseheaders getpartasstring formpassword formpassword multivaluetable multivaluetable sendreplyheaders formpassword ispartset remove_request getpartasstring remove_request getpartasstring max_identifier_length removeglobalrequestblocking messageinvalidexception senderrorpage getstring queuetoadlet failedtoremoverequest getstring queuetoadlet failedtoremove getmessage writepermanentredirect ispartset restart_request getpartasstring restart_request getpartasstring max_identifier_length restartblocking writepermanentredirect ispartset remove_allrequests getpartasstring remove_allrequests removeallglobalrequestsblocking senderrorpage getstring queuetoadlet failedtoremoverequest getstring queuetoadlet failedtoremoveall writepermanentredirect ispartset ispartset writeerror getstring queuetoadlet errornokey getstring queuetoadlet errornokeytod expectedmimetype ispartset expectedmimetype getpartasstring max_type_length getpartasstring max_key_length malformedurlexception writeerror getstring queuetoadlet errorinvaliduri getstring queuetoadlet errorinvaliduritod getpartasstring returntype getpartasstring makepersistentglobalrequestblocking expectedmimetype returntype notallowedexception writeerror getstring queuetoadlet errordtodisk getstring queuetoadlet errordtodiskconfig writepermanentredirect ispartset bulkdownloads bulkdownloadsasstring getpartasstring bulkdownloads max_value bulkdownloadsasstring bulkdownloadsasstring writepermanentredirect linkedlist linkedlist linkedlist currentkey currentkey makepersistentglobalrequestblocking currentkey currentkey currentkey getmessage displayfailurebox displaysuccessbox htmlnode pagenode getpagemaker getpagenode getstring queuetoadlet downloadfiles htmlnode contentnode getpagemaker getcontentnode pagenode htmlnode alertnode contentnode addchild getpagemaker getinfobox displayfailurebox getstring queuetoadlet downloadfiles htmlnode alertcontent getpagemaker getcontentnode alertnode displaysuccessbox htmlnode successdiv alertcontent addchild successdiv addchild getstring queuetoadlet enqueuedsuccessfully valueof hasnext htmlnode successdiv addchild addchild successdiv addchild displayfailurebox htmlnode failurediv alertcontent addchild displayfailurebox failurediv addchild getstring queuetoadlet enqueuedfailure valueof hasnext htmlnode failurediv addchild addchild failurediv addchild alertcontent addchild getstring returntoqueuepage writehtmlreply pagenode ispartset change_priority getpartasstring max_identifier_length newpriority parseshort getpartasstring modifyglobalrequestblocking newpriority writepermanentredirect getpartasstring keytype getpartasstring keytype getpartasstring malformedurlexception writeerror getstring queuetoadlet errorinvaliduri getstring queuetoadlet errorinvaliduritou httpuploadedfile getuploadedfile getfilename writeerror getstring queuetoadlet errornofileselected getstring queuetoadlet errornofileselectedu getpartasstring getfilename currenttimemillis getkeytype getfilename copiedbucket persistenttempbucketfactory makebucket getdata buckettools getdata copiedbucket mutableboolean mutableboolean dbjob objectcontainer clientcontext clientput clientput clientput clientput getglobalforeverclient max_value requeststarter bulk_splitfile_priority_class clientrequest persist_forever clientputmessage upload_from_direct getcontenttype copiedbucket clientput startblocking clientput identifiercollisionexception writepermanentredirect public void run object container container client context context try final client put client put try client put new client put fcp get global forever client inserturi identifier integer max value request starter bulk splitfile priority class client request persist forever null false compress 1 client put message upload from direct null file get content type copied bucket null fnam false fcp container if client put null try fcp start blocking client put container context catch identifier collision exception e logger error this cannot put same file twice in same millisecond write permanent redirect ctx done queue return write permanent redirect ctx done queue return catch identifier collision exception e logger error this cannot put same file twice in same millisecond write permanent redirect ctx done queue return catch not allowed exception e write error l10n get string queue toadlet error access denied l10n get string queue toadlet error access denied file new string file new string file get filename ctx return catch file not found exception e write error l10n get string queue toadlet error no file or cannot read l10n get string queue toadlet error access denied file new string file new string file get filename ctx return catch malformedurl exception mue1 write error l10n get string queue toadlet error invaliduri l10n get string queue toadlet error invaliduri tou ctx return catch metadata unresolved exception e logger error this unresolved metadata in starting insert from data uploaded from browser e e write permanent redirect ctx done queue return fixme should this be a proper localised message it shouldn t happen but we d like to get reports if it does catch throwable t write internal error t ctx finally synchronized done done value true done notify all catch io exception e ignore catch toadlet context closed exception e ignore objectcontainer clientcontext clientput clientput clientput clientput getglobalforeverclient max_value requeststarter bulk_splitfile_priority_class clientrequest persist_forever clientputmessage upload_from_direct getcontenttype copiedbucket clientput startblocking clientput identifiercollisionexception writepermanentredirect writepermanentredirect identifiercollisionexception writepermanentredirect notallowedexception writeerror getstring queuetoadlet erroraccessdenied getstring queuetoadlet erroraccessdeniedfile getfilename filenotfoundexception writeerror getstring queuetoadlet errornofileorcannotread getstring queuetoadlet erroraccessdeniedfile getfilename malformedurlexception writeerror getstring queuetoadlet errorinvaliduri getstring queuetoadlet errorinvaliduritou metadataunresolvedexception writepermanentredirect writeinternalerror notifyall ioexception toadletcontextclosedexception public void run object container container client context context final client put client put try try client put new client put fcp get global forever client furi identifier integer max value request starter bulk splitfile priority class client request persist forever null false false 1 client put message upload from disk file content type new file bucket file true false false false false null target false fcp container if logger should log logger minor this logger minor this started global request to insert file to chk as identifier if client put null try fcp start blocking client put container context catch identifier collision exception e logger error this cannot put same file twice in same millisecond write permanent redirect ctx done queue return write permanent redirect ctx done queue return catch identifier collision exception e logger error this cannot put same file twice in same millisecond write permanent redirect ctx done queue return catch malformedurl exception e write error l10n get string queue toadlet error invaliduri l10n get string queue toadlet error invaliduri tou ctx return catch file not found exception e write error l10n get string queue toadlet error no file or cannot read l10n get string queue toadlet error access denied file new string file new string target ctx return catch not allowed exception e write error l10n get string queue toadlet error access denied l10n get string queue toadlet error access denied file new string file new string file get name ctx return catch metadata unresolved exception e logger error this unresolved metadata in starting insert from data from file e e write permanent redirect ctx done queue return fixme should this be a proper localised message it shouldn t happen but we d like to get reports if it does finally synchronized done done value true done notify all catch io exception e ignore catch toadlet context closed exception e ignore objectcontainer clientcontext clientput clientput clientput clientput getglobalforeverclient max_value requeststarter bulk_splitfile_priority_class clientrequest persist_forever clientputmessage upload_from_disk contenttype filebucket shouldlog clientput startblocking clientput identifiercollisionexception writepermanentredirect writepermanentredirect identifiercollisionexception writepermanentredirect malformedurlexception writeerror getstring queuetoadlet errorinvaliduri getstring queuetoadlet errorinvaliduritou filenotfoundexception writeerror getstring queuetoadlet errornofileorcannotread getstring queuetoadlet erroraccessdeniedfile notallowedexception writeerror getstring queuetoadlet erroraccessdenied getstring queuetoadlet erroraccessdeniedfile getname metadataunresolvedexception writepermanentredirect notifyall ioexception toadletcontextclosedexception public void run object container container client context context client put dir client put dir try try boolean logminor logger should log logger minor this client put dir new client put dir fcp get global forever client furi identifier integer max value request starter bulk splitfile priority class client request persist forever null false false 1 file null false true false fcp container if logminor logger minor this started global request to insert dir file to furi as identifier if client put dir null try fcp start blocking client put dir container context catch identifier collision exception e logger error this cannot put same file twice in same millisecond write permanent redirect ctx done queue return write permanent redirect ctx done queue return catch identifier collision exception e logger error this cannot put same directory twice in same millisecond write permanent redirect ctx done queue return catch malformedurl exception e write error l10n get string queue toadlet error invaliduri l10n get string queue toadlet error invaliduri tou ctx return catch file not found exception e write error l10n get string queue toadlet error no file or cannot read l10n get string queue toadlet error access denied file new string file new string file to string ctx return finally synchronized done done value true done notify all catch io exception e ignore catch toadlet context closed exception e ignore objectcontainer clientcontext clientputdir clientputdir shouldlog clientputdir clientputdir getglobalforeverclient max_value requeststarter bulk_splitfile_priority_class clientrequest persist_forever clientputdir startblocking clientputdir identifiercollisionexception writepermanentredirect writepermanentredirect identifiercollisionexception writepermanentredirect malformedurlexception writeerror getstring queuetoadlet errorinvaliduri getstring queuetoadlet errorinvaliduritou filenotfoundexception writeerror getstring queuetoadlet errornofileorcannotread getstring queuetoadlet erroraccessdeniedfile tostring notifyall ioexception toadletcontextclosedexception private void write error string header string message toadlet context context throws toadlet context closed exception io exception write error header message context true writeerror toadletcontext toadletcontextclosedexception ioexception writeerror private void write error string header string message toadlet context context boolean return to queue page throws toadlet context closed exception io exception page maker page maker context get page maker html node page node page maker get page node header context html node content node page maker get content node page node if context is allowed full access content node add child core alerts create summary html node infobox content node add child page maker get infobox infobox error header html node infobox content page maker get content node infobox infobox content add child message if return to queue page infobox content add child div add children new html node new html node return to new html node a href queue queue page new html node writehtml reply context 400 bad request page node generate writeerror toadletcontext returntoqueuepage toadletcontextclosedexception ioexception pagemaker pagemaker getpagemaker htmlnode pagenode pagemaker getpagenode htmlnode contentnode pagemaker getcontentnode pagenode isallowedfullaccess contentnode addchild createsummary htmlnode contentnode addchild pagemaker getinfobox htmlnode infoboxcontent pagemaker getcontentnode infoboxcontent addchild returntoqueuepage infoboxcontent addchild addchildren htmlnode htmlnode htmlnode htmlnode writehtmlreply pagenode override public void handle get uri uri final http request request final toadlet context ctx throws toadlet context closed exception io exception redirect exception we ensure that we have a fcp server running if fcp enabled write error l10n get string queue toadlet fcp is missing l10n get string queue toadlet please enablefcp ctx false return if core has loaded queue write error l10n get string queue toadlet not loaded yet title l10n get string queue toadlet not loaded yet ctx false return if container public gateway mode ctx is allowed full access super send error page ctx 403 l10n get string toadlet unauthorized title l10n get string toadlet unauthorized return final string request path request get path substring queue length boolean count requests false if request path length 0 if request path equals count requests html request path equals count requests html count requests true else okay there is something in the path check it try freeneturi key new freeneturi request path locate request temp fetch result result fcp get completed request blocking key if result null bucket data result as bucket string mime type result get mime type string requested mime type request get param type null string force string request get param force f proxy toadlet handle download ctx data ctx get bucket factory mime type requested mime type force string request is parameter set forcedownload queue key queue false ctx core false if result free when done data free return catch malformedurl exception mue1 class output wrapper boolean done html node page node final output wrapper ow new output wrapper final page maker page maker ctx get page maker final boolean count count requests core client context job runner queue new db job public void run object container container client context context html node page node null try if count long queued core request starters chk fetch scheduler count persistent waiting keys container system err println total waiting ch ks queued long really queued core request starters chk fetch scheduler count persistent queued requests container system err println total queued chk requests really queued page node page maker get page node l10n get string queue toadlet title new string node name new string core get my name ctx html node content node page maker get content node page node add alert summary box if ctx is allowed full access content node add child core alerts create summary html node infobox content node add child page maker get infobox infobox information queued requests status html node infobox content page maker get content node infobox infobox content add child p total awaiting ch ks queued infobox content add child p total queued chk requests really queued return else page node handle get inner page maker container context request ctx finally synchronized ow ow done true ow page node page node ow notify all native thread high priority false html node page node synchronized ow while true if ow done page node ow page node break try ow wait catch interrupted exception e ignore multi value table string string page headers new multi value table string string if page node null writehtml reply ctx 200 ok page headers page node generate else this write error internal error internal error ctx handleget httprequest toadletcontext toadletcontextclosedexception ioexception redirectexception writeerror getstring queuetoadlet fcpismissing getstring queuetoadlet pleaseenablefcp hasloadedqueue writeerror getstring queuetoadlet notloadedyettitle getstring queuetoadlet notloadedyet publicgatewaymode isallowedfullaccess senderrorpage getstring unauthorizedtitle getstring requestpath getpath countrequests requestpath requestpath countrequests requestpath countrequests countrequests requestpath tempfetchresult getcompletedrequestblocking asbucket mimetype getmimetype requestedmimetype getparam forcestring getparam fproxytoadlet handledownload getbucketfactory mimetype requestedmimetype forcestring isparameterset freewhendone malformedurlexception outputwrapper htmlnode pagenode outputwrapper outputwrapper pagemaker pagemaker getpagemaker countrequests clientcontext jobrunner dbjob objectcontainer clientcontext htmlnode pagenode requeststarters chkfetchscheduler countpersistentwaitingkeys chks reallyqueued requeststarters chkfetchscheduler countpersistentqueuedrequests reallyqueued pagenode pagemaker getpagenode getstring queuetoadlet nodename getmyname htmlnode contentnode pagemaker getcontentnode pagenode isallowedfullaccess contentnode addchild createsummary htmlnode contentnode addchild pagemaker getinfobox htmlnode infoboxcontent pagemaker getcontentnode infoboxcontent addchild chks infoboxcontent addchild reallyqueued pagenode handlegetinner pagemaker pagenode pagenode notifyall nativethread high_priority htmlnode pagenode pagenode pagenode interruptedexception multivaluetable pageheaders multivaluetable pagenode writehtmlreply pageheaders pagenode writeerror public void run object container container client context context html node page node null try if count long queued core request starters chk fetch scheduler count persistent waiting keys container system err println total waiting ch ks queued long really queued core request starters chk fetch scheduler count persistent queued requests container system err println total queued chk requests really queued page node page maker get page node l10n get string queue toadlet title new string node name new string core get my name ctx html node content node page maker get content node page node add alert summary box if ctx is allowed full access content node add child core alerts create summary html node infobox content node add child page maker get infobox infobox information queued requests status html node infobox content page maker get content node infobox infobox content add child p total awaiting ch ks queued infobox content add child p total queued chk requests really queued return else page node handle get inner page maker container context request ctx finally synchronized ow ow done true ow page node page node ow notify all objectcontainer clientcontext htmlnode pagenode requeststarters chkfetchscheduler countpersistentwaitingkeys chks reallyqueued requeststarters chkfetchscheduler countpersistentqueuedrequests reallyqueued pagenode pagemaker getpagenode getstring queuetoadlet nodename getmyname htmlnode contentnode pagemaker getcontentnode pagenode isallowedfullaccess contentnode addchild createsummary htmlnode contentnode addchild pagemaker getinfobox htmlnode infoboxcontent pagemaker getcontentnode infoboxcontent addchild chks infoboxcontent addchild reallyqueued pagenode handlegetinner pagemaker pagenode pagenode notifyall private html node handle get inner page maker page maker final object container container client context context final http request request toadlet context ctx first get the queued requests and separate them into different types linked list client request completed download to disk new linked list client request linked list client request completed download to temp new linked list client request linked list client request completed upload new linked list client request linked list client request completed dir upload new linked list client request linked list client request failed download new linked list client request linked list client request failed upload new linked list client request linked list client request failed dir upload new linked list client request linked list client request uncompleted download new linked list client request linked list client request uncompleted upload new linked list client request linked list client request uncompleted dir upload new linked list client request client request reqs fcp get global requests container if logger should log logger minor this logger minor this request count reqs length if reqs length 1 html node page node page maker get page node l10n get string queue toadlet title new string node name new string core get my name ctx html node content node page maker get content node page node add alert summary box if ctx is allowed full access content node add child core alerts create summary html node infobox content node add child page maker get infobox infobox information l10n get string queue toadlet global queue is empty html node infobox content page maker get content node infobox infobox content add child l10n get string queue toadlet no task on global queue content node add child create insert box page maker ctx core is advanced mode enabled content node add child create bulk download form ctx page maker return page node short lowest queued prio request starter minimum priority class long total queued download size 0 long total queued upload size 0 for int i 0 i reqs length i client request req reqs i if req instanceof client get client get cg client get req if cg has succeeded if cg is direct completed download to temp add cg else if cg is to disk completed download to disk add cg else fixme logger error this don t know what to do with cg else if cg has finished failed download add cg else short prio cg get priority if prio lowest queued prio lowest queued prio prio uncompleted download add cg long size cg get data size container if size 0 total queued download size size else if req instanceof client put client put cp client put req if cp has succeeded completed upload add cp else if cp has finished failed upload add cp else short prio req get priority if prio lowest queued prio lowest queued prio prio uncompleted upload add cp long size cp get data size container if size 0 total queued upload size size else if req instanceof client put dir client put dir cp client put dir req if cp has succeeded completed dir upload add cp else if cp has finished failed dir upload add cp else short prio req get priority if prio lowest queued prio lowest queued prio prio uncompleted dir upload add cp long size cp get total data size if size 0 total queued upload size size system err println total queued downloads size util format size total queued download size system err println total queued uploads size util format size total queued upload size comparator client request job comparator new comparator client request public int compare client request first request client request second request int result 0 boolean is set true if request is parameter set sort by final string sort by request get param sort by if sort by equals id result first request get identifier compare to ignore case second request get identifier else if sort by equals size result first request get total blocks container second request get total blocks container 0 1 1 else if sort by equals progress result first request get fetched blocks container first request get min blocks container second request get fetched blocks container second request get min blocks container 0 1 1 else is set false else is set false if is set int priority difference first request get priority second request get priority if priority difference 0 result priority difference 0 1 1 else result first request get identifier compare to second request get identifier if result 0 return 0 else if request is parameter set reversed is reversed true return result 0 1 1 else is reversed false return result 0 1 1 collections sort completed download to disk job comparator collections sort completed download to temp job comparator collections sort completed upload job comparator collections sort completed dir upload job comparator collections sort failed download job comparator collections sort failed upload job comparator collections sort failed dir upload job comparator collections sort uncompleted download job comparator collections sort uncompleted upload job comparator collections sort uncompleted dir upload job comparator html node page node page maker get page node uncompleted dir upload size uncompleted download size uncompleted upload size failed dir upload size failed download size failed upload size completed dir upload size completed download to disk size completed download to temp size completed upload size l10n get string queue toadlet title new string node name new string core get my name ctx html node content node page maker get content node page node add alert summary box if ctx is allowed full access content node add child core alerts create summary final int mode page maker draw mode selection array core request content node add file insert box content node add child create insert box page maker ctx mode page maker mode advanced navigation bar html node navigation bar page maker get infobox navbar l10n get string queue toadlet request navigation html node navigation content page maker get content node navigation bar add child ul boolean include navigation bar false if completed download to temp is empty navigation content add child li add child a href completed download to temp l10n get string queue toadlet completed dto temp new string size new string string value of completed download to temp size include navigation bar true if completed download to disk is empty navigation content add child li add child a href completed download to disk l10n get string queue toadlet completed dto disk new string size new string string value of completed download to disk size include navigation bar true if completed upload is empty navigation content add child li add child a href completed upload l10n get string queue toadlet completedu new string size new string string value of completed upload size include navigation bar true if completed dir upload is empty navigation content add child li add child a href completed dir upload l10n get string queue toadlet completeddu new string size new string string value of completed dir upload size include navigation bar true if failed download is empty navigation content add child li add child a href failed download l10n get string queue toadlet failedd new string size new string string value of failed download size include navigation bar true if failed upload is empty navigation content add child li add child a href failed upload l10n get string queue toadlet failedu new string size new string string value of failed upload size include navigation bar true if failed dir upload is empty navigation content add child li add child a href failed dir upload l10n get string queue toadlet faileddu new string size new string string value of failed dir upload size include navigation bar true if uncompleted download is empty navigation content add child li add child a href uncompleted download l10n get string queue toadlet din progress new string size new string string value of uncompleted download size include navigation bar true if uncompleted upload is empty navigation content add child li add child a href uncompleted upload l10n get string queue toadlet uin progress new string size new string string value of uncompleted upload size include navigation bar true if uncompleted dir upload is empty navigation content add child li add child a href uncompleted dir upload l10n get string queue toadlet d uin progress new string size new string string value of uncompleted dir upload size include navigation bar true if total queued download size 0 navigation content add child li l10n get string queue toadlet tota htmlnode handlegetinner pagemaker pagemaker objectcontainer clientcontext httprequest toadletcontext linkedlist clientrequest completeddownloadtodisk linkedlist clientrequest linkedlist clientrequest completeddownloadtotemp linkedlist clientrequest linkedlist clientrequest completedupload linkedlist clientrequest linkedlist clientrequest completeddirupload linkedlist clientrequest linkedlist clientrequest faileddownload linkedlist clientrequest linkedlist clientrequest failedupload linkedlist clientrequest linkedlist clientrequest faileddirupload linkedlist clientrequest linkedlist clientrequest uncompleteddownload linkedlist clientrequest linkedlist clientrequest uncompletedupload linkedlist clientrequest linkedlist clientrequest uncompleteddirupload linkedlist clientrequest clientrequest getglobalrequests shouldlog htmlnode pagenode pagemaker getpagenode getstring queuetoadlet nodename getmyname htmlnode contentnode pagemaker getcontentnode pagenode isallowedfullaccess contentnode addchild createsummary htmlnode contentnode addchild pagemaker getinfobox getstring queuetoadlet globalqueueisempty htmlnode infoboxcontent pagemaker getcontentnode infoboxcontent addchild getstring queuetoadlet notaskonglobalqueue contentnode addchild createinsertbox pagemaker isadvancedmodeenabled contentnode addchild createbulkdownloadform pagemaker pagenode lowestqueuedprio requeststarter minimum_priority_class totalqueueddownloadsize totalqueueduploadsize clientrequest clientget clientget clientget hassucceeded isdirect completeddownloadtotemp istodisk completeddownloadtodisk hasfinished faileddownload getpriority lowestqueuedprio lowestqueuedprio uncompleteddownload getdatasize totalqueueddownloadsize clientput clientput clientput hassucceeded completedupload hasfinished failedupload getpriority lowestqueuedprio lowestqueuedprio uncompletedupload getdatasize totalqueueduploadsize clientputdir clientputdir clientputdir hassucceeded completeddirupload hasfinished faileddirupload getpriority lowestqueuedprio lowestqueuedprio uncompleteddirupload gettotaldatasize totalqueueduploadsize sizeutil formatsize totalqueueddownloadsize sizeutil formatsize totalqueueduploadsize clientrequest jobcomparator clientrequest clientrequest firstrequest clientrequest secondrequest isset isparameterset sortby sortby getparam sortby sortby firstrequest getidentifier comparetoignorecase secondrequest getidentifier sortby firstrequest gettotalblocks secondrequest gettotalblocks sortby firstrequest getfetchedblocks firstrequest getminblocks secondrequest getfetchedblocks secondrequest getminblocks isset isset isset prioritydifference firstrequest getpriority secondrequest getpriority prioritydifference prioritydifference firstrequest getidentifier compareto secondrequest getidentifier isparameterset isreversed isreversed completeddownloadtodisk jobcomparator completeddownloadtotemp jobcomparator completedupload jobcomparator completeddirupload jobcomparator faileddownload jobcomparator failedupload jobcomparator faileddirupload jobcomparator uncompleteddownload jobcomparator uncompletedupload jobcomparator uncompleteddirupload jobcomparator htmlnode pagenode pagemaker getpagenode uncompleteddirupload uncompleteddownload uncompletedupload faileddirupload faileddownload failedupload completeddirupload completeddownloadtodisk completeddownloadtotemp completedupload getstring queuetoadlet nodename getmyname htmlnode contentnode pagemaker getcontentnode pagenode isallowedfullaccess contentnode addchild createsummary pagemaker drawmodeselectionarray contentnode contentnode addchild createinsertbox pagemaker pagemaker mode_advanced htmlnode navigationbar pagemaker getinfobox getstring queuetoadlet requestnavigation htmlnode navigationcontent pagemaker getcontentnode navigationbar addchild includenavigationbar completeddownloadtotemp isempty navigationcontent addchild addchild completeddownloadtotemp getstring queuetoadlet completeddtotemp valueof completeddownloadtotemp includenavigationbar completeddownloadtodisk isempty navigationcontent addchild addchild completeddownloadtodisk getstring queuetoadlet completeddtodisk valueof completeddownloadtodisk includenavigationbar completedupload isempty navigationcontent addchild addchild completedupload getstring queuetoadlet valueof completedupload includenavigationbar completeddirupload isempty navigationcontent addchild addchild completeddirupload getstring queuetoadlet valueof completeddirupload includenavigationbar faileddownload isempty navigationcontent addchild addchild faileddownload getstring queuetoadlet valueof faileddownload includenavigationbar failedupload isempty navigationcontent addchild addchild failedupload getstring queuetoadlet valueof failedupload includenavigationbar faileddirupload isempty navigationcontent addchild addchild faileddirupload getstring queuetoadlet valueof faileddirupload includenavigationbar uncompleteddownload isempty navigationcontent addchild addchild uncompleteddownload getstring queuetoadlet dinprogress valueof uncompleteddownload includenavigationbar uncompletedupload isempty navigationcontent addchild addchild uncompletedupload getstring queuetoadlet uinprogress valueof uncompletedupload includenavigationbar uncompleteddirupload isempty navigationcontent addchild addchild uncompleteddirupload getstring queuetoadlet duinprogress valueof uncompleteddirupload includenavigationbar totalqueueddownloadsize navigationcontent addchild getstring queuetoadlet comparator client request job comparator new comparator client request public int compare client request first request client request second request int result 0 boolean is set true if request is parameter set sort by final string sort by request get param sort by if sort by equals id result first request get identifier compare to ignore case second request get identifier else if sort by equals size result first request get total blocks container second request get total blocks container 0 1 1 else if sort by equals progress result first request get fetched blocks container first request get min blocks container second request get fetched blocks container second request get min blocks container 0 1 1 else is set false else is set false if is set int priority difference first request get priority second request get priority if priority difference 0 result priority difference 0 1 1 else result first request get identifier compare to second request get identifier if result 0 return 0 else if request is parameter set reversed is reversed true return result 0 1 1 else is reversed false return result 0 1 1 clientrequest jobcomparator clientrequest clientrequest firstrequest clientrequest secondrequest isset isparameterset sortby sortby getparam sortby sortby firstrequest getidentifier comparetoignorecase secondrequest getidentifier sortby firstrequest gettotalblocks secondrequest gettotalblocks sortby firstrequest getfetchedblocks firstrequest getminblocks secondrequest getfetchedblocks secondrequest getminblocks isset isset isset prioritydifference firstrequest getpriority secondrequest getpriority prioritydifference prioritydifference firstrequest getidentifier compareto secondrequest getidentifier isparameterset isreversed isreversed private html node create reason cell string failure reason html node reason cell new html node td class request reason if failure reason null reason cell add child span class failure reason unknown l10n get string queue toadlet unknown else reason cell add child span class failure reason is failure reason return reason cell htmlnode createreasoncell failurereason htmlnode reasoncell htmlnode failurereason reasoncell addchild failure_reason_unknown getstring queuetoadlet reasoncell addchild failure_reason_is failurereason reasoncell private html node create progress cell boolean started int fetched int failed int fatally failed int min int total boolean finalized boolean upload html node progress cell new html node td class request progress if started progress cell add child l10n get string queue toadlet starting return progress cell double frac p get success fraction if core is advanced mode enabled total min if fetched 0 total 0 progress cell add child span class progress fraction unknown l10n get string queue toadlet unknown else int fetched percent int fetched double total 100 int failed percent int failed double total 100 int fatally failed percent int fatally failed double total 100 int min percent int min double total 100 html node progress bar progress cell add child div class progressbar progress bar add child div new string class style new string progressbar done width fetched percent if failed 0 progress bar add child div new string class style new string progressbar failed width failed percent if fatally failed 0 progress bar add child div new string class style new string progressbar failed2 width fatally failed percent if fetched failed fatally failed min progress bar add child div new string class style new string progressbar min width min percent fetched percent number format nf number format get instance nf set maximum fraction digits 1 string prefix integer to string fetched integer to string min if finalized progress bar add child div new string class title new string progress fraction finalized prefix l10n get string queue toadlet progressbar accurate nf format int fetched double min 1000 10 0 else string text nf format int fetched double min 1000 10 0 if finalized text fetched text progress bar add child div new string class title new string progress fraction not finalized prefix l10n get string upload queue toadlet upload progressbar not accurate queue toadlet progressbar not accurate text return progress cell htmlnode createprogresscell fatallyfailed htmlnode progresscell htmlnode progresscell addchild getstring queuetoadlet progresscell getsuccessfraction isadvancedmodeenabled progresscell addchild progress_fraction_unknown getstring queuetoadlet fetchedpercent failedpercent fatallyfailedpercent fatallyfailed minpercent htmlnode progressbar progresscell addchild progressbar addchild fetchedpercent progressbar addchild failedpercent fatallyfailed progressbar addchild fatallyfailedpercent fatallyfailed progressbar addchild minpercent fetchedpercent numberformat numberformat getinstance setmaximumfractiondigits tostring tostring progressbar addchild progress_fraction_finalized getstring queuetoadlet progressbaraccurate progressbar addchild progress_fraction_not_finalized getstring queuetoadlet uploadprogressbarnotaccurate queuetoadlet progressbarnotaccurate progresscell private html node create number cell int number of files html node number cell new html node td class request files number cell add child span class number of files string value of number of files return number cell htmlnode createnumbercell numberoffiles htmlnode numbercell htmlnode numbercell addchild number_of_files valueof numberoffiles numbercell private html node create filename cell file filename html node filename cell new html node td class request filename if filename null filename cell add child span class filename is filename to string else filename cell add child span class filename none l10n get string queue toadlet none return filename cell htmlnode createfilenamecell htmlnode filenamecell htmlnode filenamecell addchild filename_is tostring filenamecell addchild filename_none getstring queuetoadlet filenamecell private html node create priority cell page maker page maker string identifier short priority class toadlet context ctx string priority classes boolean advanced mode enabled html node priority cell new html node td class request priority nowrap html node priority form ctx add form child priority cell queue queue change priority cell identifier hash code priority form add child input new string type name value new string hidden identifier identifier html node priority select priority form add child select name priority for int p 0 p request starter number of priority classes p if p request starter interactive priority class advanced mode enabled continue if p priority class priority select add child option new string value selected new string string value of p selected priority classes p else priority select add child option value string value of p priority classes p priority form add child input new string type name value new string submit change priority l10n get string queue toadlet change return priority cell htmlnode createprioritycell pagemaker pagemaker priorityclass toadletcontext priorityclasses advancedmodeenabled htmlnode prioritycell htmlnode htmlnode priorityform addformchild prioritycell queuechangeprioritycell hashcode priorityform addchild htmlnode priorityselect priorityform addchild requeststarter number_of_priority_classes requeststarter interactive_priority_class advancedmodeenabled priorityclass priorityselect addchild valueof priorityclasses priorityselect addchild valueof priorityclasses priorityform addchild change_priority getstring queuetoadlet prioritycell private html node create delete cell page maker page maker string identifier client request client request toadlet context ctx html node delete node new html node td class request delete html node delete form ctx add form child delete node queue queue delete form identifier hash code delete form add child input new string type name value new string hidden identifier identifier delete form add child input new string type name value new string submit remove request l10n get string queue toadlet remove if it s failed offer to restart it if client request has finished client request has succeeded client request can restart html node retry form ctx add form child delete node queue queue restart form identifier hash code string restart name l10n get string client request instanceof client get client get client request has perm redirect queue toadlet follow queue toadlet restart retry form add child input new string type name value new string hidden identifier identifier retry form add child input new string type name value new string submit restart request restart name return delete node htmlnode createdeletecell pagemaker pagemaker clientrequest clientrequest toadletcontext htmlnode deletenode htmlnode htmlnode deleteform addformchild deletenode queuedeleteform hashcode deleteform addchild deleteform addchild remove_request getstring queuetoadlet clientrequest hasfinished clientrequest hassucceeded clientrequest canrestart htmlnode retryform addformchild deletenode queuerestartform hashcode restartname getstring clientrequest clientget clientget clientrequest haspermredirect queuetoadlet queuetoadlet retryform addchild retryform addchild restart_request restartname deletenode private html node create panic box page maker page maker toadlet context ctx html node panic box page maker get infobox infobox alert l10n get string queue toadlet panic button html node panic form ctx add form child page maker get content node panic box queue queue panic form panic form add child l10n get string queue toadlet panic button confirmation panic form add child input new string type name value new string submit remove allrequests l10n get string queue toadlet remove return panic box htmlnode createpanicbox pagemaker pagemaker toadletcontext htmlnode panicbox pagemaker getinfobox getstring queuetoadlet panicbutton htmlnode panicform addformchild pagemaker getcontentnode panicbox queuepanicform panicform addchild getstring queuetoadlet panicbuttonconfirmation panicform addchild remove_allrequests getstring queuetoadlet panicbox private html node create identifier cell freeneturi uri string identifier boolean directory html node identifier cell new html node td class request identifier if uri null identifier cell add child span class identifier with uri add child a href uri directory identifier else identifier cell add child span class identifier without uri identifier return identifier cell htmlnode createidentifiercell htmlnode identifiercell htmlnode identifiercell addchild identifier_with_uri addchild identifiercell addchild identifier_without_uri identifiercell private html node create persistence cell boolean persistent boolean persistent forever html node persistence cell new html node td class request persistence if persistent forever persistence cell add child span class persistence forever l10n get string queue toadlet persistence forever else if persistent persistence cell add child span class persistence reboot l10n get string queue toadlet persistence reboot else persistence cell add child span class persistence none l10n get string queue toadlet persistence none return persistence cell htmlnode createpersistencecell persistentforever htmlnode persistencecell htmlnode persistentforever persistencecell addchild persistence_forever getstring queuetoadlet persistenceforever persistencecell addchild persistence_reboot getstring queuetoadlet persistencereboot persistencecell addchild persistence_none getstring queuetoadlet persistencenone persistencecell private html node create download cell page maker page maker client get p object container container html node download cell new html node td class request download freeneturi uri p geturi container if uri null logger error this no uri for p new exception error else download cell add child a href uri to string l10n get string queue toadlet download return download cell htmlnode createdownloadcell pagemaker pagemaker clientget objectcontainer htmlnode downloadcell htmlnode downloadcell addchild tostring getstring queuetoadlet downloadcell private html node create type cell string type html node type cell new html node td class request type if type null type cell add child span class mimetype is type else type cell add child span class mimetype unknown l10n get string queue toadlet unknown return type cell htmlnode createtypecell htmlnode typecell htmlnode typecell addchild mimetype_is typecell addchild mimetype_unknown getstring queuetoadlet typecell private html node create size cell long data size boolean confirmed boolean advanced mode enabled html node size cell new html node td class request size if data size 0 confirmed advanced mode enabled size cell add child span class filesize is confirmed size util format size data size confirmed else size cell add child span class filesize unknown l10n get string queue toadlet unknown return size cell htmlnode createsizecell datasize advancedmodeenabled htmlnode sizecell htmlnode datasize advancedmodeenabled sizecell addchild filesize_is sizeutil formatsize datasize sizecell addchild filesize_unknown getstring queuetoadlet sizecell private html node create key cell freeneturi uri boolean add slash html node key cell new html node td class request key if uri null key cell add child span class key is add child a href uri to string add slash uri to short string add slash else key cell add child span class key unknown l10n get string queue toadlet unknown return key cell htmlnode createkeycell addslash htmlnode keycell htmlnode keycell addchild key_is addchild tostring addslash toshortstring addslash keycell addchild key_unknown getstring queuetoadlet keycell private html node create insert box page maker page maker toadlet context ctx boolean is advanced mode enabled the insert file box html node insert box page maker get infobox l10n get string queue toadlet insert file html node insert content page maker get content node insert box html node insert form ctx add form child insert content queue queue insert form insert form add child l10n get string queue toadlet insert as insert form add child input new string type name value checked new string radio keytype chk checked insert form add child chk u00a0 insert form add child input new string type name value new string radio keytype ksk insert form add child ksk ssk usk u00a0 insert form add child input new string type name value new string text key ksk if ctx is allowed full access insert form add child br insert form add child l10n get string queue toadlet insert file browse label insert form add child input new string type name value new string submit insert local l10n get string queue toadlet insert file browse button insert form add child br insert form add child l10n get string queue toadlet insert file label insert form add child input new string type name value new string file filename insert form add child u00a0 insert form add child input new string type name value new string submit insert l10n get string queue toadlet insert file insert file label insert form add child u00a0 if is advanced mode enabled insert form add child input new string type name checked new string checkbox compress checked insert form add child l10n get string queue toadlet insert file compress label u00a0 else insert form add child input new string type value new string hidden true insert form add child input new string type name new string reset l10n get string queue toadlet insert file reset form return insert box htmlnode createinsertbox pagemaker pagemaker toadletcontext isadvancedmodeenabled htmlnode insertbox pagemaker getinfobox getstring queuetoadlet insertfile htmlnode insertcontent pagemaker getcontentnode insertbox htmlnode insertform addformchild insertcontent queueinsertform insertform addchild getstring queuetoadlet insertas insertform addchild insertform addchild insertform addchild insertform addchild insertform addchild isallowedfullaccess insertform addchild insertform addchild getstring queuetoadlet insertfilebrowselabel insertform addchild getstring queuetoadlet insertfilebrowsebutton insertform addchild insertform addchild getstring queuetoadlet insertfilelabel insertform addchild insertform addchild insertform addchild getstring queuetoadlet insertfileinsertfilelabel insertform addchild isadvancedmodeenabled insertform addchild insertform addchild getstring queuetoadlet insertfilecompresslabel insertform addchild insertform addchild getstring queuetoadlet insertfileresetform insertbox private html node create bulk download form toadlet context ctx page maker page maker html node download box page maker get infobox l10n get string queue toadlet download files html node download box content page maker get content node download box html node download form ctx add form child download box content queue queue download form download form add child l10n get string queue toadlet download files instructions download form add child br download form add child textarea new string id name cols rows new string bulk downloads bulk downloads 120 8 download form add child br download form add child input new string type name value new string submit insert l10n get string queue toadlet download return download box htmlnode createbulkdownloadform toadletcontext pagemaker pagemaker htmlnode downloadbox pagemaker getinfobox getstring queuetoadlet downloadfiles htmlnode downloadboxcontent pagemaker getcontentnode downloadbox htmlnode downloadform addformchild downloadboxcontent queuedownloadform downloadform addchild getstring queuetoadlet downloadfilesinstructions downloadform addchild downloadform addchild bulkdownloads bulkdownloads downloadform addchild downloadform addchild getstring queuetoadlet downloadbox private html node create request table page maker page maker toadlet context ctx list client request requests int columns string priority classes boolean advanced mode enabled boolean is upload object container container html node table new html node table class requests html node header row table add child tr class table header header row add child th for int column index 0 column count columns length column index column count column index int column columns column index if column list identifier header row add child th add child a href is reversed sort by id sort by id reversed add child l10n get string queue toadlet identifier else if column list size header row add child th add child a href is reversed sort by size sort by size reversed add child l10n get string queue toadlet size else if column list download header row add child th l10n get string queue toadlet download else if column list mime type header row add child th l10n get string queue toadlet mime type else if column list persistence header row add child th l10n get string queue toadlet persistence else if column list key header row add child th l10n get string queue toadlet key else if column list filename header row add child th l10n get string queue toadlet file name else if column list priority header row add child th add child a href is reversed sort by priority sort by priority reversed add child l10n get string queue toadlet priority else if column list files header row add child th l10n get string queue toadlet files else if column list total size header row add child th l10n get string queue toadlet total size else if column list progress header row add child th add child a href is reversed sort by progress sort by progress reversed add child l10n get string queue toadlet progress else if column list reason header row add child th l10n get string queue toadlet reason for client request client request requests container activate client request 1 html node request row table add child tr class priority client request get priority request row add child create delete cell page maker client request get identifier client request ctx for int column index 0 column count columns length column index column count column index int column columns column index if column list identifier if client request instanceof client get request row add child create identifier cell client get client request geturi container client request get identifier false else if client request instanceof client put dir request row add child create identifier cell client put dir client request get finaluri container client request get identifier true else if client request instanceof client put request row add child create identifier cell client put client request get finaluri container client request get identifier false else if column list size if client request instanceof client get request row add child create size cell client get client request get data size container client get client request is total finalized container advanced mode enabled else if client request instanceof client put request row add child create size cell client put client request get data size container true advanced mode enabled else if column list download request row add child create download cell page maker client get client request container else if column list mime type if client request instanceof client get request row add child create type cell client get client request getmime type container else if client request instanceof client put request row add child create type cell client put client request getmime type else if column list persistence request row add child create persistence cell client request is persistent client request is persistent forever else if column list key if client request instanceof client get request row add child create key cell client get client request geturi container false else if client request instanceof client put request row add child create key cell client put client request get finaluri container false else request row add child create key cell client put dir client request get finaluri container true else if column list filename if client request instanceof client get request row add child create filename cell client get client request get dest filename container else if client request instanceof client put request row add child create filename cell client put client request get orig filename container else if column list priority request row add child create priority cell page maker client request get identifier client request get priority ctx priority classes advanced mode enabled else if column list files request row add child create number cell client put dir client request get number of files else if column list total size request row add child create size cell client put dir client request get total data size true advanced mode enabled else if column list progress request row add child create progress cell client request is started int client request get fetched blocks container int client request get failed blocks container int client request get fataly failed blocks container int client request get min blocks container int client request get total blocks container client request is total finalized container client request instanceof client put is upload else if column list reason request row add child create reason cell client request get failure reason container return table htmlnode createrequesttable pagemaker pagemaker toadletcontext clientrequest priorityclasses advancedmodeenabled isupload objectcontainer htmlnode htmlnode htmlnode headerrow addchild headerrow addchild columnindex columncount columnindex columncount columnindex columnindex list_identifier headerrow addchild addchild isreversed sortby sortby addchild getstring queuetoadlet list_size headerrow addchild addchild isreversed sortby sortby addchild getstring queuetoadlet list_download headerrow addchild getstring queuetoadlet list_mime_type headerrow addchild getstring queuetoadlet mimetype list_persistence headerrow addchild getstring queuetoadlet list_key headerrow addchild getstring queuetoadlet list_filename headerrow addchild getstring queuetoadlet filename list_priority headerrow addchild addchild isreversed sortby sortby addchild getstring queuetoadlet list_files headerrow addchild getstring queuetoadlet list_total_size headerrow addchild getstring queuetoadlet totalsize list_progress headerrow addchild addchild isreversed sortby sortby addchild getstring queuetoadlet list_reason headerrow addchild getstring queuetoadlet clientrequest clientrequest clientrequest htmlnode requestrow addchild clientrequest getpriority requestrow addchild createdeletecell pagemaker clientrequest getidentifier clientrequest columnindex columncount columnindex columncount columnindex columnindex list_identifier clientrequest clientget requestrow addchild createidentifiercell clientget clientrequest clientrequest getidentifier clientrequest clientputdir requestrow addchild createidentifiercell clientputdir clientrequest getfinaluri clientrequest getidentifier clientrequest clientput requestrow addchild createidentifiercell clientput clientrequest getfinaluri clientrequest getidentifier list_size clientrequest clientget requestrow addchild createsizecell clientget clientrequest getdatasize clientget clientrequest istotalfinalized advancedmodeenabled clientrequest clientput requestrow addchild createsizecell clientput clientrequest getdatasize advancedmodeenabled list_download requestrow addchild createdownloadcell pagemaker clientget clientrequest list_mime_type clientrequest clientget requestrow addchild createtypecell clientget clientrequest getmimetype clientrequest clientput requestrow addchild createtypecell clientput clientrequest getmimetype list_persistence requestrow addchild createpersistencecell clientrequest ispersistent clientrequest ispersistentforever list_key clientrequest clientget requestrow addchild createkeycell clientget clientrequest clientrequest clientput requestrow addchild createkeycell clientput clientrequest getfinaluri requestrow addchild createkeycell clientputdir clientrequest getfinaluri list_filename clientrequest clientget requestrow addchild createfilenamecell clientget clientrequest getdestfilename clientrequest clientput requestrow addchild createfilenamecell clientput clientrequest getorigfilename list_priority requestrow addchild createprioritycell pagemaker clientrequest getidentifier clientrequest getpriority priorityclasses advancedmodeenabled list_files requestrow addchild createnumbercell clientputdir clientrequest getnumberoffiles list_total_size requestrow addchild createsizecell clientputdir clientrequest gettotaldatasize advancedmodeenabled list_progress requestrow addchild createprogresscell clientrequest isstarted clientrequest getfetchedblocks clientrequest getfailedblocks clientrequest getfatalyfailedblocks clientrequest getminblocks clientrequest gettotalblocks clientrequest istotalfinalized clientrequest clientput isupload list_reason requestrow addchild createreasoncell clientrequest getfailurereason override public string supported methods return get post supportedmethods private final hash map string user alert alerts by identifier new hash map string user alert public void notify failure client request req object container container fixme do something hashmap useralert alertsbyidentifier hashmap useralert notifyfailure clientrequest objectcontainer public void notify success client request req object container container synchronized completed request identifiers completed request identifiers add req get identifier register alert req container should be safe here save completed identifiers off thread notifysuccess clientrequest objectcontainer completedrequestidentifiers completedrequestidentifiers getidentifier registeralert savecompletedidentifiersoffthread private void save completed identifiers off thread core get executor execute new runnable public void run save completed identifiers save completed identifiers savecompletedidentifiersoffthread getexecutor savecompletedidentifiers private void save completed identifiers off thread core get executor execute new runnable public void run save completed identifiers savecompletedidentifiersoffthread getexecutor savecompletedidentifiers private void load completed identifiers file completed identifiers list new file core node get node dir completed list file completed identifiers list new new file core node get node dir completed list bak if read completed identifiers completed identifiers list read completed identifiers completed identifiers list new core client context job runner queue new db job public void run object container container client context context string identifiers synchronized completed request identifiers identifiers completed request identifiers to array new string completed request identifiers size for int i 0 i identifiers length i client request req fcp get global request identifiers i container if req null synchronized completed request identifiers completed request identifiers remove identifiers i continue register alert req container native thread high priority false loadcompletedidentifiers completedidentifierslist getnodedir completedidentifierslistnew getnodedir readcompletedidentifiers completedidentifierslist readcompletedidentifiers completedidentifierslistnew clientcontext jobrunner dbjob objectcontainer clientcontext completedrequestidentifiers completedrequestidentifiers toarray completedrequestidentifiers clientrequest getglobalrequest completedrequestidentifiers completedrequestidentifiers registeralert nativethread high_priority public void run object container container client context context string identifiers synchronized completed request identifiers identifiers completed request identifiers to array new string completed request identifiers size for int i 0 i identifiers length i client request req fcp get global request identifiers i container if req null synchronized completed request identifiers completed request identifiers remove identifiers i continue register alert req container objectcontainer clientcontext completedrequestidentifiers completedrequestidentifiers toarray completedrequestidentifiers clientrequest getglobalrequest completedrequestidentifiers completedrequestidentifiers registeralert private boolean read completed identifiers file file file input stream fis null try fis new file input stream file buffered input stream bis new buffered input stream fis input stream reader isr new input stream reader bis utf 8 buffered reader br new buffered reader isr synchronized completed request identifiers completed request identifiers clear while true string identifier br read line if identifier null return true completed request identifiers add identifier catch eof exception e normal return true catch file not found exception e normal return false catch unsupported encoding exception e throw new error impossible jvm doesn t support utf 8 e e catch io exception e logger error this could not read completed identifiers list from file return false finally closer close fis readcompletedidentifiers fileinputstream fileinputstream bufferedinputstream bufferedinputstream inputstreamreader inputstreamreader bufferedreader bufferedreader completedrequestidentifiers completedrequestidentifiers readline completedrequestidentifiers eofexception filenotfoundexception unsupportedencodingexception ioexception private void save completed identifiers file output stream fos null buffered writer bw null file completed identifiers list new file core node get node dir completed list file completed identifiers list new new file core node get node dir completed list bak file temp try temp file create temp file completed list tmp core node get node dir temp delete on exit fos new file output stream temp output stream writer osw new output stream writer fos utf 8 bw new buffered writer osw string identifiers synchronized completed request identifiers identifiers completed request identifiers to array new string completed request identifiers size for int i 0 i identifiers length i bw write identifiers i n catch file not found exception e logger error this unable to save completed requests list can t find node directory e e return catch io exception e logger error this unable to save completed requests list e e return finally if bw null try bw close catch io exception e try fos close catch io exception e1 ignore else try fos close catch io exception e1 ignore completed identifiers list new delete temp rename to completed identifiers list new if completed identifiers list new rename to completed identifiers list completed identifiers list delete if completed identifiers list new rename to completed identifiers list logger error this unable to store completed identifiers list because unable to rename completed identifiers list new to completed identifiers list savecompletedidentifiers fileoutputstream bufferedwriter completedidentifierslist getnodedir completedidentifierslistnew getnodedir createtempfile getnodedir deleteonexit fileoutputstream outputstreamwriter outputstreamwriter bufferedwriter completedrequestidentifiers completedrequestidentifiers toarray completedrequestidentifiers filenotfoundexception ioexception ioexception ioexception ioexception completedidentifierslistnew renameto completedidentifierslistnew completedidentifierslistnew renameto completedidentifierslist completedidentifierslist completedidentifierslistnew renameto completedidentifierslist completedidentifierslistnew completedidentifierslist private void register alert client request req object container container final string identifier req get identifier boolean logminor logger should log logger minor this if logminor logger minor this registering alert for identifier if req has finished if logminor logger minor this request hasn t finished req for identifier new exception debug return if req instanceof client get freeneturi uri client get req geturi container if req is persistent forever uri null container activate uri 5 if uri null logger error this no uri for supposedly finished request req return long size client get req get data size container string name uri get preferred filename string title l10n download succeeded title filename name html node text new html node div l10n addl10n substitution text queue toadlet download succeeded new string link link origlink origlink filename size new string a href queue uri toascii string a a href uri toascii string a name size util format size size user alert alert new simplehtml user alert true title title text user alert minor override public void on dismiss synchronized completed request identifiers completed request identifiers remove identifier synchronized alerts by identifier alerts by identifier remove identifier save completed identifiers off thread override public boolean is event notification return true core alerts register alert synchronized alerts by identifier alerts by identifier put identifier alert else if req instanceof client put freeneturi uri client put req get finaluri container if req is persistent forever uri null container activate uri 5 if uri null logger error this no uri for supposedly finished request req return long size client put req get data size container string name uri get preferred filename string title l10n upload succeeded title filename name html node text new html node div l10n addl10n substitution text queue toadlet upload succeeded new string link link filename size new string a href uri toascii string a name size util format size size user alert alert new simplehtml user alert true title title text user alert minor override public void on dismiss synchronized completed request identifiers completed request identifiers remove identifier synchronized alerts by identifier alerts by identifier remove identifier save completed identifiers off thread override public boolean is event notification return true core alerts register alert synchronized alerts by identifier alerts by identifier put identifier alert else if req instanceof client put dir freeneturi uri client put dir req get finaluri container if req is persistent forever uri null container activate uri 5 if uri null logger error this no uri for supposedly finished request req return long size client put dir req get total data size int files client put dir req get number of files string name uri get preferred filename string title l10n site upload succeeded title filename name html node text new html node div l10n addl10n substitution text queue toadlet site upload succeeded new string link link filename size files new string a href uri toascii string a name size util format size size integer to string files user alert alert new simplehtml user alert true title title text user alert minor override public void on dismiss synchronized completed request identifiers completed request identifiers remove identifier synchronized alerts by identifier alerts by identifier remove identifier save completed identifiers off thread override public boolean is event notification return true core alerts register alert synchronized alerts by identifier alerts by identifier put identifier alert registeralert clientrequest objectcontainer getidentifier shouldlog hasfinished clientget clientget ispersistentforever clientget getdatasize getpreferredfilename downloadsucceededtitle htmlnode htmlnode addl10nsubstitution queuetoadlet downloadsucceeded toasciistring toasciistring sizeutil formatsize useralert simplehtmluseralert useralert ondismiss completedrequestidentifiers completedrequestidentifiers alertsbyidentifier alertsbyidentifier savecompletedidentifiersoffthread iseventnotification alertsbyidentifier alertsbyidentifier clientput clientput getfinaluri ispersistentforever clientput getdatasize getpreferredfilename uploadsucceededtitle htmlnode htmlnode addl10nsubstitution queuetoadlet uploadsucceeded toasciistring sizeutil formatsize useralert simplehtmluseralert useralert ondismiss completedrequestidentifiers completedrequestidentifiers alertsbyidentifier alertsbyidentifier savecompletedidentifiersoffthread iseventnotification alertsbyidentifier alertsbyidentifier clientputdir clientputdir getfinaluri ispersistentforever clientputdir gettotaldatasize clientputdir getnumberoffiles getpreferredfilename siteuploadsucceededtitle htmlnode htmlnode addl10nsubstitution queuetoadlet siteuploadsucceeded toasciistring sizeutil formatsize tostring useralert simplehtmluseralert useralert ondismiss completedrequestidentifiers completedrequestidentifiers alertsbyidentifier alertsbyidentifier savecompletedidentifiersoffthread iseventnotification alertsbyidentifier alertsbyidentifier new simplehtml user alert true title title text user alert minor override public void on dismiss synchronized completed request identifiers completed request identifiers remove identifier synchronized alerts by identifier alerts by identifier remove identifier save completed identifiers off thread simplehtmluseralert useralert ondismiss completedrequestidentifiers completedrequestidentifiers alertsbyidentifier alertsbyidentifier savecompletedidentifiersoffthread save completed identifiers off thread override public boolean is event notification return true savecompletedidentifiersoffthread iseventnotification new simplehtml user alert true title title text user alert minor override public void on dismiss synchronized completed request identifiers completed request identifiers remove identifier synchronized alerts by identifier alerts by identifier remove identifier save completed identifiers off thread simplehtmluseralert useralert ondismiss completedrequestidentifiers completedrequestidentifiers alertsbyidentifier alertsbyidentifier savecompletedidentifiersoffthread save completed identifiers off thread override public boolean is event notification return true savecompletedidentifiersoffthread iseventnotification new simplehtml user alert true title title text user alert minor override public void on dismiss synchronized completed request identifiers completed request identifiers remove identifier synchronized alerts by identifier alerts by identifier remove identifier save completed identifiers off thread simplehtmluseralert useralert ondismiss completedrequestidentifiers completedrequestidentifiers alertsbyidentifier alertsbyidentifier savecompletedidentifiersoffthread save completed identifiers off thread override public boolean is event notification return true savecompletedidentifiersoffthread iseventnotification string l10n string key string pattern string value return l10n get string queue toadlet key pattern value getstring queuetoadlet public void on remove client request req object container container string identifier req get identifier synchronized completed request identifiers completed request identifiers remove identifier user alert alert synchronized alerts by identifier alert alerts by identifier remove identifier core alerts unregister alert save completed identifiers off thread onremove clientrequest objectcontainer getidentifier completedrequestidentifiers completedrequestidentifiers useralert alertsbyidentifier alertsbyidentifier savecompletedidentifiersoffthread public boolean is enabled toadlet context ctx return container public gateway mode ctx is allowed full access isenabled toadletcontext publicgatewaymode isallowedfullaccess public final static string suffixes b kib mib gib tib pib eib zib yib public static string format size long sz return format size sz false formatsize formatsize public static string format size without space long sz string result formatsize sz return result 0 concat result 1 formatsizewithoutspace _formatsize public static string format size long sz boolean use non breaking space string result formatsize sz return result 0 concat use non breaking space u00a0 concat result 1 formatsize usenonbreakingspace _formatsize usenonbreakingspace public static string formatsize long sz long s 1 int i for i 0 i size util suffixes length i s 1024 if s sz break smaller than multiplier i use the previous one s 1024 we use the previous unit if s 1 bytes then we don t need real numbers with a comma return new string string value of sz size util suffixes 0 else double mantissa double sz double s string o string value of mantissa if o index of 3 o o substring 0 3 else if o index of 1 o index of e 1 o length 4 o o substring 0 4 if i size util suffixes length handle the case where the mantissa is infinity return new string o size util suffixes i return new string o _formatsize sizeutil valueof sizeutil valueof indexof indexof indexof sizeutil sizeutil public subscribeusk subscribeusk message message node client core core fcp connection handler handler throws identifier collision exception this handler handler this dont poll message dont poll this identifier message identifier this core core this usk message key prio message prio prio progress message prio progress handler add subscription identifier this core usk manager subscribe message key this message dont poll handler get reboot client low level client subscribeuskmessage nodeclientcore fcpconnectionhandler identifiercollisionexception dontpoll dontpoll prioprogress prioprogress addsubscription uskmanager dontpoll getrebootclient lowlevelclient public void on found edition long l usk key object container container client context context boolean was metadata short codec byte data boolean new known good boolean new slot too if handler is closed core usk manager unsubscribe key this return if new known good new slot too return fcp message msg new subscribedusk update identifier l key new known good new slot too handler output handler queue msg onfoundedition objectcontainer clientcontext wasmetadata newknowngood newslottoo isclosed uskmanager newknowngood newslottoo fcpmessage subscribeduskupdate newknowngood newslottoo outputhandler public short get polling priority normal return prio getpollingprioritynormal public short get polling priority progress return prio progress getpollingpriorityprogress prioprogress public void unsubscribe core usk manager unsubscribe usk this uskmanager private static final gregorian calendar m calendar new gregorian calendar time zone get time zone utc public static date get return new date gregoriancalendar mcalendar gregoriancalendar timezone gettimezone public static long get in millis return system current time millis getinmillis currenttimemillis public static int get year synchronized m calendar m calendar set time in millis system current time millis return m calendar get calendar year getyear mcalendar mcalendar settimeinmillis currenttimemillis mcalendar public static int get month synchronized m calendar m calendar set time in millis system current time millis return m calendar get calendar month getmonth mcalendar mcalendar settimeinmillis currenttimemillis mcalendar public static int get day of month synchronized m calendar m calendar set time in millis system current time millis return m calendar get calendar day of month getdayofmonth mcalendar mcalendar settimeinmillis currenttimemillis mcalendar day_of_month query node visitor public void visit full text query visitor visitor visitor visit this left visit visitor right visit visitor fulltextqueryvisitor this method checks that query can be executed by interection of keyword occurrences lists return true if quuery can be executed by full text index false otherwise public boolean is constrained return op or left is constrained right is constrained left is constrained right is constrained fulltextindex isconstrained isconstrained isconstrained isconstrained isconstrained public string to string return op or left to string or right to string left to string operator name op right to string tostring tostring tostring tostring operatorname tostring binary node constructor param op operation code param left left operand param right right operand public full text query binary op int op full text query left full text query right super op this left left this right right fulltextquerybinaryop fulltextquery fulltextquery logger register log threshold callback new log threshold callback override public void should update logminor logger should log logger minor this logdebug logger should log logger debug this registerlogthresholdcallback logthresholdcallback shouldupdate shouldlog shouldlog failure table node node entries by key new lru hashtable key failure table entry block offer list by key new lru hashtable key block offer list this node node offer authenticator key new byte 32 node random next bytes offer authenticator key offer executor new serial executor native thread high priority node ps queue timed job new failure table cleaner cleanup period failuretable entriesbykey lruhashtable failuretableentry blockofferlistbykey lruhashtable blockofferlist offerauthenticatorkey nextbytes offerauthenticatorkey offerexecutor serialexecutor nativethread high_priority queuetimedjob failuretablecleaner cleanup_period public void start offer executor start node executor failure table offers executor oom handler addoom hook this offerexecutor failuretable oomhandler addoomhook called when we route to a node and it fails for some reason but we continue the request normally the timeout will be the time it took to route to that node and wait for its response timeout waiting for its response param key param routed to param htl param timeout public void on failed key key peer node routed to short htl int timeout if node enableulpr data propagation node enable per node failure tables return long now system current time millis failure table entry entry synchronized this entry entries by key get key if entry null entry new failure table entry key entries by key push key entry trim entries now entry failed to routed to timeout now htl routedto onfailed peernode routedto enableulprdatapropagation enablepernodefailuretables currenttimemillis failuretableentry entriesbykey failuretableentry entriesbykey trimentries failedto routedto public void on final failure key key peer node routed to short htl int timeout peer node requestor if node enableulpr data propagation node enable per node failure tables return long now system current time millis failure table entry entry synchronized this entry entries by key get key if entry null entry new failure table entry key entries by key push key entry trim entries now if routed to null entry failed to routed to timeout now htl if requestor null entry add requestor requestor now onfinalfailure peernode routedto peernode enableulprdatapropagation enablepernodefailuretables currenttimemillis failuretableentry entriesbykey failuretableentry entriesbykey trimentries routedto failedto routedto addrequestor private synchronized void trim entries long now while entries by key size max entries entries by key pop key trimentries entriesbykey max_entries entriesbykey popkey final failure table entry entry block offer list failure table entry entry block offer offer this entry entry this offers new block offer offer failuretableentry blockofferlist failuretableentry blockoffer blockoffer public synchronized long expires long last 0 for int i 0 i offers length i if offers i offered time last last offers i offered time return last offer expiry time offeredtime offeredtime offer_expiry_time public synchronized boolean is empty long now for int i 0 i offers length i if offers i is expired now return false return true isempty isexpired public void delete offer block offer offer if logminor logger minor this deleting offer from this synchronized this int idx 1 final int offer length offers length for int i 0 i offer length i if offers i offer idx i if idx 0 return block offer new offers new block offer offer length 1 if idx 0 system arraycopy offers 0 new offers 0 idx if idx new offers length system arraycopy offers idx 1 new offers idx offers length idx 1 offers new offers if offers length 1 synchronized failure table this block offer list by key remove key entry key node client core dequeue offered key entry key deleteoffer blockoffer offerlength offerlength blockoffer newoffers blockoffer offerlength newoffers newoffers newoffers newoffers failuretable blockofferlistbykey removekey clientcore dequeueofferedkey public synchronized void add offer block offer offer block offer new offers new block offer offers length 1 system arraycopy offers 0 new offers 0 offers length new offers offers length offer offers new offers addoffer blockoffer blockoffer newoffers blockoffer newoffers newoffers newoffers override public string to string return super to string offers length tostring tostring block offer peer node pn long now byte authenticator long bootid this node ref pn my ref this offered time now this authenticator authenticator this bootid bootid blockoffer peernode noderef myref offeredtime public peer node get peer node return node ref get peernode getpeernode noderef public boolean is expired long now return node ref get null now offered time offer expiry time isexpired noderef offeredtime offer_expiry_time public boolean is expired return is expired system current time millis isexpired isexpired currenttimemillis called when a data block is found after it has been stored there is a good chance of its being available in the near future if there are nodes waiting for it we will offer it to them public void on found key block block if node enableulpr data propagation node enable per node failure tables return key key block get key if key null throw new null pointer exception failure table entry entry synchronized this entry entries by key get key if entry null return nobody cares entries by key remove key key block offer list by key remove key key if node enableulpr data propagation return entry offer onfound keyblock enableulprdatapropagation enablepernodefailuretables getkey nullpointerexception failuretableentry entriesbykey entriesbykey removekey blockofferlistbykey removekey enableulprdatapropagation called when we get an offer for a key if this is an ssk we will only accept it if we have previously asked for it if it is a chk we will accept it if we want it param key the key we are being offered param peer the node offering it param authenticator void on offer final key key final peer node peer final byte authenticator if node enableulpr data propagation return if logminor logger minor this offered key key by peer peer failure table entry entry synchronized this entry entries by key get key if entry null if logminor logger minor this we didn t ask for the key return we haven t asked for it offer executor execute new runnable public void run inner on offer key peer authenticator on offer onoffer peernode enableulprdatapropagation failuretableentry entriesbykey offerexecutor inneronoffer onoffer offer executor execute new runnable public void run inner on offer key peer authenticator offerexecutor inneronoffer this method runs on the serial executor therefore any blocking network i o needs to be scheduled on a separate thread however blocking disk i o should happen on this thread we deliberately serialise it as high latencies can otherwise result protected void inner on offer key key peer node peer byte authenticator if key get routing key null throw new null pointer exception nb node has key executes a datastore fetch if node has key key logger minor this already have key return re check after potentially long disk i o failure table entry entry long now system current time millis synchronized this entry entries by key get key if entry null if logminor logger minor this we didn t ask for the key return we haven t asked for it accept subject to later checks if we asked for it should we accept it if we were asked for it this is bidirectional propagation it s good because it makes the whole structure much more reliable it s bad because it s not entirely under our control we didn t choose to route it to the node the node routed it to us now it s found it before we did attacks frost spamming etc is it easier to offer data to our peers rather than inserting it will it result in it being propagated further the peer node would then do the request rather than this node doing an insert is that beneficial not relevant with ch ks anyway on the plus side propagation to nodes that have asked is worthwhile because reduced polling cost enables more secure messaging systems e g outbox polling social engineering if a key is unpopular you can put a different copy of it on different nodes you can then use this to trace the requestor identify that he is or isn t on the target you can t do this with a regular insert because it will often go several nodes even at htl 0 with subscriptions you might be able to bypass this but only if you know no other nodes in the neighbourhood are subscribed easier with ss ks with ch ks you have only binary information of whether the person got the key with social engineering hard to exploit on darknet if you re that close to the suspect there are easier ways to get at them e g correlation attacks conclusion we should accept the request if we asked for it from that node note that a node might both have asked us and been asked that node asked for it and it s a chk boolean we asked entry asked from peer peer now boolean he asked entry asked by peer peer now if we asked key instanceof nodechk he asked if logminor logger minor this not propagating key we asked we asked he asked he asked if entry is empty now synchronized this entries by key remove key key return if entry is empty now entries by key remove key key valid offer add to offers list synchronized this if logminor logger minor this valid offer block offer list bl block offer list by key get key block offer offer new block offer peer now authenticator peer get bootid if bl null bl new block offer list entry offer else bl add offer offer block offer list by key push key bl trim offers list now now does anyone want it node client core maybe queue offered key key entry others want peer serialexecutor inneronoffer peernode getroutingkey nullpointerexception haskey haskey failuretableentry currenttimemillis entriesbykey chks ssks chks weasked askedfrompeer heasked askedbypeer weasked heasked weasked weasked heasked heasked isempty entriesbykey removekey isempty entriesbykey removekey blockofferlist blockofferlistbykey blockoffer blockoffer getbootid blockofferlist addoffer blockofferlistbykey trimofferslist clientcore maybequeueofferedkey otherswant private synchronized void trim offers list long now while true if block offer list by key is empty return block offer list bl block offer list by key peek value if bl is empty now bl expires now block offer list by key size max offers if logminor logger minor this removing block offer list bl list size now block offer list by key size block offer list by key pop key else return trimofferslist blockofferlistbykey isempty blockofferlist blockofferlistbykey peekvalue isempty blockofferlistbykey max_offers blockofferlistbykey blockofferlistbykey popkey we offered a key a node has responded to the offer note that this runs on the incoming packets thread so should allocate a new thread if it does anything heavy note also that it is responsible for unlocking the uid param key the key to send param isssk whether it is an ssk param uid the uid param source the node that asked for the key throws not connected exception if the sender ceases to be connected public void send offered key final key key final boolean isssk final boolean need pub key final long uid final peer node source final offer reply tag tag throws not connected exception this offer executor execute new runnable public void run try inner send offered key key isssk need pub key uid source tag catch not connected exception e node unlockuid uid isssk false false true false tag too bad catch throwable t node unlockuid uid isssk false false true false tag logger error this caught t sending offered key send offered key notconnectedexception sendofferedkey needpubkey peernode offerreplytag notconnectedexception offerexecutor innersendofferedkey needpubkey notconnectedexception sendofferedkey this offer executor execute new runnable public void run try inner send offered key key isssk need pub key uid source tag catch not connected exception e node unlockuid uid isssk false false true false tag too bad catch throwable t node unlockuid uid isssk false false true false tag logger error this caught t sending offered key offerexecutor innersendofferedkey needpubkey notconnectedexception this method runs on the serial executor therefore any blocking network i o needs to be scheduled on a separate thread however blocking disk i o should happen on this thread we deliberately serialise it as high latencies can otherwise result protected void inner send offered key key key final boolean isssk boolean need pub key final long uid final peer node source final offer reply tag tag throws not connected exception if isssk ssk block block node fetch nodessk key false if block null don t have the key source send async dmt createfnp get offered key invalid uid dmt get offered key rejected no key null sender counter node unlockuid uid isssk false false true false tag return final message data dmt createfnpssk data found data uid block get raw data message headers dmt createfnpssk data found headers uid block get raw headers final int data length block get raw data length source send async headers null sender counter node executor execute new prio runnable public int get priority return native thread high priority public void run try source send throttled message data data length sender counter 60 1000 false null catch not connected exception e catch waited too long exception e logger error this waited too long sending ssk data catch sync send waited too long exception e impossible finally node unlockuid uid isssk false false true false tag send offered ssk if need pub key message pk dmt createfnpssk pub key uid block get pub key source send async pk null sender counter else chk block block node fetch nodechk key false if block null don t have the key source send async dmt createfnp get offered key invalid uid dmt get offered key rejected no key null sender counter node unlockuid uid isssk false false true false tag return message df dmt createfnpchk data found uid block get raw headers source send async df null sender counter partially received block prb new partially received block node packets in block node packet size block get raw data final block transmitter bt new block transmitter node usm source uid prb sender counter node executor execute new prio runnable public int get priority return native thread high priority public void run try bt send node executor catch throwable t logger error this sending offered key failed t t finally node unlockuid uid isssk false false true false tag chk offer sender serialexecutor innersendofferedkey needpubkey peernode offerreplytag notconnectedexception sskblock sendasync createfnpgetofferedkeyinvalid get_offered_key_rejected_no_key sendercounter createfnpsskdatafounddata getrawdata createfnpsskdatafoundheaders getrawheaders datalength getrawdata sendasync sendercounter priorunnable getpriority nativethread high_priority sendthrottledmessage datalength sendercounter notconnectedexception waitedtoolongexception syncsendwaitedtoolongexception needpubkey createfnpsskpubkey getpubkey sendasync sendercounter chkblock sendasync createfnpgetofferedkeyinvalid get_offered_key_rejected_no_key sendercounter createfnpchkdatafound getrawheaders sendasync sendercounter partiallyreceivedblock partiallyreceivedblock packets_in_block packet_size getrawdata blocktransmitter blocktransmitter sendercounter priorunnable getpriority nativethread high_priority node executor execute new prio runnable public int get priority return native thread high priority priorunnable getpriority nativethread high_priority public void run try source send throttled message data data length sender counter 60 1000 false null catch not connected exception e catch waited too long exception e logger error this waited too long sending ssk data catch sync send waited too long exception e impossible finally node unlockuid uid isssk false false true false tag sendthrottledmessage datalength sendercounter notconnectedexception waitedtoolongexception syncsendwaitedtoolongexception node executor execute new prio runnable public int get priority return native thread high priority priorunnable getpriority nativethread high_priority public void run try bt send node executor catch throwable t logger error this sending offered key failed t t finally node unlockuid uid isssk false false true false tag class offered keys byte counter implements byte counter public void received bytes int x node node stats offered keys sender received bytes x offeredkeysbytecounter bytecounter receivedbytes nodestats offeredkeyssenderreceivedbytes public void sent bytes int x node node stats offered keys sender sent bytes x sentbytes nodestats offeredkeyssendersentbytes public void sent payload int x node sent payload x node node stats offered keys sender sent bytes x sentpayload sentpayload nodestats offeredkeyssendersentbytes offer list block offer list offer list this offer list offer list recent offers new vector block offer expired offers new vector block offer long now system current time millis block offer offers offer list offers for int i 0 i offers length i if offers i is expired now recent offers add offers i else expired offers add offers i if logminor logger minor this offers recent offers size recent expired offers size expired offerlist blockofferlist offerlist offerlist offerlist recentoffers blockoffer expiredoffers blockoffer currenttimemillis blockoffer offerlist isexpired recentoffers expiredoffers recentoffers expiredoffers public block offer get first offer if last offer null throw new illegal state exception last offer not dealt with if recent offers is empty int x node random next int recent offers size return last offer recent offers remove x if expired offers is empty int x node random next int expired offers size return last offer expired offers remove x no more offers return null blockoffer getfirstoffer lastoffer illegalstateexception recentoffers isempty nextint recentoffers lastoffer recentoffers expiredoffers isempty nextint expiredoffers lastoffer expiredoffers delete the last offer we have used it successfully or not public void delete last offer offer list delete offer last offer last offer null deletelastoffer offerlist deleteoffer lastoffer lastoffer keep the last offer we weren t able to use it e g because of rejected overload maybe it will be useful again in the future public void keep last offer last offer null rejectedoverload keeplastoffer lastoffer public offer list get offers key key if node enableulpr data propagation return null block offer list bl synchronized this bl block offer list by key get key if bl null return null return new offer list bl offerlist getoffers enableulprdatapropagation blockofferlist blockofferlistbykey offerlist called when a node disconnects public void on disconnect final peer node pn if node enableulpr data propagation node enable per node failure tables return fixme do something off thread if expensive ondisconnect peernode enableulprdatapropagation enablepernodefailuretables public timed out nodes list get timed out nodes list key key if node enable per node failure tables return null synchronized this return entries by key get key timedoutnodeslist gettimedoutnodeslist enablepernodefailuretables entriesbykey public void run try real run catch throwable t logger error this failure table cleaner caught t t finally node ps queue timed job this cleanup period realrun failuretablecleaner queuetimedjob cleanup_period private void real run if logminor logger minor this starting failure table cleanup long start time system current time millis failure table entry entries synchronized failure table this entries new failure table entry entries by key size entries by key values to array entries for int i 0 i entries length i synchronized entries i if entries i cleanup synchronized failure table this if entries i is empty entries by key remove key entries i key long end time system current time millis if logminor logger minor this finished failure table cleanup took end time start time ms realrun failuretable starttime currenttimemillis failuretableentry failuretable failuretableentry entriesbykey entriesbykey valuestoarray failuretable isempty entriesbykey removekey endtime currenttimemillis failuretable endtime starttime public boolean peers want key key key failure table entry entry synchronized this entry entries by key get key if entry null return false nobody cares return entry others want null peerswantkey failuretableentry entriesbykey otherswant public void handle low memory throws exception synchronized this int size entries by key size do entries by key pop key while entries by key size size 2 handlelowmemory entriesbykey entriesbykey popkey entriesbykey public void handle out of memory throws exception synchronized this entries by key clear handleoutofmemory entriesbykey public shade filter bump height 1 0f bump softness 5 0f l new vector3f v new vector3f n new vector3f shaded color new color4f diffuse color new color4f specular color new color4f tmpv new vector3f tmpv2 new vector3f shadefilter bumpheight bumpsoftness shadedcolor diffuse_color specular_color public void set bump function function2d bump function this bump function bump function setbumpfunction bumpfunction bumpfunction bumpfunction public function2d get bump function return bump function getbumpfunction bumpfunction public void set bump height float bump height this bump height bump height setbumpheight bumpheight bumpheight bumpheight public float get bump height return bump height getbumpheight bumpheight public void set bump softness float bump softness this bump softness bump softness setbumpsoftness bumpsoftness bumpsoftness bumpsoftness public float get bump softness return bump softness getbumpsoftness bumpsoftness public void set environment map buffered image environment map this environment map environment map if environment map null env width environment map get width env height environment map get height env pixels getrgb environment map 0 0 env width env height null else env width env height 1 env pixels null setenvironmentmap bufferedimage environmentmap environmentmap environmentmap environmentmap envwidth environmentmap getwidth envheight environmentmap getheight envpixels environmentmap envwidth envheight envwidth envheight envpixels public buffered image get environment map return environment map bufferedimage getenvironmentmap environmentmap public void set bump source int bump source this bump source bump source setbumpsource bumpsource bumpsource bumpsource public int get bump source return bump source getbumpsource bumpsource protected final static float r255 1 0f 255 0f protected void set fromrgb color4f c int argb c set argb 16 0xff r255 argb 8 0xff r255 argb 0xff r255 argb 24 0xff r255 setfromrgb override protected int filter pixels int width int height int in pixels rectangle transformed space int index 0 int out pixels new int width height float width45 math abs 6 0f bump height boolean invert bumps bump height 0 vector3f position new vector3f 0 0f 0 0f 0 0f vector3f viewpoint new vector3f float width 2 0f float height 2 0f view distance vector3f normal new vector3f color4f c new color4f function2d bump bump function if bump source bumps from image bump source bumps from image alpha bump source bumps from map bump null if bump softness 0 int bump width width int bump height height int bump pixels in pixels if bump source bumps from map bump function instanceof image function2d image function2d if2d image function2d bump function bump width if2d get width bump height if2d get height bump pixels if2d get pixels kernel kernel gaussian filter make kernel bump softness int tmp pixels new int bump width bump height int soft pixels new int bump width bump height gaussian filter convolve and transpose kernel bump pixels tmp pixels bump width bump height true false false convolve filter clamp edges gaussian filter convolve and transpose kernel tmp pixels soft pixels bump height bump width true false false convolve filter clamp edges bump new image function2d soft pixels bump width bump height image function2d clamp bump source bumps from image alpha else bump new image function2d in pixels width height image function2d clamp bump source bumps from image alpha vector3f v1 new vector3f vector3f v2 new vector3f vector3f n new vector3f loop through each source pixel for int y 0 y height y float ny y position y y for int x 0 x width x float nx x calculate the normal at this point if bump source bumps from bevel complicated and slower method calculate four normals using the gradients in x y directions int count 0 normal x normal y normal z 0 float m0 width45 bump evaluate nx ny float m1 x 0 width45 bump evaluate nx 1 0f ny m0 2 float m2 y 0 width45 bump evaluate nx ny 1 0f m0 2 float m3 x width 1 width45 bump evaluate nx 1 0f ny m0 2 float m4 y height 1 width45 bump evaluate nx ny 1 0f m0 2 if m1 2 m4 2 v1 x 1 0f v1 y 0 0f v1 z m1 v2 x 0 0f v2 y 1 0f v2 z m4 n cross v1 v2 n normalize if n z 0 0 n z n z normal add n count if m1 2 m2 2 v1 x 1 0f v1 y 0 0f v1 z m1 v2 x 0 0f v2 y 1 0f v2 z m2 n cross v1 v2 n normalize if n z 0 0 n z n z normal add n count if m2 2 m3 2 v1 x 0 0f v1 y 1 0f v1 z m2 v2 x 1 0f v2 y 0 0f v2 z m3 n cross v1 v2 n normalize if n z 0 0 n z n z normal add n count if m3 2 m4 2 v1 x 1 0f v1 y 0 0f v1 z m3 v2 x 0 0f v2 y 1 0f v2 z m4 n cross v1 v2 n normalize if n z 0 0 n z n z normal add n count average the four normals normal x count normal y count normal z count for testing generate a sphere bump map double dx x 120 double dy y 80 double r2 dx dx dy dy double r math sqrt r2 double t math atan2 dy dx if r2 80 80 double z math sqrt 80 80 r2 normal x float dx normal y float dy normal z float z normal normalize else normal x 0 normal y 0 normal z 1 if invert bumps normal x normal x normal y normal y position x x if normal z 0 get the material colour at this point if environment map null fixme too much normalizing going on here tmpv2 set viewpoint tmpv2 sub position tmpv2 normalize tmpv set normal tmpv normalize reflect tmpv scale 2 0f tmpv dot tmpv2 tmpv sub v tmpv normalize set fromrgb c get environment mapp normal in pixels width height fixme interpolate int alpha in pixels index 0xff000000 int rgb int c x 255 16 int c y 255 8 int c z 255 out pixels index alpha rgb else out pixels index 0 else out pixels index 0 return out pixels filterpixels inpixels transformedspace outpixels bumpheight invertbumps bumpheight viewdistance bumpfunction bumpsource bumps_from_image bumpsource bumps_from_image_alpha bumpsource bumps_from_map bumpsoftness bumpwidth bumpheight bumppixels inpixels bumpsource bumps_from_map bumpfunction imagefunction2d imagefunction2d imagefunction2d bumpfunction bumpwidth getwidth bumpheight getheight bumppixels getpixels gaussianfilter makekernel bumpsoftness tmppixels bumpwidth bumpheight softpixels bumpwidth bumpheight gaussianfilter convolveandtranspose bumppixels tmppixels bumpwidth bumpheight convolvefilter clamp_edges gaussianfilter convolveandtranspose tmppixels softpixels bumpheight bumpwidth convolvefilter clamp_edges imagefunction2d softpixels bumpwidth bumpheight imagefunction2d bumpsource bumps_from_image_alpha imagefunction2d inpixels imagefunction2d bumpsource bumps_from_image_alpha bumpsource bumps_from_bevel invertbumps environmentmap setfromrgb getenvironmentmapp inpixels inpixels outpixels outpixels outpixels outpixels private int get environment mapp vector3f normal int in pixels int width int height if environment map null float x 0 5f 1 normal x float y 0 5f 1 normal y x image math clamp x env width 0 env width 1 y image math clamp y env height 0 env height 1 int ix int x int iy int y float x weight x ix float y weight y iy int i env width iy ix int dx ix env width 1 0 1 int dy iy env height 1 0 env width return image math bilinear interpolate x weight y weight env pixels i env pixels i dx env pixels i dy env pixels i dx dy return 0 getenvironmentmapp inpixels environmentmap imagemath envwidth envwidth imagemath envheight envheight xweight yweight envwidth envwidth envheight envwidth imagemath bilinearinterpolate xweight yweight envpixels envpixels envpixels envpixels override public string to string return stylize shade tostring private float gap public mirror filter mirrorfilter specifies the angle of the mirror param angle the angle of the mirror angle see get angle public void set angle float angle this angle angle getangle setangle returns the angle of the mirror return the angle of the mirror see set angle public float get angle return angle setangle getangle public void set distance float distance this distance distance setdistance public float get distance return distance getdistance public void set rotation float rotation this rotation rotation setrotation public float get rotation return rotation getrotation public void set gap float gap this gap gap setgap public float get gap return gap getgap set the opacity of the reflection param opacity the opacity see get opacity public void set opacity float opacity this opacity opacity getopacity setopacity get the opacity of the reflection return the opacity see set opacity public float get opacity return opacity setopacity getopacity public void set centrey float centrey this centrey centrey setcentrey public float get centrey return centrey getcentrey public buffered image filter buffered image src buffered image dst if dst null dst create compatible dest image src null buffered image tsrc src shape clip int width src get width int height src get height int h int centrey height int d int gap height graphics2d g dst create graphics clip g get clip g clip rect 0 0 width h g draw rendered image src null g set clip clip g clip rect 0 h d width height h d g translate 0 2 h d g scale 1 1 g draw rendered image src null g set paint new gradient paint 0 0 new color 1 0f 0 0f 0 0f 0 0f 0 h new color 0 0f 1 0f 0 0f opacity g set composite alpha composite get instance alpha composite dst in g fill rect 0 0 width h g set clip clip g dispose return dst bufferedimage bufferedimage bufferedimage createcompatibledestimage bufferedimage getwidth getheight creategraphics getclip cliprect drawrenderedimage setclip cliprect drawrenderedimage setpaint gradientpaint setcomposite alphacomposite getinstance alphacomposite dst_in fillrect setclip override public string to string return effects mirror tostring final boolean can read public directory access boolean can read boolean can write this can read can read this can write can write canread directoryaccess canread canwrite canread canread canwrite canwrite null if not requested dda check job random r file directory file read filename file write filename this directory directory this read filename read filename this write filename write filename byte random new byte 128 r next bytes random this read content hex util bytes to hex random r next bytes random this write content hex util bytes to hex random ddacheckjob readfilename writefilename readfilename readfilename writefilename writefilename nextbytes readcontent hexutil bytestohex nextbytes writecontent hexutil bytestohex static logger register log threshold callback new log threshold callback override public void should update logminor logger should log logger minor this registerlogthresholdcallback logthresholdcallback shouldupdate shouldlog public fcp connection handler socket s fcp server server this sock s this server server is closed false this bf server core temp bucket factory requests by identifier new hash map string client request usk subscriptions new hash map string subscribeusk this input handler new fcp connection input handler this this output handler new fcp connection output handler this byte identifier new byte 16 server node random next bytes identifier this connection identifier hex util bytes to hex identifier fcpconnectionhandler fcpserver isclosed tempbucketfactory requestsbyidentifier hashmap clientrequest usksubscriptions hashmap inputhandler fcpconnectioninputhandler outputhandler fcpconnectionoutputhandler nextbytes connectionidentifier hexutil bytestohex void start input handler start output handler start inputhandler outputhandler public void close client request requests if reboot client null reboot client on lost connection this if forever client null forever client on lost connection this boolean dupe subscribeusk subscriptions synchronized this is closed true requests new client request requests by identifier size requests requests by identifier values to array requests subscriptions usk subscriptions values to array new subscribeusk usk subscriptions size dupe killed dupe for int i 0 i requests length i requests i on lost connection null server core client context for subscribeusk sub subscriptions sub unsubscribe if dupe server core client context job runner queue new db job public void run object container container client context context if reboot client null reboot client has persistent requests null server unregister client reboot client null if forever client null if container ext is stored forever client logger normal this forever client is not stored in the database in lost connection non dupe callback not deleting it return container activate forever client 1 if forever client has persistent requests container server unregister client forever client container container deactivate forever client 1 native thread norm priority false output handler on closed clientrequest rebootclient rebootclient onlostconnection foreverclient foreverclient onlostconnection isclosed clientrequest requestsbyidentifier requestsbyidentifier toarray usksubscriptions toarray usksubscriptions killeddupe onlostconnection clientcontext clientcontext jobrunner dbjob objectcontainer clientcontext rebootclient rebootclient haspersistentrequests unregisterclient rebootclient foreverclient isstored foreverclient foreverclient foreverclient foreverclient haspersistentrequests unregisterclient foreverclient foreverclient nativethread norm_priority outputhandler onclosed public void run object container container client context context if reboot client null reboot client has persistent requests null server unregister client reboot client null if forever client null if container ext is stored forever client logger normal this forever client is not stored in the database in lost connection non dupe callback not deleting it return container activate forever client 1 if forever client has persistent requests container server unregister client forever client container container deactivate forever client 1 objectcontainer clientcontext rebootclient rebootclient haspersistentrequests unregisterclient rebootclient foreverclient isstored foreverclient foreverclient foreverclient foreverclient haspersistentrequests unregisterclient foreverclient foreverclient synchronized void set killed dupe killed dupe true setkilleddupe killeddupe public synchronized boolean is closed return is closed isclosed isclosed public void closed input try sock shutdown input catch io exception e ignore synchronized this input closed true if output closed return try sock close catch io exception e ignore closedinput shutdowninput ioexception inputclosed outputclosed ioexception public void closed output try sock shutdown output catch io exception e ignore synchronized this output closed true if input closed return try sock close catch io exception e ignore closedoutput shutdownoutput ioexception outputclosed inputclosed ioexception public void set client name final string name this client name name reboot client server register reboot client name server core this reboot client queue pending messages on connection restart output handler null server core client context job runner queue new db job public void run object container container client context context try create forever client name container catch throwable t logger error this caught t creating persistent client for name t failed get forever true synchronized fcp connection handler this failed get forever true fcp connection handler this notify all native thread norm priority false if logminor logger minor this set client name name setclientname clientname rebootclient registerrebootclient rebootclient queuependingmessagesonconnectionrestart outputhandler clientcontext jobrunner dbjob objectcontainer clientcontext createforeverclient failedgetforever fcpconnectionhandler failedgetforever fcpconnectionhandler notifyall nativethread norm_priority public void run object container container client context context try create forever client name container catch throwable t logger error this caught t creating persistent client for name t failed get forever true synchronized fcp connection handler this failed get forever true fcp connection handler this notify all objectcontainer clientcontext createforeverclient failedgetforever fcpconnectionhandler failedgetforever fcpconnectionhandler notifyall protected fcp client create forever client string name object container container synchronized fcp connection handler this if forever client null return forever client fcp client client server register forever client name server core fcp connection handler this container synchronized fcp connection handler this forever client client fcp connection handler this notify all client queue pending messages on connection restart output handler container return forever client fcpclient createforeverclient objectcontainer fcpconnectionhandler foreverclient foreverclient fcpclient registerforeverclient fcpconnectionhandler fcpconnectionhandler foreverclient fcpconnectionhandler notifyall queuependingmessagesonconnectionrestart outputhandler foreverclient public string get client name return client name getclientname clientname start a client get if there is an identifier collision queue an identifier collision message hence we can run stuff on other threads if we need to as long as we send the right messages public void start client get final client get message message final string id message identifier final boolean global message global client get cg null boolean success boolean persistent message persistence type client request persist connection synchronized this if is closed return we need to track non persistent requests anyway so we may as well check if persistent success true else success requests by identifier contains key id if success try if persistent cg new client get this message server null requests by identifier put id cg else if message persistence type client request persist forever server core client context job runner queue new db job public void run object container container client context context client get getter try getter new client get fcp connection handler this message server container catch identifier collision exception e1 logger normal this identifier collision on this fcp message msg new identifier collision message id message global output handler queue msg return catch message invalid exception e1 output handler queue new protocol error message e1 protocol code false e1 get message e1 ident e1 global return try getter register container false false container store getter catch identifier collision exception e logger normal this identifier collision on this fcp message msg new identifier collision message id global output handler queue msg return getter start container context container deactivate getter 1 native thread high priority 1 false user wants a response soon but doesn t want it to block the queue page etc return don t run the start below else cg new client get this message server null catch identifier collision exception e success false catch message invalid exception e output handler queue new protocol error message e protocol code false e get message e ident e global return if message persistence type client request persist reboot try cg register null false false catch identifier collision exception e success false if success logger normal this identifier collision on this fcp message msg new identifier collision message id message global output handler queue msg return else cg start null server core client context clientget identifiercollisionmessage startclientget clientgetmessage clientget persistencetype clientrequest persist_connection isclosed requestsbyidentifier containskey clientget requestsbyidentifier persistencetype clientrequest persist_forever clientcontext jobrunner dbjob objectcontainer clientcontext clientget clientget fcpconnectionhandler identifiercollisionexception fcpmessage identifiercollisionmessage outputhandler messageinvalidexception outputhandler protocolerrormessage protocolcode getmessage identifiercollisionexception fcpmessage identifiercollisionmessage outputhandler nativethread high_priority clientget identifiercollisionexception messageinvalidexception outputhandler protocolerrormessage protocolcode getmessage persistencetype clientrequest persist_reboot identifiercollisionexception fcpmessage identifiercollisionmessage outputhandler clientcontext public void run object container container client context context client get getter try getter new client get fcp connection handler this message server container catch identifier collision exception e1 logger normal this identifier collision on this fcp message msg new identifier collision message id message global output handler queue msg return catch message invalid exception e1 output handler queue new protocol error message e1 protocol code false e1 get message e1 ident e1 global return try getter register container false false container store getter catch identifier collision exception e logger normal this identifier collision on this fcp message msg new identifier collision message id global output handler queue msg return getter start container context container deactivate getter 1 objectcontainer clientcontext clientget clientget fcpconnectionhandler identifiercollisionexception fcpmessage identifiercollisionmessage outputhandler messageinvalidexception outputhandler protocolerrormessage protocolcode getmessage identifiercollisionexception fcpmessage identifiercollisionmessage outputhandler public void start client put final client put message message if logminor logger minor this starting insert id message identifier final string id message identifier final boolean global message global client put cp null boolean persistent message persistence type client request persist connection fcp message failed message null synchronized this boolean success if is closed return we need to track non persistent requests anyway so we may as well check if persistent success true else success requests by identifier contains key id if success if persistent try cp new client put this message server null catch identifier collision exception e success false catch message invalid exception e output handler queue new protocol error message e protocol code false e get message e ident e global return catch malformedurl exception e failed message new protocol error message protocol error message freenet uri parse error true null id message global requests by identifier put id cp else if message persistence type client request persist forever server core client context job runner queue new db job public void run object container container client context context client put putter try putter new client put fcp connection handler this message server container catch identifier collision exception e logger normal this identifier collision on this fcp message msg new identifier collision message id message global output handler queue msg return catch message invalid exception e output handler queue new protocol error message e protocol code false e get message e ident e global return catch malformedurl exception e output handler queue new protocol error message protocol error message freenet uri parse error true null id message global return try putter register container false false container store putter catch identifier collision exception e logger normal this identifier collision on this fcp message msg new identifier collision message id global output handler queue msg return putter start container context container deactivate putter 1 native thread high priority 1 false user wants a response soon but doesn t want it to block the queue page etc return don t run the start below else try cp new client put this message server null catch identifier collision exception e success false catch message invalid exception e output handler queue new protocol error message e protocol code false e get message e ident e global return catch malformedurl exception e failed message new protocol error message protocol error message freenet uri parse error true null id message global if success logger normal this identifier collision on this failed message new identifier collision message id message global if message persistence type client request persist reboot try cp register null false false catch identifier collision exception e failed message new identifier collision message id message global if failed message null output handler queue failed message if persistent message persistence type client request persist forever final client put c cp run on the database thread if persistent because it will try to activate stuff server core client context job runner queue new db job public void run object container container client context context if c null c free data container else message free data container native thread high priority 1 false else if cp null cp free data null else message free data null return else logger minor this starting cp cp start null server core client context startclientput clientputmessage clientput persistencetype clientrequest persist_connection fcpmessage failedmessage isclosed requestsbyidentifier containskey clientput identifiercollisionexception messageinvalidexception outputhandler protocolerrormessage protocolcode getmessage malformedurlexception failedmessage protocolerrormessage protocolerrormessage freenet_uri_parse_error requestsbyidentifier persistencetype clientrequest persist_forever clientcontext jobrunner dbjob objectcontainer clientcontext clientput clientput fcpconnectionhandler identifiercollisionexception fcpmessage identifiercollisionmessage outputhandler messageinvalidexception outputhandler protocolerrormessage protocolcode getmessage malformedurlexception outputhandler protocolerrormessage protocolerrormessage freenet_uri_parse_error identifiercollisionexception fcpmessage identifiercollisionmessage outputhandler nativethread high_priority clientput identifiercollisionexception messageinvalidexception outputhandler protocolerrormessage protocolcode getmessage malformedurlexception failedmessage protocolerrormessage protocolerrormessage freenet_uri_parse_error failedmessage identifiercollisionmessage persistencetype clientrequest persist_reboot identifiercollisionexception failedmessage identifiercollisionmessage failedmessage outputhandler failedmessage persistencetype clientrequest persist_forever clientput clientcontext jobrunner dbjob objectcontainer clientcontext freedata freedata nativethread high_priority freedata freedata clientcontext public void run object container container client context context client put putter try putter new client put fcp connection handler this message server container catch identifier collision exception e logger normal this identifier collision on this fcp message msg new identifier collision message id message global output handler queue msg return catch message invalid exception e output handler queue new protocol error message e protocol code false e get message e ident e global return catch malformedurl exception e output handler queue new protocol error message protocol error message freenet uri parse error true null id message global return try putter register container false false container store putter catch identifier collision exception e logger normal this identifier collision on this fcp message msg new identifier collision message id global output handler queue msg return putter start container context container deactivate putter 1 objectcontainer clientcontext clientput clientput fcpconnectionhandler identifiercollisionexception fcpmessage identifiercollisionmessage outputhandler messageinvalidexception outputhandler protocolerrormessage protocolcode getmessage malformedurlexception outputhandler protocolerrormessage protocolerrormessage freenet_uri_parse_error identifiercollisionexception fcpmessage identifiercollisionmessage outputhandler public void run object container container client context context if c null c free data container else message free data container objectcontainer clientcontext freedata freedata public void start client put dir final client put dir message message final hash map string object buckets final boolean was disk put if logminor logger minor this start client put dir final string id message identifier final boolean global message global client put dir cp null fcp message failed message null boolean persistent message persistence type client request persist connection we need to track non persistent requests anyway so we may as well check boolean success synchronized this if is closed return if persistent success true else success requests by identifier contains key id if success if persistent try cp new client put dir this message buckets was disk put server null synchronized this requests by identifier put id cp catch identifier collision exception e success false catch malformedurl exception e failed message new protocol error message protocol error message freenet uri parse error true null id message global fixme register non persistent requests in the constructors also we already register persistent ones else if message persistence type client request persist forever server core client context job runner queue new db job public void run object container container client context context client put dir putter try putter new client put dir fcp connection handler this message buckets was disk put server container catch identifier collision exception e logger normal this identifier collision on this fcp message msg new identifier collision message id message global output handler queue msg return catch malformedurl exception e output handler queue new protocol error message protocol error message freenet uri parse error true null id message global return try putter register container false false container store putter catch identifier collision exception e logger normal this identifier collision on this fcp message msg new identifier collision message id global output handler queue msg return putter start container context container deactivate putter 1 native thread high priority 1 false user wants a response soon but doesn t want it to block the queue page etc return don t run the start below else try cp new client put dir this message buckets was disk put server null catch identifier collision exception e success false catch malformedurl exception e failed message new protocol error message protocol error message freenet uri parse error true null id message global if success logger normal this identifier collision on this failed message new identifier collision message id message global if message persistence type client request persist reboot try cp register null false false catch identifier collision exception e failed message new identifier collision message id message global if failed message null fixme do we need to free data output handler queue failed message if cp null cp cancel null server core client context return else if logminor logger minor this starting cp cp start null server core client context startclientputdir clientputdirmessage hashmap wasdiskput clientputdir clientputdir fcpmessage failedmessage persistencetype clientrequest persist_connection isclosed requestsbyidentifier containskey clientputdir wasdiskput requestsbyidentifier identifiercollisionexception malformedurlexception failedmessage protocolerrormessage protocolerrormessage freenet_uri_parse_error persistencetype clientrequest persist_forever clientcontext jobrunner dbjob objectcontainer clientcontext clientputdir clientputdir fcpconnectionhandler wasdiskput identifiercollisionexception fcpmessage identifiercollisionmessage outputhandler malformedurlexception outputhandler protocolerrormessage protocolerrormessage freenet_uri_parse_error identifiercollisionexception fcpmessage identifiercollisionmessage outputhandler nativethread high_priority clientputdir wasdiskput identifiercollisionexception malformedurlexception failedmessage protocolerrormessage protocolerrormessage freenet_uri_parse_error failedmessage identifiercollisionmessage persistencetype clientrequest persist_reboot identifiercollisionexception failedmessage identifiercollisionmessage failedmessage freedata outputhandler failedmessage clientcontext clientcontext public void run object container container client context context client put dir putter try putter new client put dir fcp connection handler this message buckets was disk put server container catch identifier collision exception e logger normal this identifier collision on this fcp message msg new identifier collision message id message global output handler queue msg return catch malformedurl exception e output handler queue new protocol error message protocol error message freenet uri parse error true null id message global return try putter register container false false container store putter catch identifier collision exception e logger normal this identifier collision on this fcp message msg new identifier collision message id global output handler queue msg return putter start container context container deactivate putter 1 objectcontainer clientcontext clientputdir clientputdir fcpconnectionhandler wasdiskput identifiercollisionexception fcpmessage identifiercollisionmessage outputhandler malformedurlexception outputhandler protocolerrormessage protocolerrormessage freenet_uri_parse_error identifiercollisionexception fcpmessage identifiercollisionmessage outputhandler public fcp client get reboot client return reboot client fcpclient getrebootclient rebootclient public fcp client get forever client object container container synchronized this if forever client null forever client create forever client client name container container activate forever client 1 forever client init container return forever client fcpclient getforeverclient objectcontainer foreverclient foreverclient createforeverclient clientname foreverclient foreverclient foreverclient public void finished client request client request get synchronized this requests by identifier remove get get identifier finishedclientrequest clientrequest requestsbyidentifier getidentifier public boolean is global subscribed return reboot client watch global isglobalsubscribed rebootclient watchglobal public boolean has full access return server allowed hosts full access allowed sock get inet address hasfullaccess allowedhostsfullaccess getinetaddress that method ought to be called before any direct disk access operation is performed by the node param filename param write request are willing to write or to read return boolean allowed or not protected boolean allowdda from file filename boolean write request string parent directory file util get canonical file filename get parent directory access da null synchronized checked directories da checked directories get parent directory if logminor logger minor this checking dda da for parent directory if write request return da null server is downloaddda always allowed da can write else return da null server is uploaddda always allowed da can read directdiskaccess writerequest allowddafrom writerequest parentdirectory fileutil getcanonicalfile getparent directoryaccess checkeddirectories checkeddirectories parentdirectory parentdirectory writerequest isdownloadddaalwaysallowed canwrite isuploadddaalwaysallowed canread should be called only from testdda complete param path param read param write protected void register testdda result string path boolean read boolean write directory access da new directory access read write synchronized checked directories checked directories put path da if logminor logger minor this dda read read write write for path testddacomplete registertestddaresult directoryaccess directoryaccess checkeddirectories checkeddirectories return a dda check job the one we created and have enqueued param path param read is read access requested param write is write access requested return throws illegal argument exception fixme maybe we need to enqueue a ps job to delete the created file after something like 5 mins protected dda check job enqueuedda check string path boolean read boolean write throws illegal argument exception file directory file util get canonical file new file path if directory exists directory is directory throw new illegal argument exception the specified path isn t a directory or doesn t exist or the node doesn t have access to it see 1856 dda check job job null synchronized in test directories job in test directories get directory if job null throw new illegal argument exception there is already a testdda going on for that directory file write file write new file path dda check server node fast weak random next int tmp null file read file null if read try read file file create temp file dda check tmp directory read file delete on exit catch io exception e now we know it we can t write there read file null dda check job result new dda check job server node fast weak random directory read file write file synchronized in test directories in test directories put directory result if read read file null read file can write we don t want to attempt to write before in case an io exception is raised we want to inform the client somehow that the node can t write there and setting read file to null means we won t inform it on the status as if it hadn t requested us to do the test file output stream fos null buffered output stream bos null try fos new file output stream result read filename bos new buffered output stream fos bos write result read content get bytes utf 8 bos flush catch io exception e logger error this got a ioe while creating the file read file to string e get message finally closer close bos closer close fos return result ddacheckjob illegalargumentexception ddacheckjob enqueueddacheck illegalargumentexception fileutil getcanonicalfile isdirectory illegalargumentexception ddacheckjob intestdirectories intestdirectories illegalargumentexception writefile ddacheck fastweakrandom nextint readfile readfile createtempfile ddacheck readfile deleteonexit ioexception readfile ddacheckjob ddacheckjob fastweakrandom readfile writefile intestdirectories intestdirectories readfile readfile canwrite ioexception readfile fileoutputstream bufferedoutputstream fileoutputstream readfilename bufferedoutputstream readcontent getbytes ioexception readfile tostring getmessage return a dda check job or null if not found param path return the dda check job throws illegal argument exception protected dda check job popdda check string path throws illegal argument exception file directory file util get canonical file new file path if directory exists directory is directory throw new illegal argument exception the specified path isn t a directory or doesn t exist or the node doesn t have access to it synchronized in test directories return in test directories remove directory ddacheckjob ddacheckjob illegalargumentexception ddacheckjob popddacheck illegalargumentexception fileutil getcanonicalfile isdirectory illegalargumentexception intestdirectories intestdirectories delete the files we have created using dda test called by fcp client on disconnect handler protected void freedda jobs synchronized in test directories iterator file it in test directories key set iterator while it has next dda check job job in test directories get it next if job read filename null job read filename delete ddatest fcpclient ondisconnect freeddajobs intestdirectories intestdirectories keyset hasnext ddacheckjob intestdirectories readfilename readfilename public client request remove request by identifier string identifier boolean kill client request req synchronized this req requests by identifier remove identifier if req null if kill req cancel null server core client context req request was removed null server core client context return req clientrequest removerequestbyidentifier clientrequest requestsbyidentifier clientcontext requestwasremoved clientcontext client request get reboot request boolean global fcp connection handler handler string identifier if global return handler server global reboot client get request identifier null else return handler get reboot client get request identifier null clientrequest getrebootrequest fcpconnectionhandler globalrebootclient getrequest getrebootclient getrequest client request get forever request boolean global fcp connection handler handler string identifier object container container if global return handler server global forever client get request identifier container else return handler get forever client container get request identifier container clientrequest getforeverrequest fcpconnectionhandler objectcontainer globalforeverclient getrequest getforeverclient getrequest client request remove persistent reboot request boolean global string identifier throws message invalid exception fcp client client global server global reboot client get reboot client client request req client get request identifier null if req null client remove by identifier identifier true server null server core client context return req clientrequest removepersistentrebootrequest messageinvalidexception fcpclient globalrebootclient getrebootclient clientrequest getrequest removebyidentifier clientcontext client request remove persistent forever request boolean global string identifier object container container throws message invalid exception fcp client client global server global forever client get forever client container container activate client 1 client request req client get request identifier container if req null client remove by identifier identifier true server container server core client context if global container deactivate client 1 return req clientrequest removepersistentforeverrequest objectcontainer messageinvalidexception fcpclient globalforeverclient getforeverclient clientrequest getrequest removebyidentifier clientcontext public boolean object can new object container container logger error this not storing fcp connection handler in database new exception error return false objectcannew objectcontainer fcpconnectionhandler public synchronized void add subscription string identifier subscribeusk subscribeusk throws identifier collision exception if usk subscriptions contains key identifier throw new identifier collision exception usk subscriptions put identifier subscribeusk addsubscription identifiercollisionexception usksubscriptions containskey identifiercollisionexception usksubscriptions public void unsubscribe string identifier throws message invalid exception subscribeusk sub synchronized this if usk subscriptions contains key identifier throw new message invalid exception protocol error message no such identifier no such identifier unsubscribing identifier false sub usk subscriptions remove identifier sub unsubscribe messageinvalidexception usksubscriptions containskey messageinvalidexception protocolerrormessage no_such_identifier usksubscriptions insert tag boolean ssk start start super this start start this ssk ssk inserttag public void handler threw throwable t handler threw t handlerthrew handlerthrew override public void log still present long uid string buffer sb new string buffer sb append still present after append time util format time age sb append append uid append start append start sb append ssk append ssk sb append thrown append handler threw if handler threw null logger error this sb to string handler threw else logger error this sb to string logstillpresent stringbuffer stringbuffer timeutil formattime handlerthrew handlerthrew tostring handlerthrew tostring static logger register log threshold callback new log threshold callback override public void should update logminor logger should log logger minor this registerlogthresholdcallback logthresholdcallback shouldupdate shouldlog failure table entry key key this key key if key null throw new null pointer exception long now system current time millis creation time now received time 1 sent time 1 requestor nodes empty weak reference requestor times empty long array requestor booti ds empty long array requested nodes empty weak reference requested locs empty double array requested booti ds empty long array requested times empty long array requested timeouts empty long array requested timeoutht ls empty short array failuretableentry nullpointerexception currenttimemillis creationtime receivedtime senttime requestornodes empty_weak_reference requestortimes empty_long_array requestorbootids empty_long_array requestednodes empty_weak_reference requestedlocs empty_double_array requestedbootids empty_long_array requestedtimes empty_long_array requestedtimeouts empty_long_array requestedtimeouthtls empty_short_array called when there is a failure which could cause a block to be added either a data not found or a recently failed param htl2 param requestors param requested from public void on failure short htl2 peer node requestors peer node requested from int timeout long now if logminor logger minor this on failure htl2 requestors arrays to string requestors requested from arrays to string requested from timeout timeout synchronized this if requestors null for int i 0 i requestors length i add requestor requestors i now if requested from null for int i 0 i requested from length i add requested from requested from i now datanotfound recentlyfailed requestedfrom onfailure peernode peernode requestedfrom onfailure tostring requestedfrom tostring requestedfrom addrequestor requestedfrom requestedfrom addrequestedfrom requestedfrom public synchronized void failed to peer node routed to int timeout long now short htl if logminor logger minor this failed sending request to routed to short to string timeout timeout int idx add requested from routed to now long cur timeout time requested timeouts idx long new timeout time now timeout fixme htl if new timeout time cur timeout time requested timeouts idx new timeout time requested timeoutht ls idx htl failedto peernode routedto routedto shorttostring addrequestedfrom routedto curtimeouttime requestedtimeouts newtimeouttime newtimeouttime curtimeouttime requestedtimeouts newtimeouttime requestedtimeouthtls synchronized int add requestor peer node requestor long now if logminor logger minor this adding requestors requestor at now received time now boolean included already false int nulls 0 int ret 1 for int i 0 i requestor nodes length i peer node got requestor nodes i null null requestor nodes i get no longer subscribed if they have rebooted or expired if got requestor update existing entry included already true requestor times i now requestor booti ds i requestor get bootid ret i break else if got null got get bootid requestor booti ds i now requestor times i max time between request and offer requestor nodes i null got null if got null nulls if nulls 0 included already return ret int not included included already 0 1 because weak these can become null doesn t matter but we want to minimise memory usage if nulls 1 included already nice special case for int i 0 i requestor nodes length i if requestor nodes i null requestor nodes i get null requestor nodes i requestor my ref requestor times i now requestor booti ds i requestor get bootid return i suppress warnings unchecked weak reference peer node new requestor nodes new weak reference requestor nodes length not included nulls long new requestor times new long requestor nodes length not included nulls long new requestor booti ds new long requestor nodes length not included nulls int to index 0 for int i 0 i requestor nodes length i weak reference peer node ref requestor nodes i peer node pn ref null null ref get if pn null continue if pn requestor ret to index new requestor nodes to index requestor nodes i new requestor times to index requestor times i new requestor booti ds to index requestor booti ds i to index if included already new requestor nodes to index requestor my ref new requestor times to index now new requestor booti ds to index requestor get bootid ret to index to index for int i to index i new requestor nodes length i new requestor nodes i null if to index new requestor nodes length 2 suppress warnings unchecked weak reference peer node new new requestor nodes new weak reference to index long new new requestor times new long to index long new new requestor booti ds new long to index system arraycopy new requestor nodes 0 new new requestor nodes 0 to index system arraycopy new requestor times 0 new new requestor times 0 to index system arraycopy new requestor booti ds 0 new new requestor booti ds 0 to index new requestor nodes new new requestor nodes new requestor times new new requestor times new requestor booti ds new new requestor booti ds requestor nodes new requestor nodes requestor times new requestor times requestor booti ds new requestor booti ds return ret addrequestor peernode receivedtime includedalready requestornodes peernode requestornodes requestornodes includedalready requestortimes requestorbootids getbootid getbootid requestorbootids requestortimes max_time_between_request_and_offer requestornodes includedalready notincluded includedalready includedalready requestornodes requestornodes requestornodes requestornodes myref requestortimes requestorbootids getbootid suppresswarnings weakreference peernode newrequestornodes weakreference requestornodes notincluded newrequestortimes requestornodes notincluded newrequestorbootids requestornodes notincluded toindex requestornodes weakreference peernode requestornodes peernode toindex newrequestornodes toindex requestornodes newrequestortimes toindex requestortimes newrequestorbootids toindex requestorbootids toindex includedalready newrequestornodes toindex myref newrequestortimes toindex newrequestorbootids toindex getbootid toindex toindex toindex newrequestornodes newrequestornodes toindex newrequestornodes suppresswarnings weakreference peernode newnewrequestornodes weakreference toindex newnewrequestortimes toindex newnewrequestorbootids toindex newrequestornodes newnewrequestornodes toindex newrequestortimes newnewrequestortimes toindex newrequestorbootids newnewrequestorbootids toindex newrequestornodes newnewrequestornodes newrequestortimes newnewrequestortimes newrequestorbootids newnewrequestorbootids requestornodes newrequestornodes requestortimes newrequestortimes requestorbootids newrequestorbootids private synchronized int add requested from peer node requested from long now if logminor logger minor this adding requested from requested from at now sent time now boolean included already false int nulls 0 int ret 1 for int i 0 i requested nodes length i peer node got requested nodes i null null requested nodes i get if got requested from update existing entry included already true requested locs i requested from get location requested booti ds i requested from get bootid requested times i now ret i break else if got null nulls if included already nulls 0 return ret int not included included already 0 1 because weak these can become null doesn t matter but we want to minimise memory usage if nulls 1 included already nice special case for int i 0 i requested nodes length i if requested nodes i null requested nodes i get null requested nodes i requested from my ref requested locs i requested from get location requested booti ds i requested from get bootid requested times i now requested timeouts i 1 requested timeoutht ls i short 1 return i suppress warnings unchecked weak reference peer node new requested nodes new weak reference requested nodes length not included nulls double new requested locs new double requested nodes length not included nulls long new requested booti ds new long requested nodes length not included nulls long new requested times new long requested nodes length not included nulls long new requested timeouts new long requested nodes length not included nulls short new requested timeoutht ls new short requested nodes length not included nulls int to index 0 for int i 0 i requested nodes length i weak reference peer node ref requested nodes i peer node pn ref null null ref get if pn null continue if pn requested from ret to index new requested nodes to index requested nodes i new requested times to index requested times i new requested booti ds to index requested booti ds i new requested locs to index requested locs i new requested timeouts to index requested timeouts i new requested timeoutht ls to index requested timeoutht ls i to index if included already ret to index new requested nodes to index requested from my ref new requested times to index now new requested booti ds to index requested from get bootid new requested locs to index requested from get location new requested timeouts to index 1 new requested timeoutht ls to index short 1 ret to index to index for int i to index i new requested nodes length i new requested nodes i null if to index new requested nodes length 2 suppress warnings unchecked weak reference peer node new new requested nodes new weak reference to index double new new requested locs new double to index long new new requested booti ds new long to index long new new requested times new long to index long new new requested timeouts new long to index short new new requested timeoutht ls new short to index system arraycopy new requested nodes 0 new new requested nodes 0 to index system arraycopy new requested locs 0 new new requested locs 0 to index system arraycopy new requested booti ds 0 new new requested booti ds 0 to index system arraycopy new requested times 0 new new requested times 0 to index system arraycopy new requested timeouts 0 new new requested timeouts 0 to index system arraycopy new requested timeoutht ls 0 new new requested timeoutht ls 0 to index new requested nodes new new requested nodes new requested locs new new requested locs new requested booti ds new new requested booti ds new requested times new new requested times new requested timeouts new new requested timeouts new requested timeoutht ls new new requested timeoutht ls requested nodes new requested nodes requested locs new requested locs requested booti ds new requested booti ds requested times new requested times requested timeouts new requested timeouts requested timeoutht ls new requested timeoutht ls return ret addrequestedfrom peernode requestedfrom requestedfrom senttime includedalready requestednodes peernode requestednodes requestednodes requestedfrom includedalready requestedlocs requestedfrom getlocation requestedbootids requestedfrom getbootid requestedtimes includedalready notincluded includedalready includedalready requestednodes requestednodes requestednodes requestednodes requestedfrom myref requestedlocs requestedfrom getlocation requestedbootids requestedfrom getbootid requestedtimes requestedtimeouts requestedtimeouthtls suppresswarnings weakreference peernode newrequestednodes weakreference requestednodes notincluded newrequestedlocs requestednodes notincluded newrequestedbootids requestednodes notincluded newrequestedtimes requestednodes notincluded newrequestedtimeouts requestednodes notincluded newrequestedtimeouthtls requestednodes notincluded toindex requestednodes weakreference peernode requestednodes peernode requestedfrom toindex newrequestednodes toindex requestednodes newrequestedtimes toindex requestedtimes newrequestedbootids toindex requestedbootids newrequestedlocs toindex requestedlocs newrequestedtimeouts toindex requestedtimeouts newrequestedtimeouthtls toindex requestedtimeouthtls toindex includedalready toindex newrequestednodes toindex requestedfrom myref newrequestedtimes toindex newrequestedbootids toindex requestedfrom getbootid newrequestedlocs toindex requestedfrom getlocation newrequestedtimeouts toindex newrequestedtimeouthtls toindex toindex toindex toindex newrequestednodes newrequestednodes toindex newrequestednodes suppresswarnings weakreference peernode newnewrequestednodes weakreference toindex newnewrequestedlocs toindex newnewrequestedbootids toindex newnewrequestedtimes toindex newnewrequestedtimeouts toindex newnewrequestedtimeouthtls toindex newrequestednodes newnewrequestednodes toindex newrequestedlocs newnewrequestedlocs toindex newrequestedbootids newnewrequestedbootids toindex newrequestedtimes newnewrequestedtimes toindex newrequestedtimeouts newnewrequestedtimeouts toindex newrequestedtimeouthtls newnewrequestedtimeouthtls toindex newrequestednodes newnewrequestednodes newrequestedlocs newnewrequestedlocs newrequestedbootids newnewrequestedbootids newrequestedtimes newnewrequestedtimes newrequestedtimeouts newnewrequestedtimeouts newrequestedtimeouthtls newnewrequestedtimeouthtls requestednodes newrequestednodes requestedlocs newrequestedlocs requestedbootids newrequestedbootids requestedtimes newrequestedtimes requestedtimeouts newrequestedtimeouts requestedtimeouthtls newrequestedtimeouthtls offer this key to all the nodes that have requested it and all the nodes it has been requested from called after a the data has been stored and b this entry has been removed from the ft public synchronized void offer hash set peer node set new hash set peer node if logminor logger minor this sending offers to nodes which requested the key from us for int i 0 i requestor nodes length i weak reference peer node ref requestor nodes i if ref null continue peer node pn ref get if pn null continue if pn get bootid requestor booti ds i continue if set add pn logger error this node is in requestor nodes twice pn pn offer key if logminor logger minor this sending offers to nodes which we sent the key to for int i 0 i requested nodes length i weak reference peer node ref requested nodes i if ref null continue peer node pn ref get if pn null continue if pn get bootid requested booti ds i continue if set contains pn continue pn offer key hashset peernode hashset peernode requestornodes weakreference peernode requestornodes peernode getbootid requestorbootids requestornodes requestednodes weakreference peernode requestednodes peernode getbootid requestedbootids has any node asked for this key public synchronized boolean others want peer node peer boolean any valid false for int i 0 i requestor nodes length i weak reference peer node ref requestor nodes i if ref null continue peer node pn ref get if pn null requestor nodes i null continue long bootid pn get bootid if bootid requestor booti ds i requestor nodes i null continue any valid true if any valid requestor nodes empty weak reference requestor times requestor booti ds empty long array return any valid otherswant peernode anyvalid requestornodes weakreference peernode requestornodes peernode requestornodes getbootid requestorbootids requestornodes anyvalid anyvalid requestornodes empty_weak_reference requestortimes requestorbootids empty_long_array anyvalid has this peer asked us for the key public synchronized boolean asked by peer peer node peer long now boolean any valid false boolean ret false for int i 0 i requestor nodes length i weak reference peer node ref requestor nodes i if ref null continue peer node pn ref get if pn null requestor nodes i null continue long bootid pn get bootid if bootid requestor booti ds i requestor nodes i null continue if now requestor times i max time between request and offer if pn peer ret true any valid true if any valid requestor nodes empty weak reference requestor times requestor booti ds empty long array return ret askedbypeer peernode anyvalid requestornodes weakreference peernode requestornodes peernode requestornodes getbootid requestorbootids requestornodes requestortimes max_time_between_request_and_offer anyvalid anyvalid requestornodes empty_weak_reference requestortimes requestorbootids empty_long_array have we asked this peer for the key public synchronized boolean asked from peer peer node peer long now boolean any valid false boolean ret false for int i 0 i requested nodes length i weak reference peer node ref requested nodes i if ref null continue peer node pn ref get if pn null requested nodes i null continue long bootid pn get bootid if bootid requested booti ds i requested nodes i null continue any valid true if now requested times i max time between request and offer if pn peer ret true any valid true if any valid requested nodes empty weak reference requested times requested booti ds requested timeouts empty long array requested timeoutht ls empty short array return ret askedfrompeer peernode anyvalid requestednodes weakreference peernode requestednodes peernode requestednodes getbootid requestedbootids requestednodes anyvalid requestedtimes max_time_between_request_and_offer anyvalid anyvalid requestednodes empty_weak_reference requestedtimes requestedbootids requestedtimeouts empty_long_array requestedtimeouthtls empty_short_array public synchronized boolean is empty long now if requested nodes length 0 return false if requestor nodes length 0 return false return true isempty requestednodes requestornodes public synchronized long get timeout time peer node peer for int i 0 i requested nodes length i weak reference peer node ref requested nodes i if ref null ref get peer return requested timeouts i return 1 not timed out gettimeouttime peernode requestednodes weakreference peernode requestednodes requestedtimeouts public synchronized boolean cleanup long now system current time millis don t pass in as a pass over the whole ft may take a while get it in the method boolean empty cleanup requestor now empty cleanup requested now return empty currenttimemillis cleanuprequestor cleanuprequested private boolean cleanup requestor long now boolean empty true int x 0 for int i 0 i requestor nodes length i weak reference peer node ref requestor nodes i if ref null continue peer node pn ref get if pn null continue long bootid pn get bootid if bootid requestor booti ds i continue if pn is connected continue if now requestor times i max time between request and offer continue empty false requestor nodes x requestor nodes i requestor times x requestor times i requestor booti ds x requestor booti ds i x if x requestor nodes length suppress warnings unchecked weak reference peer node new requestor nodes new weak reference x long new requestor times new long x long new requestor booti ds new long x system arraycopy requestor nodes 0 new requestor nodes 0 x system arraycopy requestor times 0 new requestor times 0 x system arraycopy requestor booti ds 0 new requestor booti ds 0 x requestor nodes new requestor nodes requestor times new requestor times requestor booti ds new requestor booti ds return empty cleanuprequestor requestornodes weakreference peernode requestornodes peernode getbootid requestorbootids isconnected requestortimes max_time_between_request_and_offer requestornodes requestornodes requestortimes requestortimes requestorbootids requestorbootids requestornodes suppresswarnings weakreference peernode newrequestornodes weakreference newrequestortimes newrequestorbootids requestornodes newrequestornodes requestortimes newrequestortimes requestorbootids newrequestorbootids requestornodes newrequestornodes requestortimes newrequestortimes requestorbootids newrequestorbootids private boolean cleanup requested long now boolean empty true int x 0 for int i 0 i requested nodes length i weak reference peer node ref requested nodes i if ref null continue peer node pn ref get if pn null continue long bootid pn get bootid if bootid requested booti ds i continue if pn is connected continue if now requested times i max time between request and offer continue empty false requested nodes x requested nodes i requested times x requested times i requested booti ds x requested booti ds i requested locs x requested locs i if now requested timeouts x requested timeouts x requested timeouts i requested timeoutht ls x requested timeoutht ls i else requested timeouts x 1 requested timeoutht ls x short 1 x if x requested nodes length suppress warnings unchecked weak reference peer node new requested nodes new weak reference x long new requested times new long x long new requested booti ds new long x double new requested locs new double x long new requested timeouts new long x short new requested timeoutht ls new short x system arraycopy requested nodes 0 new requested nodes 0 x system arraycopy requested times 0 new requested times 0 x system arraycopy requested booti ds 0 new requested booti ds 0 x system arraycopy requested locs 0 new requested locs 0 x system arraycopy requested timeouts 0 new requested timeouts 0 x system arraycopy requested timeoutht ls 0 new requested timeoutht ls 0 x requested nodes new requested nodes requested times new requested times requested booti ds new requested booti ds requested locs new requested locs requested timeouts new requested timeouts requested timeoutht ls new requested timeoutht ls return empty cleanuprequested requestednodes weakreference peernode requestednodes peernode getbootid requestedbootids isconnected requestedtimes max_time_between_request_and_offer requestednodes requestednodes requestedtimes requestedtimes requestedbootids requestedbootids requestedlocs requestedlocs requestedtimeouts requestedtimeouts requestedtimeouts requestedtimeouthtls requestedtimeouthtls requestedtimeouts requestedtimeouthtls requestednodes suppresswarnings weakreference peernode newrequestednodes weakreference newrequestedtimes newrequestedbootids newrequestedlocs newrequestedtimeouts newrequestedtimeouthtls requestednodes newrequestednodes requestedtimes newrequestedtimes requestedbootids newrequestedbootids requestedlocs newrequestedlocs requestedtimeouts newrequestedtimeouts requestedtimeouthtls newrequestedtimeouthtls requestednodes newrequestednodes requestedtimes newrequestedtimes requestedbootids newrequestedbootids requestedlocs newrequestedlocs requestedtimeouts newrequestedtimeouts requestedtimeouthtls newrequestedtimeouthtls public boolean is empty return is empty system current time millis isempty isempty currenttimemillis construct a diffusion filter public diffusion filter set matrix diffusion matrix diffusionfilter diffusionfilter setmatrix diffusionmatrix set whether to use a serpentine pattern for return or not this can reduce avalanche artifacts in the output param serpentine true to use serpentine pattern see get serpentine public void set serpentine boolean serpentine this serpentine serpentine getserpentine setserpentine return the serpentine setting return the current setting see set serpentine public boolean get serpentine return serpentine setserpentine getserpentine set whether to use a color dither param color dither true to use a color dither see get color dither public void set color dither boolean color dither this color dither color dither colordither getcolordither setcolordither colordither colordither colordither get whether to use a color dither return true to use a color dither see set color dither public boolean get color dither return color dither setcolordither getcolordither colordither set the dither matrix param matrix the dither matrix see get matrix public void set matrix int matrix this matrix matrix sum 0 for int i 0 i matrix length i sum matrix i getmatrix setmatrix get the dither matrix return the dither matrix see set matrix public int get matrix return matrix setmatrix getmatrix set the number of dither levels param levels the number of levels see get levels public void set levels int levels this levels levels getlevels setlevels get the number of dither levels return the number of levels see set levels public int get levels return levels setlevels getlevels override protected int filter pixels int width int height int in pixels rectangle transformed space int out pixels new int width height int index 0 int map new int levels for int i 0 i levels i int v 255 i levels 1 map i v int div new int 256 for int i 0 i 256 i div i levels i 256 for int y 0 y height y boolean reverse serpentine y 1 1 int direction if reverse index y width width 1 direction 1 else index y width direction 1 for int x 0 x width x int rgb1 in pixels index int r1 rgb1 16 0xff int g1 rgb1 8 0xff int b1 rgb1 0xff if color dither r1 g1 b1 r1 g1 b1 3 int r2 map div r1 int g2 map div g1 int b2 map div b1 out pixels index 0xff000000 r2 16 g2 8 b2 int er r1 r2 int eg g1 g2 int eb b1 b2 for int i 1 i 1 i int iy i y if 0 iy iy height for int j 1 j 1 j int jx j x if 0 jx jx width int w if reverse w matrix i 1 3 j 1 else w matrix i 1 3 j 1 if w 0 int k reverse index j index j rgb1 in pixels k r1 rgb1 16 0xff g1 rgb1 8 0xff b1 rgb1 0xff r1 er w sum g1 eg w sum b1 eb w sum in pixels k pixel utils clamp r1 16 pixel utils clamp g1 8 pixel utils clamp b1 index direction return out pixels filterpixels inpixels transformedspace outpixels inpixels colordither outpixels inpixels inpixels pixelutils pixelutils pixelutils outpixels override public string to string return colors diffusion dither tostring public float x y z w public tuple4f this 0 0 0 0 public tuple4f float x this x x 0 this y x 1 this z x 2 this w x 2 public tuple4f float x float y float z float w this x x this y y this z z this w w public tuple4f tuple4f t this x t x this y t y this z t z this w t w public void absolute x math abs x y math abs y z math abs z w math abs w public void absolute tuple4f t x math abs t x y math abs t y z math abs t z w math abs t w public void clamp float min float max if x min x min else if x max x max if y min y min else if y max y max if z min z min else if z max z max if w min w min else if w max w max public void set float x float y float z float w this x x this y y this z z this w w public void set float x this x x 0 this y x 1 this z x 2 this w x 2 public void set tuple4f t x t x y t y z t z w t w public void get tuple4f t t x x t y y t z z t w w public void get float t t 0 x t 1 y t 2 z t 3 w public void negate x x y y z z w w public void negate tuple4f t x t x y t y z t z w t w public void interpolate tuple4f t float alpha float a 1 alpha x a x alpha t x y a y alpha t y z a z alpha t z w a w alpha t w public void scale float s x s y s z s w s public void add tuple4f t x t x y t y z t z w t w public void add tuple4f t1 tuple4f t2 x t1 x t2 x y t1 y t2 y z t1 z t2 z w t1 w t2 w public void sub tuple4f t x t x y t y z t z w t w public void sub tuple4f t1 tuple4f t2 x t1 x t2 x y t1 y t2 y z t1 z t2 z w t1 w t2 w override public string to string return x y z w tostring set the number of iterations the effect is performed param iterations the number of iterations min value 0 see get iterations public void set iterations int iterations this iterations iterations getiterations setiterations get the number of iterations the effect is performed return the number of iterations see set iterations public int get iterations return iterations setiterations getiterations set the colormap to be used for the filter param colormap the colormap see get colormap public void set colormap colormap colormap this colormap colormap getcolormap setcolormap get the colormap to be used for the filter return the colormap see set colormap public colormap get colormap return colormap setcolormap getcolormap public void set new color int new color this new color new color setnewcolor newcolor newcolor newcolor public int get new color return new color getnewcolor newcolor public void set black function binary function black function this black function black function setblackfunction binaryfunction blackfunction blackfunction blackfunction public binary function get black function return black function binaryfunction getblackfunction blackfunction creates a new config object and stores the default values in it protected config freetalk my freetalk ext object container db m freetalk my freetalk mdb db m string params new hash map string string m int params new hash map string integer set default values false myfreetalk extobjectcontainer mfreetalk myfreetalk mstringparams hashmap mintparams hashmap setdefaultvalues protected void initialize transient freetalk my freetalk ext object container db m freetalk my freetalk mdb db initializetransient myfreetalk extobjectcontainer mfreetalk myfreetalk loads an existing config object from the database and adds any missing default values to it creates and stores a new one if none exists return the config object public static config load or create freetalk my freetalk ext object container db synchronized db lock config config object set config result db query by example config class if result size 0 logger debug my freetalk creating new config config new config my freetalk db config store and commit else if result size 1 do not throw we do not want to prevent freetalk from starting up logger error my freetalk multiple config objects stored logger debug my freetalk loaded config config result next config initialize transient my freetalk db config set default values false return config loadorcreate myfreetalk extobjectcontainer objectset querybyexample myfreetalk myfreetalk storeandcommit myfreetalk myfreetalk initializetransient myfreetalk setdefaultvalues stores the config object in the database please call this after any modifications to the config it is not done automatically because the user interface will usually change many values at once public synchronized void store and commit synchronized mdb lock try mdb store m string params 3 mdb store m int params 3 mdb store this catch runtime exception e mdb rollback throw e storeandcommit mstringparams mintparams runtimeexception sets a string configuration parameter you have to call store and commit to write it to disk param key name of the config parameter param value value of the config parameter public synchronized void set string key string value m string params put key value storeandcommit mstringparams sets an integer configuration parameter and stores it in the database you have to call store and commit to write it to disk param key name of the config parameter param value value of the config parameter public synchronized void set string key int value m int params put key value storeandcommit mintparams gets a string configuration parameter public synchronized string get string string key return m string params get key getstring mstringparams gets an integer configuration parameter public synchronized int get int string key return m int params get key getint mintparams check wheter a string config parameter exists public synchronized boolean contains string string key return m string params contains key key containsstring mstringparams containskey check wheter an integer config parameter exists public synchronized boolean contains int string key return m int params contains key key containsint mintparams containskey get all valid string configuration keys return a string array containing a copy of all keys in the database at the point of calling the function changes to the array do not change the database public synchronized string get all string keys we return a copy of the key set if we returned an iterator of the key set modifications on the configuration hash map would be reflected in the iterator this might lead to problems if the configuration is modified while someone is using an iterator returned by this function further the iterator would allow the user to delete keys from the configuration fixme there is a null pointer somewhere in here i don t have the time for fixing it right now return m string params key set to array new string m string params size getallstringkeys keyset keyset hashmap mstringparams keyset toarray mstringparams get all valid string configuration keys return a string array containing a copy of all keys in the database at the point of calling the function changes to the array do not change the database public synchronized string get all int keys we return a copy of the key set if we returned an iterator of the key set modifications on the configuration hash map would be reflected in the iterator this might lead to problems if the configuration is modified while someone is using an iterator returned by this function further the iterator would allow the user to delete keys from the configuration fixme there is a null pointer somewhere in here i don t have the time for fixing it right now return m int params key set to array new string m string params size getallintkeys keyset keyset hashmap mintparams keyset toarray mstringparams add the default configuration values to the database param overwrite if true overwrite already set values with the default value public synchronized void set default values boolean overwrite do not overwrite it shall only be overwritten when the database has been converted to a new format if contains int database format version set database format version freetalk database format version setdefaultvalues containsint database_format_version database_format_version database_format_version private final boolean require7 bit public identity encoding boolean require short lines boolean require7 bit this require short lines require short lines this require7 bit require7 bit require7bit identityencoding requireshortlines require7bit requireshortlines requireshortlines require7bit require7bit public void set ignore errors boolean ignore setignoreerrors public byte buffer encode byte buffer input fixme maybe we should validate the input here return input slice bytebuffer bytebuffer public byte buffer decode byte buffer input return input slice bytebuffer bytebuffer private static final int marker rst7 0xd7 last reset marker jpeg filter boolean delete comments boolean delete exif this delete comments delete comments this delete exif delete exif marker_rst7 jpegfilter deletecomments deleteexif deletecomments deletecomments deleteexif deleteexif public bucket read filter bucket data bucket factory bf string charset hash map string string other params filter callback cb throws data filter exception io exception bucket output read filter data bf charset other params cb delete comments delete exif null if output null return output if logger should log logger minor this logger minor this need to modify jpeg bucket filtered bf make bucket 1 output stream os new buffered output stream filtered get output stream try read filter data bf charset other params cb delete comments delete exif os os flush os close os null finally closer close os return filtered readfilter bucketfactory hashmap otherparams filtercallback datafilterexception ioexception readfilter otherparams deletecomments deleteexif shouldlog makebucket outputstream bufferedoutputstream getoutputstream readfilter otherparams deletecomments deleteexif public bucket read filter bucket data bucket factory bf string charset hash map string string other params filter callback cb boolean delete comments boolean delete exif output stream output throws data filter exception io exception boolean logminor logger should log logger minor this long length data size if length 6 throw error l10n too short title l10n too short input stream is data get input stream buffered input stream bis new buffered input stream is counted input stream cis new counted input stream bis data input stream dis new data input stream cis try assert header dis soi if output null output write soi byte array output stream baos null data output stream dos null if output null baos new byte array output stream dos new data output stream baos check the chunks boolean finished false int force marker type 1 while dos null finished if baos null baos reset int marker type if force marker type 1 marker type force marker type force marker type 1 else int marker start dis read if marker start 1 no more chunks to scan break else if finished if logminor logger minor this more data after eoi copying to truncate return null if marker start 0xff throw error invalid marker the file includes an invalid marker start integer to hex string marker start and cannot be parsed further if baos null baos write 0xff marker type dis read unsigned byte if baos null baos write marker type if logminor logger minor this marker type integer to hex string marker type long count at start cis count after marker but before type int block length if marker type marker eoi marker type marker rst0 marker type marker rst7 block length 0 else block length dis read unsigned short if dos null dos write short block length if marker type 0xda start of scan marker copy marker if block length 2 throw error invalid frame length the file includes an invalid frame length block length if dos null byte buf new byte block length 2 dis read fully buf dos write buf else skip bytes dis block length 2 logger minor this copied start of frame marker length block length 2 if baos null baos write to output will continue at end now copy the scan itself int prev char 1 while true int x dis read if prev char 1 output null output write prev char if x 1 termination inside a scan valid i suppose break if prev char 0xff x 0 x marker rst0 x marker rst7 reset markers can occur in the scan force marker type x if logminor logger minor this moved scan at cis count found a marker type integer to hex string x if output null output write x break end of scan new marker prev char x continue avoid writing the header twice else if marker type 0xe0 app0 if logminor logger minor this app0 string type read null terminated ascii string dis if baos null write null terminated string baos type if logminor logger minor this type type length type length if type equals jfif logger minor this jfif header file header int major version dis read unsigned byte if major version 1 throw error invalid header unrecognized major version major version if dos null dos write major version int minor version dis read unsigned byte if minor version 2 throw error invalid header unrecognized version 1 minor version if dos null dos write minor version int units dis read unsigned byte if units 2 throw error invalid header unrecognized units type units if dos null dos write units if dos null dos write short dis read short copy xdensity dos write short dis read short copy ydensity else dis read short ignore xdensity dis read short ignore ydensity int thumbx dis read unsigned byte if dos null dos write byte thumbx int thumby dis read unsigned byte if dos null dos write byte thumby int thumb len thumbx thumby 3 if thumb len length cis count throw error invalid header there should be thumb len bytes of thumbnail but there are only length cis count bytes left in the file if dos null byte buf new byte thumb len dis read fully buf dos write buf else skip bytes dis thumb len else if type equals jfxx jfif extension marker int extension code dis read unsigned byte if extension code 0x10 extension code 0x11 extension code 0x13 alternate thumbnail perfectly valid skip rest block length count at start cis dis dos thumbnail frame logger minor this thumbnail frame else throw error unknown jfxx extension extension code the file contains an unknown jfxx extension else if logminor logger minor this dropping application specific app0 chunk named type application specific extension if output null return null skip rest block length count at start cis dis dos application specific frame continue don t write the frame else if marker type 0xe1 exif if output null delete exif return null if delete exif if logminor logger minor this dropping exif data skip bytes dis block length 2 continue don t write the frame skip rest block length count at start cis dis dos exif frame else if marker type 0xfe comment if output null delete comments return null if delete comments skip bytes dis block length 2 if logminor logger minor this dropping comment length block length 2 continue don t write the frame skip rest block length count at start cis dis dos comment else if marker type 0xd9 end of image finished true if logminor logger minor this end of image else boolean valid false we used to support only db c4 c0 because some website said they were sufficient for decoding a jpeg unfortunately they are not jpeg is a very complex standard and the full spec is only available for a fee fixme somebody who has access to the spec should have a look at this and ideally write some chunk sanitizers switch marker type descriptions from http svn xiph org experimental giles jpegdump c gpl case 0xc0 start of frame case 0xc1 extended sequential huffman case 0xc2 progressive huffman case 0xc3 lossless huffman case 0xc5 differential sequential huffman case 0xc6 differential progressive huffman case 0xc7 differential lossless huffman delete 0xc8 reserved for jpeg extension likely to be used for bad things case 0xc9 extended sequential arithmetic case 0xca progressive arithmetic case 0xcb lossless arithmetic case 0xcd differential sequential arithmetic case 0xcf differential lossless arithmetic case 0xc4 define huffman tables case 0xcc define arithmetic coding conditioning restart markers case 0xd0 case 0xd1 case 0xd2 case 0xd3 case 0xd4 case 0xd5 case 0xd6 case 0xd7 delimiters case 0xd8 start of image case 0xd9 end of image case 0xda start of scan case 0xdb define quantization tables case 0xdc define number of lines case 0xdd define restart interval case 0xde define hierarchical progression case 0xdf expand reference components delete app0 app15 application data sections likely to be troublesome delete extension data sections jpg0 6 sof48 lse jpg9 jpg13 jcom comment tem temporary private use for arithmetic coding delete 0x02 0xbf reserved sections do not support jpeg2000 at the moment probably has different headers fixme valid true if valid essential non terminal but unparsed frames if block length 2 throw error invalid frame length the file includes an invalid frame length block length if dos null byte buf new byte block length 2 dis read fully buf dos write buf else skip bytes dis block length 2 logger minor this essential frame type integer to hex string marker type length block length 2 offset at end cis count else if marker type 0xe0 marker type 0xef app marker can be safely deleted if logminor logger minor this dropping application marker type integer to hex string marker type length block length else if logminor logger minor this dropping unknown frame type integer to hex string marker type block length readfilter bucketfactory hashmap otherparams filtercallback deletecomments deleteexif outputstream datafilterexception ioexception shouldlog throwerror tooshorttitle tooshort inputstream getinputstream bufferedinputstream bufferedinputstream countedinputstream countedinputstream datainputstream datainputstream assertheader bytearrayoutputstream dataoutputstream bytearrayoutputstream dataoutputstream forcemarkertype markertype forcemarkertype markertype forcemarkertype forcemarkertype markerstart markerstart markerstart throwerror tohexstring markerstart markertype readunsignedbyte markertype tohexstring markertype countatstart blocklength markertype marker_eoi markertype marker_rst0 markertype marker_rst7 blocklength blocklength readunsignedshort writeshort blocklength markertype blocklength throwerror blocklength blocklength readfully skipbytes blocklength blocklength writeto prevchar prevchar prevchar prevchar marker_rst0 marker_rst7 forcemarkertype tohexstring prevchar markertype readnullterminatedasciistring writenullterminatedstring majorversion readunsignedbyte majorversion throwerror majorversion majorversion minorversion readunsignedbyte minorversion throwerror minorversion minorversion readunsignedbyte throwerror writeshort readshort writeshort readshort readshort readshort readunsignedbyte writebyte readunsignedbyte writebyte thumblen thumblen throwerror thumblen thumblen readfully skipbytes thumblen extensioncode readunsignedbyte extensioncode extensioncode extensioncode skiprest blocklength countatstart throwerror extensioncode skiprest blocklength countatstart markertype deleteexif deleteexif skipbytes blocklength skiprest blocklength countatstart markertype deletecomments deletecomments skipbytes blocklength blocklength skiprest blocklength countatstart markertype markertype blocklength throwerror blocklength blocklength readfully skipbytes blocklength tohexstring markertype blocklength markertype markertype tohexstring markertype blocklength tohexstring markertype blocklength private static string l10n string key return l10n get string jpeg filter key getstring jpegfilter private void write null terminated string byte array output stream baos string type throws io exception try byte data type get bytes iso 8859 1 ascii near enough baos write data baos write 0 catch unsupported encoding exception e throw new error impossible jvm doesn t support iso 8859 1 e e writenullterminatedstring bytearrayoutputstream ioexception getbytes unsupportedencodingexception private string read null terminated ascii string data input stream dis throws io exception string builder sb new string builder while true int x dis read if x 1 throw error invalid extension frame could not read an extension frame name if x 0 break char c char x ascii if x 128 c 32 c 10 c 13 throw error invalid extension frame name non ascii character in extension frame name sb append c return sb to string readnullterminatedasciistring datainputstream ioexception stringbuilder stringbuilder throwerror throwerror tostring private void skip rest int block length long count at start counted input stream cis data input stream dis data output stream dos string thing throws io exception skip the rest of the data int skip int block length cis count count at start if skip 0 throw error invalid thing the file includes an invalid thing if skip 0 return if dos null byte buf new byte skip dis read fully buf dos write buf else skip bytes dis skip skiprest blocklength countatstart countedinputstream datainputstream dataoutputstream ioexception blocklength countatstart throwerror readfully skipbytes fixme factor this out somewhere an io util class maybe private void skip bytes data input stream dis int skip throws io exception int skipped 0 while skipped skip long x dis skip skip skipped if x 0 byte buf new byte math min 4096 skip skipped dis read fully buf skipped buf length else skipped x ioutil skipbytes datainputstream ioexception readfully private void assert header data input stream dis byte expected throws io exception byte read new byte expected length dis read fully read if arrays equals read expected throw error invalid header the file does not start with a valid jpeg jfif header assertheader datainputstream ioexception readfully throwerror private void throw error string short reason string reason throws data filter exception throw an exception string message l10n not jpeg if reason null message reason if short reason null message short reason data filter exception e new data filter exception short reason short reason p message p new html node p add child message if logger should log logger normal this logger normal this throwing e e throw e throwerror shortreason datafilterexception notjpeg shortreason shortreason datafilterexception datafilterexception shortreason shortreason htmlnode addchild shouldlog public bucket write filter bucket data bucket factory bf string charset hash map string string other params filter callback cb throws data filter exception io exception return null writefilter bucketfactory hashmap otherparams filtercallback datafilterexception ioexception public class simple help toadlet extends toadlet simple help toadlet high level simple client client node client core c super client this core c simplehelptoadlet simplehelptoadlet highlevelsimpleclient nodeclientcore override public void handle get uri uri http request request toadlet context ctx throws toadlet context closed exception io exception html node page node ctx get page maker get page node freenet l10n get string f proxy toadlet help ctx html node content node ctx get page maker get content node page node if ctx is allowed full access content node add child core alerts create summary description infobox html node help screen box1 content node add child ctx get page maker get infobox infobox content l10n get string simple help toadlet description title html node help screen content1 ctx get page maker get content node help screen box1 help screen content1 add child l10n get string simple help toadlet description text definitions infobox html node help screen box2 content node add child ctx get page maker get infobox infobox content l10n get string simple help toadlet definitions title html node help screen content2 ctx get page maker get content node help screen box2 html node table help screen content2 add child table new string border style new string 0 border none html node row table add child tr html node cell row add child td style border none cell add child cell row add child td style border none cell add child a new string href title new string ctx fix link item get key item get description item get name row add child l10n get string simple help toadlet chk row add child br row add child l10n get string simple help toadlet ssk row add child br row add child l10n get string simple help toadlet usk help screen content2 addchild l10n get string simple help toadlet chk help screen content2 addchild br help screen content2 addchild l10n get string simple help toadlet ssk help screen content2 addchild br help screen content2 addchild l10n get string simple help toadlet usk port forwarding etc html node help screen box3 content node add child ctx get page maker get infobox infobox content l10n get string simple help toadlet connectivity title html node help screen content3 ctx get page maker get content node help screen box3 help screen content3 add child l10n get string simple help toadlet connectivity text this writehtml reply ctx 200 ok page node generate handleget httprequest toadletcontext toadletcontextclosedexception ioexception htmlnode pagenode getpagemaker getpagenode getstring fproxytoadlet htmlnode contentnode getpagemaker getcontentnode pagenode isallowedfullaccess contentnode addchild createsummary htmlnode helpscreenbox1 contentnode addchild getpagemaker getinfobox getstring simplehelptoadlet descriptiontitle htmlnode helpscreencontent1 getpagemaker getcontentnode helpscreenbox1 helpscreencontent1 addchild getstring simplehelptoadlet descriptiontext htmlnode helpscreenbox2 contentnode addchild getpagemaker getinfobox getstring simplehelptoadlet definitionstitle htmlnode helpscreencontent2 getpagemaker getcontentnode helpscreenbox2 htmlnode helpscreencontent2 addchild htmlnode addchild htmlnode addchild addchild addchild addchild fixlink getkey getdescription getname addchild getstring simplehelptoadlet addchild addchild getstring simplehelptoadlet addchild addchild getstring simplehelptoadlet helpscreencontent2 getstring simplehelptoadlet helpscreencontent2 helpscreencontent2 getstring simplehelptoadlet helpscreencontent2 helpscreencontent2 getstring simplehelptoadlet htmlnode helpscreenbox3 contentnode addchild getpagemaker getinfobox getstring simplehelptoadlet connectivitytitle htmlnode helpscreencontent3 getpagemaker getcontentnode helpscreenbox3 helpscreencontent3 addchild getstring simplehelptoadlet connectivitytext writehtmlreply pagenode override public string supported methods return get supportedmethods public revocation checker node update manager manager file blob file this manager manager core manager node client core this revocationdnf counter 0 this blob file blob file this logminor logger should log logger minor this ctx revocation core make client short 0 true get fetch context ctx revocation allow splitfiles false ctx revocation cache local requests false ctx revocation max archive levels 1 big enough ctx revocation max output length 4096 ctx revocation max temp length 4096 ctx revocation max splitfile block retries 1 if we find content try forever to get it not used because of the above size limits ctx revocation max non splitfile retries 0 but return quickly normally revocationchecker nodeupdatemanager blobfile clientcore revocationdnfcounter blobfile blobfile shouldlog ctxrevocation makeclient getfetchcontext ctxrevocation allowsplitfiles ctxrevocation cachelocalrequests ctxrevocation maxarchivelevels ctxrevocation maxoutputlength ctxrevocation maxtemplength ctxrevocation maxsplitfileblockretries ctxrevocation maxnonsplitfileretries public int get revocationdnf counter return revocationdnf counter getrevocationdnfcounter revocationdnfcounter public void start boolean aggressive start aggressive true start a fetch param aggressive if set to true then we have just fetched an update and therefore can increase the priority of the fetch to maximum public void start boolean aggressive boolean reset if manager is blown logger error this not starting revocation checker key already blown return logminor logger should log logger minor this try client getter cg null client getter to cancel null synchronized this if aggressive was aggressive ignore old one to cancel revocation getter if logminor logger minor this ignoring old request because was low priority revocation getter null was aggressive aggressive if revocation getter null revocation getter is cancelled revocation getter is finished if logminor logger minor this not queueing another revocation fetcher yet old one still running reset false else if reset if logminor logger minor this resetting dnf count from revocationdnf counter new exception debug revocationdnf counter 0 else if logminor logger minor this revocation count revocationdnf counter if logminor logger minor this fetcher revocation getter if revocation getter null logminor logger minor this revocation fetcher cancelled revocation getter is cancelled finished revocation getter is finished try tmp blob file file create temp file revocation fblob tmp manager node client core get persistent temp dir catch io exception e logger error this cannot record revocation fetch therefore cannot pass it on to peers e e cg revocation getter new client getter this manager revocationuri ctx revocation aggressive request starter maximum priority class request starter immediate splitfile priority class this null tmp blob file null null new file bucket tmp blob file false false false false false if logminor logger minor this queued another revocation fetcher count revocationdnf counter if to cancel null to cancel cancel null core client context if cg null core client context start cg if logminor logger minor this started revocation fetcher catch fetch exception e logger error this not able to start the revocation fetcher manager blow cannot fetch the auto update uri isblown shouldlog clientgetter clientgetter tocancel wasaggressive tocancel revocationgetter revocationgetter wasaggressive revocationgetter revocationgetter iscancelled revocationgetter isfinished revocationdnfcounter revocationdnfcounter revocationdnfcounter revocationgetter revocationgetter revocationgetter iscancelled revocationgetter isfinished tmpblobfile createtempfile clientcore getpersistenttempdir ioexception revocationgetter clientgetter ctxrevocation requeststarter maximum_priority_class requeststarter immediate_splitfile_priority_class tmpblobfile filebucket tmpblobfile revocationdnfcounter tocancel tocancel clientcontext clientcontext fetchexception long last succeeded return last succeeded lastsucceeded lastsucceeded long last succeeded delta if last succeeded 0 return 1 return system current time millis last succeeded lastsucceededdelta lastsucceeded currenttimemillis lastsucceeded called when the revocation uri changes public void on change revocationuri kill start was aggressive onchangerevocationuri wasaggressive public void on success fetch result result client getter state object container container on success result state tmp blob file onsuccess fetchresult clientgetter objectcontainer onsuccess tmpblobfile void on success fetch result result client getter state file blob the key has been blown fixme maybe we need a bigger warning message move blob blob string msg null try byte buf result as byte array msg new string buf catch throwable t try msg failed to extract result when key blown t logger error this msg t system err println msg t print stack trace catch throwable t1 msg internal error after retreiving revocation key manager blow msg onsuccess fetchresult clientgetter moveblob asbytearray printstacktrace private void move blob file tmp blob file if tmp blob file null logger error this no temporary binary blob file moving it may not be able to propagate revocation bug return file util rename to tmp blob file blob file moveblob tmpblobfile tmpblobfile fileutil renameto tmpblobfile blobfile public void on failure fetch exception e client getter state object container container on failure e state tmp blob file onfailure fetchexception clientgetter objectcontainer onfailure tmpblobfile void on failure fetch exception e client getter state file tmp blob file logminor logger should log logger minor this if logminor logger minor this revocation fetch failed e int error code e get mode boolean completed false long now system current time millis if error code fetch exception cancelled if tmp blob file null tmp blob file delete return cancelled by us above or killed either way irrelevant and doesn t need to be restarted if e is fatal manager blow permanent error fetching revocation error inserting the revocation key e to string move blob tmp blob file other peers need to know return if tmp blob file null tmp blob file delete if e newuri null manager blow revocation uri redirecting to e newuri maybe you set the revocation uri to the update uri synchronized this if error code fetch exception data not found revocationdnf counter if logminor logger minor this incremented dnf counter to revocationdnf counter if revocationdnf counter 3 last succeeded now completed true revocationdnf counter 0 revocation getter null if completed manager no revocation found else start was aggressive false onfailure fetchexception clientgetter tmpblobfile shouldlog errorcode getmode currenttimemillis errorcode fetchexception tmpblobfile tmpblobfile isfatal tostring moveblob tmpblobfile tmpblobfile tmpblobfile errorcode fetchexception data_not_found revocationdnfcounter revocationdnfcounter revocationdnfcounter lastsucceeded revocationdnfcounter revocationgetter norevocationfound wasaggressive public void on success base client putter state object container container todo auto generated method stub onsuccess baseclientputter objectcontainer public void on failure insert exception e base client putter state object container container todo auto generated method stub onfailure insertexception baseclientputter objectcontainer public void on generateduri freeneturi uri base client putter state object container container todo auto generated method stub ongenerateduri baseclientputter objectcontainer public void on major progress object container container todo auto generated method stub onmajorprogress objectcontainer public void on fetchable base client putter state object container container todo auto generated method stub onfetchable baseclientputter objectcontainer public void kill if revocation getter null revocation getter cancel null core client context revocationgetter revocationgetter clientcontext public long get blob size return blob file length getblobsize blobfile get the binary blob if we have fetched it public file get blob file if manager is blown return null if blob file exists return blob file return null getblobfile isblown blobfile blobfile public boolean persistent return false public void remove from object container container throw new unsupported operation exception removefrom objectcontainer unsupportedoperationexception construct a circle filter public circle filter set edge action zero circlefilter circlefilter setedgeaction set the height of the arc param height the height see get height public void set height float height this height height getheight setheight get the height of the arc return the height see set height public float get height return height setheight getheight set the angle of the arc param angle the angle of the arc angle see get angle public void set angle float angle this angle angle getangle setangle returns the angle of the arc return the angle of the arc see set angle public float get angle return angle setangle getangle set the spread angle of the arc param spread angle the angle angle see get spread angle public void set spread angle float spread angle this spread angle spread angle spreadangle getspreadangle setspreadangle spreadangle spreadangle spreadangle get the spread angle of the arc return the angle angle see set spread angle public float get spread angle return spread angle setspreadangle getspreadangle spreadangle set the radius of the effect param radius the radius min value 0 see get radius public void set radius float radius this radius radius getradius setradius get the radius of the effect return the radius see set radius public float get radius return radius setradius getradius set the centre of the effect in the y direction as a proportion of the image size param centrex the center see get centrex public void set centrex float centrex this centrex centrex getcentrex setcentrex get the centre of the effect in the x direction as a proportion of the image size return the center see set centrex public float get centrex return centrex setcentrex getcentrex set the centre of the effect in the y direction as a proportion of the image size param centrey the center see get centrey public void set centrey float centrey this centrey centrey getcentrey setcentrey get the centre of the effect in the y direction as a proportion of the image size return the center see set centrey public float get centrey return centrey setcentrey getcentrey set the centre of the effect as a proportion of the image size param centre the center see get centre public void set centre point2d centre this centrex float centre getx this centrey float centre gety getcentre setcentre get the centre of the effect as a proportion of the image size return the center see set centre public point2d get centre return new point2d float centrex centrey setcentre getcentre override public buffered image filter buffered image src buffered image dst i width src get width i height src get height icentrex i width centrex icentrey i height centrey i width return super filter src dst bufferedimage bufferedimage bufferedimage iwidth getwidth iheight getheight iwidth iheight iwidth override protected void transform inverse int x int y float out float dx x icentrex float dy y icentrey float theta float math atan2 dy dx angle float r float math sqrt dx dx dy dy theta image math mod theta 2 float math pi out 0 i width theta spread angle 0 00001f out 1 i height 1 r radius height 0 00001f transforminverse imagemath iwidth spreadangle iheight override public string to string return distort circle tostring public get failed message fetch exception e string identifier boolean global if logger should log logger minor this logger minor this creating get failed from e for identifier e this tracker e error codes this code e mode this code description fetch exception get message code this extra description e extra message this short code description fetch exception get short message code this is fatal e is fatal this identifier identifier this global global this expected data length e expected size this expected mime type e get expected mime type this finalized expected e finalized size this redirecturi e newuri getfailedmessage fetchexception shouldlog errorcodes codedescription fetchexception getmessage extradescription extramessage shortcodedescription fetchexception getshortmessage isfatal isfatal expecteddatalength expectedsize expectedmimetype getexpectedmimetype finalizedexpected finalizedsize construct from a fieldset used in serialization of persistent requests will need to be made more tolerant of syntax errors if is used in an fcp client library fixme param use verbose fields if true read in verbose fields code description etc if false reconstruct them from the error code public get failed message simple field set fs boolean use verbose fields throws malformedurl exception identifier fs get identifier if identifier null throw new null pointer exception code integer parse int fs get code if use verbose fields code description fs get code description is fatal fields string to bool fs get fatal false short code description fs get short code description else code description fetch exception get message code is fatal fetch exception is fatal code short code description fetch exception get short message code extra description fs get extra description simple field set tracker subset fs subset errors if tracker subset null tracker new failure code tracker true tracker subset else tracker null expected mime type fs get expected mime type finalized expected fields string to bool fs get finalized expected false string s fs get expected data length if s null expected data length long parse long s else expected data length 1 s fs get redirecturi if s null this redirecturi new freeneturi s else this redirecturi null this global fields string to bool fs get global false useverbosefields codedescription getfailedmessage simplefieldset useverbosefields malformedurlexception nullpointerexception parseint useverbosefields codedescription codedescription isfatal stringtobool shortcodedescription shortcodedescription codedescription fetchexception getmessage isfatal fetchexception isfatal shortcodedescription fetchexception getshortmessage extradescription extradescription simplefieldset trackersubset trackersubset failurecodetracker trackersubset expectedmimetype expectedmimetype finalizedexpected stringtobool finalizedexpected expecteddatalength expecteddatalength parselong expecteddatalength stringtobool override public simple field set get field set return get field set true simplefieldset getfieldset getfieldset write to a simple field set for storage or transmission param verbose if true include fields which derive directly from static stuff on insert exception and therefore can be omitted if talking to self or another node public simple field set get field set boolean verbose simple field set sfs new simple field set true sfs put single code integer to string code if verbose sfs put single code description code description if extra description null sfs put single extra description extra description if verbose sfs put single fatal boolean to string is fatal if tracker null sfs tput errors tracker to field set verbose if verbose sfs put single short code description short code description sfs put single identifier identifier if expected data length 1 sfs put single expected data length long to string expected data length if expected mime type null sfs put single expected metadata content type expected mime type if finalized expected sfs put single finalized expected true if redirecturi null sfs put single redirecturi redirecturi to string false false return sfs simplefieldset insertexception simplefieldset getfieldset simplefieldset simplefieldset putsingle tostring putsingle codedescription codedescription extradescription putsingle extradescription extradescription putsingle tostring isfatal tofieldset putsingle shortcodedescription shortcodedescription putsingle expecteddatalength putsingle expecteddatalength tostring expecteddatalength expectedmimetype putsingle expectedmetadata contenttype expectedmimetype finalizedexpected putsingle finalizedexpected putsingle tostring override public string get name return get failed getname getfailed override public void run fcp connection handler handler node node throws message invalid exception throw new message invalid exception protocol error message invalid message get failed goes from server to client not the other way around identifier global fcpconnectionhandler messageinvalidexception messageinvalidexception protocolerrormessage invalid_message getfailed override public void remove from object container container if redirecturi null container activate redirecturi 5 redirecturi remove from container uri belongs to the parent which is also being removed if tracker null container activate tracker 5 tracker remove from container container delete this removefrom objectcontainer removefrom removefrom public control response set server u pnp get server name controlresponse setserver upnp getservername public control response soap response soap res super soap res controlresponse soapresponse soapres soapres public void set fault response int err code string err descr set status code http status internal server error node body node get body node node fault node create fault response node err code err descr body node add node fault node node env node get envelope node set content env node setfaultresponse errcode errdescr setstatuscode httpstatus internal_server_error bodynode getbodynode faultnode createfaultresponsenode errcode errdescr bodynode addnode faultnode envnode getenvelopenode setcontent envnode public void set fault response int err code set fault response err code u pnp status code2 string err code setfaultresponse errcode setfaultresponse errcode upnpstatus code2string errcode private node create fault response node int err code string err descr s fault node fault node new node soap xmlns soap delim soap fault faultcode s client faultcode node fault code node new node soap fault code fault code node set value soap xmlns soap delim fault code fault node add node fault code node faultstring u pnp error faultstring node fault string node new node soap fault string fault string node set value fault string fault node add node fault string node detail node detail node new node soap detail fault node add node detail node u pnp error xmlns urn schemas upnp org control 1 0 node upnp error node new node fault string upnp error node set attribute xmlns control xmlns detail node add node upnp error node error code error code error code node error code node new node soap error code error code node set value err code upnp error node add node error code node error description error string error description node error desctiprion node new node soap error description error desctiprion node set value err descr upnp error node add node error desctiprion node return fault node createfaultresponsenode errcode errdescr faultnode faultcodenode fault_code faultcodenode setvalue fault_code faultnode addnode faultcodenode upnperror faultstringnode fault_string faultstringnode setvalue fault_string faultnode addnode faultstringnode detailnode faultnode addnode detailnode upnperror upnperrornode fault_string upnperrornode setattribute detailnode addnode upnperrornode errorcode errorcode errorcodenode error_code errorcodenode setvalue errcode upnperrornode addnode errorcodenode errordescription errordescription errordesctiprionnode error_description errordesctiprionnode setvalue errdescr upnperrornode addnode errordesctiprionnode faultnode private node getu pnp error node node detail node get fault detail node if detail node null return null return detail node get node ends with soap upnp error getupnperrornode detailnode getfaultdetailnode detailnode detailnode getnodeendswith upnp_error private node getu pnp error code node node error node getu pnp error node if error node null return null return error node get node ends with soap error code getupnperrorcodenode errornode getupnperrornode errornode errornode getnodeendswith error_code private node getu pnp error description node node error node getu pnp error node if error node null return null return error node get node ends with soap error description getupnperrordescriptionnode errornode getupnperrornode errornode errornode getnodeendswith error_description public int getu pnp error code node error code node getu pnp error code node if error code node null return 1 string error code str error code node get value try return integer parse int error code str catch exception e return 1 getupnperrorcode errorcodenode getupnperrorcodenode errorcodenode errorcodestr errorcodenode getvalue parseint errorcodestr public string getu pnp error description node error desc node getu pnp error description node if error desc node null return return error desc node get value getupnperrordescription errordescnode getupnperrordescriptionnode errordescnode errordescnode getvalue public u pnp status getu pnp error int code 0 string desc code getu pnp error code desc getu pnp error description upnp err set code code upnp err set description desc return upnp err upnpstatus getupnperror getupnperrorcode getupnperrordescription upnperr setcode upnperr setdescription upnperr public client put disk dir message simple field set fs throws message invalid exception super fs allow unreadable files fields string to bool fs get allow unreadable files false string fnam fs get filename if fnam null throw new message invalid exception protocol error message missing field filename missing identifier global dirname new file fnam clientputdiskdirmessage simplefieldset messageinvalidexception allowunreadablefiles stringtobool allowunreadablefiles messageinvalidexception protocolerrormessage missing_field override public string get name return name getname override public void run fcp connection handler handler node node throws message invalid exception if handler server core allow upload from dirname throw new message invalid exception protocol error message access denied not allowed to upload from dirname identifier global create a directory listing of buckets of data mapped to manifest element s directories are sub hash map s hash map string object buckets make buckets by name dirname handler start client put dir this buckets true fcpconnectionhandler messageinvalidexception allowuploadfrom messageinvalidexception protocolerrormessage access_denied manifestelement hashmap hashmap makebucketsbyname startclientputdir create a map of string bucket for every file in a directory and its subdirs throws message invalid exception private hash map string object make buckets by name file thisdir string prefix throws message invalid exception if logger should log logger minor this logger minor this listing directory thisdir hash map string object ret new hash map string object file filelist thisdir list files if filelist null throw new message invalid exception protocol error message file not found no such directory identifier global for int i 0 i filelist length i skip unreadable files and dirs skip files nonexistant dangling symlinks check last if filelist i can read filelist i exists if filelist i is file file f filelist i file bucket bucket new file bucket f true false false false false ret put f get name new manifest element f get name prefix f get name bucket defaultmime types guessmime type f get name true f length else if filelist i is directory hash map string object subdir make buckets by name new file thisdir filelist i get name prefix filelist i get name ret put filelist i get name subdir else if allow unreadable files throw new message invalid exception protocol error message file not found not directory and not file filelist i identifier global else if allow unreadable files throw new message invalid exception protocol error message file not found not readable or doesn t exist filelist i identifier global return ret messageinvalidexception hashmap makebucketsbyname messageinvalidexception shouldlog hashmap hashmap listfiles messageinvalidexception protocolerrormessage file_not_found canread isfile filebucket filebucket getname manifestelement getname getname defaultmimetypes guessmimetype getname isdirectory hashmap makebucketsbyname getname getname getname allowunreadablefiles messageinvalidexception protocolerrormessage file_not_found allowunreadablefiles messageinvalidexception protocolerrormessage file_not_found override long data length return 0 datalength string get identifier return identifier getidentifier override public void read from input stream is bucket factory bf fcp server server throws io exception message invalid exception do nothing readfrom inputstream bucketfactory fcpserver ioexception messageinvalidexception override protected void write data output stream os throws io exception do nothing writedata outputstream ioexception override public void remove from object container container container delete dirname container delete this removefrom objectcontainer private t source public string set source string source throws plugin not found exception this source check source source return get plugin name source _source setsource pluginnotfoundexception _source checksource getpluginname public t get source return source getsource _source abstract input stream get input stream throws io exception plugin not found exception inputstream getinputstream ioexception pluginnotfoundexception abstract input stream get input stream throws io exception plugin not found exception abstract t check source string source throws plugin not found exception inputstream getinputstream ioexception pluginnotfoundexception checksource pluginnotfoundexception abstract t check source string source throws plugin not found exception abstract string get plugin name string source throws plugin not found exception checksource pluginnotfoundexception getpluginname pluginnotfoundexception abstract string get plugin name string source throws plugin not found exception abstract string getsha1sum throws plugin not found exception getpluginname pluginnotfoundexception pluginnotfoundexception abstract string getsha1sum throws plugin not found exception abstract string getsha256sum throws plugin not found exception pluginnotfoundexception pluginnotfoundexception private boolean closed public multi reader bucket bucket underlying bucket underlying multireaderbucket get a reader bucket public bucket get reader bucket synchronized this if closed return null bucket d new reader bucket if readers null readers new array list bucket 1 readers add d if logger should log logger minor this logger minor this get reader bucket returning d for this for bucket return d getreaderbucket readerbucket arraylist shouldlog getreaderbucket public void free if logger should log logger minor this logger minor this reader bucket this for multi reader bucket this free ing for bucket synchronized multi reader bucket this if freed return freed true readers remove this if readers is empty return readers null if closed return closed true bucket free shouldlog readerbucket multireaderbucket multireaderbucket isempty public input stream get input stream throws io exception synchronized multi reader bucket this if freed closed throw new io exception already freed return new reader bucket input stream inputstream getinputstream ioexception multireaderbucket ioexception readerbucketinputstream input stream is reader bucket input stream throws io exception is bucket get input stream inputstream readerbucketinputstream ioexception getinputstream override public final int read throws io exception synchronized multi reader bucket this if freed closed throw new io exception already closed return is read ioexception multireaderbucket ioexception override public final int read byte data int offset int length throws io exception synchronized multi reader bucket this if freed closed throw new io exception already closed return is read data offset length ioexception multireaderbucket ioexception override public final int read byte data throws io exception synchronized multi reader bucket this if freed closed throw new io exception already closed return is read data ioexception multireaderbucket ioexception override public final void close throws io exception is close ioexception public string get name return bucket get name getname getname public output stream get output stream throws io exception throw new io exception read only outputstream getoutputstream ioexception ioexception public boolean is read only return true isreadonly public void set read only already read only setreadonly public long size return bucket size override protected void finalize free public void store to object container container container store this storeto objectcontainer public void remove from object container container container delete this synchronized multi reader bucket this if closed return bucket remove from container container delete readers container delete multi reader bucket this removefrom objectcontainer multireaderbucket removefrom multireaderbucket public bucket create shadow throws io exception return null createshadow ioexception override public own introduction puzzle generate puzzle introduction puzzle store store own identity inserter throws io exception byte array output stream out new byte array output stream 10 1024 todo find out the maximum size of the captchas and put it here try default kaptcha captcha new default kaptcha captcha set config new config new properties string text captcha create text buffered image img captcha create image text imageio write img jpg out date date of insertion current timeutc get synchronized store own introduction puzzle puzzle new own introduction puzzle inserter puzzle type captcha image jpeg out to byte array text date of insertion store get free index inserter date of insertion store store and commit puzzle return puzzle finally closer close out ownintroductionpuzzle generatepuzzle introductionpuzzlestore ownidentity ioexception bytearrayoutputstream bytearrayoutputstream defaultkaptcha defaultkaptcha setconfig createtext bufferedimage createimage dateofinsertion currenttimeutc ownintroductionpuzzle ownintroductionpuzzle puzzletype tobytearray dateofinsertion getfreeindex dateofinsertion storeandcommit private int offset public contour composite int offset this offset offset contourcomposite public composite context create context color model src color model color model dst color model rendering hints hints return new contour composite context offset src color model dst color model compositecontext createcontext colormodel srccolormodel colormodel dstcolormodel renderinghints contourcompositecontext srccolormodel dstcolormodel override public int hash code return 0 hashcode override public boolean equals object o if o instanceof contour composite return false return true contourcomposite private int offset public contour composite context int offset color model src color model color model dst color model this offset offset contourcompositecontext colormodel srccolormodel colormodel dstcolormodel public void dispose public void compose raster src raster dst in writable raster dst out int x src get minx int y src get miny int w src get width int h src get height int src pix null int src pix2 null int dst in pix null int dst out pix new int w 4 for int i 0 i h i src pix src get pixels x y w 1 src pix dst in pix dst in get pixels x y w 1 dst in pix int last alpha 0 int k 0 for int j 0 j w j int alpha src pix k 3 int alpha above i 0 src pix2 k 3 alpha if i 0 j 0 alpha last alpha 0x80 0 alpha alpha above 0x80 0 if offset i j 10 4 dst out pix k 0x00 dst out pix k 1 0x00 dst out pix k 2 0x00 else dst out pix k 0xff dst out pix k 1 0xff dst out pix k 2 0x7f dst out pix k 3 0xff else dst out pix k dst in pix k dst out pix k 1 dst in pix k 1 dst out pix k 2 dst in pix k 2 if dst out dst in dst out pix k 0xff dst out pix k 1 0 dst out pix k 2 0 dst out pix k 3 0 else dst out pix k 3 dst in pix k 3 last alpha alpha k 4 dst out set pixels x y w 1 dst out pix int t src pix src pix src pix2 src pix2 t y dstin writableraster dstout getminx getminy getwidth getheight srcpix srcpix2 dstinpix dstoutpix srcpix getpixels srcpix dstinpix dstin getpixels dstinpix lastalpha srcpix alphaabove srcpix2 lastalpha alphaabove dstoutpix dstoutpix dstoutpix dstoutpix dstoutpix dstoutpix dstoutpix dstoutpix dstinpix dstoutpix dstinpix dstoutpix dstinpix dstout dstin dstoutpix dstoutpix dstoutpix dstoutpix dstoutpix dstinpix lastalpha dstout setpixels dstoutpix srcpix srcpix srcpix2 srcpix2 private int n members private ttree nmembers private ttree ttree persistent comparator t comparator boolean unique this comparator comparator this unique unique persistentcomparator get comparator used in this collection return collection comparator public persistent comparator t get comparator return comparator persistentcomparator getcomparator public boolean recursive loading return false recursiveloading public t get object key if root null array list list new array list root find comparator key 1 key 1 list if list size 1 throw new storage error storage error key not unique else if list size 0 return null else return t list get 0 return null arraylist arraylist storageerror storageerror key_not_unique public array list t get list object from object till array list list new array list if root null root find comparator from 1 till 1 list return list arraylist getlist arraylist arraylist public array list t get list object from boolean from inclusive object till boolean till inclusive array list list new array list if root null root find comparator from from inclusive 1 0 till till inclusive 1 0 list return list arraylist getlist frominclusive tillinclusive arraylist arraylist frominclusive tillinclusive public i persistent get object from object till array list t list get list from till return i persistent list to array new i persistent list size ipersistent arraylist getlist ipersistent toarray ipersistent public i persistent get object from boolean from inclusive object till boolean till inclusive array list t list get list from from inclusive till till inclusive return i persistent list to array new i persistent list size ipersistent frominclusive tillinclusive arraylist getlist frominclusive tillinclusive ipersistent toarray ipersistent add new member to collection param obj new member return code true code if object is successfully added in the index code false code if collection was declared as unique and there is already member with such value of the key in the collection public boolean add t obj ttree page new root if root null new root new ttree page obj else ttree page page reference ref new ttree page page reference root if root insert comparator obj unique ref ttree page not unique return false new root ref pg root new root n members 1 modify return true ttreepage newroot newroot ttreepage ttreepage pagereference ttreepage pagereference ttreepage not_unique newroot newroot nmembers check if collections contains specified member return code true code if specified member belongs to the collection public boolean contains object t member return root null member null root contains object comparator member false containsobject containsobject public boolean contains t member return root null member null root contains comparator member false public boolean contains key object key return root null key null root contains key comparator key false containskey containskey remove member from collection param obj member to be removed exception storage error storage error key not found exception if there is no such key in the collection public void remove t obj if root null throw new storage error storage error key not found ttree page page reference ref new ttree page page reference root if root remove comparator obj ref ttree page not found throw new storage error storage error key not found root ref pg n members 1 modify storageerror storageerror key_not_found storageerror storageerror key_not_found ttreepage pagereference ttreepage pagereference ttreepage not_found storageerror storageerror key_not_found nmembers get number of objects in the collection return number of objects in the collection public int size return n members nmembers remove all objects from the collection public void clear if root null root prune root null n members 0 modify nmembers t tree destructor public void deallocate if root null root prune super deallocate public i persistent to persistent array if root null return empty selection i persistent arr new i persistent n members root to array arr 0 return arr ipersistent topersistentarray emptyselection ipersistent ipersistent nmembers toarray public object to array return to persistent array toarray topersistentarray get all objects in the index as array ordered by index key the runtime type of the returned array is that of the specified array if the index fits in the specified array it is returned therein otherwise a new array is allocated with the runtime type of the specified array and the size of this index p if this index fits in the specified array with room to spare i e the array has more elements than this index the element in the array immediately following the end of the index is set to tt null tt this is useful in determining the length of this index i only i if the caller knows that this index does not contain any tt null tt elements p return array of objects in the index ordered by key value public e e to array e arr if arr length n members arr e array new instance arr get class get component type n members if root null root to array i persistent arr 0 if arr length n members arr n members null return arr toarray nmembers newinstance getclass getcomponenttype nmembers toarray ipersistent nmembers nmembers ttree iterator ttree tree array list list this tree tree this list list i 1 ttreeiterator arraylist public t next if i 1 list size throw new no such element exception removed false return t list get i nosuchelementexception public int next oid return i persistent next get oid nextoid ipersistent getoid public void remove if removed i 0 i list size throw new illegal state exception tree remove i persistent list get i list remove i removed true illegalstateexception ipersistent public boolean has next return i 1 list size hasnext public iterator t iterator return iterator null null public iterable iterator t iterator object from object till return iterator from true till true iterableiterator public iterable iterator t iterator object from boolean from inclusive object till boolean till inclusive array list list new array list if root null root find comparator from from inclusive 1 0 till till inclusive 1 0 list return new ttree iterator t this list iterableiterator frominclusive tillinclusive arraylist arraylist frominclusive tillinclusive ttreeiterator clamp a value to the range 0 255 public static int clamp int c if c 0 return 0 if c 255 return 255 return c public static int interpolate int v1 int v2 float f return clamp int v1 f v2 v1 public static int brightness int rgb int r rgb 16 0xff int g rgb 8 0xff int b rgb 0xff return r g b 3 public static boolean near colors int rgb1 int rgb2 int tolerance int r1 rgb1 16 0xff int g1 rgb1 8 0xff int b1 rgb1 0xff int r2 rgb2 16 0xff int g2 rgb2 8 0xff int b2 rgb2 0xff return math abs r1 r2 tolerance math abs g1 g2 tolerance math abs b1 b2 tolerance nearcolors return rgb1 painted onto rgb2 public static int combine pixels int rgb1 int rgb2 int op return combine pixels rgb1 rgb2 op 0xff combinepixels combinepixels public static int combine pixels int rgb1 int rgb2 int op int extra alpha int channel mask return rgb2 channel mask combine pixels rgb1 channel mask rgb2 op extra alpha combinepixels extraalpha channelmask channelmask combinepixels channelmask extraalpha public static int combine pixels int rgb1 int rgb2 int op int extra alpha if op replace return rgb1 int a1 rgb1 24 0xff int r1 rgb1 16 0xff int g1 rgb1 8 0xff int b1 rgb1 0xff int a2 rgb2 24 0xff int r2 rgb2 16 0xff int g2 rgb2 8 0xff int b2 rgb2 0xff switch op case normal break case min r1 math min r1 r2 g1 math min g1 g2 b1 math min b1 b2 break case max r1 math max r1 r2 g1 math max g1 g2 b1 math max b1 b2 break case add r1 clamp r1 r2 g1 clamp g1 g2 b1 clamp b1 b2 break case subtract r1 clamp r2 r1 g1 clamp g2 g1 b1 clamp b2 b1 break case difference r1 clamp math abs r1 r2 g1 clamp math abs g1 g2 b1 clamp math abs b1 b2 break case multiply r1 clamp r1 r2 255 g1 clamp g1 g2 255 b1 clamp b1 b2 255 break case dissolve if random generator next int 0xff a1 r1 r2 g1 g2 b1 b2 break case average r1 r1 r2 2 g1 g1 g2 2 b1 b1 b2 2 break case hue case saturation case value case color color rg btohsb r1 g1 b1 hsb1 color rg btohsb r2 g2 b2 hsb2 switch op case hue hsb2 0 hsb1 0 break case saturation hsb2 1 hsb1 1 break case value hsb2 2 hsb1 2 break case color hsb2 0 hsb1 0 hsb2 1 hsb1 1 break rgb1 color hs btorgb hsb2 0 hsb2 1 hsb2 2 r1 rgb1 16 0xff g1 rgb1 8 0xff b1 rgb1 0xff break case screen r1 255 255 r1 255 r2 255 g1 255 255 g1 255 g2 255 b1 255 255 b1 255 b2 255 break case overlay int m s s 255 255 r1 255 r2 255 m r1 r2 255 r1 s r1 m 255 r1 255 s 255 255 g1 255 g2 255 m g1 g2 255 g1 s g1 m 255 g1 255 s 255 255 b1 255 b2 255 m b1 b2 255 b1 s b1 m 255 b1 255 break case clear r1 g1 b1 0xff break case dst in r1 clamp r2 a1 255 g1 clamp g2 a1 255 b1 clamp b2 a1 255 a1 clamp a2 a1 255 return a1 24 r1 16 g1 8 b1 case alpha a1 a1 a2 255 return a1 24 r2 16 g2 8 b2 case alpha to gray int na 255 a1 return a1 24 na 16 na 8 na if extra alpha 0xff a1 0xff a1 a1 extra alpha 255 int a3 255 a1 a2 255 r1 clamp r1 a1 r2 a3 255 g1 clamp g1 a1 g2 a3 255 b1 clamp b1 a1 b2 a3 255 a1 clamp a1 a3 return a1 24 r1 16 g1 8 b1 combinepixels extraalpha randomgenerator nextint rgbtohsb rgbtohsb hsbtorgb dst_in alpha_to_gray extraalpha extraalpha link items object get int i return items get i i persistent get position tree position pos int i pos page this pos index i return items get i ipersistent getposition treeposition i persistent get raw position tree position pos int i pos page this pos index i return items get raw i ipersistent getrawposition treeposition getraw object set int i object obj return items set i i persistent obj ipersistent void clear int i int len while len 0 items set object i null setobject void prune deallocate void copy int dst offs list page src int src offs int len system arraycopy src items to raw array src offs items to raw array dst offs len dstoffs listpage srcoffs torawarray srcoffs torawarray dstoffs int get max items return n leaf page items getmaxitems nleafpageitems void set item int i i persistent obj items set object i obj setitem ipersistent setobject int size return n items nitems list page clone page return new list page get storage listpage clonepage listpage getstorage list page listpage list page storage storage super storage int max get max items items storage create link max items set size max listpage getmaxitems createlink setsize i persistent remove int i i persistent obj items get i n items 1 copy i this i 1 n items i items set object n items null modify return obj ipersistent ipersistent nitems nitems setobject nitems boolean underflow return n items get max items 2 nitems getmaxitems list page add int i i persistent obj int max get max items modify if n items max copy i 1 this i n items i set item i obj n items 1 return null else list page b clone page int m max 2 if i m b copy 0 this 0 i b copy i 1 this i m i 1 copy 0 this m 1 max m 1 b set item i obj else b copy 0 this 0 m copy 0 this m i m copy i m 1 this i max i set item i m obj clear max m 1 m 1 n items max m 1 b n items m return b listpage ipersistent getmaxitems nitems nitems setitem nitems listpage clonepage setitem setitem nitems nitems i persistent get position tree position pos int i int j for j 0 i n children j j i n children j return list page items get j get position pos i ipersistent getposition treeposition nchildren nchildren listpage getposition i persistent get raw position tree position pos int i int j for j 0 i n children j j i n children j return list page items get j get raw position pos i ipersistent getrawposition treeposition nchildren nchildren listpage getrawposition object get int i int j for j 0 i n children j j i n children j return list page items get j get i nchildren nchildren listpage object set int i object obj int j for j 0 i n children j j i n children j return list page items get j set i obj nchildren nchildren listpage list page add int i i persistent obj int j for j 0 i n children j j i n children j list page pg list page items get j list page overflow pg add i obj if overflow null count children j pg overflow super add j overflow else modify if n children j integer max value n children j 1 return overflow listpage ipersistent nchildren nchildren listpage listpage listpage countchildren nchildren max_value nchildren i persistent remove int i int j for j 0 i n children j j i n children j list page pg list page items get j i persistent obj pg remove i modify if pg underflow handle page underflow pg j else if n children j integer max value n children j 1 return obj ipersistent nchildren nchildren listpage listpage ipersistent handlepageunderflow nchildren max_value nchildren void count children int i list page pg if n children i integer max value n children i pg size countchildren listpage nchildren max_value nchildren void prune for int i 0 i n items i list page items get i prune deallocate nitems listpage void handle page underflow list page a int r int an a n items int max a get max items if r 1 n items exists greater page list page b list page items get r 1 int bn b n items assert that bn an if an bn max reallocation of nodes between pages a and b int i bn an bn 1 b modify a copy an b 0 i b copy 0 b i bn i b clear bn i i b n items i a n items i n children r a size count children r 1 b else merge page b to a a copy an b 0 bn a n items bn n items 1 n children r n children r 1 copy r 1 this r 2 n items r 1 count children r a items set n items null b deallocate else page b is before a list page b list page items get r 1 int bn b n items assert that bn an b modify if an bn max reallocation of nodes between pages a and b int i bn an bn 1 a copy i a 0 an a copy 0 b bn i i b clear bn i i b n items i a n items i n children r 1 b size count children r a else merge page b to a b copy bn a 0 an b n items an n items 1 n children r 1 n children r count children r 1 b items set r null a deallocate handlepageunderflow listpage nitems getmaxitems nitems listpage listpage nitems nitems nitems nchildren countchildren nitems nitems nchildren nchildren nitems countchildren nitems listpage listpage nitems nitems nitems nchildren countchildren nitems nitems nchildren nchildren countchildren void copy int dst offs list page src int src offs int len super copy dst offs src src offs len system arraycopy list intermediate page src n children src offs n children dst offs len dstoffs listpage srcoffs dstoffs srcoffs listintermediatepage nchildren srcoffs nchildren dstoffs int get max items return n intermediate page items getmaxitems nintermediatepageitems void set item int i i persistent obj super set item i obj n children i list page obj size setitem ipersistent setitem nchildren listpage int size if n children n items 1 integer max value return integer max value else int n 0 for int i 0 i n items i n n children i return n nchildren nitems max_value max_value nitems nchildren list page clone page return new list intermediate page get storage listpage clonepage listintermediatepage getstorage list intermediate page listintermediatepage list intermediate page list intermediate page storage storage super storage n children new int n intermediate page items listintermediatepage listintermediatepage nchildren nintermediatepageitems public e get int i if i 0 i n elems throw new index out of bounds exception index i size n elems return e root get i nelems indexoutofboundsexception nelems e get position tree position pos int i if i 0 i n elems throw new index out of bounds exception index i size n elems if pos page null i pos index i pos index pos page n items return e pos page items get i pos index pos index i return e root get position pos i getposition treeposition nelems indexoutofboundsexception nelems nitems getposition i persistent get raw position tree position pos int i if i 0 i n elems throw new index out of bounds exception index i size n elems if pos page null i pos index i pos index pos page n items return pos page items get raw i pos index pos index i return root get raw position pos i ipersistent getrawposition treeposition nelems indexoutofboundsexception nelems nitems getraw getrawposition public e set int i e obj if i 0 i n elems throw new index out of bounds exception index i size n elems return e root set i obj nelems indexoutofboundsexception nelems public object to array int n n elems object arr new object n iterator e iterator list iterator 0 for int i 0 i n i arr i iterator next return arr toarray nelems listiterator public t t to array t arr int n n elems if arr length n arr t array new instance arr get class get component type n iterator e iterator list iterator 0 for int i 0 i n i arr i t iterator next return arr toarray nelems newinstance getclass getcomponenttype listiterator public boolean is empty return n elems 0 isempty nelems public int size return n elems nelems public boolean contains object o iterator e iterator if o null while e has next if e next null return true else while e has next if o equals e next return true return false hasnext hasnext public boolean add e o add n elems o return true nelems public void add int i e o if i 0 i n elems throw new index out of bounds exception index i size n elems i persistent obj i persistent o list page overflow root add i obj if overflow null list intermediate page pg new list intermediate page get storage pg set item 0 overflow pg items set object 1 root pg n children 1 integer max value pg n items 2 root pg n elems 1 mod count 1 modify nelems indexoutofboundsexception nelems ipersistent ipersistent listpage listintermediatepage listintermediatepage getstorage setitem setobject nchildren max_value nitems nelems modcount public e remove int i if i 0 i n elems throw new index out of bounds exception index i size n elems e obj e root remove i if root n items 1 root instanceof list intermediate page list page new root list page root items get 0 root deallocate root new root n elems 1 mod count 1 modify return obj nelems indexoutofboundsexception nelems nitems listintermediatepage listpage newroot listpage newroot nelems modcount public void clear mod count 1 root prune root new list page get storage n elems 0 modify modcount listpage getstorage nelems public int index of object o list iterator e e list iterator if o null while e has next if e next null return e previous index else while e has next if o equals e next return e previous index return 1 indexof listiterator listiterator hasnext previousindex hasnext previousindex public int last index of object o list iterator e e list iterator size if o null while e has previous if e previous null return e next index else while e has previous if o equals e previous return e next index return 1 lastindexof listiterator listiterator hasprevious nextindex hasprevious nextindex public boolean add all int index collection extends e c boolean modified false iterator extends e e c iterator while e has next add index e next modified true return modified addall hasnext public iterator e iterator return new itr public list iterator e list iterator return list iterator 0 listiterator listiterator listiterator public list iterator e list iterator int index if index 0 index size throw new index out of bounds exception index index return new list itr index listiterator listiterator indexoutofboundsexception listitr int expected mod count mod count public boolean has next return cursor size expectedmodcount modcount hasnext public int next oid check for comodification try int oid get raw position this cursor get oid last ret cursor return oid catch index out of bounds exception e check for comodification throw new no such element exception nextoid checkforcomodification getrawposition getoid lastret indexoutofboundsexception checkforcomodification nosuchelementexception public e next check for comodification try e next get position this cursor last ret cursor return next catch index out of bounds exception e check for comodification throw new no such element exception checkforcomodification getposition lastret indexoutofboundsexception checkforcomodification nosuchelementexception public void remove if last ret 1 throw new illegal state exception check for comodification try persistent list impl this remove last ret if last ret cursor cursor page null last ret 1 expected mod count mod count catch index out of bounds exception e throw new concurrent modification exception lastret illegalstateexception checkforcomodification persistentlistimpl lastret lastret lastret expectedmodcount modcount indexoutofboundsexception concurrentmodificationexception final void check for comodification if mod count expected mod count throw new concurrent modification exception checkforcomodification modcount expectedmodcount concurrentmodificationexception private class list itr extends itr implements list iterator e list itr int index cursor index listitr listiterator listitr public boolean has previous return cursor 0 hasprevious public e previous check for comodification try int i cursor 1 e previous get position this i last ret cursor i return previous catch index out of bounds exception e check for comodification throw new no such element exception checkforcomodification getposition lastret indexoutofboundsexception checkforcomodification nosuchelementexception public int next index return cursor nextindex public int previous index return cursor 1 previousindex public void set e o if last ret 1 throw new illegal state exception check for comodification try persistent list impl this set last ret o expected mod count mod count catch index out of bounds exception e throw new concurrent modification exception lastret illegalstateexception checkforcomodification persistentlistimpl lastret expectedmodcount modcount indexoutofboundsexception concurrentmodificationexception public void add e o check for comodification try persistent list impl this add cursor o last ret 1 page null expected mod count mod count catch index out of bounds exception e throw new concurrent modification exception checkforcomodification persistentlistimpl lastret expectedmodcount modcount indexoutofboundsexception concurrentmodificationexception public list e sub list int from index int to index return new sub list e this from index to index sublist fromindex toindex sublist fromindex toindex protected void remove range int from index int to index while from index to index remove from index to index 1 removerange fromindex toindex fromindex toindex fromindex toindex persistent list impl persistentlistimpl persistent list impl persistent list impl storage storage super storage root new list page storage persistentlistimpl persistentlistimpl listpage sub list persistent list impl e list int from index int to index if from index 0 throw new index out of bounds exception from index from index if to index list size throw new index out of bounds exception to index to index if from index to index throw new illegal argument exception from index from index to index to index l list offset from index size to index from index expected mod count l mod count sublist persistentlistimpl fromindex toindex fromindex indexoutofboundsexception fromindex fromindex toindex indexoutofboundsexception toindex toindex fromindex toindex illegalargumentexception fromindex fromindex toindex toindex fromindex toindex fromindex expectedmodcount modcount public e set int index e element range check index check for comodification return l set index offset element rangecheck checkforcomodification public e get int index range check index check for comodification return l get index offset rangecheck checkforcomodification public int size check for comodification return size checkforcomodification public void add int index e element if index 0 index size throw new index out of bounds exception check for comodification l add index offset element expected mod count l mod count size mod count indexoutofboundsexception checkforcomodification expectedmodcount modcount modcount public e remove int index range check index check for comodification e result l remove index offset expected mod count l mod count size mod count return result rangecheck checkforcomodification expectedmodcount modcount modcount protected void remove range int from index int to index check for comodification l remove range from index offset to index offset expected mod count l mod count size to index from index mod count removerange fromindex toindex checkforcomodification removerange fromindex toindex expectedmodcount modcount toindex fromindex modcount public boolean add all collection extends e c return add all size c addall addall public boolean add all int index collection extends e c if index 0 index size throw new index out of bounds exception index index size size int c size c size if c size 0 return false check for comodification l add all offset index c expected mod count l mod count size c size mod count return true addall indexoutofboundsexception csize csize checkforcomodification addall expectedmodcount modcount csize modcount public iterator e iterator return list iterator listiterator public list iterator e list iterator final int index check for comodification if index 0 index size throw new index out of bounds exception index index size size return new list iterator e private list iterator e i l list iterator index offset public boolean has next return next index size public e next if has next return i next else throw new no such element exception public boolean has previous return previous index 0 public e previous if has previous return i previous else throw new no such element exception public int next index return i next index offset public int previous index return i previous index offset public void remove i remove expected mod count l mod count size mod count public void set e o i set o public void add e o i add o expected mod count l mod count size mod count listiterator listiterator checkforcomodification indexoutofboundsexception listiterator listiterator listiterator hasnext nextindex hasnext nosuchelementexception hasprevious previousindex hasprevious nosuchelementexception nextindex nextindex previousindex previousindex expectedmodcount modcount modcount expectedmodcount modcount modcount private list iterator e i l list iterator index offset public boolean has next return next index size listiterator listiterator hasnext nextindex public e next if has next return i next else throw new no such element exception hasnext nosuchelementexception public boolean has previous return previous index 0 hasprevious previousindex public e previous if has previous return i previous else throw new no such element exception hasprevious nosuchelementexception public int next index return i next index offset nextindex nextindex public int previous index return i previous index offset previousindex previousindex public void remove i remove expected mod count l mod count size mod count expectedmodcount modcount modcount public void set e o i set o public void add e o i add o expected mod count l mod count size mod count expectedmodcount modcount modcount public list e sub list int from index int to index return new sub list e l offset from index offset to index sublist fromindex toindex sublist fromindex toindex private void range check int index if index 0 index size throw new index out of bounds exception index index size size rangecheck indexoutofboundsexception private void check for comodification if l mod count expected mod count throw new concurrent modification exception checkforcomodification modcount expectedmodcount concurrentmodificationexception public class service data extends node data public service data servicedata nodedata servicedata private listener list control action listener list new listener list public listener list get control action listener list return control action listener list listenerlist controlactionlistenerlist listenerlist listenerlist getcontrolactionlistenerlist controlactionlistenerlist private node scpd node null public node getscpd node return scpd node scpdnode getscpdnode scpdnode public void setscpd node node node scpd node node setscpdnode scpdnode private subscriber list subscriber list new subscriber list public subscriber list get subscriber list return subscriber list subscriberlist subscriberlist subscriberlist subscriberlist getsubscriberlist subscriberlist private string sid public string getsid return sid public void setsid string id sid id private long timeout 0 public long get timeout return timeout gettimeout public void set timeout long value timeout value settimeout public http response set content type html content type set server http server get name set content httpresponse setcontenttype content_type setserver httpserver getname setcontent public http response http response http res set http res httpresponse httpresponse httpres httpres public http response input stream in super in httpresponse inputstream public http response http socket http sock this http sock get input stream httpresponse httpsocket httpsock httpsock getinputstream private int status code 0 public void set status code int code status code code statuscode setstatuscode statuscode public int get status code if status code 0 return status code http status http status new http status get first line return http status get status code getstatuscode statuscode statuscode httpstatus httpstatus httpstatus getfirstline httpstatus getstatuscode public boolean is successful return http status is successful get status code issuccessful httpstatus issuccessful getstatuscode public string get status line string return http get version get status code http status code2 string status code http crlf getstatuslinestring getversion getstatuscode httpstatus code2string statuscode public string get header string builder str new string builder str append get status line string str append get header string return str to string getheader stringbuilder stringbuilder getstatuslinestring getheaderstring tostring public string to string string builder str new string builder str append get status line string str append get header string str append http crlf str append get content string return str to string tostring stringbuilder stringbuilder getstatuslinestring getheaderstring getcontentstring tostring public void print system out println to string tostring public class life filter extends binary filter public life filter lifefilter binaryfilter lifefilter override protected int filter pixels int width int height int in pixels rectangle transformed space int index 0 int out pixels new int width height for int y 0 y height y for int x 0 x width x int r 0 g 0 b 0 int pixel in pixels y width x int a pixel 0xff000000 int neighbours 0 for int row 1 row 1 row int iy y row int ioffset if 0 iy iy height ioffset iy width for int col 1 col 1 col int ix x col if row 0 col 0 0 ix ix width int rgb in pixels ioffset ix if black function is black rgb neighbours if black function is black pixel out pixels index neighbours 2 neighbours 3 pixel 0xffffffff else out pixels index neighbours 3 0xff000000 pixel return out pixels filterpixels inpixels transformedspace outpixels inpixels inpixels blackfunction isblack blackfunction isblack outpixels outpixels outpixels override public string to string return binary life tostring logger register log threshold callback new log threshold callback override public void should update logminor logger should log logger minor this logdebug logger should log logger debug this registerlogthresholdcallback logthresholdcallback shouldupdate shouldlog shouldlog final int receivedbytecount public static message decode message from packet byte buf int offset int length peer context peer int overhead byte buffer input stream bb new byte buffer input stream buf offset length return decode message bb peer length overhead true false _receivedbytecount decodemessagefrompacket peercontext bytebufferinputstream bytebufferinputstream decodemessage private static message decode message byte buffer input stream bb peer context peer int recv byte count boolean may have sub messages boolean in sub message message type mspec try mspec message type get spec integer value of bb read int catch io exception e1 if logdebug logger debug message class failed to read message type e1 e1 return null if mspec null return null if mspec is internal only return null silently discard internal only messages message m new message mspec peer recv byte count try for string name mspec get ordered fields class type mspec get fields get name if type equals linked list class special handling for linked list to deal with element type m set name serializer read list from data input stream mspec get linked list types get name bb else m set name serializer read from data input stream type bb if may have sub messages while bb remaining 2 sizeof unsigned short 2 byte buffer input stream bb2 try int size bb read unsigned short if bb remaining size return m bb2 bb slice size catch eof exception e if logminor logger minor message class no submessages returning m return m try message sub message decode message bb2 peer 0 false true if sub message null return m if logminor logger minor message class adding submessage sub message m add sub message sub message catch throwable t logger error message class failed to read sub message t t catch eof exception e string msg peer get peer sent a message packet that ends prematurely while deserialising mspec get name if in sub message logger minor message class msg in sub message e else logger error message class msg e return null catch io exception e logger error message class unexpected io exception e reading from buffer stream e return null if logminor logger minor message class returning message m return m decodemessage bytebufferinputstream peercontext recvbytecount mayhavesubmessages insubmessage messagetype messagetype getspec valueof readint ioexception isinternalonly recvbytecount getorderedfields getfields linkedlist linkedlist readlistfromdatainputstream getlinkedlisttypes readfromdatainputstream mayhavesubmessages bytebufferinputstream readunsignedshort eofexception submessage decodemessage submessage submessage addsubmessage submessage eofexception getpeer getname insubmessage ioexception ioexception public message message type spec this spec null 0 messagetype private message message type spec peer context source int recv byte count local instantiation time system current time millis spec spec if source null internal true sourceref null else internal false sourceref source get weak ref receivedbytecount recv byte count messagetype peercontext recvbytecount localinstantiationtime currenttimemillis _spec _internal _sourceref _internal _sourceref getweakref _receivedbytecount recvbytecount public boolean get boolean string key return boolean payload get key boolean value getboolean _payload booleanvalue public byte get byte string key return byte payload get key byte value getbyte _payload bytevalue public short get short string key return short payload get key short value getshort _payload shortvalue public int get int string key return integer payload get key int value getint _payload intvalue public long get long string key return long payload get key long value getlong _payload longvalue public double get double string key return double payload get key double value getdouble _payload doublevalue public string get string string key return string payload get key getstring _payload public object get object string key return payload get key getobject _payload public void set string key boolean b set key boolean value of b valueof public void set string key byte b set key byte value of b valueof public void set string key short s set key short value of s valueof public void set string key int i set key integer value of i valueof public void set string key long l set key long value of l valueof public void set string key double d set key new double d public void set string key object value if spec check type key value if value null throw new incorrect type exception got null for key throw new incorrect type exception got value get class expected spec type of key payload put key value _spec checktype incorrecttypeexception incorrecttypeexception getclass _spec typeof _payload public byte encode to packet peer context destination return encode to packet destination true false encodetopacket peercontext encodetopacket private byte encode to packet peer context destination boolean include sub messages boolean is sub message if this get spec message types ping this get spec message types pong logger log minor send message this if logdebug logger debug this my spec code spec get name hash code for spec get name byte array output stream baos new byte array output stream data output stream dos new data output stream baos try dos write int spec get name hash code for string name spec get ordered fields serializer write to data output stream payload get name dos destination dos flush catch io exception e e print stack trace throw new illegal state exception e get message if submessages null include sub messages for int i 0 i submessages size i byte temp submessages get i encode to packet destination false true try dos write short temp length dos write temp catch io exception e e print stack trace throw new illegal state exception e get message byte buf baos to byte array if logdebug logger debug this length buf length hash fields hash code buf return buf encodetopacket peercontext includesubmessages issubmessage getspec messagetypes getspec messagetypes logminor _spec getname hashcode _spec getname bytearrayoutputstream bytearrayoutputstream dataoutputstream dataoutputstream writeint _spec getname hashcode _spec getorderedfields writetodataoutputstream _payload ioexception printstacktrace illegalstateexception getmessage _submessages includesubmessages _submessages _submessages encodetopacket writeshort ioexception printstacktrace illegalstateexception getmessage tobytearray hashcode override public string to string string builder ret new string builder 1000 string comma ret append spec get name append for string name spec get fields key set ret append comma ret append name append append payload get name comma ret append return ret to string tostring stringbuilder stringbuilder _spec getname _spec getfields keyset _payload tostring public peer context get source return sourceref null null peer context sourceref get peercontext getsource _sourceref peercontext _sourceref public boolean is internal return internal isinternal _internal public message type get spec return spec messagetype getspec _spec public boolean is set string field name return payload contains key field name isset fieldname _payload containskey fieldname public object get from payload string field name throws field not set exception object r payload get field name if r null throw new field not set exception field name not set return r getfrompayload fieldname fieldnotsetexception _payload fieldname fieldnotsetexception fieldname private static final long serial versionuid 1l public field not set exception string message super message serialversionuid fieldnotsetexception set fields for a routed to a specific node message param node identity public void set routed to node fields long uid double target location short htl byte node identity set dmt uid uid set dmt target location target location set dmt htl htl set dmt node identity new short buffer node identity nodeidentity setroutedtonodefields targetlocation nodeidentity target_location targetlocation node_identity shortbuffer nodeidentity public int received byte count return receivedbytecount receivedbytecount _receivedbytecount public void add sub message message sub message if submessages null submessages new array list message submessages add sub message addsubmessage submessage _submessages _submessages arraylist _submessages submessage public message get sub message message type t if submessages null return null for int i 0 i submessages size i message m submessages get i if m get spec t return m return null getsubmessage messagetype _submessages _submessages _submessages getspec public message grab sub message message type t if submessages null return null for int i 0 i submessages size i message m submessages get i if m get spec t submessages remove i return m return null grabsubmessage messagetype _submessages _submessages _submessages getspec _submessages public long age return system current time millis local instantiation time currenttimemillis localinstantiationtime construct an all black colormap public array colormap this map new int 256 arraycolormap construct a colormap with the given map param map the array of argb colors public array colormap int map this map map arraycolormap override public object clone try array colormap g array colormap super clone g map int map clone return g catch clone not supported exception e return null arraycolormap arraycolormap clonenotsupportedexception set the array of colors for the colormap param map the colors see get map public void set map int map this map map getmap setmap get the array of colors for the colormap return the colors see set map public int get map return map setmap getmap convert a value in the range 0 1 to an rgb color param v a value in the range 0 1 return an rgb color see set color public int get color float v v 255 int n int v float f v n if n 0 return map 0 else if n 255 return map 255 return image math mix colors f map n map n 1 int n int v 255 if n 0 n 0 else if n 255 n 255 return map n setcolor getcolor imagemath mixcolors set the color at index to color entries are interpolated linearly from the existing entries at first index and last index to the new entry first index index last index must hold param index the position to set param first index the position of the first color from which to interpolate param last index the position of the second color from which to interpolate param color the color to set public void set color interpolated int index int first index int last index int color int first color map first index int last color map last index for int i first index i index i map i image math mix colors float i first index index first index first color color for int i index i last index i map i image math mix colors float i index last index index color last color firstindex lastindex firstindex lastindex firstindex lastindex setcolorinterpolated firstindex lastindex firstcolor firstindex lastcolor lastindex firstindex imagemath mixcolors firstindex firstindex firstcolor lastindex imagemath mixcolors lastindex lastcolor set a range of the colormap interpolating between two colors param first index the position of the first color param last index the position of the second color param color1 the first color param color2 the second color public void set color range int first index int last index int color1 int color2 for int i first index i last index i map i image math mix colors float i first index last index first index color1 color2 firstindex lastindex setcolorrange firstindex lastindex firstindex lastindex imagemath mixcolors firstindex lastindex firstindex set a range of the colormap to a single color param first index the position of the first color param last index the position of the second color param color the color public void set color range int first index int last index int color for int i first index i last index i map i color firstindex lastindex setcolorrange firstindex lastindex firstindex lastindex set one element of the colormap to a given color param index the position of the color param color the color see get color public void set color int index int color map index color getcolor setcolor public class byte buffer public final void extend int size if size arr length int new len size arr length 2 size arr length 2 byte new arr new byte new len system arraycopy arr 0 new arr 0 used arr new arr used size bytebuffer newlen newarr newlen newarr newarr final byte to array byte result new byte used system arraycopy arr 0 result 0 used return result toarray int pack string int dst string value string encoding if value null extend dst 4 bytes pack4 arr dst 1 dst 4 else int length value length if encoding null extend dst 4 2 length bytes pack4 arr dst length dst 4 for int i 0 i length i bytes pack2 arr dst short value char at i dst 2 else try byte bytes value get bytes encoding extend dst 4 bytes length bytes pack4 arr dst 2 bytes length system arraycopy bytes 0 arr dst 4 bytes length dst 4 bytes length catch unsupported encoding exception x throw new storage error storage error unsupported encoding return dst packstring charat getbytes unsupportedencodingexception storageerror storageerror unsupported_encoding class byte buffer output stream extends output stream public void write int b write new byte byte b 0 1 bytebufferoutputstream outputstream public void write byte b int off int len int pos used extend pos len system arraycopy b off arr pos len public output stream get output stream return new byte buffer output stream outputstream getoutputstream bytebufferoutputstream public int size return used byte buffer arr new byte 64 bytebuffer protected l2 list elem prev public l2 list elem next prev this l2listelem l2listelem get next list element been call for the last list element this method will return first element of the list or list header public l2 list elem get next return next l2listelem getnext get previous list element been call for the first list element this method will return last element of the list or list header public l2 list elem get prev return prev l2listelem getprev make list empty this method should be applied to list header public void prune modify next prev this link specified element in the list after this element param elem element to be linked in the list after this elemen public void link after l2 list elem elem modify next modify elem modify elem next next elem prev this next prev elem next elem linkafter l2listelem link specified element in the list before this element param elem element to be linked in the list before this elemen public void link before l2 list elem elem modify prev modify elem modify elem next this elem prev prev prev next elem prev elem linkbefore l2listelem remove element from the list public void unlink next modify prev modify next prev prev prev next next construct a new empty frost message object public frost message frostmessageobject frostmessage public frost message string base frost board b string from string subject string content set base base set board b set name from if subject null subject equals set subject subject set content content frostmessage frostboard setbase setboard setname setsubject setcontent public string get date and time if date and time null java text simple date format date format new java text simple date format yyyy mm dd hh mm ssz date format set time zone time zone get time zone gmt date and time date format format new date return date and time getdateandtime dateandtime simpledateformat dateformat simpledateformat dateformat settimezone timezone gettimezone dateandtime dateformat dateandtime 2006 9 6 if not pad public string get date str boolean pad string date str java text simple date format date format if pad date format new java text simple date format yyyy mm dd else date format new java text simple date format yyyy m d date format set time zone time zone get time zone gmt date str date format format new date return date str getdatestr datestr simpledateformat dateformat dateformat simpledateformat dateformat simpledateformat dateformat settimezone timezone gettimezone datestr dateformat datestr 02 01 53gmt public string get time str if time str null java text simple date format date format new java text simple date format hh mm ssz date format set time zone time zone get time zone gmt time str date format format new date return time str gettimestr timestr simpledateformat dateformat simpledateformat dateformat settimezone timezone gettimezone timestr dateformat timestr public frost board get board return board frostboard getboard public void set board frost board board this board board setboard frostboard public string get name return name getname public string get id random rnd new random new date get time string builder sb new string builder for int i 0 i 4 i sb append long to hex string rnd next long to upper case return sb to string getid gettime stringbuilder stringbuilder tohexstring nextlong touppercase tostring public void set name string name this name name setname dummy public boolean contains attachments return false containsattachments public int get index return index getindex public void set index int index this index index setindex public string get invalid reason return invalid reason getinvalidreason invalidreason public void set invalid reason string invalid reason this invalid reason invalid reason setinvalidreason invalidreason invalidreason invalidreason public boolean is valid return is valid isvalid isvalid public void set valid boolean is valid this is valid is valid setvalid isvalid isvalid isvalid override public string to string return get subject tostring getsubject return get subject public string get content return content getsubject getcontent return content public string get subject return subject getsubject public void set content string content this content content setcontent this content content public void set subject string subject this subject subject setsubject public void set base string base this base base setbase hack private final string get xml if xml null string message content new string builder append append this get name append append this get date str true append append this get time str append n n append this get content to string string builder sb new string builder sb append xml version 1 0 encoding utf 8 n sb append frost message sb append message id cdata append this get id append message id sb append in reply to in reply to sb append from cdata append this get name append from sb append subject cdata append this get subject append subject non padded string sb append date cdata append this get date str false append date format 02 01 53gmt sb append time cdata append this get time str append time might be a good idea to add anon 2006 09 13 01 53 20gmt sb append body cdata append message content append body sb append board cdata append this get board get name append board sb append signature status cdata old signature status sb append frost message xml sb to string return xml getxml messagecontent stringbuilder getname getdatestr gettimestr getcontent tostring stringbuilder stringbuilder frostmessage messageid getid messageid inreplyto inreplyto getname getsubject getdatestr gettimestr messagecontent getboard getname signaturestatus signaturestatus frostmessage tostring public string get message base return base getmessagebase this method composes the uploading key for the message given a certain index number param index index number to use to compose the key return they composed key public freeneturi compose upload key int index throws malformedurl exception freeneturi key if board is write access board key new freeneturi new string builder append board get private key append append board get name append append this get date str false append append index append xml to string else key new freeneturi ksk new string builder append frost message append this get message base append append this get date str false append append board get name append append index append xml to string system err println fin key is key to string return key composeuploadkey malformedurlexception iswriteaccessboard stringbuilder getprivatekey getname getdatestr tostring stringbuilder getmessagebase getdatestr getname tostring tostring public final freeneturi insert message high level simple client client int innitial index throws insert exception malformedurl exception boolean keepgoing freeneturi key null freeneturi return key null string type text xml int more tries 50 byte data try data this get xml get bytes utf 8 catch unsupported encoding exception e1 throw new error impossible jvm doesn t support utf 8 e1 e1 insert block block null do until the message is inserted key this compose upload key innitial index keepgoing false block new insert block new array bucket data new client metadata type key try inserting the message with the key try return key client insert block false null i don t know what that false is catch insert exception e system err println fin insert failed with the message e get message if more tries 0 throw e keepgoing true innitial index while keepgoing return return key insertmessage highlevelsimpleclient innitialindex insertexception malformedurlexception returnkey moretries getxml getbytes unsupportedencodingexception insertblock composeuploadkey innitialindex insertblock arraybucket clientmetadata returnkey insertexception getmessage moretries innitialindex returnkey construct a kaleidoscope filter with no distortion public kaleidoscope filter set edge action clamp kaleidoscopefilter kaleidoscopefilter setedgeaction set the number of sides of the kaleidoscope param sides the number of sides min value 2 see get sides public void set sides int sides this sides sides getsides setsides get the number of sides of the kaleidoscope return the number of sides see set sides public int get sides return sides setsides getsides set the angle of the kaleidoscope param angle the angle of the kaleidoscope angle see get angle public void set angle float angle this angle angle getangle setangle get the angle of the kaleidoscope return the angle of the kaleidoscope see set angle public float get angle return angle setangle getangle set the secondary angle of the kaleidoscope param angle2 the angle angle see get angle2 public void set angle2 float angle2 this angle2 angle2 getangle2 setangle2 get the secondary angle of the kaleidoscope return the angle see set angle2 public float get angle2 return angle2 setangle2 getangle2 set the centre of the effect in the x direction as a proportion of the image size param centrex the center see get centrex public void set centrex float centrex this centrex centrex getcentrex setcentrex get the centre of the effect in the x direction as a proportion of the image size return the center see set centrex public float get centrex return centrex setcentrex getcentrex set the centre of the effect in the y direction as a proportion of the image size param centrey the center see get centrey public void set centrey float centrey this centrey centrey getcentrey setcentrey get the centre of the effect in the y direction as a proportion of the image size return the center see set centrey public float get centrey return centrey setcentrey getcentrey set the centre of the effect as a proportion of the image size param centre the center see get centre public void set centre point2d centre this centrex float centre getx this centrey float centre gety getcentre setcentre get the centre of the effect as a proportion of the image size return the center see set centre public point2d get centre return new point2d float centrex centrey setcentre getcentre set the radius of the effect param radius the radius min value 0 see get radius public void set radius float radius this radius radius getradius setradius get the radius of the effect return the radius see set radius public float get radius return radius setradius getradius override public buffered image filter buffered image src buffered image dst icentrex src get width centrex icentrey src get height centrey return super filter src dst bufferedimage bufferedimage bufferedimage getwidth getheight override protected void transform inverse int x int y float out double dx x icentrex double dy y icentrey double r math sqrt dx dx dy dy double theta math atan2 dy dx angle angle2 theta image math triangle float theta math pi sides 5 if radius 0 double c math cos theta double radiusc radius c r radiusc image math triangle float r radiusc theta angle out 0 float icentrex r math cos theta out 1 float icentrey r math sin theta transforminverse imagemath imagemath override public string to string return distort kaleidoscope tostring public argument list argumentlist public argument get argument int n return argument get n getargument public argument get argument string name int n args size for int n 0 n n args n argument arg get argument n string arg name arg get name if arg name null continue if arg name equals name true return arg return null getargument nargs nargs getargument argname getname argname argname public void set argument list in arg list int n in args in arg list size for int n 0 n n in args n argument in arg in arg list get argument n string in arg name in arg get name argument arg get argument in arg name if arg null continue arg set value in arg get value argumentlist inarglist ninargs inarglist ninargs inarg inarglist getargument inargname inarg getname getargument inargname setvalue inarg getvalue get version history containing this versioned object public synchronized version history get version history return history versionhistory getversionhistory get predecessors of this version return array of predecessor versions public synchronized version get predecessors return predecessors to array new version predecessors size getpredecessors toarray get successors of this version return array of predecessor versions public synchronized version get successors return successors to array new version successors size getsuccessors toarray check if version is checked in return code true code if version belongs to version history public boolean is checked in return id null ischeckedin check if version is checked out return code true code if version is cjust created and not checked in yet and so belongs to version history public boolean is checked out return id null ischeckedout create new version which will be direct successor of this version this version has to be checked in in order to be placed in version history public version new version try version new version version clone new version predecessors get storage version create link 1 new version predecessors add this new version successors get storage version create link 1 new version labels new string 0 new version id null new version oid 0 new version state 0 return new version catch clone not supported exception x could not happen sense we clone ourselves throw new assertion failed clone not supported newversion newversion newversion getstorage createlink newversion newversion getstorage createlink newversion newversion newversion newversion newversion clonenotsupportedexception assertionfailed check in new version this method inserts in version history version created by code version new version code or code version history checkout code method public void checkin synchronized history assert that is checked out for int i 0 i predecessors size i version predecessor predecessors get i synchronized predecessor if i 0 id predecessor construct id predecessor successors add this date new date history versions add this history current this modify newversion versionhistory ischeckedout constructid make specified version predecessor of this version this method can be used to perfrom merge of two versions merging of version data should be done by application itself param predecessor version to merged with public void add predecessor version predecessor synchronized predecessor synchronized this predecessors add predecessor if is checked in predecessor successors add this addpredecessor ischeckedin get date of version creation return date when this version was created public date get date return date getdate get labels associated with this version return array of labels assigned to this version public synchronized string get labels return labels getlabels add new label to this version param label label to be associated with this version public synchronized void add label string label string new labels new string labels length 1 system arraycopy labels 0 new labels 0 labels length new labels new labels length 1 label labels new labels modify addlabel newlabels newlabels newlabels newlabels newlabels check if version has specified label param label version label public synchronized boolean has label string label for int i 0 i labels length i if labels i equals label return true return false haslabel get identifier of the version return version identifier automatically assigned by system public string get id return id getid constructor of root version all other versions should be created using code version new version code or code version history checkout code methods protected version storage storage super storage successors storage create link 1 predecessors storage create link 1 labels new string 0 date new date id 1 newversion versionhistory createlink createlink default constuctor not directly accessible private version private string construct id int suffix pos id last index of int suffix integer parse int id substring suffix pos 1 string next id suffix pos 0 integer to string suffix 1 id substring 0 suffix pos integer to string suffix 1 if successors size 0 next id successors size 1 return next id constructid suffixpos lastindexof parseint suffixpos nextid suffixpos tostring suffixpos tostring nextid nextid return the random text public string get text int length get config get text producer char length char chars get config get text producer char string int random context chars length 1 random rand new random string buffer text new string buffer for int i 0 i length i text append chars rand next int random context 1 return text to string gettext getconfig gettextproducercharlength getconfig gettextproducercharstring randomcontext stringbuffer stringbuffer nextint randomcontext tostring private boolean read only public array bucket this array bucket readonly arraybucket arraybucket public array bucket byte initdata this array bucket data initdata arraybucket arraybucket public array bucket string name data new byte 0 this name name arraybucket public output stream get output stream throws io exception if read only throw new io exception read only return new array bucket output stream outputstream getoutputstream ioexception readonly ioexception arraybucketoutputstream public input stream get input stream return new byte array input stream data inputstream getinputstream bytearrayinputstream override public string to string return new string data tostring public long size return data length public string get name return name getname private boolean has been closed false public array bucket output stream super hasbeenclosed arraybucketoutputstream override public synchronized void close throws io exception if has been closed return data super to byte array if read only throw new io exception read only fixme maybe we should throw on write instead has been closed true ioexception hasbeenclosed tobytearray readonly ioexception hasbeenclosed public boolean is read only return read only isreadonly readonly public void set read only read only true setreadonly readonly public void free data new byte 0 not much else we can do public byte to byte array long sz size int size int sz byte buf new byte size system arraycopy data 0 buf 0 size return buf tobytearray public void store to object container container container store data container store this storeto objectcontainer public void remove from object container container container delete data container delete this removefrom objectcontainer public bucket create shadow throws io exception return null createshadow ioexception private node icon node public node get icon node return icon node iconnode geticonnode iconnode public icon node node icon node node iconnode public static boolean is icon node node node return icon elem name equals node get name isiconnode elem_name getname private final static string mime type mime type public void set mime type string value get icon node set node mime type value mime_type mimetype setmimetype geticonnode setnode mime_type public string get mime type return get icon node get node value mime type getmimetype geticonnode getnodevalue mime_type private final static string width width public void set width string value get icon node set node width value setwidth geticonnode setnode public string get width return get icon node get node value width getwidth geticonnode getnodevalue private final static string height height public void set height string value get icon node set node height value setheight geticonnode setnode public string get height return get icon node get node value height getheight geticonnode getnodevalue private final static string depth depth public void set depth string value get icon node set node depth value setdepth geticonnode setnode public string get depth return get icon node get node value depth getdepth geticonnode getnodevalue private final static string url url public void seturl string value get icon node set node url value geticonnode setnode public string geturl return get icon node get node value url geticonnode getnodevalue private final boolean auto register public proxy user alert user alert manager uam boolean auto register this uam uam this auto register auto register autoregister proxyuseralert useralertmanager autoregister autoregister autoregister public void set alert user alert a user alert old alert alert a if auto register if old null alert null uam register this if auto register if alert null uam unregister this setalert useralert useralert autoregister autoregister public boolean user can dismiss return alert user can dismiss usercandismiss usercandismiss public string get title return alert get title gettitle gettitle public string get text return alert get text gettext gettext public html node gethtml text return alert gethtml text htmlnode gethtmltext gethtmltext public short get priority class return alert get priority class getpriorityclass getpriorityclass public boolean is valid return alert null alert is valid isvalid isvalid public void is valid boolean validity if alert null alert is valid validity isvalid isvalid public string dismiss button text return alert dismiss button text dismissbuttontext dismissbuttontext public boolean should unregister on dismiss return alert should unregister on dismiss shouldunregisterondismiss shouldunregisterondismiss public void on dismiss if alert null alert on dismiss ondismiss ondismiss inherit doc public object get user identifier return alert get user identifier inheritdoc getuseridentifier getuseridentifier public string anchor return anchor integer to string hash code tostring hashcode public string get short text return alert get short text getshorttext getshorttext public boolean is event notification if alert null return false return alert is event notification iseventnotification iseventnotification construct a whole image filter public whole image filter wholeimagefilter wholeimagefilter public buffered image filter buffered image src buffered image dst int width src get width int height src get height int type src get type writable raster src raster src get raster original space new rectangle 0 0 width height transformed space new rectangle 0 0 width height transform space transformed space if dst null color model dstcm src get color model dst new buffered image dstcm dstcm create compatible writable raster transformed space width transformed space height dstcm is alpha premultiplied null writable raster dst raster dst get raster int in pixels getrgb src 0 0 width height null in pixels filter pixels width height in pixels transformed space setrgb dst 0 0 transformed space width transformed space height in pixels return dst bufferedimage bufferedimage bufferedimage getwidth getheight gettype writableraster srcraster getraster originalspace transformedspace transformspace transformedspace colormodel getcolormodel bufferedimage createcompatiblewritableraster transformedspace transformedspace isalphapremultiplied writableraster dstraster getraster inpixels inpixels filterpixels inpixels transformedspace transformedspace transformedspace inpixels calculate output bounds for given input bounds param rect input and output rectangle protected void transform space rectangle rect transformspace actually filter the pixels param width the image width param height the image height param in pixels the image pixels param transformed space the output bounds return the output pixels inpixels transformedspace public modify config simple field set fs this fs fs this identifier fs get identifier fs remove value identifier modifyconfig simplefieldset removevalue override public simple field set get field set return new simple field set true simplefieldset getfieldset simplefieldset override public string get name return name getname override public void run fcp connection handler handler node node throws message invalid exception if handler has full access throw new message invalid exception protocol error message access denied modify config requires full access identifier false config config node config sub config sc config get configs boolean logminor logger should log logger minor this for int i 0 i sc length i option o sc i get options string prefix sc i get prefix string config name for int j 0 j o length j config name o j get name if logminor logger minor this setting prefix config name we ignore unreconized parameters if fs get prefix config name null if o j get value string equals fs get prefix config name if logminor logger minor this setting prefix config name to fs get prefix config name try o j set value fs get prefix config name catch exception e bad values silently fail from an fcp perspective but the fcp client can tell if a change took by comparing config data messages before and after logger error this caught e e node client core store config handler output handler queue new config data node true false false false false false false false identifier fcpconnectionhandler messageinvalidexception hasfullaccess messageinvalidexception protocolerrormessage access_denied modifyconfig subconfig getconfigs shouldlog getoptions getprefix configname configname getname configname configname getvaluestring configname configname configname setvalue configname configdata clientcore storeconfig outputhandler configdata override public void remove from object container container throw new unsupported operation exception removefrom objectcontainer unsupportedoperationexception logger register log threshold callback new log threshold callback override public void should update logminor logger should log logger minor this registerlogthresholdcallback logthresholdcallback shouldupdate shouldlog override public object clone try return super clone catch clone not supported exception e throw new error yes it is clonenotsupportedexception parse a block of bytes into a metadata structure constructor method because of need to catch impossible exceptions throws metadata parse exception if the metadata is invalid public static metadata construct byte data throws metadata parse exception try return new metadata data catch io exception e metadata parse exception e1 new metadata parse exception caught e e1 init cause e throw e1 metadataparseexception metadataparseexception ioexception metadataparseexception metadataparseexception initcause parse a bucket of data into a metadata structure throws metadata parse exception if the parsing failed because of invalid metadata throws io exception if we could not read the metadata from the bucket public static metadata construct bucket data throws metadata parse exception io exception input stream is data get input stream buffered input stream bis new buffered input stream is 4096 metadata m try data input stream dis new data input stream bis m new metadata dis data size finally is close return m metadataparseexception ioexception metadataparseexception ioexception inputstream getinputstream bufferedinputstream bufferedinputstream datainputstream datainputstream parse some metadata from a byte throws io exception if the data is incomplete or something wierd happens throws metadata parse exception private metadata byte data throws io exception metadata parse exception this new data input stream new byte array input stream data data length ioexception metadataparseexception ioexception metadataparseexception datainputstream bytearrayinputstream override public int hash code return hash code hashcode hashcode parse some metadata from a data input stream throws io exception if an i o error occurs or the data is incomplete public metadata data input stream dis long length throws io exception metadata parse exception hash code super hash code long magic dis read long if magic freenet metadata magic throw new metadata parse exception invalid magic magic short version dis read short if version 0 throw new metadata parse exception unsupported version version document type dis read byte if document type 0 document type 5 throw new metadata parse exception unsupported document type document type if logminor logger minor this document type document type boolean compressed false if have flags short flags dis read short splitfile flags flags splitfile flags splitfile dbr flags flags dbr flags dbr nomime flags flags no mime flags no mime compressedmime flags flags compressed mime flags compressed mime extra metadata flags flags extra metadata flags extra metadata full keys flags flags full keys flags full keys compressed flags flags compressed flags compressed if document type archive manifest if logminor logger minor this archive manifest archive type archive type get archive type dis read short if archive type null throw new metadata parse exception unrecognized archive type archive type if splitfile if logminor logger minor this splitfile data length dis read long if data length 1 throw new metadata parse exception invalid real content length data length if data length 1 if splitfile throw new metadata parse exception splitfile must have a real length if compressed compression codec compressor type get compressor by metadataid dis read short if compression codec null throw new metadata parse exception unrecognized splitfile compression codec compression codec decompressed length dis read long if nomime mime type null if logminor logger minor this nomime enabled else if compressedmime if logminor logger minor this compressed mime short x dis read short compressedmime value short x 32767 chop off last bit has compressedmime params compressedmime value 32768 32768 if has compressedmime params compressedmime params dis read short if compressedmime params 0 throw new metadata parse exception unrecognized mime params id not yet implemented mime type defaultmime types by number x else read an actual raw mime type byte l dis read byte int len l 0xff positive byte to read new byte len dis read fully to read use utf 8 for everything for simplicity mime type new string to read utf 8 if logminor logger minor this raw mime if logminor logger minor this mime mime type if dbr throw new metadata parse exception do not support db rs pending decision on putting them in the key if extra metadata int number of extra fields dis read short 0xffff for int i 0 i number of extra fields i short type dis read short int len dis read byte 0xff byte buf new byte len dis read fully buf logger normal this ignoring type type extra client metadata field of len bytes extra metadata false can t parse can t write client metadata new client metadata mime type if splitfile document type simple redirect document type archive manifest simple redirect key read key dis else if splitfile splitfile algorithm dis read short if splitfile algorithm splitfile nonredundant splitfile algorithm splitfile onion standard throw new metadata parse exception unknown splitfile algorithm splitfile algorithm if splitfile algorithm splitfile nonredundant throw new metadata parse exception non redundant splitfile invalid int params length dis read int if params length max splitfile params length throw new metadata parse exception too many bytes of splitfile parameters params length if params length 0 splitfile params new byte params length dis read fully splitfile params else if params length 0 throw new metadata parse exception invalid splitfile params length params length splitfile blocks dis read int 64tb file size limit if splitfile blocks 0 throw new metadata parse exception invalid number of blocks splitfile blocks if splitfile blocks max splitfile blocks throw new metadata parse exception too many splitfile blocks soft limit to prevent memory dos splitfile blocks splitfile check blocks dis read int if splitfile check blocks 0 throw new metadata parse exception invalid number of check blocks splitfile check blocks if splitfile check blocks max splitfile blocks throw new metadata parse exception too many splitfile check blocks soft limit to prevent memory dos splitfile check blocks splitfile data keys new clientchk splitfile blocks splitfile check keys new clientchk splitfile check blocks for int i 0 i splitfile data keys length i if splitfile data keys i readchk dis null throw new metadata parse exception null data key i for int i 0 i splitfile check keys length i if splitfile check keys i readchk dis null throw new metadata parse exception null check key i if document type simple manifest int manifest entry count dis read int if manifest entry count 0 throw new metadata parse exception invalid manifest entry count manifest entry count manifest entries new hash map string metadata parse the sub manifest if logminor logger minor this simple manifest manifest entry count entries for int i 0 i manifest entry count i short name length dis read short byte buf new byte name length dis read fully buf string name new string buf utf 8 intern if logminor logger minor this entry i name name short len dis read short if len 0 throw new metadata parse exception invalid manifest entry size len if len length throw new metadata parse exception impossibly long manifest entry len metadata size length byte data new byte len dis read fully data try metadata m metadata construct data manifest entries put name m catch throwable t logger error this could not parse sub manifest t t if logminor logger minor this end of manifest make it easy to search for it if document type archive internal redirect document type archive metadata redirect int len dis read short if logminor logger minor this reading archive internal redirect length len byte buf new byte len dis read fully buf name in archive new string buf utf 8 if logminor logger minor this archive internal redirect name in archive len datainputstream ioexception datainputstream ioexception metadataparseexception hashcode hashcode readlong freenet_metadata_magic metadataparseexception readshort metadataparseexception documenttype readbyte documenttype documenttype metadataparseexception documenttype documenttype haveflags readshort flags_splitfile flags_splitfile flags_dbr flags_dbr flags_no_mime flags_no_mime flags_compressed_mime flags_compressed_mime extrametadata flags_extra_metadata flags_extra_metadata fullkeys flags_full_keys flags_full_keys flags_compressed flags_compressed documenttype archive_manifest archivetype archive_type getarchivetype readshort archivetype metadataparseexception archivetype datalength readlong datalength metadataparseexception datalength datalength metadataparseexception compressioncodec compressor_type getcompressorbymetadataid readshort compressioncodec metadataparseexception compressioncodec decompressedlength readlong mimetype readshort compressedmimevalue hascompressedmimeparams compressedmimevalue hascompressedmimeparams compressedmimeparams readshort compressedmimeparams metadataparseexception mimetype defaultmimetypes bynumber readbyte toread readfully toread mimetype toread mimetype metadataparseexception dbrs extrametadata numberofextrafields readshort numberofextrafields readshort readbyte readfully extrametadata clientmetadata clientmetadata mimetype documenttype simple_redirect documenttype archive_manifest simpleredirectkey readkey splitfilealgorithm readshort splitfilealgorithm splitfile_nonredundant splitfilealgorithm splitfile_onion_standard metadataparseexception splitfilealgorithm splitfilealgorithm splitfile_nonredundant metadataparseexception paramslength readint paramslength max_splitfile_params_length metadataparseexception paramslength paramslength splitfileparams paramslength readfully splitfileparams paramslength metadataparseexception paramslength splitfileblocks readint splitfileblocks metadataparseexception splitfileblocks splitfileblocks max_splitfile_blocks metadataparseexception splitfileblocks splitfilecheckblocks readint splitfilecheckblocks metadataparseexception splitfilecheckblocks splitfilecheckblocks max_splitfile_blocks metadataparseexception splitfilecheckblocks splitfiledatakeys splitfileblocks splitfilecheckkeys splitfilecheckblocks splitfiledatakeys splitfiledatakeys metadataparseexception splitfilecheckkeys splitfilecheckkeys metadataparseexception documenttype simple_manifest manifestentrycount readint manifestentrycount metadataparseexception manifestentrycount manifestentries hashmap manifestentrycount manifestentrycount namelength readshort namelength readfully readshort metadataparseexception metadataparseexception readfully manifestentries documenttype archive_internal_redirect documenttype archive_metadata_redirect readshort readfully nameinarchive nameinarchive create an empty metadata object private metadata hash code super hash code should be followed by add redirection manifest hashcode hashcode addredirectionmanifest create a metadata object and add data for redirection to it param dir a map of names string to either files same string or directories more hash map s throws malformedurl exception one of the uri s were malformed private void add redirection manifest hash map string object dir throws malformedurl exception simple manifest contains actual redirects not archive manifest which is basically a redirect document type simple manifest nomime true mime type null client metadata new client metadata null manifest entries new hash map string metadata int count 0 for iterator entry string object i dir entry set iterator i has next map entry string object entry i next string key entry get key intern count object o entry get value metadata target if o instanceof string external redirect freeneturi uri new freeneturi string o target new metadata simple redirect null null uri null else if o instanceof hash map target new metadata target add redirection manifest hash map string object o else throw new illegal argument exception not string nor hash map o manifest entries put key target hashmap malformedurlexception addredirectionmanifest hashmap malformedurlexception documenttype simple_manifest mimetype clientmetadata clientmetadata manifestentries hashmap entryset hasnext getkey getvalue simple_redirect hashmap addredirectionmanifest hashmap illegalargumentexception hashmap manifestentries create a metadata object and add data for redirection to it param dir a map of names string to either files same string or directories more hash map s throws malformedurl exception one of the uri s were malformed public static metadata mk redirection manifest hash map string object dir throws malformedurl exception metadata ret new metadata ret add redirection manifest dir return ret hashmap malformedurlexception mkredirectionmanifest hashmap malformedurlexception addredirectionmanifest create a metadata object and add manifest entries from the given map the map can contain either string metadata or string map the latter indicating subdirs public static metadata mk redirection manifest with metadata hash map string object dir metadata ret new metadata ret add redirection manifest with metadata dir return ret mkredirectionmanifestwithmetadata hashmap addredirectionmanifestwithmetadata private void add redirection manifest with metadata hash map string object dir simple manifest contains actual redirects not archive manifest which is basically a redirect document type simple manifest nomime true mime type null client metadata new client metadata null manifest entries new hash map string metadata int count 0 for iterator string i dir key set iterator i has next string key i next intern if key index of 1 throw new illegal argument exception slashes in simple redirect manifest filenames slashes denote sub manifests key count object o dir get key if o instanceof metadata metadata data metadata dir get key if data null throw new null pointer exception if logger should log logger debug this logger debug this putting metadata for key manifest entries put key data else if o instanceof hash map hash map string object hm hash map string object o if logger should log logger debug this logger debug this making metadata map for key metadata sub map mk redirection manifest with metadata hm manifest entries put key sub map if logger should log logger debug this logger debug this putting metadata map for key addredirectionmanifestwithmetadata hashmap documenttype simple_manifest mimetype clientmetadata clientmetadata manifestentries hashmap keyset hasnext indexof illegalargumentexception nullpointerexception shouldlog manifestentries hashmap hashmap hashmap shouldlog submap mkredirectionmanifestwithmetadata manifestentries submap shouldlog create a metadata object for an archive which does not have its own metadata param dir a map of names string to either files same string or directories more hash map s metadata hash map string object dir string prefix hash code super hash code simple manifest contains actual redirects not archive manifest which is basically a redirect document type simple manifest nomime true mime type null client metadata new client metadata manifest entries new hash map string metadata int count 0 for iterator string i dir key set iterator i has next string key i next intern count object o dir get key metadata target if o instanceof string archive internal redirect target new metadata archive internal redirect null null prefix key new client metadata defaultmime types guessmime type key false else if o instanceof hash map target new metadata hash map string object o prefix key else throw new illegal argument exception not string nor hash map o manifest entries put key target hashmap hashmap hashcode hashcode documenttype simple_manifest mimetype clientmetadata clientmetadata manifestentries hashmap keyset hasnext archive_internal_redirect clientmetadata defaultmimetypes guessmimetype hashmap hashmap illegalargumentexception hashmap manifestentries create a really simple metadata object param doc type the document type must be something that takes a single argument at the moment this means archive internal redirect param arg the argument in the case of archive internal redirect the filename in the archive to read from public metadata byte doc type archive type archive type compressor type compression codec string arg client metadata cm hash code super hash code if doc type archive internal redirect document type doc type this archive type archive type determine mime type this client metadata cm this compression codec compression codec if cm null this setmime type cm getmime type name in archive arg else throw new illegal argument exception doctype archive_internal_redirect archive_internal_redirect doctype archive_type archivetype compressor_type compressioncodec clientmetadata hashcode hashcode doctype archive_internal_redirect documenttype doctype archivetype archivetype clientmetadata compressioncodec compressioncodec setmimetype getmimetype nameinarchive illegalargumentexception create a metadata redircet object that points to resolved metadata inside container doc type archive metadata redirect param name the filename in the archive to read from must be metadata n scheme private metadata byte doc type string name hash code super hash code nomime true if doc type archive metadata redirect document type doc type name in archive name else throw new illegal argument exception doctype archive_metadata_redirect doctype hashcode hashcode doctype archive_metadata_redirect documenttype doctype nameinarchive illegalargumentexception create another kind of simple metadata object a redirect or similar object param doc type the document type param uri the uri pointed to param cm the client metadata if any public metadata byte doc type archive type archive type compressor type compression codec freeneturi uri client metadata cm hash code super hash code if doc type simple redirect doc type archive manifest document type doc type this archive type archive type this compression codec compression codec client metadata cm if cm null cm is trivial setmime type cm getmime type else setmime type defaultmime types default mime type nomime true if uri null throw new null pointer exception simple redirect key uri if uri get key type equals chk uri has meta strings full keys true else throw new illegal argument exception doctype doctype archive_type archivetype compressor_type compressioncodec clientmetadata hashcode hashcode doctype simple_redirect doctype archive_manifest documenttype doctype archivetype archivetype compressioncodec compressioncodec clientmetadata istrivial setmimetype getmimetype setmimetype defaultmimetypes default_mime_type nullpointerexception simpleredirectkey getkeytype hasmetastrings fullkeys illegalargumentexception public metadata short algo clientchk dataur is clientchk checkur is int segment size int check segment size client metadata cm long data length archive type archive type compressor type compression codec long decompressed length boolean is metadata hash code super hash code if is metadata document type multi level metadata else if archive type null document type archive manifest this archive type archive type else document type simple redirect splitfile true splitfile algorithm algo this data length data length this compression codec compression codec splitfile blocks dataur is length splitfile check blocks checkur is length splitfile data keys dataur is assert keys valid splitfile data keys splitfile check keys checkur is assert keys valid splitfile check keys client metadata cm this compression codec compression codec this decompressed length decompressed length if cm null setmime type cm getmime type else setmime type defaultmime types default mime type splitfile params fields ints to bytes new int segment size check segment size datauris checkuris segmentsize checksegmentsize clientmetadata datalength archive_type archivetype compressor_type compressioncodec decompressedlength ismetadata hashcode hashcode ismetadata documenttype multi_level_metadata archivetype documenttype archive_manifest archivetype archivetype documenttype simple_redirect splitfilealgorithm datalength datalength compressioncodec compressioncodec splitfileblocks datauris splitfilecheckblocks checkuris splitfiledatakeys datauris keysvalid splitfiledatakeys splitfilecheckkeys checkuris keysvalid splitfilecheckkeys clientmetadata compressioncodec compressioncodec decompressedlength decompressedlength setmimetype getmimetype setmimetype defaultmimetypes default_mime_type splitfileparams intstobytes segmentsize checksegmentsize private boolean keys valid clientchk keys for int i 0 i keys length i if keys i get nodechk get routing key null return false return true keysvalid getnodechk getroutingkey set the mime type to a string compresses it if possible for transit private void setmime type string type nomime false short s defaultmime types by name type if s 0 compressedmime true compressedmime value s else compressedmime false mime type type setmimetype defaultmimetypes byname compressedmimevalue mimetype write the data to a byte array throws metadata unresolved exception public byte write to byte array throws metadata unresolved exception byte array output stream baos new byte array output stream data output stream dos new data output stream baos try write to dos catch io exception e throw new error could not write to byte array e e return baos to byte array metadataunresolvedexception writetobytearray metadataunresolvedexception bytearrayoutputstream bytearrayoutputstream dataoutputstream dataoutputstream writeto ioexception tobytearray private clientchk readchk data input stream dis throws io exception metadata parse exception if full keys throw new metadata parse exception full keys not supported on a splitfile return clientchk read raw binary key dis datainputstream ioexception metadataparseexception fullkeys metadataparseexception fullkeys readrawbinarykey read a key using the current settings throws io exception throws malformedurl exception if the key could not be read due to an error in parsing the key redflag may want to recover from these in future hence the short length private freeneturi read key data input stream dis throws io exception read url if full keys return freeneturi read full binary key with length dis else return clientchk read raw binary key dis geturi ioexception malformedurlexception readkey datainputstream ioexception fullkeys readfullbinarykeywithlength readrawbinarykey write a key using the current settings throws io exception throws malformedurl exception if an error in the key itself prevented it from being written private void write key data output stream dos freeneturi freeneturi throws io exception if full keys freeneturi write full binary key with length dos else string meta freeneturi get all meta strings if meta null meta length 0 throw new malformedurl exception not a plain chk base client key key base client key get base key freeneturi if key instanceof clientchk clientchk key write raw binary key dos else throw new illegal argument exception full keys must be enabled to write non ch ks ioexception malformedurlexception writekey dataoutputstream ioexception fullkeys writefullbinarykeywithlength getallmetastrings malformedurlexception baseclientkey baseclientkey getbasekey writerawbinarykey illegalargumentexception chks private void writechk data output stream dos clientchk chk throws io exception if full keys throw new unsupported operation exception full keys not supported on splitfiles else chk write raw binary key dos dataoutputstream ioexception fullkeys unsupportedoperationexception writerawbinarykey is a manifest public boolean is simple manifest return document type simple manifest issimplemanifest documenttype simple_manifest get the sub document in a manifest file with the given name throws metadata parse exception public metadata get document string name return manifest entries get name metadataparseexception getdocument manifestentries return and remove a specific document used in persistent requests so that when remove from is called the default document won t be removed since it is being processed public metadata grab document string name return manifest entries remove name removefrom grabdocument manifestentries the default document is the one which has an empty name throws metadata parse exception public metadata get default document throws metadata parse exception return get document metadataparseexception getdefaultdocument metadataparseexception getdocument return and remove the default document used in persistent requests so that when remove from is called the default document won t be removed since it is being processed public metadata grab default document return grab document removefrom grabdefaultdocument grabdocument get all documents in the manifest ignores default doc throws metadata parse exception public hash map string metadata get documents hash map string metadata docs new hash map string metadata set string s manifest entries key set iterator string i s iterator while i has next string st i next if st length 1 docs put st manifest entries get st return docs metadataparseexception hashmap getdocuments hashmap hashmap manifestentries keyset hasnext manifestentries does the metadata point to a single uri public boolean is single file redirect return splitfile document type simple redirect document type multi level metadata document type archive manifest issinglefileredirect documenttype simple_redirect documenttype multi_level_metadata documenttype archive_manifest return the single target of this uri public freeneturi get single target return simple redirect key getsingletarget simpleredirectkey is this a archive manifest public boolean is archive manifest return document type archive manifest isarchivemanifest documenttype archive_manifest is this a archive internal metadata redirect return public boolean is archive metadata redirect return document type archive metadata redirect isarchivemetadataredirect documenttype archive_metadata_redirect is this a archive internal redirect return public boolean is archive internal redirect return document type archive internal redirect isarchiveinternalredirect documenttype archive_internal_redirect return the name of the document referred to in the archive if this is a archive internal redirect public string get archive internal name return name in archive getarchiveinternalname nameinarchive return the client metadata mime type etc public client metadata get client metadata return client metadata clientmetadata getclientmetadata clientmetadata is this a splitfile manifest public boolean is splitfile return splitfile issplitfile is this a simple splitfile public boolean is simple splitfile return splitfile document type simple redirect issimplesplitfile documenttype simple_redirect is multi level indirect metadata public boolean is multi level metadata return document type multi level metadata ismultilevelmetadata documenttype multi_level_metadata what kind of archive is it public archive type get archive type return archive type archive_type getarchivetype archivetype change the document type to a simple redirect used by the archive code to fetch split archive manifests public void set simple redirect document type simple redirect setsimpleredirect documenttype simple_redirect write the metadata as binary throws io exception if an i o error occurred while writing the data throws metadata unresolved exception public void write to data output stream dos throws io exception metadata unresolved exception dos write long freenet metadata magic dos write short 0 version dos write byte document type if have flags short flags 0 if splitfile flags flags splitfile if dbr flags flags dbr if nomime flags flags no mime if compressedmime flags flags compressed mime if extra metadata flags flags extra metadata if full keys flags flags full keys if compression codec null flags flags compressed dos write short flags if document type archive manifest short code archive type metadataid dos write short code if splitfile dos write long data length if compression codec null dos write short compression codec metadataid dos write long decompressed length if nomime if compressedmime int x compressedmime value if has compressedmime params x 32768 dos write short short x if has compressedmime params dos write short compressedmime params else byte data mime type get bytes utf 8 if data length 255 throw new error mime type too long data length bytes mime type dos write byte byte data length dos write data if dbr throw new unsupported operation exception no dbr support yet if extra metadata throw new unsupported operation exception no extra metadata support yet if splitfile document type simple redirect document type archive manifest write key dos simple redirect key else if splitfile dos write short splitfile algorithm if splitfile params null dos write int splitfile params length dos write splitfile params else dos write int 0 dos write int splitfile blocks dos write int splitfile check blocks for int i 0 i splitfile blocks i writechk dos splitfile data keys i for int i 0 i splitfile check blocks i writechk dos splitfile check keys i if document type simple manifest dos write int manifest entries size boolean kill false linked list metadata unresolved metadata null for iterator string i manifest entries key set iterator i has next string name i next byte name data name get bytes utf 8 if name data length short max value throw new illegal argument exception manifest name too long dos write short name data length dos write name data metadata meta manifest entries get name try byte data meta write to byte array if data length max size in manifest freeneturi uri meta resolveduri string n meta resolved name if uri null meta new metadata simple redirect null null uri null data meta write to byte array else if n null meta new metadata archive metadata redirect n data meta write to byte array else kill true if unresolved metadata null unresolved metadata new linked list metadata unresolved metadata add last meta dos write short data length dos write data catch metadata unresolved exception e metadata m e must resolve if unresolved metadata null unresolved metadata new linked list metadata for int j 0 j m length j unresolved metadata add first m j kill true if kill metadata meta unresolved metadata to array new metadata unresolved metadata size throw new metadata unresolved exception meta manifest data too long and not resolved if document type archive internal redirect document type archive metadata redirect byte data name in archive get bytes utf 8 if data length short max value throw new illegal argument exception archive internal redirect name too long dos write short data length dos write data ioexception metadataunresolvedexception writeto dataoutputstream ioexception metadataunresolvedexception writelong freenet_metadata_magic writeshort writebyte documenttype haveflags flags_splitfile flags_dbr flags_no_mime flags_compressed_mime extrametadata flags_extra_metadata fullkeys flags_full_keys compressioncodec flags_compressed writeshort documenttype archive_manifest archivetype writeshort writelong datalength compressioncodec writeshort compressioncodec writelong decompressedlength compressedmimevalue hascompressedmimeparams writeshort hascompressedmimeparams writeshort compressedmimeparams mimetype getbytes mimetype writebyte unsupportedoperationexception extrametadata unsupportedoperationexception documenttype simple_redirect documenttype archive_manifest writekey simpleredirectkey writeshort splitfilealgorithm splitfileparams writeint splitfileparams splitfileparams writeint writeint splitfileblocks writeint splitfilecheckblocks splitfileblocks splitfiledatakeys splitfilecheckblocks splitfilecheckkeys documenttype simple_manifest writeint manifestentries linkedlist unresolvedmetadata manifestentries keyset hasnext namedata getbytes namedata max_value illegalargumentexception writeshort namedata namedata manifestentries writetobytearray max_size_in_manifest resolvedname simple_redirect writetobytearray archive_metadata_redirect writetobytearray unresolvedmetadata unresolvedmetadata linkedlist unresolvedmetadata addlast writeshort metadataunresolvedexception mustresolve unresolvedmetadata unresolvedmetadata linkedlist unresolvedmetadata addfirst unresolvedmetadata toarray unresolvedmetadata metadataunresolvedexception documenttype archive_internal_redirect documenttype archive_metadata_redirect nameinarchive getbytes max_value illegalargumentexception writeshort have this metadata flags public boolean have flags return document type simple redirect document type multi level metadata document type archive manifest document type archive internal redirect document type archive metadata redirect haveflags documenttype simple_redirect documenttype multi_level_metadata documenttype archive_manifest documenttype archive_internal_redirect documenttype archive_metadata_redirect get the splitfile type public short get splitfile type return splitfile algorithm getsplitfiletype splitfilealgorithm public clientchk get splitfile data keys return splitfile data keys getsplitfiledatakeys splitfiledatakeys public clientchk get splitfile check keys return splitfile check keys getsplitfilecheckkeys splitfilecheckkeys public boolean is compressed return compression codec null iscompressed compressioncodec public compressor type get compression codec return compression codec compressor_type getcompressioncodec compressioncodec public long data length return data length datalength datalength public byte splitfile params return splitfile params splitfileparams splitfileparams public long uncompressed data length return this decompressed length uncompresseddatalength decompressedlength public freeneturi get resolveduri return resolveduri getresolveduri public void resolve freeneturi uri this resolveduri uri public void resolve string name this resolved name name resolvedname public bucket to bucket bucket factory bf throws metadata unresolved exception io exception byte buf write to byte array return bucket tools make immutable bucket bf buf tobucket bucketfactory metadataunresolvedexception ioexception writetobytearray buckettools makeimmutablebucket public boolean is resolved return resolveduri null resolved name null isresolved resolvedname public void set archive manifest archive type type archive type get archive type client metadata getmime type archive type type compression codec null client metadata clear document type archive manifest setarchivemanifest archive_type archive_type getarchivetype clientmetadata getmimetype archivetype compressioncodec clientmetadata documenttype archive_manifest public string getmime type if client metadata null return null return client metadata getmime type getmimetype clientmetadata clientmetadata getmimetype public void remove from object container container if resolveduri null container activate resolveduri 5 resolveduri remove from container if simple redirect key null container activate simple redirect key 5 simple redirect key remove from container if splitfile data keys null for clientchk key splitfile data keys if key null container activate key 5 key remove from container if splitfile check keys null for clientchk key splitfile check keys if key null container activate key 5 key remove from container if manifest entries null container activate manifest entries 2 for object m manifest entries values metadata meta metadata m container activate meta 1 meta remove from container container delete manifest entries if client metadata null container activate client metadata 1 client metadata remove from container container delete this removefrom objectcontainer removefrom simpleredirectkey simpleredirectkey simpleredirectkey removefrom splitfiledatakeys splitfiledatakeys removefrom splitfilecheckkeys splitfilecheckkeys removefrom manifestentries manifestentries manifestentries removefrom manifestentries clientmetadata clientmetadata clientmetadata removefrom public void clear splitfile keys splitfile data keys null splitfile check keys null clearsplitfilekeys splitfiledatakeys splitfilecheckkeys private float hsb new float 3 public hsb adjust filter this 0 0 0 hsbadjustfilter public hsb adjust filter float r float g float b h factor r s factor g b factor b can filter index color model true hsbadjustfilter hfactor sfactor bfactor canfilterindexcolormodel public void seth factor float h factor this h factor h factor sethfactor hfactor hfactor hfactor public float geth factor return h factor gethfactor hfactor public void sets factor float s factor this s factor s factor setsfactor sfactor sfactor sfactor public float gets factor return s factor getsfactor sfactor public void setb factor float b factor this b factor b factor setbfactor bfactor bfactor bfactor public float getb factor return b factor getbfactor bfactor override public int filterrgb int x int y int rgb int a rgb 0xff000000 int r rgb 16 0xff int g rgb 8 0xff int b rgb 0xff color rg btohsb r g b hsb hsb 0 h factor while hsb 0 0 hsb 0 math pi 2 hsb 1 s factor if hsb 1 0 hsb 1 0 else if hsb 1 1 0 hsb 1 1 0f hsb 2 b factor if hsb 2 0 hsb 2 0 else if hsb 2 1 0 hsb 2 1 0f rgb color hs btorgb hsb 0 hsb 1 hsb 2 return a rgb 0xffffff rgbtohsb hfactor sfactor bfactor hsbtorgb override public string to string return colors adjust hsb tostring for construction of a puzzle which is meant to be inserted param new type param new data public own introduction puzzle own identity new inserter puzzle type new type string new mime type byte new data string new solution date new date of insertion int my index super new inserter uuid randomuuid to string new inserter getid new type new mime type new data new date of insertion get time introduction server puzzle invalid after days 24 60 60 1000 new date of insertion my index if new solution length minimal solution length throw new illegal argument exception solution is too short new solution length minimal length is minimal solution length m solver null m solution new solution if check consistency false throw new illegal argument exception trying to costruct a corrupted puzzle newtype newdata ownintroductionpuzzle ownidentity newinserter puzzletype newtype newmimetype newdata newsolution newdateofinsertion myindex newinserter tostring newinserter newtype newmimetype newdata newdateofinsertion gettime introductionserver puzzle_invalid_after_days newdateofinsertion myindex newsolution minimal_solution_length illegalargumentexception newsolution minimal_solution_length msolver msolution newsolution checkconsistency illegalargumentexception get the uri at which to insert this puzzle ssk asdfasdf wot introduction yyyy mm dd index of the puzzle public freeneturi get inserturi assert m was inserted false m was solved false string day of insertion synchronized m date format day of insertion m date format format get date of insertion freeneturi baseuri own identity get inserter get inserturi set key type ssk baseuri baseuri set doc name wot wot name introduction context day of insertion get index return baseuri set meta string null getinserturi mwasinserted mwassolved dayofinsertion mdateformat dayofinsertion mdateformat getdateofinsertion ownidentity getinserter getinserturi setkeytype setdocname wot_name introduction_context dayofinsertion getindex setmetastring used by the introduction server to mark a puzzle as solved so it will not try to fetch solutions for it anymore public synchronized void set solved if m was solved throw new runtime exception the puzzle was already solved by m solver m was solved true introductionserver setsolved mwassolved runtimeexception msolver mwassolved public class mock input stream extends input stream public mock input stream mockinputstream inputstream mockinputstream override public int read return 1 override public int read byte data int offset int len return len final static int code 0x0a public int get code return code getcode public string get description return sending to network getdescription public final class welcome extends web page impl public welcome web interface my web interface ft own identity viewer http request request super my web interface viewer request todo auto generated constructor stub webpageimpl webinterface mywebinterface ftownidentity httprequest mywebinterface public final void make make welcome box make overview box makewelcomebox makeoverviewbox private final void make welcome box html node welcome box add content box welcome welcome box add child p important note all messages you post with the current freetalk release are considered as testing messages and will not be readable by the first stable release this is necessary so that we could change internal stuff completely if there is a need to do so html node p welcome box add child p you can use freetalk via the webinterface p add child strike or with a newsreader connected to localhost port 1199 p add child unfortunately the newsreader interface seems to have a bug which makes it cause 100 cpu usage when it is not even being used until we find the time to debug it it is disabled welcome box add child p for the newsreader as the account name specify the nickname of an own identity and as the e mail address specify the freetalk address you can look it up on the identities page a password is not required makewelcomebox htmlnode welcomebox addcontentbox welcomebox addchild htmlnode welcomebox addchild addchild addchild welcomebox addchild private final void make overview box html node overview box add content box overview html node list overview box add child ul list add child new html node li known identities m freetalk get identity manager count known identities list add child new html node li messages waiting to be sent m freetalk get message manager count unsent messages makeoverviewbox htmlnode overviewbox addcontentbox htmlnode overviewbox addchild addchild htmlnode mfreetalk getidentitymanager countknownidentities addchild htmlnode mfreetalk getmessagemanager countunsentmessages create a new http request for the given uri and parse its request parameters param uri the uri being requested public http request impl uri uri this uri uri this parse request parameters uri get raw query true false this data null this parts null this bucketfactory null httprequest httprequestimpl parserequestparameters getrawquery creates a new http request for the given path and url encoded query string param path i e test test html param encoded query string a some text b abc 40def de throws uri syntax exception if the uri is invalid public http request impl string path string encoded query string throws uri syntax exception this data null this parts null this bucketfactory null if encoded query string null encoded query string length 0 this uri new uri path encoded query string else this uri new uri path this parse request parameters uri get raw query true false httprequest encodedquerystring urisyntaxexception httprequestimpl encodedquerystring urisyntaxexception encodedquerystring encodedquerystring encodedquerystring parserequestparameters getrawquery creates a new http request for the given uri and data param uri the uri being requested param h client headers param d the data param ctx the toadlet context for headers and bucket factory throws uri syntax exception if the uri is invalid public http request impl uri uri bucket d toadlet context ctx this uri uri this headers ctx get headers this parse request parameters uri get raw query true false this data d this parts new hash map string bucket this bucketfactory ctx get bucket factory if data null try this parse multi part data catch io exception ioe logger error this temporary files error could not parse ioe ioe httprequest urisyntaxexception httprequestimpl toadletcontext getheaders parserequestparameters getrawquery hashmap getbucketfactory parsemultipartdata ioexception see freenet clients http http request get path public string get path return this uri get path httprequest getpath getpath getpath see freenet clients http http request has parameters public boolean has parameters return this parameter name values map is empty httprequest hasparameters hasparameters parameternamevaluesmap isempty parse the query string and populate link parameter name values map with the lists of values for each parameter if this method is not called at all all other methods would be useless because they rely on the parameter map to be filled param query string the query string in its raw form not yet url decoded param do url decoding todo private void parse request parameters string query string boolean do url decoding boolean as parts boolean logminor logger should log logger minor this if logminor logger minor this query string is query string do url decoding do url decoding nothing to do if there was no query string in the uri if query string null query string length 0 return iterate over all tokens in the query string seperated by string tokenizer tokenizer new string tokenizer query string while tokenizer has more tokens string name value token tokenizer next token if logminor logger minor this token name value token a token can be either a name or a name value pair string name null string value int index of equals char name value token index of if index of equals char 0 it s only a name so the value stays emptys name name value token if logminor logger minor this name name else if index of equals char name value token length 1 it s a name with an empty value so remove the character name name value token substring 0 index of equals char if logminor logger minor this name name else it s a name value pair split into name and value name name value token substring 0 index of equals char value name value token substring index of equals char 1 if logminor logger minor this name name value value url decode the name and value if do url decoding try name url decoder decode name utf 8 value url decoder decode value utf 8 catch unsupported encoding exception e throw new error impossible jvm doesn t support utf 8 e e if logminor logger minor this decoded name name logger minor this decoded value value if as parts store as a part byte buf try buf value get bytes utf 8 catch unsupported encoding exception e throw new error impossible jvm doesn t support utf 8 e e fixme some other encoding bucket b new simple read only array bucket buf parts put name b if logminor logger minor this added as part name name value value else get the list of values for this parameter that were parsed so far list string value list this get parameter value list name add this value to the list value list add value parameternamevaluesmap querystring dourldecoding parserequestparameters querystring dourldecoding asparts shouldlog querystring querystring dourldecoding dourldecoding querystring querystring stringtokenizer stringtokenizer querystring hasmoretokens namevaluetoken nexttoken namevaluetoken indexofequalschar namevaluetoken indexof indexofequalschar namevaluetoken indexofequalschar namevaluetoken namevaluetoken indexofequalschar namevaluetoken indexofequalschar namevaluetoken indexofequalschar dourldecoding urldecoder urldecoder unsupportedencodingexception asparts getbytes unsupportedencodingexception simplereadonlyarraybucket valuelist getparametervaluelist valuelist get the first value of the parameter with the given name param name the name of the parameter to get return the first value or code null code if the parameter was not set private string get parameter value string name if this is parameter set name return null list string all values this get parameter value list name return all values get 0 getparametervalue isparameterset allvalues getparametervaluelist allvalues get the list of all values for the parameter with the given name when this method is called for a given parameter for the first time a new empty list of values is created and stored in link parameter name values map this list is returned and should be used to add parameter values if you only want to check if a parameter is set at all you must use link is parameter set string param name the name of the parameter to get return the list of all values for this parameter that were parsed so far private list string get parameter value list string name list string values this parameter name values map get name if values null values new linked list string this parameter name values map put name values return values parameternamevaluesmap isparameterset getparametervaluelist parameternamevaluesmap linkedlist parameternamevaluesmap see freenet clients http http request is parameter set java lang string public boolean is parameter set string name return this parameter name values map contains key name httprequest isparameterset isparameterset parameternamevaluesmap containskey see freenet clients http http request get param java lang string public string get param string name return this get param name httprequest getparam getparam getparam public string get param string name string default value string value this get parameter value name if value null return default value return value getparam defaultvalue getparametervalue defaultvalue see freenet clients http http request get int param java lang string public int get int param string name return this get int param name 0 httprequest getintparam getintparam getintparam public int get int param string name int default value if this is parameter set name return default value string value this get parameter value name try return integer parse int value catch number format exception e return default value getintparam defaultvalue isparameterset defaultvalue getparametervalue parseint numberformatexception defaultvalue public int get int part string name int default value if this is part set name return default value string value this get part as string name 32 try return integer parse int value catch number format exception e return default value getintpart defaultvalue ispartset defaultvalue getpartasstring parseint numberformatexception defaultvalue public string get multiple param string name list string value list this get parameter value list name string values new string value list size value list to array values return values getmultipleparam valuelist getparametervaluelist valuelist valuelist toarray public int get multiple int param string name list string value list this get parameter value list name try parsing all values and put the valid integers in a new list list integer int value list new array list integer for int i 0 i value list size i try int value list add integer value of value list get i catch exception e ignore invalid parameter values convert the valid integers to an array of ints int values new int int value list size for int i 0 i int value list size i values i int value list get i return values getmultipleintparam valuelist getparametervaluelist intvaluelist arraylist valuelist intvaluelist valueof valuelist intvaluelist intvaluelist intvaluelist parse submitted data from a bucket note that if this is application x www form urlencoded it will come out as params whereas if it is multipart form data it will be separated into buckets private void parse multi part data throws io exception input stream is null buffered input stream bis null line reading input stream lis null output stream bucketos null output stream bbos null try boolean logminor logger should log logger minor this if data null return string ctype this headers get content type if ctype null return if logminor logger minor this uploaded content type ctype string ctypeparts ctype split if ctypeparts 0 equals ignore case application x www form urlencoded completely different encoding but easy to handle if data size 1024 1024 throw new io exception too big byte buf bucket tools to byte array data string s new string buf us ascii parse request parameters s true true if ctypeparts 0 trim equals ignore case multipart form data ctypeparts length 2 return string boundary null for int i 0 i ctypeparts length i string subparts ctypeparts i split if subparts length 2 subparts 0 trim equals ignore case boundary boundary subparts 1 if boundary null boundary length 0 return if boundary char at 0 boundary boundary substring 1 if boundary char at boundary length 1 boundary boundary substring 0 boundary length 1 boundary boundary if logminor logger minor this boundary is boundary is this data get input stream bis new buffered input stream is 32768 lis new line reading input stream bis string line line lis read line 100 100 false really it s us ascii but iso 8859 1 is close enough while bis available 0 line equals boundary line lis read line 100 100 false boundary r n boundary bucket filedata null string name null string filename null string content type null while bis available 0 name null filename null content type null chomp headers while line lis read line 200 200 true should be utf 8 as we told the browser to send utf 8 null if line length 0 break string lineparts line split if lineparts null lineparts length 0 continue string hdrname lineparts 0 trim if hdrname equals ignore case content disposition if lineparts length 2 continue string valueparts lineparts 1 split for int i 0 i valueparts length i string subparts valueparts i split if subparts length 2 continue string fieldname subparts 0 trim string value subparts 1 trim if value starts with value ends with value value substring 1 value length 1 if fieldname equals ignore case name name value else if fieldname equals ignore case filename filename value else if hdrname equals ignore case content type content type lineparts 1 trim if logger should log logger minor this logger minor this parsed type content type else do nothing irrelevant header if name null continue we should be at the data now start reading it in checking for the boundary string we can only give an upper bound for the size of the bucket filedata this bucketfactory make bucket bis available bucketos filedata get output stream bbos new buffered output stream bucketos 32768 buffer characters that match the boundary so far fixme use whatever charset was used byte bbound boundary get bytes utf 8 iso 8859 1 boundary should be in us ascii int offset 0 while bis available 0 offset bbound length byte b byte bis read if b bbound offset offset else if b bbound offset offset 0 offset bytes matched but no more write the bytes that matched then the non matching byte bbos write bbound 0 offset offset 0 if b bbound 0 offset 1 else bbos write b else bbos write b bbos flush bbos close parts put name filedata if logminor logger minor this name name length filedata size filename filename if filename null uploaded files put name new http uploaded file impl filename content type filedata finally closer close bbos closer close bucketos closer close lis closer close bis closer close is parsemultipartdata ioexception inputstream bufferedinputstream linereadinginputstream outputstream outputstream shouldlog equalsignorecase ioexception buckettools tobytearray parserequestparameters equalsignorecase equalsignorecase charat charat getinputstream bufferedinputstream linereadinginputstream readline readline contenttype contenttype readline equalsignorecase startswith endswith equalsignorecase equalsignorecase equalsignorecase contenttype shouldlog contenttype makebucket getoutputstream bufferedoutputstream getbytes uploadedfiles httpuploadedfileimpl contenttype see freenet clients http http request get uploaded file java lang string public http uploaded file get uploaded file string name return uploaded files get name httprequest getuploadedfile httpuploadedfile getuploadedfile uploadedfiles see freenet clients http http request get part java lang string public bucket get part string name return this parts get name httprequest getpart getpart public boolean is part set string name if parts null return false return this parts contains key name ispartset containskey public string get part as string string name int maxlength try return new string get part as bytes name maxlength utf 8 catch unsupported encoding exception e throw new error impossible jvm doesn t support utf 8 e e getpartasstring getpartasbytes unsupportedencodingexception public byte get part as bytes string name int maxlength bucket part this parts get name if part null return new byte 0 if part size maxlength return new byte 0 input stream is null data input stream dis null try is part get input stream dis new data input stream is byte buf new byte is available dis read fully buf return buf catch io exception ioe logger error this caught ioe ioe get message finally closer close dis closer close is fixme why are we doing this dis close should close the input stream return new byte 0 getpartasbytes inputstream datainputstream getinputstream datainputstream readfully ioexception getmessage inputstream public void free parts if this parts null return for bucket b this parts values b free parts clear do not free data caller is responsible for that freeparts public long get long param string name long default value if this is parameter set name return default value string value this get parameter value name try return fields parse long value catch number format exception e return default value getlongparam defaultvalue isparameterset defaultvalue getparametervalue parselong numberformatexception defaultvalue creates a new file with the specified filename content type and data param filename the name of the file param content type the content type of the file param data the data of the file public http uploaded file impl string filename string content type bucket data this filename filename this content type content type this data data contenttype httpuploadedfileimpl contenttype contenttype contenttype see freenet clients http http uploaded file get content type public string get content type return content type httpuploadedfile getcontenttype getcontenttype contenttype see freenet clients http http uploaded file get data public bucket get data return data httpuploadedfile getdata getdata see freenet clients http http uploaded file get filename public string get filename return filename httpuploadedfile getfilename getfilename public static void addoom hook oom hook hook synchronized oom hooks oom hooks add hook addoomhook oomhook oomhooks oomhooks call this when running low of memory public static void low memory system gc system run finalization iterate all oom hooks iterator oom hook it oom hooks iterator while it has next oom hook hook it next if hook null try hook handle low memory catch throwable t ignore system gc system run finalization lowmemory runfinalization oomhook oomhooks hasnext oomhook handlelowmemory runfinalization public static void handleoom out of memory error e if isoom logger error null double oom e return isoom true runtime r null try r runtime get runtime long used at start r total memory r free memory if emergency pool null emergency pool null system gc system run finalization iterate all oom hooks iterator oom hook it oom hooks iterator while it has next oom hook hook it next if hook null try hook handle out of memory catch throwable t ignore system gc system run finalization system err println e get class system err println e get message e print stack trace if e get message equals java heap space thread dump stack long used now r total memory r free memory system err println memory gc size util format size used at start false size util format size used now false total size util format size r total memory false free size util format size r free memory false max size util format size r max memory false thread group tg thread current thread get thread group while tg get parent null tg tg get parent system err println running threads tg active count logger after everything else since it might throw logger error null caught e e logger error null memory gc size util format size used at start false size util format size used now false total size util format size r total memory false free size util format size r free memory false max size util format size r max memory false logger error null running threads tg active count catch throwable t try without g cing it might be a thread error g cing creates a thread system err println caught handling oom e t e print stack trace if r null system err println memory total size util format size r total memory false free size util format size r free memory false max size util format size r max memory false thread group tg thread current thread get thread group while tg get parent null tg tg get parent system err println running threads tg active count wrapper manager request thread dump will probably crash but never mind finally isoom false outofmemoryerror getruntime usedatstart totalmemory freememory emergencypool emergencypool runfinalization oomhook oomhooks hasnext oomhook handleoutofmemory runfinalization getclass getmessage printstacktrace getmessage dumpstack usednow totalmemory freememory sizeutil formatsize usedatstart sizeutil formatsize usednow sizeutil formatsize totalmemory sizeutil formatsize freememory sizeutil formatsize maxmemory threadgroup currentthread getthreadgroup getparent getparent activecount sizeutil formatsize usedatstart sizeutil formatsize usednow sizeutil formatsize totalmemory sizeutil formatsize freememory sizeutil formatsize maxmemory activecount gcing gcing printstacktrace sizeutil formatsize totalmemory sizeutil formatsize freememory sizeutil formatsize maxmemory threadgroup currentthread getthreadgroup getparent getparent activecount wrappermanager requestthreaddump public node set user data null set parent node null setuserdata setparentnode public node string name this set name name setname public node string ns string name this set name ns name setname private node parent node null public void set parent node node node parent node node parentnode setparentnode parentnode public node get parent node return parent node getparentnode parentnode public node get root node node root node null node parent node get parent node while parent node null root node parent node parent node root node get parent node return root node getrootnode rootnode parentnode getparentnode parentnode rootnode parentnode parentnode rootnode getparentnode rootnode private string name new string public void set name string name this name name setname public void set name string ns string name this name ns name setname public string get name return name getname public boolean is name string value return name equals value isname private string value public void set value string value this value value setvalue public void set value int value set value integer to string value setvalue setvalue tostring public string get value return value getvalue private attribute list attr list new attribute list public int getn attributes return attr list size attributelist attrlist attributelist getnattributes attrlist public attribute get attribute int index return attr list get attribute index getattribute attrlist getattribute public attribute get attribute string name return attr list get attribute name getattribute attrlist getattribute public void add attribute attribute attr attr list add attr addattribute attrlist public void insert attribute at attribute attr int index attr list insert element at attr index insertattributeat attrlist insertelementat public void add attribute string name string value attribute attr new attribute name value add attribute attr addattribute addattribute public boolean remove attribute attribute attr return attr list remove attr removeattribute attrlist public boolean remove attribute string name return remove attribute get attribute name removeattribute removeattribute getattribute public boolean has attributes if 0 getn attributes return true return false hasattributes getnattributes public void set attribute string name string value attribute attr get attribute name if attr null attr set value value return attr new attribute name value add attribute attr setattribute getattribute setvalue addattribute public void set attribute string name int value set attribute name integer to string value setattribute setattribute tostring public string get attribute value string name attribute attr get attribute name if attr null return attr get value return getattributevalue getattribute getvalue public int get attribute integer value string name string val get attribute value name try return integer parse int val catch exception e return 0 getattributeintegervalue getattributevalue parseint public void set name space string ns string value set attribute xmlns ns value setnamespace setattribute private node list node list new node list public int getn nodes return node list size nodelist nodelist nodelist getnnodes nodelist public node get node int index return node list get node index getnode nodelist getnode public node get node string name return node list get node name getnode nodelist getnode public node get node ends with string name return node list get ends with name getnodeendswith nodelist getendswith public void add node node node node set parent node this node list add node addnode setparentnode nodelist public void insert node node node int index node set parent node this node list insert element at node index insertnode setparentnode nodelist insertelementat public boolean remove node node node node set parent node null return node list remove node removenode setparentnode nodelist public boolean remove node string name return node list remove get node name removenode nodelist getnode public void remove all nodes node list clear removeallnodes nodelist public boolean has nodes if 0 getn nodes return true return false hasnodes getnnodes public void set node string name string value node node get node name if node null node set value value return node new node name node set value value add node node setnode getnode setvalue setvalue addnode public string get node value string name node node get node name if node null return node get value return getnodevalue getnode getvalue private object user data null public void set user data object data user data data userdata setuserdata userdata public object get user data return user data getuserdata userdata public string get indent level string int n indent level char indent string new char n indent level for int n 0 n n indent level n indent string n t return new string indent string getindentlevelstring nindentlevel indentstring nindentlevel nindentlevel indentstring indentstring public void output attributes print writer ps int n attributes getn attributes for int n 0 n n attributes n attribute attr get attribute n ps print attr get name xml escapexml chars attr get value outputattributes printwriter nattributes getnattributes nattributes getattribute getname escapexmlchars getvalue public void output print writer ps int indent level boolean has child node string indent string get indent level string indent level string name get name string value get value if has nodes false has child node false ps print indent string name output attributes ps thnaks for tho beisch 11 09 04 if value null value length 0 no value so use short notation node ps println else ps println xml escapexml chars value name return ps print indent string name output attributes ps ps println int n child nodes getn nodes for int n 0 n n child nodes n node cnode get node n cnode output ps indent level 1 true ps println indent string name printwriter indentlevel haschildnode indentstring getindentlevelstring indentlevel getname getvalue hasnodes haschildnode indentstring outputattributes escapexmlchars indentstring outputattributes nchildnodes getnnodes nchildnodes getnode indentlevel indentstring public string to string boolean has child node byte array output stream byte out new byte array output stream print writer pr new print writer byte out output pr 0 has child node pr flush return byte out to string tostring haschildnode bytearrayoutputstream byteout bytearrayoutputstream printwriter printwriter byteout haschildnode byteout tostring override public string to string return to string true tostring tostring public string toxml string boolean has child node string xml str to string xml str xml str replace all lt xml str xml str replace all gt thanks for theo beisch 11 09 04 xml str xml str replace all amp xml str xml str replace all quot thanks for brian owens 12 02 04 xml str xml str replace all apos return xml str toxmlstring haschildnode xmlstr tostring xmlstr xmlstr replaceall xmlstr xmlstr replaceall xmlstr xmlstr replaceall xmlstr xmlstr replaceall xmlstr xmlstr replaceall xmlstr public string toxml string return toxml string true toxmlstring toxmlstring public void print boolean has child node print writer pr new print writer system out output pr 0 has child node pr flush haschildnode printwriter printwriter haschildnode public void print print true return the build number not svn revision number of this node public static final int build number return build number buildnumber buildnumber return the lowest build number with which the node will connect and exchange data normally public static final int last good build if system current time millis transition time return new last good build else return old last good build lastgoodbuild currenttimemillis transitiontime newlastgoodbuild oldlastgoodbuild return the node s version designators as an array public static final string get version string ret node name node version protocol version build number return ret getversion nodename nodeversion protocolversion buildnumber public static final string get last good version string ret node name node version protocol version last good build return ret getlastgoodversion nodename nodeversion protocolversion lastgoodbuild return the version string that should be presented in the node reference public static final string get version string return fields comma list get version nodereference getversionstring commalist getversion return is needed for the freeviz public static final string get last good version string return fields comma list get last good version getlastgoodversionstring commalist getlastgoodversion return true if requests should be accepted from nodes brandishing this protocol version string private static boolean good protocol string prot if prot equals protocol version uncomment next line to accept stable see also explain bad version below prot equals stable protocol version return true return false goodprotocol protocolversion explainbadversion stableprotocolversion return true if requests should be accepted from nodes brandishing this version string public static final boolean check good version string version if version null logger error version class version null new exception error return false string v fields comma list version if v length 3 good protocol v 2 return false if same version v try int build integer parse int v 3 int req last good build if build req if logdebug logger debug version class not accepting unstable from version version last good build req return false catch number format exception e if logger should log logger minor version class logger minor version class not accepting e from version return false if stable version v try int build integer parse int v 3 if build last good stable build if logdebug logger debug version class not accepting stable from version version last good stable build last good stable build return false catch number format exception e logger minor version class not accepting e from version return false if logdebug logger minor version class accepting version return true checkgoodversion commalist goodprotocol sameversion parseint lastgoodbuild lastgoodbuild numberformatexception shouldlog stableversion parseint lastgoodstablebuild lastgoodstablebuild lastgoodstablebuild numberformatexception return true if requests should be accepted from nodes brandishing this version string given an arbitrary last good version public static final boolean check arbitrary good version string version string last good version if version null logger error version class version null new exception error return false if last good version null logger error version class last good version null new exception error return false string v fields comma list version string lgv fields comma list last good version if v null v length 3 good protocol v 2 return false if lgv null lgv length 3 good protocol lgv 2 return false if same arbitrary version v lgv try int build integer parse int v 3 int min build integer parse int lgv 3 if build min build if logdebug logger debug version class not accepting unstable from version version last good version last good version return false catch number format exception e if logger should log logger minor version class logger minor version class not accepting e from version and or last good version return false if stable version v try int build integer parse int v 3 if build last good stable build if logdebug logger debug version class not accepting stable from version version last good stable build last good stable build return false catch number format exception e logger minor version class not accepting e from version return false if logdebug logger minor version class accepting version return true lastgoodversion checkarbitrarygoodversion lastgoodversion lastgoodversion lastgoodversion commalist commalist lastgoodversion goodprotocol goodprotocol samearbitraryversion parseint min_build parseint min_build lastgoodversion lastgoodversion numberformatexception shouldlog lastgoodversion stableversion parseint lastgoodstablebuild lastgoodstablebuild lastgoodstablebuild numberformatexception return string explaining why a version string is rejected public static final string explain bad version string version string v fields comma list version if v length 3 good protocol v 2 return required protocol version is protocol version uncomment next line if accepting stable see also good protocol above or stable protocol version if same version v try int build integer parse int v 3 int req last good build if build req return build older than last good build req catch number format exception e return build number not numeric if stable version v try int build integer parse int v 3 if build last good stable build return build older than last good stable build last good stable build catch number format exception e return build number not numeric return null explainbadversion commalist goodprotocol protocolversion goodprotocol stableprotocolversion sameversion parseint lastgoodbuild numberformatexception stableversion parseint lastgoodstablebuild lastgoodstablebuild numberformatexception return the build number of an arbitrary version string public static final int get arbitrary build number string version throws version parse exception if version null logger error version class version null new exception error throw new version parse exception version null string v fields comma list version if v length 3 good protocol v 2 throw new version parse exception not long enough or bad protocol version try return integer parse int v 3 catch number format exception e version parse exception ve new version parse exception got number format exception on v 3 e for version ve init cause e throw ve getarbitrarybuildnumber versionparseexception versionparseexception commalist goodprotocol versionparseexception parseint numberformatexception versionparseexception versionparseexception numberformatexception initcause public static final int get arbitrary build number string version int default value try return get arbitrary build number version catch version parse exception e return default value getarbitrarybuildnumber defaultvalue getarbitrarybuildnumber versionparseexception defaultvalue update static variable highest seen build anytime we encounter a new node with a higher version than we ve seen before public static final void seen version string version string v fields comma list version if v null v length 3 return bad but that will be discovered elsewhere if same version v int build no try build no integer parse int v 3 catch number format exception e return if build no highest seen build if logger should log logger minor version class logger minor version class new highest seen build build no highest seen build build no highestseenbuild seenversion commalist sameversion buildno buildno parseint numberformatexception buildno highestseenbuild shouldlog buildno highestseenbuild buildno return true if the string describes the same node version as ours note that the build number may be different and is ignored public static boolean same version string v return v 0 equals node name v 1 equals node version v length 4 sameversion nodename nodeversion return true if the string describes the same node version as an arbitrary one note that the build number may be different and is ignored public static boolean same arbitrary version string v string lgv return v 0 equals lgv 0 v 1 equals lgv 1 v length 4 lgv length 4 samearbitraryversion return true if the string describes a stable node version private static boolean stable version string v return v 0 equals node name v 1 equals stable node version v length 4 stableversion nodename stablenodeversion public static void main string args throws throwable system out println freenet node name node version protocol protocol version build build number last good build last good build nodename nodeversion protocolversion buildnumber lastgoodbuild final object client public random grab array with client object client boolean persistent object container container remove random parent parent super persistent container parent this client client randomgrabarraywithclient objectcontainer removerandomparent public final object get object return client getobject creates a new trust relationship web page param my web interface a reference to the web interface which created the page used to get resources the page needs param my request the request sent by the user throws unknown identity exception public identity page web interface my web interface http request my request throws unknown identity exception super my web interface my request identity wot get identity byid request get param id mywebinterface webinterface myrequest unknownidentityexception identitypage webinterface mywebinterface httprequest myrequest unknownidentityexception mywebinterface myrequest getidentitybyid getparam inherit doc see web page make public void make synchronized identity does not matter much if this information is not synchronous to the trust tables so we put it outside the lock on the wot to reduce the time the whole wot is locked makeuri box make services box html node trustee trusts node add content box identities that identity get nickname trusts html node trustees table trustee trusts node add child table html node trustees table header trustees table add child tr trustees table header add child th nickname trustees table header add child th identity trustees table header add child th value trustees table header add child th comment html node truster trusts node add content box identities that trust identity get nickname html node trusters table truster trusts node add child table html node trusters table header trusters table add child tr trusters table header add child th nickname trusters table header add child th identity trusters table header add child th value trusters table header add child th comment synchronized wot for trust trust wot get given trusts identity html node trust row trustees table add child tr identity trustee trust get trustee trust row add child td add child a href show identity id trustee getid trustee get nickname trust row add child td trustee getid trust row add child td align right byte to string trust get value trust row add child td trust get comment for trust trust wot get received trusts identity html node trust row trusters table add child tr identity truster trust get truster trust row add child td add child a href show identity id truster getid truster get nickname trust row add child td truster getid trust row add child td align right byte to string trust get value trust row add child td trust get comment inheritdoc webpage makeuribox makeservicesbox htmlnode trusteetrustsnode addcontentbox getnickname htmlnode trusteestable trusteetrustsnode addchild htmlnode trusteestableheader trusteestable addchild trusteestableheader addchild trusteestableheader addchild trusteestableheader addchild trusteestableheader addchild htmlnode trustertrustsnode addcontentbox getnickname htmlnode trusterstable trustertrustsnode addchild htmlnode trusterstableheader trusterstable addchild trusterstableheader addchild trusterstableheader addchild trusterstableheader addchild trusterstableheader addchild getgiventrusts htmlnode trustrow trusteestable addchild gettrustee trustrow addchild addchild showidentity getnickname trustrow addchild trustrow addchild tostring getvalue trustrow addchild getcomment getreceivedtrusts htmlnode trustrow trusterstable addchild gettruster trustrow addchild addchild showidentity getnickname trustrow addchild trustrow addchild tostring getvalue trustrow addchild getcomment private void makeuri box html node box content add content box reference of identity identity get nickname box content add child p the following freenet uri is a reference to this identity if you want to tell other people about this identity give the uri to them box content add child p identity get requesturi to string makeuribox htmlnode boxcontent addcontentbox getnickname boxcontent addchild boxcontent addchild getrequesturi tostring private void make services box html node box content add content box services of identity identity get nickname iterator string iter identity get contexts iterator string builder contexts new string builder 128 while iter has next contexts append iter next if iter has next contexts append box content add child p contexts to string makeservicesbox htmlnode boxcontent addcontentbox getnickname getcontexts stringbuilder stringbuilder hasnext hasnext boxcontent addchild tostring public client get message simple field set fs throws message invalid exception short default priority client token fs get client token global fields string to bool fs get global false ignoreds fields string to bool fs get ignoreds false ds only fields string to bool fs get ds only false identifier fs get identifier allowedmime types fs get all allowedmime types if identifier null throw new message invalid exception protocol error message missing field no identifier null global try uri new freeneturi fs get uri catch malformedurl exception e throw new message invalid exception protocol error message freenet uri parse error e get message identifier global string verbosity string fs get verbosity if verbosity string null verbosity 0 else try verbosity integer parse int verbosity string 10 catch number format exception e throw new message invalid exception protocol error message error parsing number error parsing verbosity field e get message identifier global string return type string fs get return type return type parse return typefcp return type string if return type return type direct disk file null temp file null default just below f proxy default priority request starter immediate splitfile priority class else if return type return type none disk file null temp file null default priority request starter prefetch priority class else if return type return type disk default priority request starter bulk splitfile priority class string filename fs get filename if filename null throw new message invalid exception protocol error message missing field missing filename identifier global disk file new file filename string temp filename fs get temp filename if temp filename null temp filename filename freenet tmp temp file new file temp filename if disk file get absolute file get parent file equals temp file get absolute file get parent file throw new message invalid exception protocol error message filename and temp filename must be in same dir null identifier global if temp file exists throw new message invalid exception protocol error message disk target exists temp file exists identifier global if disk file exists throw new message invalid exception protocol error message disk target exists null identifier global try check whether we can create it so that we return an error early on then delete it as we have to rename over it anyway atomic creation of a file does not guarantee that it won t be replaced with a symlink if temp file create new file temp file exists temp file can read temp file can write throw new message invalid exception protocol error message could not create file could not create temp file temp file identifier global temp file delete catch io exception e throw new message invalid exception protocol error message could not create file e get message identifier global else throw new message invalid exception protocol error message message parse error unknown return type identifier global string max size string fs get max size if max size string null default to unlimited max size long max value else try max size long parse long max size string 10 catch number format exception e throw new message invalid exception protocol error message error parsing number error parsing max size field e get message identifier global string max temp size string fs get max temp size if max temp size string null default to unlimited max temp size long max value else try max temp size long parse long max temp size string 10 catch number format exception e throw new message invalid exception protocol error message error parsing number error parsing max size field e get message identifier global string max retries string fs get max retries if max retries string null default to 0 max retries 0 else try max retries integer parse int max retries string 10 catch number format exception e throw new message invalid exception protocol error message error parsing number error parsing max size field e get message identifier global if logger should log logger minor this logger minor this max retries max retries string priority string fs get priority class if priority string null defaults to the one just below f proxy priority class default priority else try priority class short parse short priority string 10 if priority class request starter maximum priority class priority class request starter minimum priority class throw new message invalid exception protocol error message invalid field valid priorities are from request starter maximum priority class to request starter minimum priority class identifier global catch number format exception e throw new message invalid exception protocol error message error parsing number error parsing priority class field e get message identifier global string persistence string fs get persistence if persistence string null persistence string equals ignore case connection default persists until connection loss persistence type client request persist connection else if persistence string equals ignore case reboot reports to client by name persists over connection loss not saved to disk so dies on reboot persistence type client request persist reboot else if persistence string equals ignore case forever same as reboot but saved to disk persists forever persistence type client request persist forever else throw new message invalid exception protocol error message error parsing number error parsing persistence field persistence string identifier global if global persistence type client request persist connection throw new message invalid exception protocol error message not supported global requests must be persistent identifier global binary blob fields string to bool fs get binary blob false clientgetmessage simplefieldset messageinvalidexception defaultpriority clienttoken clienttoken stringtobool stringtobool dsonly stringtobool dsonly allowedmimetypes getall allowedmimetypes messageinvalidexception protocolerrormessage missing_field malformedurlexception messageinvalidexception protocolerrormessage freenet_uri_parse_error getmessage verbositystring verbositystring parseint verbositystring numberformatexception messageinvalidexception protocolerrormessage error_parsing_number getmessage returntypestring returntype returntype parsereturntypefcp returntypestring returntype return_type_direct diskfile tempfile fproxy defaultpriority requeststarter immediate_splitfile_priority_class returntype return_type_none diskfile tempfile defaultpriority requeststarter prefetch_priority_class returntype return_type_disk defaultpriority requeststarter bulk_splitfile_priority_class messageinvalidexception protocolerrormessage missing_field diskfile tempfilename tempfilename tempfilename tempfilename tempfile tempfilename diskfile getabsolutefile getparentfile tempfile getabsolutefile getparentfile messageinvalidexception protocolerrormessage filename_and_temp_filename_must_be_in_same_dir tempfile messageinvalidexception protocolerrormessage disk_target_exists diskfile messageinvalidexception protocolerrormessage disk_target_exists tempfile createnewfile tempfile tempfile canread tempfile canwrite messageinvalidexception protocolerrormessage could_not_create_file tempfile tempfile ioexception messageinvalidexception protocolerrormessage could_not_create_file getmessage messageinvalidexception protocolerrormessage message_parse_error maxsizestring maxsize maxsizestring maxsize max_value maxsize parselong maxsizestring numberformatexception messageinvalidexception protocolerrormessage error_parsing_number maxsize getmessage maxtempsizestring maxtempsize maxtempsizestring maxtempsize max_value maxtempsize parselong maxtempsizestring numberformatexception messageinvalidexception protocolerrormessage error_parsing_number maxsize getmessage maxretriesstring maxretries maxretriesstring maxretries maxretries parseint maxretriesstring numberformatexception messageinvalidexception protocolerrormessage error_parsing_number maxsize getmessage shouldlog maxretries prioritystring priorityclass prioritystring fproxy priorityclass defaultpriority priorityclass parseshort prioritystring priorityclass requeststarter maximum_priority_class priorityclass requeststarter minimum_priority_class messageinvalidexception protocolerrormessage invalid_field requeststarter maximum_priority_class requeststarter minimum_priority_class numberformatexception messageinvalidexception protocolerrormessage error_parsing_number priorityclass getmessage persistencestring persistencestring persistencestring equalsignorecase persistencetype clientrequest persist_connection persistencestring equalsignorecase persistencetype clientrequest persist_reboot persistencestring equalsignorecase persistencetype clientrequest persist_forever messageinvalidexception protocolerrormessage error_parsing_number persistencestring persistencetype clientrequest persist_connection messageinvalidexception protocolerrormessage not_supported binaryblob stringtobool binaryblob override public simple field set get field set simple field set fs new simple field set true fs put single ignoreds boolean to string ignoreds fs put single uri uri to string false false fs put single identifier identifier fs put single verbosity integer to string verbosity fs put single return type get return type string fs put single max size long to string max size fs put single max temp size long to string max temp size fs put single max retries integer to string max retries fs put binary blob binary blob return fs simplefieldset getfieldset simplefieldset simplefieldset putsingle tostring putsingle tostring putsingle putsingle tostring putsingle returntype getreturntypestring putsingle maxsize tostring maxsize putsingle maxtempsize tostring maxtempsize putsingle maxretries tostring maxretries binaryblob binaryblob private string get return type string return return type string return type getreturntypestring returntypestring returntype override public string get name return name getname override public void run fcp connection handler handler node node handler start client get this fcpconnectionhandler startclientget public static string return type string short type switch type case return type direct return direct case return type none return none case return type disk return disk case return type chunked return chunked default return short to string type returntypestring return_type_direct return_type_none return_type_disk return_type_chunked tostring short parse return typefcp string string throws message invalid exception try return parse return type string catch number format exception e throw new message invalid exception protocol error message invalid field unable to parse return type string e identifier global parsereturntypefcp messageinvalidexception parsereturntype numberformatexception messageinvalidexception protocolerrormessage invalid_field returntype public static short parse return type string string if string null return return type direct if string equals ignore case direct return return type direct if string equals ignore case none return return type none if string equals ignore case disk return return type disk if string equals ignore case chunked return return type chunked return short parse short string parsereturntype return_type_direct equalsignorecase return_type_direct equalsignorecase return_type_none equalsignorecase return_type_disk equalsignorecase return_type_chunked parseshort public static short parse valid return type string string short s parse return type string if s return type direct s return type none s return type disk return s throw new illegal argument exception invalid or unsupported return type return type string s parsevalidreturntype parsereturntype return_type_direct return_type_none return_type_disk illegalargumentexception returntypestring override public void remove from object container container uri remove from container container delete disk file container delete temp file container delete this removefrom objectcontainer removefrom diskfile tempfile public class peer parse exception extends exception private static final long serial versionuid 1 public peer parse exception exception e super e peerparseexception serialversionuid peerparseexception public peer parse exception super peerparseexception public peer parse exception string string super string peerparseexception public final class identity editor extends web page impl public identity editor web interface my web interface ft own identity viewer http request request super my web interface viewer request todo auto generated constructor stub identityeditor webpageimpl identityeditor webinterface mywebinterface ftownidentity httprequest mywebinterface public final void make make own identities box make known identities box makeownidentitiesbox makeknownidentitiesbox private final void make own identities box html node box add content box own identities iterator ft own identity own identities m freetalk get identity manager own identity iterator if own identities has next false box add child p no own identities received from the wot plugin yet please create one there and wait for 15 minutes until it appears here else html node identities table box add child table html node row identities table add child tr row add child th name row add child th freetalk address while own identities has next ft own identity id own identities next row identities table add child tr row add child td id get nickname row add child td id get freetalk address html node last update cell row add child td if id get last insert null last update cell add child p insert in progress else if id get last insert equals new date 0 last update cell add child p never else last update cell add child new html node a href id get requesturi to string id get last insert to string fixme repair i e make it use the wot plugin html node delete cell row add child td html node delete form ft m plugin respirator add form child delete cell freetalk plugin uri delete own identity delete form delete form add child input new string type name value new string hidden identity id get requesturi toacii string delete form add child input new string type name value new string submit delete delete fixme repair i e make it use the wot plugin content node add child create new own identity box ft makeownidentitiesbox htmlnode addcontentbox ftownidentity ownidentities mfreetalk getidentitymanager ownidentityiterator ownidentities hasnext addchild htmlnode identitiestable addchild htmlnode identitiestable addchild addchild addchild ownidentities hasnext ftownidentity ownidentities identitiestable addchild addchild getnickname addchild getfreetalkaddress htmlnode lastupdatecell addchild getlastinsert lastupdatecell addchild getlastinsert lastupdatecell addchild lastupdatecell addchild htmlnode getrequesturi tostring getlastinsert tostring htmlnode deletecell addchild htmlnode deleteform mpluginrespirator addformchild deletecell plugin_uri deleteownidentity deleteform deleteform addchild getrequesturi toaciistring deleteform addchild contentnode addchild createnewownidentitybox private final void make known identities box html node box add content box known identities html node identities table box add child table border 0 html node row identities table add child tr row add child th name row add child th freetalk address row add child th for ft identity id m freetalk get identity manager get all identities if id instanceof ft own identity continue row identities table add child tr row add child td id get nickname row add child td id get freetalk address html node delete cell row add child td fixme repair i e make it use the wot plugin html node delete form ft m plugin respirator add form child delete cell freetalk plugin uri delete identity delete form delete form add child input new string type name value new string hidden identity id get requesturi toacii string delete form add child input new string type name value new string submit delete delete fixme repair i e make it use the wot plugin content node add child create new known identity box ft makeknownidentitiesbox htmlnode addcontentbox htmlnode identitiestable addchild htmlnode identitiestable addchild addchild addchild addchild ftidentity mfreetalk getidentitymanager getallidentities ftownidentity identitiestable addchild addchild getnickname addchild getfreetalkaddress htmlnode deletecell addchild htmlnode deleteform mpluginrespirator addformchild deletecell plugin_uri deleteidentity deleteform deleteform addchild getrequesturi toaciistring deleteform addchild contentnode addchild createnewknownidentitybox final clientchk key override public string to string return super to string key key tostring tostring construct from data retrieved and a key do not do full decode verify what can be verified without doing a full decode param key2 the client key param header the header param data the data public clientchk block byte data byte header clientchk key2 boolean verify throws chk verify exception super data header key2 get nodechk verify key2 crypto algorithm this key key2 clientchkblock chkverifyexception getnodechk cryptoalgorithm construct from a chk block and a key public clientchk block chk block block clientchk key2 throws chk verify exception this block get data block get headers key2 true chkblock clientchkblock chkblock chkverifyexception getdata getheaders decode into ram if short throws chk decode exception public byte memory decode throws chk decode exception try array bucket a array bucket decode new array bucket factory 32 1024 false return bucket tools to byte array a fixme catch io exception e throw new error e chkdecodeexception memorydecode chkdecodeexception arraybucket arraybucket arraybucketfactory buckettools tobytearray ioexception decode the chk and recover the original data return the original data throws io exception if there is a bucket error public bucket decode bucket factory bf int max length boolean dont compress throws chk decode exception io exception overall hash already verified so first job is to decrypt if key crypto algorithm key algo aes pcfb 256 sha256 throw new unsupported operation exception block cipher cipher try cipher new rijndael 256 256 catch unsupported cipher exception e fixme log this properly throw new error e byte crypto key key crypto key if crypto key length node symmetric key length throw new chk decode exception crypto key too short cipher initialize key crypto key pcfb mode pcfb pcfb mode create cipher byte hbuf new byte headers length 2 system arraycopy headers 2 hbuf 0 headers length 2 byte dbuf new byte data length system arraycopy data 0 dbuf 0 data length decipher header first functions as iv pcfb block decipher hbuf 0 hbuf length pcfb block decipher dbuf 0 dbuf length check decryption key hash of data not including header message digest md256 sha256 get message digest byte dkey md256 digest dbuf if java util arrays equals dkey key crypto key sha256 return message digest md256 throw new chk decode exception check failed decrypt key h data check iv hash of decryption key byte prediv md256 digest dkey sha256 return message digest md256 md256 null extract the iv byte iv new byte 32 system arraycopy hbuf 0 iv 0 32 if arrays equals iv prediv throw new chk decode exception check failed decrypted iv h decryption key checks complete int size hbuf 32 0xff 8 hbuf 33 0xff if size 32768 size 0 throw new chk decode exception invalid size size return key decompress dont compress false key is compressed dbuf size bf math min max length max length before compression key compression algorithm false ioexception bucketfactory maxlength dontcompress chkdecodeexception ioexception cryptoalgorithm algo_aes_pcfb_256_sha256 unsupportedoperationexception blockcipher unsupportedcipherexception cryptokey cryptokey cryptokey symmetric_key_length chkdecodeexception cryptokey pcfbmode pcfbmode blockdecipher blockdecipher messagedigest getmessagedigest cryptokey returnmessagedigest chkdecodeexception returnmessagedigest chkdecodeexception chkdecodeexception dontcompress iscompressed maxlength max_length_before_compression compressionalgorithm encode a bucket of data to a chk block param source data the bucket of data to encode can be arbitrarily large param as metadata is this a metadata key param dont compress if set don t even try to compress param already compressed codec if dont compress and this is 0 then the data is already compressed and this is the algorithm throws chk encode exception throws io exception if there is an error reading from the bucket static public clientchk block encode bucket source data boolean as metadata boolean dont compress short already compressed codec long source length throws chk encode exception io exception byte final data null byte data byte header clientchk key short compression algorithm 1 try compressed comp key compress source data dont compress already compressed codec source length max length before compression chk block data length false final data comp compressed data compression algorithm comp compression algorithm catch key encode exception e2 throw new chk encode exception e2 get message e2 now do the actual encode message digest md256 sha256 get message digest first pad it if final data length 32768 hash the data if final data length 0 md256 update final data byte digest md256 digest mersenne twister mt new mersenne twister digest data new byte 32768 system arraycopy final data 0 data 0 final data length byte random bytes new byte 32768 final data length mt next bytes random bytes system arraycopy random bytes 0 data final data length 32768 final data length else data final data now make the header byte enc key md256 digest data md256 reset iv e h crypto key byte plainiv md256 digest enc key header new byte plainiv length 2 2 header 0 byte key block hash sha256 8 header 1 byte key block hash sha256 0xff system arraycopy plainiv 0 header 2 plainiv length header plainiv length 2 byte final data length 8 header plainiv length 3 byte final data length 0xff grrr java 1 4 does not have any symmetric crypto despite exposing asymmetric and hashes now encrypt the header then the data using the same pcfb instance block cipher cipher try cipher new rijndael 256 256 catch unsupported cipher exception e fixme log this properly throw new error e cipher initialize enc key pcfb mode pcfb pcfb mode create cipher pcfb block encipher header 2 header length 2 pcfb block encipher data 0 data length now calculate the final hash md256 update header byte final hash md256 digest data sha256 return message digest md256 now convert it into a clientchk key new clientchk final hash enc key as metadata key algo aes pcfb 256 sha256 compression algorithm try return new clientchk block data header key false catch chk verify exception e3 wtf throw new error e3 chkblock sourcedata asmetadata dontcompress alreadycompressedcodec dontcompress chkencodeexception ioexception clientchkblock sourcedata asmetadata dontcompress alreadycompressedcodec sourcelength chkencodeexception ioexception finaldata compressionalgorithm sourcedata dontcompress alreadycompressedcodec sourcelength max_length_before_compression chkblock data_length finaldata compresseddata compressionalgorithm compressionalgorithm keyencodeexception chkencodeexception getmessage messagedigest getmessagedigest finaldata finaldata finaldata mersennetwister mersennetwister finaldata finaldata randombytes finaldata nextbytes randombytes randombytes finaldata finaldata finaldata enckey enckey keyblock hash_sha256 keyblock hash_sha256 finaldata finaldata blockcipher unsupportedcipherexception enckey pcfbmode pcfbmode blockencipher blockencipher finalhash returnmessagedigest finalhash enckey asmetadata algo_aes_pcfb_256_sha256 compressionalgorithm clientchkblock chkverifyexception encode a block of data to a chk block param source data the data to encode param as metadata is this a metadata key param dont compress if set don t even try to compress param already compressed codec if dont compress and this is 0 then the data is already compressed and this is the algorithm static public clientchk block encode byte source data boolean as metadata boolean dont compress short already compressed codec int source length throws chk encode exception try return encode new array bucket source data as metadata dont compress already compressed codec source length catch io exception e can t happen throw new error e chkblock sourcedata asmetadata dontcompress alreadycompressedcodec dontcompress clientchkblock sourcedata asmetadata dontcompress alreadycompressedcodec sourcelength chkencodeexception arraybucket sourcedata asmetadata dontcompress alreadycompressedcodec sourcelength ioexception public client key get client key return key clientkey getclientkey public boolean is metadata return key is metadata ismetadata ismetadata override public boolean object can new object container container useful to be able to tell whether it s a chk block or a clientchk block so override here too throw new unsupported operation exception clientchk block storage in database not supported objectcannew objectcontainer chkblock clientchkblock unsupportedoperationexception clientchkblock override public int hash code return key hash code hashcode hashcode override public boolean equals object o if o instanceof clientchk block return false clientchk block block clientchk block o if key equals block key return false return super equals o clientchkblock clientchkblock clientchkblock private final void modify if owner null owner modify public int size return used public object clone throws clone not supported exception return super clone clonenotsupportedexception public void set size int new size if new size used for int i used i new size arr i null else reserve space new size used used new size setsize newsize newsize newsize reservespace newsize newsize public t get int i if i 0 i used throw new index out of bounds exception return t load elem i indexoutofboundsexception loadelem public i persistent get raw int i if i 0 i used throw new index out of bounds exception return arr i ipersistent getraw indexoutofboundsexception public void pin for int i 0 n used i n i arr i load elem i loadelem public void unpin for int i 0 n used i n i i persistent elem arr i if elem null elem is raw elem is persistent arr i new persistent stub elem get storage elem get oid ipersistent israw ispersistent persistentstub getstorage getoid public t set int i t obj if i 0 i used throw new index out of bounds exception t prev t load elem i arr i obj modify return prev indexoutofboundsexception loadelem public void set object int i t obj if i 0 i used throw new index out of bounds exception arr i obj modify setobject indexoutofboundsexception public boolean is empty return used 0 isempty protected void remove range int from index int to index int size used int num moved size to index system arraycopy arr to index arr from index num moved let gc do its work int new size size to index from index while size new size arr size null used size modify removerange fromindex toindex nummoved toindex toindex fromindex nummoved newsize toindex fromindex newsize public void remove object int i if i 0 i used throw new index out of bounds exception used 1 system arraycopy arr i 1 arr i used i arr used null modify removeobject indexoutofboundsexception public t remove int i if i 0 i used throw new index out of bounds exception t obj t load elem i used 1 system arraycopy arr i 1 arr i used i arr used null modify return obj indexoutofboundsexception loadelem void reserve space int len if used len arr length i persistent new arr new i persistent used len arr length 2 used len arr length 2 system arraycopy arr 0 new arr 0 used arr new arr modify reservespace ipersistent newarr ipersistent newarr newarr public void add int i t obj insert i obj public void insert int i t obj if i 0 i used throw new index out of bounds exception reserve space 1 system arraycopy arr i arr i 1 used i arr i obj used 1 indexoutofboundsexception reservespace public boolean add t obj reserve space 1 arr used obj return true reservespace public void add all t a add all a 0 a length addall addall public boolean add all int index collection extends t c boolean modified false iterator extends t e c iterator while e has next add index e next modified true return modified addall hasnext public void add all t a int from int length reserve space length system arraycopy a from arr used length used length addall reservespace public boolean add all link t link int n link size reserve space n for int i 0 j used i n i j arr j link get raw i used n return true addall reservespace getraw public object to array return to persistent array toarray topersistentarray public i persistent to raw array return arr ipersistent torawarray public i persistent to persistent array i persistent a new i persistent used for int i used i 0 a i load elem i return a ipersistent topersistentarray ipersistent ipersistent loadelem public t t to array t arr if arr length used arr t array new instance arr get class get component type used for int i used i 0 arr i t load elem i if arr length used arr used null return arr toarray newinstance getclass getcomponenttype loadelem public boolean contains object obj return index of obj 0 indexof public boolean contains object t obj return index of object obj 0 containsobject indexofobject public int last index of object object obj int oid i persistent a arr if obj instanceof i persistent oid i persistent obj get oid 0 for int i used i 0 i persistent elem a i if elem null elem get oid oid return i else for int i used i 0 if a i obj return i return 1 lastindexofobject ipersistent ipersistent ipersistent getoid ipersistent getoid public int index of object object obj int oid i persistent a arr if obj instanceof i persistent oid i persistent obj get oid 0 for int i 0 n used i n i i persistent elem a i if elem null elem get oid oid return i else for int i 0 n used i n i if a i obj return i return 1 indexofobject ipersistent ipersistent ipersistent getoid ipersistent getoid public int index of object obj if obj null for int i 0 n used i n i if arr i null return i else for int i 0 n used i n i if obj equals load elem i return i return 1 indexof loadelem public int last index of object obj if obj null for int i used i 0 if arr i null return i else for int i used i 0 if obj equals load elem i return i return 1 lastindexof loadelem public boolean contains element int i t obj i persistent elem arr i return elem obj elem null elem get oid 0 elem get oid obj get oid containselement ipersistent getoid getoid getoid public void clear for int i used i 0 arr i null used 0 modify public list t sub list int from index int to index return new sub list t this from index to index sublist fromindex toindex sublist fromindex toindex sub list link impl t list int from index int to index if from index 0 throw new index out of bounds exception from index from index if to index list size throw new index out of bounds exception to index to index if from index to index throw new illegal argument exception from index from index to index to index l list offset from index size to index from index sublist linkimpl fromindex toindex fromindex indexoutofboundsexception fromindex fromindex toindex indexoutofboundsexception toindex toindex fromindex toindex illegalargumentexception fromindex fromindex toindex toindex fromindex toindex fromindex public t set int index t element range check index return l set index offset element rangecheck public t get int index range check index return l get index offset rangecheck public int size return size public void add int index t element if index 0 index size throw new index out of bounds exception l add index offset element size indexoutofboundsexception public t remove int index range check index t result l remove index offset size return result rangecheck protected void remove range int from index int to index l remove range from index offset to index offset size to index from index removerange fromindex toindex removerange fromindex toindex toindex fromindex public boolean add all collection extends t c return add all size c addall addall public boolean add all int index collection extends t c if index 0 index size throw new index out of bounds exception index index size size int c size c size if c size 0 return false l add all offset index c size c size return true addall indexoutofboundsexception csize csize addall csize public iterator t iterator return list iterator listiterator public list iterator t list iterator final int index if index 0 index size throw new index out of bounds exception index index size size return new list iterator t private list iterator t i l list iterator index offset public boolean has next return next index size public t next if has next return i next else throw new no such element exception public boolean has previous return previous index 0 public t previous if has previous return i previous else throw new no such element exception public int next index return i next index offset public int previous index return i previous index offset public void remove i remove size public void set t o i set o public void add t o i add o size listiterator listiterator indexoutofboundsexception listiterator listiterator listiterator hasnext nextindex hasnext nosuchelementexception hasprevious previousindex hasprevious nosuchelementexception nextindex nextindex previousindex previousindex private list iterator t i l list iterator index offset public boolean has next return next index size listiterator listiterator hasnext nextindex public t next if has next return i next else throw new no such element exception hasnext nosuchelementexception public boolean has previous return previous index 0 hasprevious previousindex public t previous if has previous return i previous else throw new no such element exception hasprevious nosuchelementexception public int next index return i next index offset nextindex nextindex public int previous index return i previous index offset previousindex previousindex public void remove i remove size public void set t o i set o public void add t o i add o size public list t sub list int from index int to index return new sub list t l offset from index offset to index sublist fromindex toindex sublist fromindex toindex private void range check int index if index 0 index size throw new index out of bounds exception index index size size rangecheck indexoutofboundsexception link iterator link t link int index this link link i index last 1 linkiterator public boolean has next return i link size hasnext public t next throws no such element exception if has next throw new no such element exception last i return link get i nosuchelementexception hasnext nosuchelementexception public int next index return i nextindex public boolean has previous return i 0 hasprevious public t previous throws no such element exception if has previous throw new no such element exception return link get last i nosuchelementexception hasprevious nosuchelementexception public int previous index return i 1 previousindex public int next oid throws no such element exception if has next throw new no such element exception return link get raw i get oid nextoid nosuchelementexception hasnext nosuchelementexception getraw getoid public void remove if last 0 throw new illegal state exception link remove object last if last i i 1 illegalstateexception removeobject public void set t o if last 0 throw new illegal state exception link set object last o illegalstateexception setobject public void add t o link insert i o last 1 public boolean remove object o int i index of o if i 0 remove i return true return false indexof public boolean contains all collection c iterator e c iterator while e has next if contains e next return false return true containsall hasnext public boolean add all collection extends t c boolean modified false iterator extends t e c iterator while e has next if add e next modified true return modified addall hasnext public boolean remove all collection c boolean modified false iterator e iterator while e has next if c contains e next e remove modified true return modified removeall hasnext public boolean retain all collection c boolean modified false iterator t e iterator while e has next if c contains e next e remove modified true return modified retainall hasnext public iterator t iterator return new link iterator t this 0 linkiterator public list iterator t list iterator int index return new link iterator t this index listiterator listiterator linkiterator public list iterator t list iterator return list iterator 0 listiterator listiterator listiterator private final t load elem int i i persistent elem arr i if elem null elem is raw elem storage impl elem get storage lookup object elem get oid null return t elem loadelem ipersistent israw storageimpl getstorage lookupobject getoid public iterable iterator t select class cls string predicate query t query new query impl t null return query select cls iterator predicate iterableiterator queryimpl public void set owner i persistent obj owner obj setowner ipersistent public i persistent get owner return owner ipersistent getowner link impl linkimpl link impl public link impl int init size arr new i persistent init size linkimpl linkimpl initsize ipersistent initsize public link impl t arr i persistent owner this arr arr this owner owner used arr length linkimpl ipersistent public link impl link link i persistent owner used link size arr new i persistent used system arraycopy arr 0 link to raw array 0 used this owner owner linkimpl ipersistent ipersistent torawarray private float scale 1 0f public rescale filter rescalefilter public rescale filter float scale this scale scale rescalefilter override protected float transfer function float v return v scale transferfunction specifies the scale factor param scale the scale factor min value 1 max value 5 see get scale public void set scale float scale this scale scale initialized false getscale setscale returns the scale factor return the scale factor see set scale public float get scale return scale setscale getscale override public string to string return colors rescale tostring public class full text search hit implements comparable get document matching full text query public i persistent get document return storage get object byoid oid fulltextsearchhit ipersistent getdocument getobjectbyoid public final storage storage public int compare to object o float o rank full text search hit o rank return rank o rank 1 rank o rank 1 0 compareto orank fulltextsearchhit orank orank constructor of the full text search result hit public full text search hit storage storage int oid float rank this storage storage this oid oid this rank rank fulltextsearchhit public client put base freeneturi uri string identifier int verbosity fcp connection handler handler short priority class short persistence type string client token boolean global boolean getchk only boolean dont compress int max retries boolean early encode fcp server server object container container throws malformedurl exception super uri identifier verbosity handler priority class persistence type client token global container this getchk only getchk only ctx new insert context server default insert context new simple event producer ctx dont compress dont compress ctx event producer add event listener this ctx max insert retries max retries this early encode early encode publicuri get publicuri uri clientputbase fcpconnectionhandler priorityclass persistencetype clienttoken getchkonly dontcompress maxretries earlyencode fcpserver objectcontainer malformedurlexception priorityclass persistencetype clienttoken getchkonly getchkonly insertcontext defaultinsertcontext simpleeventproducer dontcompress dontcompress eventproducer addeventlistener maxinsertretries maxretries earlyencode earlyencode getpublicuri public client put base freeneturi uri string identifier int verbosity fcp connection handler handler fcp client client short priority class short persistence type string client token boolean global boolean getchk only boolean dont compress int max retries boolean early encode fcp server server object container container throws malformedurl exception super uri identifier verbosity handler client priority class persistence type client token global container this getchk only getchk only ctx new insert context server default insert context new simple event producer ctx dont compress dont compress ctx event producer add event listener this ctx max insert retries max retries this early encode early encode publicuri get publicuri uri clientputbase fcpconnectionhandler fcpclient priorityclass persistencetype clienttoken getchkonly dontcompress maxretries earlyencode fcpserver objectcontainer malformedurlexception priorityclass persistencetype clienttoken getchkonly getchkonly insertcontext defaultinsertcontext simpleeventproducer dontcompress dontcompress eventproducer addeventlistener maxinsertretries maxretries earlyencode earlyencode getpublicuri public client put base simple field set fs fcp client client2 fcp server server throws malformedurl exception super fs client2 publicuri get publicuri uri getchk only fields string to bool fs get chk only false boolean dont compress fields string to bool fs get dont compress false int max retries integer parse int fs get max retries client token fs get client token finished fields string to bool fs get finished false finished false succeeded fields string to bool fs get succeeded false ctx new insert context server default insert context new simple event producer ctx dont compress dont compress ctx event producer add event listener this ctx max insert retries max retries string genuri fs get generateduri if genuri null generateduri new freeneturi genuri if finished string ctime fs get completion time if ctime null completion time long parse long ctime if succeeded put failed message new put failed message fs subset put failed false early encode fields string to bool fs get early encode false clientputbase simplefieldset fcpclient fcpserver malformedurlexception getpublicuri getchkonly stringtobool chkonly dontcompress stringtobool dontcompress maxretries parseint maxretries clienttoken clienttoken stringtobool stringtobool insertcontext defaultinsertcontext simpleeventproducer dontcompress dontcompress eventproducer addeventlistener maxinsertretries maxretries completiontime completiontime parselong putfailedmessage putfailedmessage putfailed earlyencode stringtobool earlyencode private freeneturi get publicuri freeneturi uri throws malformedurl exception string type uri get key type if type equals ignore case chk return uri else if type equals ignore case ssk type equals ignore case usk if type equals ignore case usk uri uri set key type ssk insertable clientssk issk insertable clientssk create uri uri uri set routing key issk geturi get routing key uri uri set key type type return uri else if type equals ignore case ksk return uri else throw new illegal argument exception getpublicuri malformedurlexception getkeytype equalsignorecase equalsignorecase equalsignorecase equalsignorecase setkeytype insertableclientssk insertableclientssk setroutingkey getroutingkey setkeytype equalsignorecase illegalargumentexception override public void on lost connection object container container client context context if persistence type persist connection cancel container context otherwise ignore onlostconnection objectcontainer clientcontext persistencetype persist_connection public void on success base client putter state object container container synchronized this including this helps with certain bugs progress message null succeeded true finished true if generateduri null logger error this no generated uri in on success for this from state could restart and is on the putter don t free data until we remove the putter free data container finish container try send final message null container if client null client notify success this container onsuccess baseclientputter objectcontainer progressmessage onsuccess freedata trysendfinalmessage notifysuccess public void on failure insert exception e base client putter state object container container if finished return synchronized this finished true put failed message new put failed message e identifier global if persistence type persist forever container store this could restart and is on the putter don t free data until we remove the putter free data container finish container try send final message null container if client null client notify failure this container onfailure insertexception baseclientputter objectcontainer putfailedmessage putfailedmessage persistencetype persist_forever freedata trysendfinalmessage notifyfailure public void on generateduri freeneturi uri base client putter state object container container synchronized this if generateduri null if uri equals generateduri logger error this on generateduri uri state but already set generateduri to generateduri else if logger should log logger minor this logger minor this on generateduri twice with same value generateduri uri else generateduri uri if persistence type persist forever container store this try send generateduri message null container ongenerateduri baseclientputter objectcontainer ongenerateduri shouldlog ongenerateduri persistencetype persist_forever trysendgeneratedurimessage override public void request was removed object container container client context context if request is still running send a put failed with code cancelled if finished synchronized this finished true insert exception cancelled new insert exception insert exception cancelled put failed message new put failed message cancelled identifier global try send final message null container notify client that request was removed fcp message msg new persistent request removed message get identifier global if persistence type persist connection orig handler output handler queue msg else client queue client request message msg 0 container free data container if persistence type persist forever container activate ctx 2 ctx remove from container put failed message pfm freeneturi uri freeneturi puburi fcp message progress synchronized this pfm put failed message put failed message null uri generateduri generateduri null puburi publicuri progress progress message progress message null if pfm null container activate pfm 5 pfm remove from container if uri null container activate uri 5 uri remove from container if progress null container activate progress 1 progress remove from container if puburi null container activate puburi 5 puburi remove from container super request was removed container context requestwasremoved objectcontainer clientcontext putfailed insertexception insertexception insertexception putfailedmessage putfailedmessage trysendfinalmessage fcpmessage persistentrequestremovedmessage getidentifier persistencetype persist_connection orighandler outputhandler queueclientrequestmessage freedata persistencetype persist_forever removefrom putfailedmessage fcpmessage putfailedmessage putfailedmessage progressmessage progressmessage removefrom removefrom removefrom removefrom requestwasremoved public void receive final client event ce object container container client context context if finished return if persistence type persist forever container null context job runner queue new db job public void run object container container client context context container activate client put base this 1 receive ce container context container deactivate client put base this 1 native thread norm priority false return if ce instanceof splitfile progress event if verbosity verbosity splitfile progress verbosity splitfile progress simple progress message progress new simple progress message identifier global splitfile progress event ce try send progress message progress verbosity splitfile progress null container context else if ce instanceof started compression event if verbosity verbosity compression start end verbosity compression start end started compression message msg new started compression message identifier global started compression event ce codec try send progress message msg verbosity compression start end null container context else if ce instanceof finished compression event if verbosity verbosity compression start end verbosity compression start end finished compression message msg new finished compression message identifier global finished compression event ce try send progress message msg verbosity compression start end null container context clientevent objectcontainer clientcontext persistencetype persist_forever jobrunner dbjob objectcontainer clientcontext clientputbase clientputbase nativethread norm_priority splitfileprogressevent verbosity_splitfile_progress verbosity_splitfile_progress simpleprogressmessage simpleprogressmessage splitfileprogressevent trysendprogressmessage verbosity_splitfile_progress startedcompressionevent verbosity_compression_start_end verbosity_compression_start_end startedcompressionmessage startedcompressionmessage startedcompressionevent trysendprogressmessage verbosity_compression_start_end finishedcompressionevent verbosity_compression_start_end verbosity_compression_start_end finishedcompressionmessage finishedcompressionmessage finishedcompressionevent trysendprogressmessage verbosity_compression_start_end public void on fetchable base client putter putter object container container if finished return if verbosity verbosity put fetchable verbosity put fetchable freeneturi temp synchronized this temp generateduri put fetchable message msg new put fetchable message identifier global temp try send progress message msg verbosity put fetchable null container null onfetchable baseclientputter objectcontainer verbosity_put_fetchable verbosity_put_fetchable putfetchablemessage putfetchablemessage trysendprogressmessage verbosity_put_fetchable private void try send final message fcp connection output handler handler object container container fcp message msg synchronized this freeneturi uri generateduri if persistence type persist forever uri null container activate uri 5 uri uri clone if succeeded msg new put successful message identifier global uri startup time completion time else msg put failed message if msg null logger error this trying to send null message on this new exception error else if persistence type persist connection handler null handler orig handler output handler if handler null handler queue msg else client queue client request message msg 0 container trysendfinalmessage fcpconnectionoutputhandler objectcontainer fcpmessage persistencetype persist_forever putsuccessfulmessage startuptime completiontime putfailedmessage persistencetype persist_connection orighandler outputhandler queueclientrequestmessage private void try send generateduri message fcp connection output handler handler object container container fcp message msg if persistence type persist forever container activate client 1 container activate generateduri 5 synchronized this msg new uri generated message generateduri identifier is global queue if persistence type persist connection handler null handler orig handler output handler if handler null handler queue msg else client queue client request message msg 0 container trysendgeneratedurimessage fcpconnectionoutputhandler objectcontainer fcpmessage persistencetype persist_forever urigeneratedmessage isglobalqueue persistencetype persist_connection orighandler outputhandler queueclientrequestmessage param msg param verbosity param handler param container either container or context is required for a persistent request param context can be null if container is not null private void try send progress message final fcp message msg final int verbosity fcp connection output handler handler object container container client context context if persistence type persist forever if container null fcp message old progress null synchronized this if persistence type persist connection old progress progress message progress message msg if old progress null container activate old progress 1 old progress remove from container container store this else final fcp connection output handler h handler context job runner queue new db job public void run object container container client context context container activate client put base this 1 try send progress message msg verbosity h container context container deactivate client put base this 1 native thread norm priority false return else synchronized this if persistence type persist connection progress message msg if persistence type persist connection handler null handler orig handler output handler if handler null handler queue msg else client queue client request message msg verbosity container trysendprogressmessage fcpmessage fcpconnectionoutputhandler objectcontainer clientcontext persistencetype persist_forever fcpmessage oldprogress persistencetype persist_connection oldprogress progressmessage progressmessage oldprogress oldprogress oldprogress removefrom fcpconnectionoutputhandler jobrunner dbjob objectcontainer clientcontext clientputbase trysendprogressmessage clientputbase nativethread norm_priority persistencetype persist_connection progressmessage persistencetype persist_connection orighandler outputhandler queueclientrequestmessage override public void send pending messages fcp connection output handler handler boolean include persistent request boolean include data boolean only data object container container if persistence type persist connection logger error this wtf persistence type persistence type new exception error return if include persistent request fcp message msg persistent tag message container handler queue msg boolean generated false fcp message msg null boolean fin false synchronized this generated generateduri null msg progress message fin finished if persistence type persist forever msg null container activate msg 5 if generated try send generateduri message handler container if msg null handler queue msg if fin try send final message handler container sendpendingmessages fcpconnectionoutputhandler includepersistentrequest includedata onlydata objectcontainer persistencetype persist_connection persistencetype persistencetype includepersistentrequest fcpmessage persistenttagmessage fcpmessage progressmessage persistencetype persist_forever trysendgeneratedurimessage trysendfinalmessage override public synchronized simple field set get field set simple field set fs new simple field set false we will need multi level later fs put single type get type name fs put single uri uri to string false false fs put single identifier identifier fs put single verbosity integer to string verbosity fs put single priority class short to string priority class fs put single persistence client request persistence type string persistence type fs put single client name client name fs put single client token client token fs put single dont compress boolean to string ctx dont compress fs put single max retries integer to string ctx max insert retries fs put single finished boolean to string finished fs put single succeeded boolean to string succeeded fs put single getchk only boolean to string getchk only if generateduri null fs put single generateduri generateduri to string false false if finished succeeded should have a put failed message unless there is a race condition fs put put failed put failed message get field set false fs put single global boolean to string client is global queue fs put startup time startup time if finished fs put completion time completion time return fs simplefieldset getfieldset simplefieldset simplefieldset putsingle gettypename putsingle tostring putsingle putsingle tostring putsingle priorityclass tostring priorityclass putsingle clientrequest persistencetypestring persistencetype putsingle clientname putsingle clienttoken clienttoken putsingle dontcompress tostring dontcompress putsingle maxretries tostring maxinsertretries putsingle tostring putsingle tostring putsingle getchkonly tostring getchkonly putsingle tostring putfailedmessage putfailed putfailedmessage getfieldset putsingle tostring isglobalqueue startuptime startuptime completiontime completiontime protected abstract string get type name gettypename override public synchronized double get success fraction object container container if persistence type persist forever progress message null container activate progress message 2 if progress message null if progress message instanceof simple progress message return simple progress message progress message get fraction else return 0 else return 1 getsuccessfraction objectcontainer persistencetype persist_forever progressmessage progressmessage progressmessage progressmessage simpleprogressmessage simpleprogressmessage progressmessage getfraction override public synchronized double get total blocks object container container if persistence type persist forever progress message null container activate progress message 2 if progress message null if progress message instanceof simple progress message return simple progress message progress message get total blocks else return 0 else return 1 gettotalblocks objectcontainer persistencetype persist_forever progressmessage progressmessage progressmessage progressmessage simpleprogressmessage simpleprogressmessage progressmessage gettotalblocks override public synchronized double get min blocks object container container if persistence type persist forever progress message null container activate progress message 2 if progress message null if progress message instanceof simple progress message return simple progress message progress message get min blocks else return 0 else return 1 getminblocks objectcontainer persistencetype persist_forever progressmessage progressmessage progressmessage progressmessage simpleprogressmessage simpleprogressmessage progressmessage getminblocks override public synchronized double get failed blocks object container container if persistence type persist forever progress message null container activate progress message 2 if progress message null if progress message instanceof simple progress message return simple progress message progress message get failed blocks else return 0 else return 1 getfailedblocks objectcontainer persistencetype persist_forever progressmessage progressmessage progressmessage progressmessage simpleprogressmessage simpleprogressmessage progressmessage getfailedblocks override public synchronized double get fataly failed blocks object container container if persistence type persist forever progress message null container activate progress message 2 if progress message null if progress message instanceof simple progress message return simple progress message progress message get fataly failed blocks else return 0 else return 1 getfatalyfailedblocks objectcontainer persistencetype persist_forever progressmessage progressmessage progressmessage progressmessage simpleprogressmessage simpleprogressmessage progressmessage getfatalyfailedblocks override public synchronized double get fetched blocks object container container if persistence type persist forever progress message null container activate progress message 2 if progress message null if progress message instanceof simple progress message return simple progress message progress message get fetched blocks else return 0 else return 1 getfetchedblocks objectcontainer persistencetype persist_forever progressmessage progressmessage progressmessage progressmessage simpleprogressmessage simpleprogressmessage progressmessage getfetchedblocks override public synchronized boolean is total finalized object container container if progress message instanceof simple progress message return false else if persistence type persist forever container activate progress message 5 return simple progress message progress message is total finalized istotalfinalized objectcontainer progressmessage simpleprogressmessage persistencetype persist_forever progressmessage simpleprogressmessage progressmessage istotalfinalized override public synchronized string get failure reason object container container if put failed message null return null if persistence type persist forever container activate put failed message 5 string s put failed message short code description if put failed message extra description null s put failed message extra description return s getfailurereason objectcontainer putfailedmessage persistencetype persist_forever putfailedmessage putfailedmessage shortcodedescription putfailedmessage extradescription putfailedmessage extradescription public void set vars restart object container container put failed message pfm fcp message progress synchronized this finished false pfm put failed message progress progress message this put failed message null this progress message null started false if pfm null container activate pfm 1 pfm remove from container if progress null container activate progress 1 progress remove from container if persistence type persist forever container store this setvarsrestart objectcontainer putfailedmessage fcpmessage putfailedmessage progressmessage putfailedmessage progressmessage removefrom removefrom persistencetype persist_forever public class unpremultiply filter extends point filter public unpremultiply filter unpremultiplyfilter pointfilter unpremultiplyfilter override public int filterrgb int x int y int rgb int a rgb 24 0xff int r rgb 16 0xff int g rgb 8 0xff int b rgb 0xff if a 0 a 255 return rgb float f 255 0f a r f g f b f if r 255 r 255 if g 255 g 255 if b 255 b 255 return a 24 r 16 g 8 b override public string to string return alpha unpremultiply tostring public peer removed string identity string node identifier string identifier this identity identity this node identifier node identifier this identifier identifier peerremoved nodeidentifier nodeidentifier nodeidentifier override public simple field set get field set simple field set fs new simple field set true fs put single identity identity fs put single node identifier node identifier if identifier null fs put single identifier identifier return fs simplefieldset getfieldset simplefieldset simplefieldset putsingle putsingle nodeidentifier nodeidentifier putsingle override public string get name return name getname override public void run fcp connection handler handler node node throws message invalid exception throw new message invalid exception protocol error message invalid message peer removed goes from server to client not the other way around identifier false fcpconnectionhandler messageinvalidexception messageinvalidexception protocolerrormessage invalid_message peerremoved override public void remove from object container container container delete this removefrom objectcontainer public final string extra get the failure mode public int get mode return mode getmode logger register log threshold callback new log threshold callback override public void should update logminor logger should log logger minor this registerlogthresholdcallback logthresholdcallback shouldupdate shouldlog public insert exception int m string msg freeneturi expecteduri super get message m msg extra msg mode m if logminor logger minor this creating insert exception get message mode msg this error codes null this uri expecteduri insertexception getmessage insertexception getmessage errorcodes public insert exception int m freeneturi expecteduri super get message m extra null mode m if logminor logger minor this creating insert exception get message mode this error codes null this uri expecteduri insertexception getmessage insertexception getmessage errorcodes public insert exception int mode throwable e freeneturi expecteduri super get message mode e get message extra e get message if logminor logger minor this creating insert exception get message mode e e this mode mode error codes null init cause e this uri expecteduri insertexception getmessage getmessage getmessage insertexception getmessage errorcodes initcause public insert exception int mode failure code tracker error codes freeneturi expecteduri super get message mode extra null this mode mode if logminor logger minor this creating insert exception get message mode this this error codes error codes this uri expecteduri insertexception failurecodetracker errorcodes getmessage insertexception getmessage errorcodes errorcodes public insert exception int mode super get message mode extra null this mode mode this error codes null this uri null insertexception getmessage errorcodes public insert exception insert exception e super e get message extra e extra mode e mode error codes e error codes clone if e uri null uri null else uri e uri clone insertexception insertexception getmessage errorcodes errorcodes public static string get message int mode string ret l10n get string insert exception long error mode if ret null return unknown error mode else return ret getmessage getstring insertexception longerror public static string get short message int mode string ret l10n get string insert exception short error mode if ret null return unknown error mode else return ret getshortmessage getstring insertexception shorterror is this error fatal non fatal errors are errors which are likely to go away with more retries or at least for which there is some point retrying public boolean is fatal return is fatal mode isfatal isfatal public static boolean is fatal int mode switch mode case invalid uri case fatal errors in blocks case collision case cancelled case meta strings not supported case binary blob format error return true case bucket error maybe case internal error maybe case rejected overload case too many retries in blocks case route not found case route really not found return false default logger error insert exception class error unknown to is fatal get message mode return false isfatal invalid_uri fatal_errors_in_blocks meta_strings_not_supported binary_blob_format_error bucket_error internal_error rejected_overload too_many_retries_in_blocks route_not_found route_really_not_found insertexception isfatal getmessage public static insert exception construct failure code tracker errors if errors null return null if errors is empty return null if errors is one code only return new insert exception errors get first code int mode if errors is fatal true mode fatal errors in blocks else mode too many retries in blocks return new insert exception mode errors null insertexception failurecodetracker isempty isonecodeonly insertexception getfirstcode isfatal fatal_errors_in_blocks too_many_retries_in_blocks insertexception override public insert exception clone return new insert exception this insertexception insertexception public void remove from object container container if error codes null container activate error codes 1 error codes remove from container if uri null container activate uri 5 uri remove from container stack trace element elements get stack trace if elements null for stack trace element element elements container delete element container delete this removefrom objectcontainer errorcodes errorcodes errorcodes removefrom removefrom stacktraceelement getstacktrace stacktraceelement private static final string svn revision custom static string get svn revision return svn revision svnrevision getsvnrevision svnrevision public wot message fetcher node my node high level simple client my client string my name wot identity manager my identity manager wot message manager my message manager super my node my client my name my identity manager my message manager m random m node fast weak random request client my message manager request client start wotmessagefetcher mynode highlevelsimpleclient myclient myname wotidentitymanager myidentitymanager wotmessagemanager mymessagemanager mynode myclient myname myidentitymanager mymessagemanager mrandom mnode fastweakrandom requestclient mymessagemanager requestclient override protected collection client getter create fetch storage return new hash set client getter max parallel message fetch count 2 clientgetter createfetchstorage hashset clientgetter max_parallel_message_fetch_count override protected collection base client putter create insert storage return null baseclientputter createinsertstorage override public int get priority return native thread norm priority getpriority nativethread norm_priority override protected long get startup delay return startup delay 2 m random next int startup delay getstartupdelay startup_delay mrandom nextint startup_delay override protected long get sleep time return thread period 2 m random next int thread period getsleeptime thread_period mrandom nextint thread_period override protected synchronized void iterate abort all transfers fixme i think the counterpart of this synchronized which ensures that message lists are not created when this lock is help might be missing check through the other code and add it where it s needed synchronized message list class todo obtain wot message lists only not all iterator message list message reference iter m message manager not downloaded message iterator while iter has next message list message reference ref iter next fetch message ref get message list ref fixme investigate whether this is fair i e whether it will not always try to download the same messages if downloading of some of them stalls for so long that the thread re iterates before on failure is called which results in the messages not being marked as undownloadable currently we do not mark messages as undownloadable anyway however on failure should do that in the future if fetch count max parallel message fetch count break abortalltransfers messagelists messagelist wotmessagelists messagelist messagereference mmessagemanager notdownloadedmessageiterator hasnext messagelist messagereference fetchmessage getmessagelist onfailure onfailure fetchcount max_parallel_message_fetch_count you have to synchronize on this code wot message fetcher code when using this function private void fetch message message list list message list message reference ref try fetch message list ref geturi catch exception e logger error this error while trying to fetch message ref geturi e wotmessagefetcher fetchmessage messagelist messagelist messagereference fetchmessage you have to synchronize on this code wot message fetcher code when using this function private void fetch message message list list freeneturi uri throws fetch exception todo if a single message is posted to multiple boards a message list message reference is stored for each boards because we query the message manager for message reference objects it might happen that this function is called twice for a single message on the one hand because of this we should check whether we are already downloading the given uri on the other hand most messages will be posted to only a single board so the overhead of creating a hash set freeneturi might not be worthwhile the message manager will ignore duplicates of already downloaded messages anyway fetch context fetch context m client get fetch context fetch context max splitfile block retries 2 fetch context max non splitfile retries 2 client getter g m client fetch uri 1 request client this fetch context g set priority class request starter update priority class pluginmanager defaults to interactive priority add fetch g m message lists put g list getid logger debug this trying to fetch message from uri wotmessagefetcher fetchmessage messagelist fetchexception messagelist messagereference messagemanager messagereference hashset messagemanager fetchcontext fetchcontext mclient getfetchcontext fetchcontext maxsplitfileblockretries fetchcontext maxnonsplitfileretries clientgetter mclient requestclient fetchcontext setpriorityclass requeststarter update_priority_class addfetch mmessagelists override public synchronized void on success fetch result result client getter state object container container logger debug this fetched message state geturi input stream input null wot message list list null try list wot message list m message manager get message list m message lists get state input result as bucket get input stream message message wot messagexml decode m message manager input list state geturi m message manager on message received message catch exception e logger error this parsing failed for message state geturi e if list null try m message manager on message fetch failed list get reference state geturi message list message fetch failed reference reason parsing failed catch no such message exception ex assert false logger error this should not happen ex finally closer close input remove fetch state fixme this was in the try block somewhere else in the ft wot code move it to finally there too fixme this will wake up the loop over and over again we need to store the previous parallel fetch count and if waking up does not increase the fetch count do not wake up again if fetch count min parallel message fetch count next iteration onsuccess fetchresult clientgetter objectcontainer inputstream wotmessagelist wotmessagelist mmessagemanager getmessagelist mmessagelists asbucket getinputstream wotmessagexml mmessagemanager mmessagemanager onmessagereceived mmessagemanager onmessagefetchfailed getreference messagelist messagefetchfailedreference parsingfailed nosuchmessageexception removefetch fetchcount min_parallel_message_fetch_count nextiteration override public synchronized void on failure fetch exception e client getter state object container container try switch e get mode case fetch exception data not found try wot message list list wot message list m message manager get message list m message lists get state m message manager on message fetch failed list get reference state geturi message list message fetch failed reference reason data not found catch exception ex no such message list no such message assert false logger error this should not happen ex finally logger error this dnf for message state geturi break case fetch exception cancelled logger debug this cancelled downloading message state geturi break default logger error this downloading message state geturi failed e break finally remove fetch state fixme this will wake up the loop over and over again we need to store the previous parallel fetch count and if waking up does not increase the fetch count do not wake up again if fetch count min parallel message fetch count next iteration onfailure fetchexception clientgetter objectcontainer getmode fetchexception data_not_found wotmessagelist wotmessagelist mmessagemanager getmessagelist mmessagelists mmessagemanager onmessagefetchfailed getreference messagelist messagefetchfailedreference datanotfound nosuchmessagelist nosuchmessage fetchexception removefetch fetchcount min_parallel_message_fetch_count nextiteration you have to synchronize on this code wot message fetcher code when using this function override protected void abort all transfers super abort all transfers m message lists clear wotmessagefetcher abortalltransfers abortalltransfers mmessagelists you have to synchronize on this code wot message fetcher code when using this function override protected void remove fetch client getter g super remove fetch g m message lists remove g wotmessagefetcher removefetch clientgetter removefetch mmessagelists not needed functions called for inserts override public void on generateduri freeneturi uri base client putter state object container container ongenerateduri baseclientputter objectcontainer public void on generateduri freeneturi uri base client putter state object container container override public void on success base client putter state object container container ongenerateduri baseclientputter objectcontainer onsuccess baseclientputter objectcontainer public void on success base client putter state object container container override public void on failure insert exception e base client putter state object container container onsuccess baseclientputter objectcontainer onfailure insertexception baseclientputter objectcontainer public void on failure insert exception e base client putter state object container container override public void on fetchable base client putter state object container container onfailure insertexception baseclientputter objectcontainer onfetchable baseclientputter objectcontainer public void on fetchable base client putter state object container container override public void on major progress object container container onfetchable baseclientputter objectcontainer onmajorprogress objectcontainer public skeleton filter new color 0xffffffff skeletonfilter newcolor override protected int filter pixels int width int height int in pixels rectangle transformed space int out pixels new int width height int count 0 int black 0xff000000 int white 0xffffffff for int i 0 i iterations i count 0 for int pass 0 pass 2 pass for int y 1 y height 1 y int offset y width 1 for int x 1 x width 1 x int pixel in pixels offset if pixel black int table index 0 if in pixels offset width 1 black table index 1 if in pixels offset width black table index 2 if in pixels offset width 1 black table index 4 if in pixels offset 1 black table index 8 if in pixels offset width 1 black table index 16 if in pixels offset width black table index 32 if in pixels offset width 1 black table index 64 if in pixels offset 1 black table index 128 int code skeleton table table index if pass 1 if code 2 code 3 if colormap null pixel colormap get color float i iterations else pixel new color count else if code 1 code 3 if colormap null pixel colormap get color float i iterations else pixel new color count out pixels offset pixel if pass 0 in pixels out pixels out pixels new int width height if count 0 break return out pixels filterpixels inpixels transformedspace outpixels inpixels tableindex inpixels tableindex inpixels tableindex inpixels tableindex inpixels tableindex inpixels tableindex inpixels tableindex inpixels tableindex inpixels tableindex skeletontable tableindex getcolor newcolor getcolor newcolor outpixels inpixels outpixels outpixels outpixels override public string to string return binary skeletonize tostring override public void should update logminor logger should log logger minor this logdebug logger should log logger debug this shouldupdate shouldlog shouldlog protected put handler final simple manifest putter smp string name bucket data client metadata cm boolean getchk only super smp priority class smp client this persistent simple manifest putter this persistent this cm cm this data data insert block block new insert block data cm persistent freeneturi empty chk uri clone freeneturi empty chk uri this origsfi new single file inserter this this block false ctx false getchk only true null null false null early encode metadata null container handle null puthandler simplemanifestputter clientmetadata getchkonly priorityclass simplemanifestputter insertblock insertblock empty_chk_uri empty_chk_uri singlefileinserter getchkonly earlyencode containerhandle protected put handler final simple manifest putter smp string name freeneturi target client metadata cm super smp get priority class smp client this persistent simple manifest putter this persistent this cm cm this data null metadata m new metadata metadata simple redirect null null target cm metadata m if logminor logger minor this simple redirect metadata m origsfi null container handle null puthandler simplemanifestputter clientmetadata getpriorityclass simplemanifestputter simple_redirect containerhandle protected put handler final simple manifest putter smp string name string target in archive client metadata cm bucket data super smp get priority class smp client this persistent simple manifest putter this persistent this cm cm this data data this target in archive target in archive metadata m new metadata metadata archive internal redirect null null target in archive cm metadata m if logminor logger minor this internal redirect m origsfi null container handle null puthandler simplemanifestputter targetinarchive clientmetadata getpriorityclass simplemanifestputter targetinarchive targetinarchive archive_internal_redirect targetinarchive containerhandle public void start object container container client context context throws insert exception if origsfi null logger error this origsfi is null on start should be impossible new exception debug return if metadata null logger error this metdata metadata on start should be impossible new exception debug return client put state sfi synchronized this sfi origsfi current state sfi origsfi null if persistent container activate sfi 1 container store this sfi schedule container context if persistent container deactivate sfi 1 objectcontainer clientcontext insertexception clientputstate currentstate override public void cancel object container container client context context if logger should log logger minor this logger minor this cancelling this new exception debug client put state old state null synchronized this if cancelled return super cancel old state current state if persistent container store this if old state null container activate old state 1 if old state null old state cancel container context on failure new insert exception insert exception cancelled null container context objectcontainer clientcontext shouldlog clientputstate oldstate oldstate currentstate oldstate oldstate oldstate oldstate onfailure insertexception insertexception override public freeneturi geturi return null override public boolean is finished return simple manifest putter this finished cancelled simple manifest putter this cancelled isfinished simplemanifestputter simplemanifestputter public void on success client put state state object container container client context context if logminor logger minor this completed this if persistent container activate simple manifest putter this 1 container activate running put handlers 2 simple manifest putter this on fetchable this container client put state old state boolean inserted all files true synchronized this old state current state current state null synchronized simple manifest putter this if persistent container store this running put handlers remove this if persistent container ext store running put handlers 2 container activate put handlers waiting for metadata 2 if put handlers waiting for metadata contains this put handlers waiting for metadata remove this container ext store put handlers waiting for metadata 2 logger error this put handler was in waiting for metadata in on success on this for simple manifest putter this if persistent container deactivate put handlers waiting for metadata 1 container activate waiting for block sets 2 if waiting for block sets contains this waiting for block sets remove this container store waiting for block sets logger error this put handler was in waiting for block sets in on success on this for simple manifest putter this if persistent container deactivate waiting for block sets 1 container deactivate put handlers waiting for fetchable 1 container activate put handlers waiting for fetchable 2 if put handlers waiting for fetchable contains this put handlers waiting for fetchable remove this container ext store put handlers waiting for fetchable 2 not getting an on fetchable is not unusual just ignore it if logminor logger minor this put handler was in waiting for fetchable in on success on this for simple manifest putter this if persistent container deactivate put handlers waiting for fetchable 1 if running put handlers is empty if logminor logger minor this running put handlers running put handlers size for object o running put handlers boolean activated true if persistent activated container ext is active o if activated container activate o 1 logger minor this still running o if activated container deactivate o 1 inserted all files false if old state null old state state persistent container activate old state 1 old state remove from container context else if state null persistent state remove from container context if inserted all files inserted all files container context if persistent container deactivate running put handlers 1 container deactivate simple manifest putter this 1 onsuccess clientputstate objectcontainer clientcontext simplemanifestputter runningputhandlers simplemanifestputter onfetchable clientputstate oldstate insertedallfiles oldstate currentstate currentstate simplemanifestputter runningputhandlers runningputhandlers puthandlerswaitingformetadata puthandlerswaitingformetadata puthandlerswaitingformetadata puthandlerswaitingformetadata puthandler waitingformetadata onsuccess simplemanifestputter puthandlerswaitingformetadata waitingforblocksets waitingforblocksets waitingforblocksets waitingforblocksets puthandler waitingforblocksets onsuccess simplemanifestputter waitingforblocksets puthandlerswaitingforfetchable puthandlerswaitingforfetchable puthandlerswaitingforfetchable puthandlerswaitingforfetchable puthandlerswaitingforfetchable onfetchable puthandler waitingforfetchable onsuccess simplemanifestputter puthandlerswaitingforfetchable runningputhandlers isempty runningputhandlers runningputhandlers isactive insertedallfiles oldstate oldstate oldstate oldstate removefrom removefrom insertedallfiles insertedallfiles runningputhandlers simplemanifestputter public void on failure insert exception e client put state state object container container client context context client put state old state synchronized this old state current state current state null if old state null old state state persistent container activate old state 1 old state remove from container context else if state null persistent state remove from container context if logminor logger minor this failed this e e if persistent container activate simple manifest putter this 1 fail e container context if persistent container deactivate simple manifest putter this 1 onfailure insertexception clientputstate objectcontainer clientcontext clientputstate oldstate oldstate currentstate currentstate oldstate oldstate oldstate oldstate removefrom removefrom simplemanifestputter simplemanifestputter public void on encode base client key key client put state state object container container client context context if logminor logger minor this on encode key for this if metadata null the file was too small to have its own metadata we get this instead so we make the key into metadata if persistent container activate key 5 container activate simple manifest putter this 1 metadata m new metadata metadata simple redirect null null key geturi cm on metadata m null container context if persistent container deactivate simple manifest putter this 1 onencode baseclientkey clientputstate objectcontainer clientcontext onencode simplemanifestputter simple_redirect onmetadata simplemanifestputter the caller of on transition removes the old state so we don t have to however in on success or on failure we need to remove the new state even if what is passed in is different in which case we remove that too public void on transition client put state old state client put state new state object container container if new state null throw new null pointer exception on transition is not responsible for removing the old state the caller is synchronized this if current state old state current state new state if persistent container store this if logminor logger minor this on transition cur current state old old state new new state for this return logger error this ignoring on transition cur current state old old state new new state for this ontransition onsuccess onfailure ontransition clientputstate oldstate clientputstate newstate objectcontainer newstate nullpointerexception ontransition currentstate oldstate currentstate newstate ontransition currentstate oldstate newstate ontransition currentstate oldstate newstate public void on metadata metadata m client put state state object container container client context context if logminor logger minor this assigning metadata m for this from state persistent persistent new exception debug if metadata null logger error this reassigning metadata new exception debug return metadata m if persistent container activate simple manifest putter this 1 container activate put handlers waiting for metadata 2 boolean all metadatas false synchronized simple manifest putter this put handlers waiting for metadata remove this if persistent container ext store put handlers waiting for metadata 2 container store this all metadatas put handlers waiting for metadata is empty if all metadatas if logminor logger minor this still waiting for metadata put handlers waiting for metadata size if all metadatas will resolve etc got all metadata container context else resolve now to speed up the insert try byte buf m write to byte array if buf length metadata max size in manifest throw new metadata unresolved exception new metadata m too big catch metadata unresolved exception e try resolve e container context catch io exception e1 fail new insert exception insert exception bucket error e1 null container context return catch insert exception e1 fail e1 container context if persistent container deactivate put handlers waiting for metadata 1 container deactivate simple manifest putter this 1 onmetadata clientputstate objectcontainer clientcontext simplemanifestputter puthandlerswaitingformetadata allmetadatas simplemanifestputter puthandlerswaitingformetadata puthandlerswaitingformetadata allmetadatas puthandlerswaitingformetadata isempty allmetadatas puthandlerswaitingformetadata allmetadatas gotallmetadata writetobytearray max_size_in_manifest metadataunresolvedexception metadataunresolvedexception ioexception insertexception insertexception bucket_error insertexception puthandlerswaitingformetadata simplemanifestputter override public void add block object container container if persistent container activate simple manifest putter this 1 simple manifest putter this add block container if persistent container deactivate simple manifest putter this 1 addblock objectcontainer simplemanifestputter simplemanifestputter addblock simplemanifestputter override public void add blocks int num object container container if persistent container activate simple manifest putter this 1 simple manifest putter this add blocks num container if persistent container deactivate simple manifest putter this 1 addblocks objectcontainer simplemanifestputter simplemanifestputter addblocks simplemanifestputter override public void completed block boolean dont notify object container container client context context if persistent container activate simple manifest putter this 1 simple manifest putter this completed block dont notify container context if persistent container deactivate simple manifest putter this 1 completedblock dontnotify objectcontainer clientcontext simplemanifestputter simplemanifestputter completedblock dontnotify simplemanifestputter override public void failed block object container container client context context if persistent container activate simple manifest putter this 1 simple manifest putter this failed block container context if persistent container deactivate simple manifest putter this 1 failedblock objectcontainer clientcontext simplemanifestputter simplemanifestputter failedblock simplemanifestputter override public void fatally failed block object container container client context context if persistent container activate simple manifest putter this 1 simple manifest putter this fatally failed block container context if persistent container deactivate simple manifest putter this 1 fatallyfailedblock objectcontainer clientcontext simplemanifestputter simplemanifestputter fatallyfailedblock simplemanifestputter override public void add must succeed blocks int blocks object container container if persistent container activate simple manifest putter this 1 simple manifest putter this add must succeed blocks blocks container if persistent container deactivate simple manifest putter this 1 addmustsucceedblocks objectcontainer simplemanifestputter simplemanifestputter addmustsucceedblocks simplemanifestputter override public void notify clients object container container client context context if persistent container activate simple manifest putter this 1 simple manifest putter this notify clients container context if persistent container deactivate simple manifest putter this 1 notifyclients objectcontainer clientcontext simplemanifestputter simplemanifestputter notifyclients simplemanifestputter public void on block set finished client put state state object container container client context context if persistent container activate simple manifest putter this 1 container activate waiting for block sets 2 boolean all block sets false synchronized simple manifest putter this waiting for block sets remove this if persistent container store waiting for block sets all block sets waiting for block sets is empty if all block sets simple manifest putter this block set finalized container context if persistent container deactivate waiting for block sets 1 container deactivate simple manifest putter this 1 onblocksetfinished clientputstate objectcontainer clientcontext simplemanifestputter waitingforblocksets allblocksets simplemanifestputter waitingforblocksets waitingforblocksets allblocksets waitingforblocksets isempty allblocksets simplemanifestputter blocksetfinalized waitingforblocksets simplemanifestputter override public void on major progress object container container if persistent container activate simple manifest putter this 1 simple manifest putter this on major progress container if persistent container deactivate simple manifest putter this 1 onmajorprogress objectcontainer simplemanifestputter simplemanifestputter onmajorprogress simplemanifestputter public void on fetchable client put state state object container container if persistent container activate simple manifest putter this 1 simple manifest putter this on fetchable this container if persistent container deactivate simple manifest putter this 1 onfetchable clientputstate objectcontainer simplemanifestputter simplemanifestputter onfetchable simplemanifestputter override public void on transition client get state old state client get state new state object container container ignore ontransition clientgetstate oldstate clientgetstate newstate objectcontainer public void clear metadata object container container metadata null if persistent container store this clearmetadata objectcontainer override public void remove from object container container client context context if logminor logger minor this removing this client put state oldsfi client put state old state synchronized this oldsfi origsfi old state current state origsfi null current state null if oldsfi null logger error this origsfi is set in remove from on this for simple manifest putter this new exception debug container activate oldsfi 1 oldsfi cancel container context oldsfi remove from container context if old state oldsfi old state null if old state null logger error this current state is set in remove from on this for simple manifest putter this new exception debug container activate old state 1 old state cancel container context old state remove from container context if cm null container activate cm 5 cm remove from container if metadata null possible if cancelled logger normal this metadata is set in remove from on this for simple manifest putter this container activate metadata 1 metadata remove from container data is responsibility of original caller usually client put dir we don t support free data atm super remove from container context removefrom objectcontainer clientcontext clientputstate clientputstate oldstate oldstate currentstate currentstate removefrom simplemanifestputter removefrom oldstate oldstate oldstate currentstate removefrom simplemanifestputter oldstate oldstate oldstate removefrom removefrom removefrom simplemanifestputter removefrom clientputdir freedata removefrom public boolean object can new object container container if cancelled logger error this storing this when already cancelled new exception error return false if logminor logger minor this storing this activated container ext is active this stored container ext is stored this new exception debug return true objectcannew objectcontainer isactive isstored override protected void inner to network object container container client context context ignore innertonetwork objectcontainer clientcontext public simple manifest putter client callback cb hash map string object manifest elements short prio class freeneturi target string default name insert context ctx boolean getchk only request client client context boolean early encode super prio class client context this default name default name if client persistent this targeturi target clone else this targeturi target this cb cb this ctx ctx this getchk only getchk only this early encode early encode put handlers by name new hash map string object running put handlers new hash set put handler put handlers waiting for metadata new hash set put handler put handlers waiting for fetchable new hash set put handler waiting for block sets new hash set put handler metadata putters by metadata new hash map metadata client put state metadata putters unfetchable new hash map metadata client put state elements to put in archive new array list put handler make put handlers manifest elements put handlers by name check zips simplemanifestputter clientcallback hashmap manifestelements prioclass defaultname insertcontext getchkonly requestclient clientcontext earlyencode prioclass clientcontext defaultname defaultname getchkonly getchkonly earlyencode earlyencode puthandlersbyname hashmap runningputhandlers hashset puthandler puthandlerswaitingformetadata hashset puthandler puthandlerswaitingforfetchable hashset puthandler waitingforblocksets hashset puthandler metadataputtersbymetadata hashmap clientputstate metadataputtersunfetchable hashmap clientputstate elementstoputinarchive arraylist puthandler makeputhandlers manifestelements puthandlersbyname checkzips private void check zips if there are too few files in the zip then insert them directly instead fixme do something checkzips public void start object container container client context context throws insert exception if logminor logger minor this starting this persistence persistent put handler running if persistent container activate running put handlers 2 synchronized this running running put handlers to array new put handler running put handlers size try boolean persistent persistent this might get deactivated for int i 0 i running length i running i start container context if persistent container ext is active this container activate this 1 if logminor logger minor this started i of running length if is finished if logminor logger minor this already finished killing start on this return if logminor logger minor this started running length put handler s for this if running length 0 inserted all files true if persistent container store this got all metadata container context catch insert exception e synchronized this finished true cancel and finish container context throw e objectcontainer clientcontext insertexception puthandler runningputhandlers runningputhandlers toarray puthandler runningputhandlers isactive isfinished puthandler insertedallfiles gotallmetadata insertexception cancelandfinish protected void make put handlers hash map string object manifest elements hash map string object put handlers by name make put handlers manifest elements put handlers by name makeputhandlers hashmap manifestelements hashmap puthandlersbyname makeputhandlers manifestelements puthandlersbyname private void make put handlers hash map string object manifest elements hash map string object put handlers by name string zip prefix iterator string it manifest elements key set iterator while it has next string name it next object o manifest elements get name if o instanceof hash map hash map string object sub map new hash map string object put handlers by name put name sub map make put handlers hash map string object o sub map zip prefix name if logger should log logger debug this logger debug this sub map for name sub map size elements from hash map o size else manifest element element manifest element o string mime type element mime override if mime type null mime type defaultmime types guessmime type name true client metadata cm if mime type null mime type equals defaultmime types default mime type cm null else cm new client metadata mime type put handler ph bucket data element data if element targeturi null ph new put handler this name element targeturi cm just a placeholder don t actually run it else decide whether to put it in the zip fixme support multiple zi ps and size limits fixme support better heuristics zip is slightly more compact can use this formula int sz int data size 40 element full name length tar is less compact but with a chained compressor is far more efficient due to inter file compression int sz 512 int data size 511 512 512 if data size 65536 tar pads to next 10k and has 1k end headers fixme this also needs to include the metadata fixme no way to know at this point how big that is need major refactoring to make this work for now just assume 64k will cover it bytes on zip sz 2038 64 1024 totally dumb heuristic bytes on zip sz put it in the zip if logminor logger minor this putting into zip name ph new put handler this name zip prefix element full name cm data if logminor logger minor this putting file into container element full name ph elements to put in archive add ph number of files total size data size else ph new put handler this name data cm getchk only running put handlers add ph put handlers waiting for metadata add ph put handlers waiting for fetchable add ph if logminor logger minor this inserting separately as put handler name ph persistent ph persistent ph persistent persistent number of files total size data size put handlers by name put name ph makeputhandlers hashmap manifestelements hashmap puthandlersbyname zipprefix manifestelements keyset hasnext manifestelements hashmap hashmap submap hashmap puthandlersbyname submap makeputhandlers hashmap submap zipprefix shouldlog submap hashmap manifestelement manifestelement mimetype mimeoverride mimetype mimetype defaultmimetypes guessmimetype clientmetadata mimetype mimetype defaultmimetypes default_mime_type clientmetadata mimetype puthandler puthandler zips fullname bytesonzip bytesonzip puthandler zipprefix fullname fullname elementstoputinarchive numberoffiles totalsize puthandler getchkonly runningputhandlers puthandlerswaitingformetadata puthandlerswaitingforfetchable puthandler numberoffiles totalsize puthandlersbyname override public freeneturi geturi return finaluri override public synchronized boolean is finished return finished cancelled isfinished public void run object container container client context context context job runner remove restart job this native thread norm priority container container activate simple manifest putter this 1 inner got all metadata container context container deactivate simple manifest putter this 1 objectcontainer clientcontext jobrunner removerestartjob nativethread norm_priority simplemanifestputter innergotallmetadata simplemanifestputter called when we have metadata for all the put handler s this does not necessarily mean we can immediately insert the final metadata since if these metadata s are too big they will need to be inserted separately see resolve and start base param container param context private void got all metadata object container container client context context this can be huge run it on its own transaction to minimize the build up of stuff to commit and maximise the opportunities for garbage collection if persistent container activate run got all metadata 1 need to activate this context job runner queue restart job run got all metadata native thread norm priority container false context job runner queue run got all metadata native thread norm priority false else inner got all metadata null context puthandler resolveandstartbase gotallmetadata objectcontainer clientcontext rungotallmetadata jobrunner queuerestartjob rungotallmetadata nativethread norm_priority jobrunner rungotallmetadata nativethread norm_priority innergotallmetadata generate the global metadata and then call resolve and start base param container param context private void inner got all metadata object container container client context context cor 1582 we have to carefully avoid activating any hashmap to depth 2 however we cannot afford the memory to activate everything to max depth in advance it looks like activating the hashmap at the top to depth 2 and then activating the sub maps to depth 2 as well works if persistent container activate put handlers by name 2 depth 2 to load elements if logminor logger minor this got all metadata hash map string object names to byte arrays new hash map string object names to byte arrays put handlers by name names to byte arrays container if default name null metadata meta metadata names to byte arrays get default name if meta null fail new insert exception insert exception invalid uri default name default name does not exist null container context return names to byte arrays put meta else for int j 0 j default default names length j string name default default names j metadata meta metadata names to byte arrays get name if meta null names to byte arrays put meta break base metadata metadata mk redirection manifest with metadata names to byte arrays if persistent container store base metadata container store this resolve and start base container context resolveandstartbase innergotallmetadata objectcontainer clientcontext puthandlersbyname hashmap namestobytearrays hashmap namestobytearrays puthandlersbyname namestobytearrays defaultname namestobytearrays defaultname insertexception insertexception invalid_uri defaultname namestobytearrays defaultdefaultnames defaultdefaultnames namestobytearrays namestobytearrays basemetadata mkredirectionmanifestwithmetadata namestobytearrays basemetadata resolveandstartbase attempt to insert the base metadata and the container if the base metadata cannot be resolved try to resolve it start inserts for each part that cannot be resolved and wait for them to generate ur is that can be incorporated into the metadata this method will then be called again and will complete or do more resolutions as necessary param container param context private void resolve and start base object container container client context context bucket bucket null synchronized this if has resolved base return while true try if persistent container activate base metadata integer max value bucket bucket tools make immutable bucket context get bucket factory persistent base metadata write to byte array if logminor logger minor this metadata bucket is bucket size bytes long break catch io exception e fail new insert exception insert exception bucket error e null container context return catch metadata unresolved exception e try start the insert for the sub metadata eventually it will generate a uri and call on encode which will call back here if logminor logger minor this main metadata needs resolving e resolve e container context if persistent container deactivate base metadata 1 return catch io exception e1 if persistent container deactivate base metadata 1 fail new insert exception insert exception bucket error e null container context return catch insert exception e2 if persistent container deactivate base metadata 1 fail e2 container context return if bucket null return synchronized this if has resolved base return has resolved base true if persistent container store this container activate elements to put in archive 2 insert block block boolean is metadata true boolean insert as archive manifest false archive type archive type null if elements to put in archive is empty there is an archive to insert we want to include the metadata we have the metadata fortunately enough because everything has been resolve d so all we need to do is create the actual archive try bucket output bucket context get bucket factory persistent make bucket base metadata data length todo try both maybe not worth it archive type archive type get default string mime type archive type archive type tar create tar bucket bucket output bucket container create zip bucket bucket output bucket container bucket free if persistent bucket remove from container if logminor logger minor this we are using archive type now we have to insert the archive we have generated can we just insert it and not bother with a redirect to it thereby exploiting implicit manifest support which will pick up on metadata we ought to be able to if persistent container activate targeturi 5 block new insert block output bucket new client metadata mime type persistent targeturi clone targeturi is metadata false insert as archive manifest true catch io exception e fail new insert exception insert exception bucket error e null container context if persistent container deactivate base metadata 1 return else block new insert block bucket null persistent targeturi clone targeturi single file inserter metadata inserter try metadata inserter new single file inserter this this block is metadata ctx archive type archive type zip getchk only false base metadata archive type true null early encode if logminor logger minor this inserting main metadata metadata inserter for base metadata if persistent container activate metadata putters by metadata 2 container activate metadata putters unfetchable 2 this metadata putters by metadata put base metadata metadata inserter metadata putters unfetchable put base metadata metadata inserter if persistent container ext store metadata putters by metadata 2 container ext store metadata putters unfetchable 2 container deactivate metadata putters by metadata 1 container deactivate metadata putters unfetchable 1 container deactivate base metadata 1 metadata inserter start null container context catch insert exception e fail e container context return if persistent container deactivate metadata inserter 1 container deactivate elements to put in archive 1 uris resolveandstartbase objectcontainer clientcontext hasresolvedbase basemetadata max_value buckettools makeimmutablebucket getbucketfactory basemetadata writetobytearray ioexception insertexception insertexception bucket_error metadataunresolvedexception onencode basemetadata ioexception basemetadata insertexception insertexception bucket_error insertexception basemetadata hasresolvedbase hasresolvedbase elementstoputinarchive insertblock ismetadata insertasarchivemanifest archive_type archivetype elementstoputinarchive isempty outputbucket getbucketfactory makebucket basemetadata datalength archivetype archive_type getdefault mimetype archivetype archive_type createtarbucket outputbucket createzipbucket outputbucket removefrom archivetype insertblock outputbucket clientmetadata mimetype ismetadata insertasarchivemanifest ioexception insertexception insertexception bucket_error basemetadata insertblock singlefileinserter metadatainserter metadatainserter singlefileinserter ismetadata archivetype archive_type getchkonly basemetadata archivetype earlyencode metadatainserter basemetadata metadataputtersbymetadata metadataputtersunfetchable metadataputtersbymetadata basemetadata metadatainserter metadataputtersunfetchable basemetadata metadatainserter metadataputtersbymetadata metadataputtersunfetchable metadataputtersbymetadata metadataputtersunfetchable basemetadata metadatainserter insertexception metadatainserter elementstoputinarchive private string create tar bucket bucket input bucket bucket output bucket object container container throws io exception if logminor logger minor this create a tar bucket output stream os new buffered output stream output bucket get output stream tar output stream taros new tar output stream os taros set long file mode tar output stream longfile gnu tar entry ze for put handler ph elements to put in archive if persistent container activate ph 1 container activate ph data 1 if logminor logger minor this putting into tar ph data length ph data size name ph target in archive ze new tar entry ph target in archive ze set mod time 0 long size ph data size ze set size size taros put next entry ze bucket tools copy to ph data taros size taros close entry add metadata after the rest if logminor logger minor this putting metadata into tar length is input bucket size ze new tar entry metadata ze set mod time 0 1 now 0 1970 long size input bucket size ze set size size taros put next entry ze bucket tools copy to input bucket taros size taros close entry both finish and close are necessary taros finish taros flush taros close if logminor logger minor this archive size is output bucket size return archive type tar mime types 0 createtarbucket inputbucket outputbucket objectcontainer ioexception outputstream bufferedoutputstream outputbucket getoutputstream taroutputstream taroutputstream setlongfilemode taroutputstream longfile_gnu tarentry puthandler elementstoputinarchive targetinarchive tarentry targetinarchive setmodtime setsize putnextentry buckettools copyto closeentry inputbucket tarentry setmodtime inputbucket setsize putnextentry buckettools copyto inputbucket closeentry outputbucket archive_type mimetypes private string create zip bucket bucket input bucket bucket output bucket object container container throws io exception if logminor logger minor this create a zip bucket output stream os new buffered output stream output bucket get output stream zip output stream zos new zip output stream os zip entry ze for iterator put handler i elements to put in archive iterator i has next put handler ph i next if persistent container activate ph 1 container activate ph data 1 ze new zip entry ph target in archive ze set time 0 zos put next entry ze bucket tools copy to ph data zos ph data size zos close entry add metadata after the rest ze new zip entry metadata ze set time 0 1 now 0 1970 zos put next entry ze bucket tools copy to input bucket zos input bucket size zos close entry both finish and close are necessary zos finish zos flush zos close return archive type zip mime types 0 createzipbucket inputbucket outputbucket objectcontainer ioexception outputstream bufferedoutputstream outputbucket getoutputstream zipoutputstream zipoutputstream zipentry puthandler elementstoputinarchive hasnext puthandler zipentry targetinarchive settime putnextentry buckettools copyto closeentry zipentry settime putnextentry buckettools copyto inputbucket inputbucket closeentry archive_type mimetypes start inserts for unresolved too big metadata s eventually these will call back with an on encode meaning they have the chk and we can progress to resolve and start base param e param container param context return throws insert exception throws io exception private void resolve metadata unresolved exception e object container container client context context throws insert exception io exception metadata metas e must resolve if persistent container activate metadata putters by metadata 2 for int i 0 i metas length i metadata m metas i if persistent container activate m 100 if logminor logger minor this resolving m synchronized this if metadata putters by metadata contains key m if logminor logger minor this already started insert for m in resolve for metas length metadata s continue if m is resolved logger error this already resolved m in resolve race condition if persistent container deactivate m 1 continue try bucket b m to bucket context get bucket factory persistent insert block ib new insert block b null persistent freeneturi empty chk uri clone freeneturi empty chk uri single file inserter metadata inserter new single file inserter this this ib true ctx false getchk only false m null true null early encode if logminor logger minor this inserting subsidiary metadata metadata inserter for m synchronized this this metadata putters by metadata put m metadata inserter metadata inserter start null container context if persistent container deactivate metadata inserter 1 container deactivate m 1 catch metadata unresolved exception e1 resolve e1 container context container deactivate m 1 if persistent container ext store metadata putters by metadata 2 container deactivate metadata putters by metadata 1 onencode resolveandstartbase insertexception ioexception metadataunresolvedexception objectcontainer clientcontext insertexception ioexception mustresolve metadataputtersbymetadata metadataputtersbymetadata containskey isresolved tobucket getbucketfactory insertblock insertblock empty_chk_uri empty_chk_uri singlefileinserter metadatainserter singlefileinserter getchkonly earlyencode metadatainserter metadataputtersbymetadata metadatainserter metadatainserter metadatainserter metadataunresolvedexception metadataputtersbymetadata metadataputtersbymetadata private void names to byte arrays hash map string object put handlers by name hash map string object names to byte arrays object container container iterator string i put handlers by name key set iterator while i has next string name i next object o put handlers by name get name if o instanceof put handler put handler ph put handler o if persistent container activate ph 1 metadata meta ph metadata if ph metadata null logger error this metadata for name ph is null else ph clear metadata container if persistent container activate meta 100 logger minor this putting name names to byte arrays put name meta if logminor logger minor this putting put handler into base metadata ph name name else if o instanceof hash map hash map string object sub map new hash map string object if persistent container activate o 2 depth 1 doesn t load the elements names to byte arrays put name sub map if logminor logger minor this putting hashmap into base metadata name size hash map o size active container null null boolean to string container ext is active o logger minor this putting directory name names to byte arrays hash map string object o sub map container else throw new illegal state exception namestobytearrays hashmap puthandlersbyname hashmap namestobytearrays objectcontainer puthandlersbyname keyset hasnext puthandlersbyname puthandler puthandler puthandler clearmetadata namestobytearrays puthandler hashmap hashmap submap hashmap namestobytearrays submap hashmap tostring isactive namestobytearrays hashmap submap illegalstateexception private void inserted all files object container container client context context if logminor logger minor this inserted all files synchronized this inserted all files true if finished cancelled if logminor logger minor this already finished finished cancelled if persistent container store this return if inserted manifest if logminor logger minor this haven t inserted manifest if persistent container store this return finished true if persistent container store this complete container context insertedallfiles objectcontainer clientcontext insertedallfiles insertedmanifest private void complete object container container client context context fixme we could remove the put handlers after inserting all files but not having finished the insert of the manifest however it would complicate matters for no real gain in most cases also doing it this way means we don t need to worry about if persistent remove put handlers container context boolean deactivatecb false if persistent deactivatecb container ext is active cb container activate cb 1 cb on success this container if deactivatecb container deactivate cb 1 objectcontainer clientcontext removeputhandlers isactive onsuccess private void fail insert exception e object container container client context context cancel all then call the callback synchronized this if finished return finished true cancel and finish container context if persistent remove put handlers container context if persistent container activate cb 1 cb on failure e this container insertexception objectcontainer clientcontext cancelandfinish removeputhandlers onfailure private void remove put handlers object container container client context context container activate put handlers by name 2 container activate running put handlers 2 container activate put handlers waiting for metadata 2 container activate waiting for block sets 2 container activate put handlers waiting for fetchable 2 container activate elements to put in archive 2 remove put handlers by name container context put handlers by name put handlers by name null if running put handlers is empty logger error this running put handlers not part of put handlers by name running put handlers size in remove put handlers on this new exception error put handler handlers running put handlers to array new put handler running put handlers size for put handler handler handlers container activate handler 1 logger error this still running but not in put handlers by name handler handler cancel handler remove from container context running put handlers clear if put handlers waiting for metadata is empty logger error this put handlers waiting for metadata not part of put handlers by name put handlers waiting for metadata size in remove put handlers on this new exception error put handler handlers put handlers waiting for metadata to array new put handler put handlers waiting for metadata size for put handler handler handlers container activate handler 1 logger error this still waiting for metadata but not in put handlers by name handler handler cancel handler remove from container context put handlers waiting for metadata clear if waiting for block sets is empty logger error this put handlers waiting for block sets not part of put handlers by name waiting for block sets size in remove put handlers on this new exception error put handler handlers waiting for block sets to array new put handler waiting for block sets size for put handler handler handlers container activate handler 1 logger error this still waiting for block set but not in put handlers by name handler handler cancel handler remove from container context waiting for block sets clear if put handlers waiting for fetchable is empty logger error this put handlers waiting for fetchable not part of put handlers by name put handlers waiting for fetchable size in remove put handlers on this new exception error put handler handlers put handlers waiting for fetchable to array new put handler put handlers waiting for fetchable size for put handler handler handlers container activate handler 1 logger error this still waiting for fetchable but not in put handlers by name handler handler cancel handler remove from container context put handlers waiting for fetchable clear if elements to put in archive is empty logger error this elements to put in archive not part of put handlers by name elements to put in archive size in remove put handlers on this new exception error put handler handlers elements to put in archive to array new put handler elements to put in archive size for put handler handler handlers container activate handler 1 logger error this to put in archive but not in put handlers by name handler handler remove from container context elements to put in archive clear container delete running put handlers container delete put handlers waiting for metadata container delete waiting for block sets container delete put handlers waiting for fetchable container delete elements to put in archive running put handlers null put handlers waiting for metadata null waiting for block sets null put handlers waiting for fetchable null elements to put in archive null container store this removeputhandlers objectcontainer clientcontext puthandlersbyname runningputhandlers puthandlerswaitingformetadata waitingforblocksets puthandlerswaitingforfetchable elementstoputinarchive removeputhandlersbyname puthandlersbyname puthandlersbyname runningputhandlers isempty puthandlersbyname runningputhandlers removeputhandlers puthandler runningputhandlers toarray puthandler runningputhandlers puthandler puthandlersbyname removefrom runningputhandlers puthandlerswaitingformetadata isempty puthandlersbyname puthandlerswaitingformetadata removeputhandlers puthandler puthandlerswaitingformetadata toarray puthandler puthandlerswaitingformetadata puthandler puthandlersbyname removefrom puthandlerswaitingformetadata waitingforblocksets isempty puthandlersbyname waitingforblocksets removeputhandlers puthandler waitingforblocksets toarray puthandler waitingforblocksets puthandler puthandlersbyname removefrom waitingforblocksets puthandlerswaitingforfetchable isempty puthandlersbyname puthandlerswaitingforfetchable removeputhandlers puthandler puthandlerswaitingforfetchable toarray puthandler puthandlerswaitingforfetchable puthandler puthandlersbyname removefrom puthandlerswaitingforfetchable elementstoputinarchive isempty puthandlersbyname elementstoputinarchive removeputhandlers puthandler elementstoputinarchive toarray puthandler elementstoputinarchive puthandler puthandlersbyname removefrom elementstoputinarchive runningputhandlers puthandlerswaitingformetadata waitingforblocksets puthandlerswaitingforfetchable elementstoputinarchive runningputhandlers puthandlerswaitingformetadata waitingforblocksets puthandlerswaitingforfetchable elementstoputinarchive remove all put handler s from the given put handlers by name sub map remove the put handler s themselves also remove them from and complain about running put handlers put handlers waiting for metadata waiting for block sets put handlers waiting for fetchable which must have been activated by the caller param container param put handlers by name private void remove put handlers by name object container container client context context hash map string object put handlers by name if logminor logger minor this remove put handlers by name on this map size put handlers by name size for map entry string object entry put handlers by name entry set string key entry get key object value entry get value if value instanceof put handler put handler handler put handler value container activate handler 1 if running put handlers remove handler container ext store running put handlers 2 if put handlers waiting for metadata remove handler container ext store put handlers waiting for metadata 2 if waiting for block sets remove handler container ext store waiting for block sets 2 if put handlers waiting for fetchable remove handler container ext store put handlers waiting for fetchable 2 if elements to put in archive remove handler container ext store elements to put in archive 2 handler remove from container context else hash map string object sub map hash map string object value container activate sub map 2 remove put handlers by name container context sub map container delete key put handlers by name clear container delete put handlers by name puthandler puthandlersbyname puthandler runningputhandlers puthandlerswaitingformetadata waitingforblocksets puthandlerswaitingforfetchable puthandlersbyname removeputhandlersbyname objectcontainer clientcontext hashmap puthandlersbyname removeputhandlersbyname puthandlersbyname puthandlersbyname entryset getkey getvalue puthandler puthandler puthandler runningputhandlers runningputhandlers puthandlerswaitingformetadata puthandlerswaitingformetadata waitingforblocksets waitingforblocksets puthandlerswaitingforfetchable puthandlerswaitingforfetchable elementstoputinarchive elementstoputinarchive removefrom hashmap submap hashmap submap removeputhandlersbyname submap puthandlersbyname puthandlersbyname cancel all running inserters private void cancel and finish object container container client context context put handler running boolean persistent persistent if persistent container activate running put handlers 2 synchronized this running running put handlers to array new put handler running put handlers size if logminor logger minor this put handler s to cancel running length for put handler putter running boolean active true if persistent active container ext is active putter if active container activate putter 1 putter cancel container context if active container deactivate putter 1 if persistent container activate this 1 client put state running meta if persistent container activate metadata putters by metadata 2 synchronized this running meta metadata putters by metadata values to array new client put state metadata putters by metadata size if logminor logger minor this metadata putters to cancel running meta length for client put state putter running meta boolean active true if persistent active container ext is active putter if active container activate putter 1 putter cancel container context if active container deactivate putter 1 if persistent container activate this 1 cancelandfinish objectcontainer clientcontext puthandler runningputhandlers runningputhandlers toarray puthandler runningputhandlers puthandler puthandler isactive clientputstate runningmeta metadataputtersbymetadata runningmeta metadataputtersbymetadata toarray clientputstate metadataputtersbymetadata runningmeta clientputstate runningmeta isactive override public void cancel object container container client context context synchronized this if finished return if super cancel return if persistent container store this fail new insert exception insert exception cancelled container context objectcontainer clientcontext insertexception insertexception public void on success client put state state object container container client context context if persistent container activate metadata putters by metadata 2 boolean fin false client put state old state null metadata token metadata state get token synchronized this if persistent container activate token 1 boolean present metadata putters by metadata contains key token if present old state metadata putters by metadata remove token if persistent container activate metadata putters unfetchable 2 if metadata putters unfetchable contains key token metadata putters unfetchable remove token if persistent container ext store metadata putters unfetchable 2 if metadata putters by metadata is empty if logminor logger minor this still running metadata putters metadata putters by metadata size else logger minor this inserted manifest successfully on this state inserted manifest true if finished if logminor logger minor this already finished if persistent container store this else if inserted all files if logminor logger minor this not inserted all files if persistent container store this else finished true if persistent container store this fin true if token base metadata token remove from container if persistent container ext store metadata putters by metadata 2 container deactivate metadata putters by metadata 1 state remove from container context if old state state old state null container activate old state 1 old state remove from container context if fin complete container context onsuccess clientputstate objectcontainer clientcontext metadataputtersbymetadata clientputstate oldstate gettoken metadataputtersbymetadata containskey oldstate metadataputtersbymetadata metadataputtersunfetchable metadataputtersunfetchable containskey metadataputtersunfetchable metadataputtersunfetchable metadataputtersbymetadata isempty metadataputtersbymetadata insertedmanifest insertedallfiles basemetadata removefrom metadataputtersbymetadata metadataputtersbymetadata removefrom oldstate oldstate oldstate oldstate removefrom public void on failure insert exception e client put state state object container container client context context if persistent container activate metadata putters by metadata 2 client put state old state null metadata token metadata state get token synchronized this if persistent container activate token 1 boolean present metadata putters by metadata contains key token if present old state metadata putters by metadata remove token if persistent container activate metadata putters unfetchable 2 if metadata putters unfetchable contains key token metadata putters unfetchable remove token container ext store metadata putters unfetchable 2 if token base metadata token remove from container if persistent container ext store metadata putters by metadata 2 container deactivate metadata putters by metadata 1 state remove from container context if old state state old state null container activate old state 1 old state remove from container context fail e container context onfailure insertexception clientputstate objectcontainer clientcontext metadataputtersbymetadata clientputstate oldstate gettoken metadataputtersbymetadata containskey oldstate metadataputtersbymetadata metadataputtersunfetchable metadataputtersunfetchable containskey metadataputtersunfetchable metadataputtersunfetchable basemetadata removefrom metadataputtersbymetadata metadataputtersbymetadata removefrom oldstate oldstate oldstate oldstate removefrom public void on encode base client key key client put state state object container container client context context if state get token base metadata this finaluri key geturi if logminor logger minor this got metadata key finaluri if persistent container activate cb 1 cb on generateduri persistent finaluri clone finaluri this container if persistent container deactivate cb 1 if persistent container store this else it s a sub metadata metadata m metadata state get token if persistent container activate m 2 m resolve key geturi if persistent container store m if logminor logger minor this resolved m key geturi resolve and start base container context onencode baseclientkey clientputstate objectcontainer clientcontext gettoken basemetadata ongenerateduri gettoken resolveandstartbase public void on transition client put state old state client put state new state object container container metadata m metadata old state get token if persistent container activate m 100 container activate metadata putters unfetchable 2 container activate metadata putters by metadata 2 synchronized this if metadata putters by metadata contains key m client put state prev state metadata putters by metadata get m if prev state old state if logminor logger minor this ignoring transition in this for metadata putter old state new state because current for m is prev state container deactivate metadata putters unfetchable 1 container deactivate metadata putters by metadata 1 return if persistent container store new state metadata putters by metadata put m new state if persistent container ext store metadata putters by metadata 2 if logminor logger minor this metadata putter transition old state new state if metadata putters unfetchable contains key m metadata putters unfetchable put m new state if persistent container ext store metadata putters unfetchable 2 if logminor logger minor this unfetchable metadata putter transition old state new state if logminor logger minor this transition old state new state else logger error this on transition but metadata putters by metadata does not contain metadata tag m for old state should new state if persistent container deactivate m 100 container deactivate metadata putters unfetchable 2 container deactivate metadata putters by metadata 2 ontransition clientputstate oldstate clientputstate newstate objectcontainer oldstate gettoken metadataputtersunfetchable metadataputtersbymetadata metadataputtersbymetadata containskey clientputstate prevstate metadataputtersbymetadata prevstate oldstate oldstate newstate prevstate metadataputtersunfetchable metadataputtersbymetadata newstate metadataputtersbymetadata newstate metadataputtersbymetadata oldstate newstate metadataputtersunfetchable containskey metadataputtersunfetchable newstate metadataputtersunfetchable oldstate newstate oldstate newstate ontransition metadataputtersbymetadata oldstate newstate metadataputtersunfetchable metadataputtersbymetadata public void on metadata metadata m client put state state object container container client context context ignore onmetadata clientputstate objectcontainer clientcontext override public void notify clients object container container client context context if persistent container activate ctx 1 container activate ctx event producer 1 ctx event producer produce event new splitfile progress event this total blocks this successful blocks this failed blocks this fatally failed blocks this min success blocks this block set finalized container context notifyclients objectcontainer clientcontext eventproducer eventproducer produceevent splitfileprogressevent totalblocks successfulblocks failedblocks fatallyfailedblocks minsuccessblocks blocksetfinalized public void on block set finished client put state state object container container client context context synchronized this this metadata block set finalized true if persistent container activate waiting for block sets 2 if waiting for block sets is empty if persistent container store this container deactivate waiting for block sets 1 return this block set finalized container context if persistent container store this container deactivate waiting for block sets 1 onblocksetfinished clientputstate objectcontainer clientcontext metadatablocksetfinalized waitingforblocksets waitingforblocksets isempty waitingforblocksets blocksetfinalized waitingforblocksets override public void block set finalized object container container client context context synchronized this if metadata block set finalized return if persistent container activate waiting for block sets 2 if waiting for block sets is empty if persistent container deactivate waiting for block sets 1 return if persistent container deactivate waiting for block sets 1 super block set finalized container context if persistent container store this blocksetfinalized objectcontainer clientcontext metadatablocksetfinalized waitingforblocksets waitingforblocksets isempty waitingforblocksets waitingforblocksets blocksetfinalized convert a hash map of name bucket to a hash set of manifest entry s all are to have mime override null i e we use the auto detected mime type from the filename public static hash map string object buckets by name to manifest entries hash map string object buckets by name hash map string object manifest entries new hash map string object iterator string i buckets by name key set iterator while i has next string name i next object o buckets by name get name if o instanceof bucket bucket data bucket buckets by name get name manifest entries put name new manifest element name data null data size else if o instanceof hash map manifest entries put name buckets by name to manifest entries hash map string object o else throw new illegal argument exception string value of o return manifest entries hashmap hashset manifestentry mimeoverride hashmap bucketsbynametomanifestentries hashmap bucketsbyname hashmap manifestentries hashmap bucketsbyname keyset hasnext bucketsbyname bucketsbyname manifestentries manifestelement hashmap manifestentries bucketsbynametomanifestentries hashmap illegalargumentexception valueof manifestentries convert a hierarchy of hash map s of manifest entries into a series of manifest element s each of which has a full path public static manifest element flatten hash map string object manifest elements vector manifest element v new vector manifest element flatten manifest elements v return v to array new manifest element v size hashmap manifestentries manifestelement manifestelement hashmap manifestelements manifestelement manifestelement manifestelements toarray manifestelement public static void flatten hash map string object manifest elements vector manifest element v string prefix iterator string i manifest elements key set iterator while i has next string name i next string full name prefix length 0 name prefix name object o manifest elements get name if o instanceof hash map flatten hash map string object o v full name else if o instanceof manifest element manifest element me manifest element o v add new manifest element me full name else throw new illegal state exception string value of o hashmap manifestelements manifestelement manifestelements keyset hasnext fullname manifestelements hashmap hashmap fullname manifestelement manifestelement manifestelement manifestelement fullname illegalstateexception valueof opposite of flatten note that this can throw a class cast exception if the vector passed in is bogus has files pretending to be directories public static t hash map string object unflatten list manifest element v hash map string object manifest elements new hash map string object for manifest element old element v add old element old element get name manifest elements return manifest elements classcastexception hashmap manifestelement hashmap manifestelements hashmap manifestelement oldelement oldelement oldelement getname manifestelements manifestelements private static void add manifest element e string name part map string object target int idx name part index of if idx 0 target put name part new manifest element e name part else string before name part substring 0 idx string after name part substring idx 1 suppress warnings unchecked hash map string object hm hash map string object target get before if hm null hm new hash map string object target put before intern hm add e after hm manifestelement namepart namepart indexof namepart manifestelement namepart namepart namepart suppresswarnings hashmap hashmap hashmap public int count files return number of files countfiles numberoffiles public long total size return total size totalsize totalsize override public void on major progress object container container boolean deactivate false if persistent deactivate container ext is active cb if deactivate container activate cb 1 cb on major progress container if deactivate container deactivate cb 1 onmajorprogress objectcontainer isactive onmajorprogress protected void on fetchable put handler handler object container container if persistent container activate put handlers waiting for fetchable 2 container activate metadata putters unfetchable 2 if check fetchable handler if persistent container ext store put handlers waiting for metadata 2 container store this container deactivate put handlers waiting for fetchable 1 container deactivate metadata putters unfetchable 1 container activate cb 1 cb on fetchable this container if persistent container deactivate cb 1 else if persistent container deactivate put handlers waiting for fetchable 1 container deactivate metadata putters unfetchable 1 onfetchable puthandler objectcontainer puthandlerswaitingforfetchable metadataputtersunfetchable checkfetchable puthandlerswaitingformetadata puthandlerswaitingforfetchable metadataputtersunfetchable onfetchable puthandlerswaitingforfetchable metadataputtersunfetchable private synchronized boolean check fetchable put handler handler put handlers waiting for fetchable remove handler if fetchable return false if put handlers waiting for fetchable is empty return false if has resolved base return false if metadata putters unfetchable is empty return false fetchable true return true checkfetchable puthandler puthandlerswaitingforfetchable puthandlerswaitingforfetchable isempty hasresolvedbase metadataputtersunfetchable isempty public void on fetchable client put state state object container container metadata m metadata state get token if persistent container activate m 100 container activate metadata putters unfetchable 2 container activate put handlers waiting for fetchable 2 if check fetchable m if persistent container ext store metadata putters unfetchable 2 container store this container activate cb 1 cb on fetchable this container if persistent container deactivate cb 1 if persistent container deactivate metadata putters unfetchable 1 container deactivate put handlers waiting for fetchable 1 onfetchable clientputstate objectcontainer gettoken metadataputtersunfetchable puthandlerswaitingforfetchable checkfetchable metadataputtersunfetchable onfetchable metadataputtersunfetchable puthandlerswaitingforfetchable private synchronized boolean check fetchable metadata m metadata putters unfetchable remove m if metadata putters unfetchable is empty return false if fetchable return false if put handlers waiting for fetchable is empty return false fetchable true return true checkfetchable metadataputtersunfetchable metadataputtersunfetchable isempty puthandlerswaitingforfetchable isempty override public void on transition client get state old state client get state new state object container container ignore ontransition clientgetstate oldstate clientgetstate newstate objectcontainer override public void remove from object container container client context context if put handlers by name null logger error this put handlers list still present in remove from on this remove put handlers container context if finaluri null container activate finaluri 5 finaluri remove from container container activate targeturi 5 targeturi remove from container this is passed in we should not remove it because the caller client put dir should remove it container activate ctx 1 ctx remove from container container activate metadata putters by metadata 2 container activate metadata putters unfetchable 2 array list metadata metas null if metadata putters by metadata is empty logger error this metadata putters by metadata not empty in remove from on this for map entry metadata client put state entry metadata putters by metadata entry set metadata meta entry get key container activate meta 1 client put state sfi entry get value container activate sfi 1 metadata putters unfetchable remove meta logger error this metadata putters not empty sfi for this sfi cancel container context sfi remove from container context if metas null metas new array list metadata metas add meta if metadata putters unfetchable is empty logger error this metadata putters unfetchable by metadata not empty in remove from on this for map entry metadata client put state entry metadata putters by metadata entry set metadata meta entry get key container activate meta 1 client put state sfi entry get value container activate sfi 1 metadata putters unfetchable remove meta logger error this metadata putters unfetchable not empty sfi for this sfi cancel container context sfi remove from container context if metas null for metadata meta metas if meta base metadata continue container activate meta 1 meta remove from container metadata putters by metadata clear metadata putters unfetchable clear container delete metadata putters by metadata container delete metadata putters unfetchable if base metadata null container activate base metadata 1 base metadata remove from container container activate run got all metadata 1 container delete run got all metadata super remove from container context removefrom objectcontainer clientcontext puthandlersbyname removefrom removeputhandlers removefrom removefrom clientputdir removefrom metadataputtersbymetadata metadataputtersunfetchable arraylist metadataputtersbymetadata isempty removefrom clientputstate metadataputtersbymetadata entryset getkey clientputstate getvalue metadataputtersunfetchable removefrom arraylist metadataputtersunfetchable isempty removefrom clientputstate metadataputtersbymetadata entryset getkey clientputstate getvalue metadataputtersunfetchable removefrom basemetadata removefrom metadataputtersbymetadata metadataputtersunfetchable metadataputtersbymetadata metadataputtersunfetchable basemetadata basemetadata basemetadata removefrom rungotallmetadata rungotallmetadata removefrom public void object on update object container container if logdebug logger debug this updating this activated container ext is active this stored container ext is stored this new exception debug objectonupdate objectcontainer isactive isstored public boolean object can new object container container if finished logger error this storing this when already finished new exception error return false if logdebug logger debug this storing this activated container ext is active this stored container ext is stored this new exception debug return true objectcannew objectcontainer isactive isstored protected final client metadata guess mime string name manifest element me string mime type me mime override if mime type null mime type defaultmime types guessmime type name true client metadata cm if mime type null mime type equals defaultmime types default mime type cm null else cm new client metadata mime type return cm clientmetadata guessmime manifestelement mimetype mimeoverride mimetype mimetype defaultmimetypes guessmimetype clientmetadata mimetype mimetype defaultmimetypes default_mime_type clientmetadata mimetype protected final void add redirect no mime string name manifest element me hash map string object put handlers by name2 add redirect name me null put handlers by name2 addredirectnomime manifestelement hashmap puthandlersbyname2 addredirect puthandlersbyname2 protected final void add redirect string name manifest element me hash map string object put handlers by name2 add redirect name me guess mime name me put handlers by name2 addredirect manifestelement hashmap puthandlersbyname2 addredirect guessmime puthandlersbyname2 protected final void add redirect string name manifest element me client metadata cm hash map string object put handlers by name2 put handler ph bucket data me data if me targeturi null ph new put handler this name me targeturi cm just a placeholder don t actually run it else ph new put handler this name data cm getchk only running put handlers add ph put handlers waiting for metadata add ph put handlers waiting for fetchable add ph if logminor logger minor this inserting separately as put handler name ph persistent ph persistent ph persistent persistent number of files total size data size put handlers by name2 put name ph addredirect manifestelement clientmetadata hashmap puthandlersbyname2 puthandler puthandler puthandler getchkonly runningputhandlers puthandlerswaitingformetadata puthandlerswaitingforfetchable puthandler numberoffiles totalsize puthandlersbyname2 override protected void inner to network object container container client context context ignore innertonetwork objectcontainer clientcontext private static final long serial versionuid 1 promiscuous item exception doubly linked list item item super item to string serialversionuid promiscuousitemexception doublylinkedlist tostring public promiscuous item exception item item doubly linked list parent super item to string parent promiscuousitemexception doublylinkedlist tostring public ram freenet store store callback callback int max keys this callback callback this blocks by routing key new lru hashtable byte array wrapper block this max keys max keys callback set store this ramfreenetstore storecallback maxkeys blocksbyroutingkey lruhashtable bytearraywrapper maxkeys maxkeys setstore public synchronized storable block fetch byte routing key byte full key boolean dont promote throws io exception byte array wrapper key new byte array wrapper routing key block block blocks by routing key get key if block null misses return null try storable block ret callback construct block data block header routing key block full key hits if dont promote blocks by routing key push key block return ret catch key verify exception e blocks by routing key remove key key misses return null storableblock routingkey fullkey dontpromote ioexception bytearraywrapper bytearraywrapper routingkey blocksbyroutingkey storableblock routingkey fullkey dontpromote blocksbyroutingkey keyverifyexception blocksbyroutingkey removekey public synchronized long get max keys return max keys getmaxkeys maxkeys public synchronized long hits return hits public synchronized long key count return blocks by routing key size keycount blocksbyroutingkey public synchronized long misses return misses public synchronized void put storable block block byte routingkey byte full key byte data byte header boolean overwrite throws io exception key collision exception writes byte array wrapper key new byte array wrapper routingkey block old block blocks by routing key get key boolean store full keys callback store full keys if old block null if callback collision possible boolean equals arrays equals old block data data arrays equals old block header header store full keys arrays equals old block full key full key true if equals return if overwrite old block data data old block header header if store full keys old block full key full key else throw new key collision exception return else return block store block new block store block data data store block header header if store full keys store block full key full key blocks by routing key push key store block while blocks by routing key size max keys blocks by routing key pop key storableblock fullkey ioexception keycollisionexception bytearraywrapper bytearraywrapper oldblock blocksbyroutingkey storefullkeys storefullkeys oldblock collisionpossible oldblock oldblock storefullkeys oldblock fullkey fullkey oldblock oldblock storefullkeys oldblock fullkey fullkey keycollisionexception storeblock storeblock storeblock storefullkeys storeblock fullkey fullkey blocksbyroutingkey storeblock blocksbyroutingkey maxkeys blocksbyroutingkey popkey public synchronized void set max keys long max store keys boolean shrink now throws database exception io exception this max keys int math min integer max value max store keys always shrink now regardless of parameter as we will shrink on the next put anyway while blocks by routing key size max keys blocks by routing key pop key setmaxkeys maxstorekeys shrinknow databaseexception ioexception maxkeys max_value maxstorekeys blocksbyroutingkey maxkeys blocksbyroutingkey popkey public long writes return writes public long get bloom false positive return 1 getbloomfalsepositive public boolean probably in store byte routing key byte array wrapper key new byte array wrapper routing key return blocks by routing key get key null probablyinstore routingkey bytearraywrapper bytearraywrapper routingkey blocksbyroutingkey private static final long serial versionuid 1 public aborted exception string msg super msg serialversionuid abortedexception transient field fld alt btree multi field index altbtreemultifieldindex alt btree multi field index class cls string field name boolean unique this cls cls this unique unique this field name field name this class name class descriptor get class name cls locate fields type class descriptor tp raw altbtreemultifieldindex fieldname fieldname fieldname classname classdescriptor getclassname locatefields classdescriptor tpraw private final void locate fields class scope cls fld new field field name length for int i 0 i field name length i fld i class descriptor locate field cls field name i if fld i null throw new storage error storage error indexed field not found class name field name i locatefields fieldname fieldname classdescriptor locatefield fieldname storageerror storageerror indexed_field_not_found classname fieldname public class get indexed class return cls getindexedclass public field get key fields return fld getkeyfields public void on load cls class descriptor load class get storage class name locate fields onload classdescriptor loadclass getstorage classname locatefields public int compare to object o compound key c compound key o int n keys length c keys length keys length c keys length for int i 0 i n i int diff comparable keys i compare to c keys i if diff 0 return diff return 0 allow to compare part of the compound key compareto compoundkey compoundkey compareto compound key object keys this keys keys compoundkey private key convert key key key if key null return null if key type class descriptor tp array of object throw new storage error storage error incompatible key type return new key new compound key object key oval key inclusion 0 convertkey classdescriptor tparrayofobject storageerror storageerror incompatible_key_type compoundkey private key extract key i persistent obj object keys new object fld length try for int i 0 i keys length i keys i fld i get obj if keys i instanceof i persistent i persistent p i persistent keys i if p is persistent get storage make persistent p catch exception x throw new storage error storage error access violation x return new key new compound key keys extractkey ipersistent ipersistent ipersistent ipersistent ispersistent getstorage makepersistent storageerror storageerror access_violation compoundkey public boolean put t obj return super put extract key obj obj extractkey public t set t obj return super set extract key obj obj extractkey public void remove t obj super remove extract key obj obj extractkey public t remove key key return super remove convert key key convertkey public boolean contains object t obj key key extract key obj if unique return super get key null else i persistent mbrs get key key for int i 0 i mbrs length i if mbrs i obj return true return false containsobject extractkey ipersistent public boolean contains t obj key key extract key obj if unique return super get key null else i persistent mbrs get key key for int i 0 i mbrs length i if mbrs i equals obj return true return false extractkey ipersistent public void append t obj throw new storage error storage error unsupported index type storageerror storageerror unsupported_index_type public t get key from key till array list list new array list if root null root find convert key from convert key till height list return t list to array t array new instance cls list size arraylist arraylist convertkey convertkey toarray newinstance public t get prefix string prefix throw new storage error storage error incompatible key type getprefix storageerror storageerror incompatible_key_type public t prefix search string key throw new storage error storage error incompatible key type prefixsearch storageerror storageerror incompatible_key_type public t to persistent array t arr t array new instance cls n elems if root null root traverse forward height arr 0 return arr topersistentarray newinstance nelems traverseforward public t get key key return super get convert key key convertkey public iterable iterator t iterator key from key till int order return super iterator convert key from convert key till order iterableiterator convertkey convertkey public iterable iterator map entry object t entry iterator key from key till int order return super entry iterator convert key from convert key till order iterableiterator entryiterator entryiterator convertkey convertkey public iterable iterator t query by example t obj key key extract key obj return iterator key key ascent order iterableiterator querybyexample extractkey ascent_order public iterable iterator t select string predicate query t query new query impl t get storage return query select cls iterator predicate iterableiterator queryimpl getstorage public boolean is case insensitive return false iscaseinsensitive class alt btree case insensitive multi field index t extends i persistent extends alt btree multi field index t alt btree case insensitive multi field index altbtreecaseinsensitivemultifieldindex ipersistent altbtreemultifieldindex altbtreecaseinsensitivemultifieldindex alt btree case insensitive multi field index alt btree case insensitive multi field index class cls string field names boolean unique super cls field names unique altbtreecaseinsensitivemultifieldindex altbtreecaseinsensitivemultifieldindex fieldnames fieldnames key check key key key if key null compound key ck compound key key oval for int i 0 i ck keys length i if ck keys i instanceof string ck keys i string ck keys i to lower case return super check key key checkkey compoundkey compoundkey tolowercase checkkey public boolean is case insensitive return true iscaseinsensitive return a nodechk corresponding to this key basically keep the routing key and lose everything else routingkey public abstract key get node key public abstract client key clone key getnodekey clientkey clonekey public abstract client key clone key public abstract void remove from object container container clientkey clonekey removefrom objectcontainer public boolean equals object o if o instanceof key key key key o return key type type key ival ival key lval lval key dval dval key oval oval return false constructor of boolean key boundary is inclusive public key boolean v this v true constructor of byte key boundary is inclusive public key byte v this v true constructor of char key boundary is inclusive public key char v this v true constructor of short key boundary is inclusive public key short v this v true constructor of int key boundary is inclusive public key int v this v true constructor of long key boundary is inclusive public key long v this v true constructor of float key boundary is inclusive public key float v this v true constructor of double key boundary is inclusive public key double v this v true constructor of date key boundary is inclusive public key java util date v this v true constructor of string key boundary is inclusive public key string v this v true constructor of array of char key boundary is inclusive public key char v this v true constructor of array of byte key boundary is inclusive public key byte v this v true constructor of key of user defined type boundary is inclusive param v user defined value public key comparable v this v true constructor of key of enum type boundary is inclusive param v array of key of enum type public key enum v this v true constructor of compound key boundary is inclusive param v array of compound key values public key object v this v true constructor of compound key with two values boundary is inclusive param v1 first value of compund key param v2 second value of compund key public key object v1 object v2 this new object v1 v2 true constructor of key with persistent object reference boundary is inclusive public key i persistent v this v true ipersistent private key int type long lval double dval object oval boolean inclusive this type type this ival int lval this lval lval this dval dval this oval oval this inclusion inclusive 1 0 constructor of boolean key param v key value param inclusive whether boundary is inclusive or exclusive public key boolean v boolean inclusive this class descriptor tp boolean v 1 0 0 0 null inclusive classdescriptor tpboolean constructor of byte key param v key value param inclusive whether boundary is inclusive or exclusive public key byte v boolean inclusive this class descriptor tp byte v 0 0 null inclusive classdescriptor tpbyte constructor of char key param v key value param inclusive whether boundary is inclusive or exclusive public key char v boolean inclusive this class descriptor tp char v 0 0 null inclusive classdescriptor tpchar constructor of short key param v key value param inclusive whether boundary is inclusive or exclusive public key short v boolean inclusive this class descriptor tp short v 0 0 null inclusive classdescriptor tpshort constructor of int key param v key value param inclusive whether boundary is inclusive or exclusive public key int v boolean inclusive this class descriptor tp int v 0 0 null inclusive classdescriptor tpint constructor of long key param v key value param inclusive whether boundary is inclusive or exclusive public key long v boolean inclusive this class descriptor tp long v 0 0 null inclusive classdescriptor tplong constructor of float key param v key value param inclusive whether boundary is inclusive or exclusive public key float v boolean inclusive this class descriptor tp float 0 v null inclusive classdescriptor tpfloat constructor of double key param v key value param inclusive whether boundary is inclusive or exclusive public key double v boolean inclusive this class descriptor tp double 0 v null inclusive classdescriptor tpdouble constructor of date key param v key value param inclusive whether boundary is inclusive or exclusive public key java util date v boolean inclusive this class descriptor tp date v null 1 v get time 0 0 null inclusive classdescriptor tpdate gettime constructor of string key param v key value param inclusive whether boundary is inclusive or exclusive public key string v boolean inclusive this class descriptor tp string 0 0 0 v inclusive classdescriptor tpstring constructor of array of char key param v key value param inclusive whether boundary is inclusive or exclusive public key char v boolean inclusive this class descriptor tp string 0 0 0 v inclusive classdescriptor tpstring constructor of key with persistent object reference param v key value param inclusive whether boundary is inclusive or exclusive public key i persistent v boolean inclusive this class descriptor tp object v null 0 v get oid 0 0 v inclusive ipersistent classdescriptor tpobject getoid constructor of compound key param v array of key values param inclusive whether boundary is inclusive or exclusive public key object v boolean inclusive this class descriptor tp array of object 0 0 0 v inclusive classdescriptor tparrayofobject constructor of key of used defined type param v user defined value param inclusive whether boundary is inclusive or exclusive public key comparable v boolean inclusive this class descriptor tp raw 0 0 0 v inclusive classdescriptor tpraw constructor of key of enum type param v enum value param inclusive whether boundary is inclusive or exclusive public key enum v boolean inclusive this class descriptor tp enum v ordinal 0 0 v inclusive classdescriptor tpenum constructor of compound key with two values param v1 first value of compund key param v2 second value of compund key param inclusive whether boundary is inclusive or exclusive public key object v1 object v2 boolean inclusive this new object v1 v2 inclusive constructor of byte array key param v byte array value param inclusive whether boundary is inclusive or exclusive public key byte v boolean inclusive this class descriptor tp array of byte 0 0 0 v inclusive classdescriptor tparrayofbyte rtree page storage storage i persistent obj rectangle r branch storage create link card branch set size card b new rectangle card set branch 0 new rectangle r obj n 1 for int i 1 i card i b i new rectangle rtreepage ipersistent createlink setsize setbranch rtree page storage storage rtree page root rtree page p branch storage create link card branch set size card b new rectangle card n 2 set branch 0 root cover root set branch 1 p cover p for int i 2 i card i b i new rectangle rtreepage rtreepage rtreepage createlink setsize setbranch setbranch rtree page rtreepage rtree page insert storage storage rectangle r i persistent obj int level modify if level 0 not leaf page int i mini 0 long min incr long max value long min area long max value for i 0 i n i long area b i area long incr rectangle join area b i r area if incr min incr min incr incr min area area mini i else if incr min incr area min area min area area mini i rtree page p rtree page branch get mini rtree page q p insert storage r obj level if q null child was not split b mini join r return null else child was split set branch mini p cover p return add branch storage q cover q else return add branch storage new rectangle r obj rtreepage ipersistent minincr max_value minarea max_value joinarea minincr minincr minarea minincr minarea minarea rtreepage rtreepage rtreepage setbranch addbranch addbranch int remove rectangle r i persistent obj int level array list reinsert list if level 0 for int i 0 i n i if r intersects b i rtree page pg rtree page branch get i int reinsert level pg remove r obj level reinsert list if reinsert level 0 if pg n min fill set branch i pg cover pg modify else not enough entries in child reinsert list add pg reinsert level level 1 remove branch i return reinsert level else for int i 0 i n i if branch contains element i obj remove branch i return 0 return 1 ipersistent arraylist reinsertlist rtreepage rtreepage reinsertlevel reinsertlist reinsertlevel minfill setbranch reinsertlist reinsertlevel removebranch reinsertlevel containselement removebranch void find rectangle r array list result int level if level 0 this is an internal node in the tree for int i 0 i n i if r intersects b i rtree page branch get i find r result level else this is a leaf node for int i 0 i n i if r intersects b i result add branch get i arraylist rtreepage void purge int level if level 0 this is an internal node in the tree for int i 0 i n i rtree page branch get i purge level deallocate rtreepage final void set branch int i rectangle r i persistent obj b i r branch set object i obj setbranch ipersistent setobject final void remove branch int i n 1 system arraycopy b i 1 b i n i branch remove i branch set size card modify removebranch setsize final rtree page add branch storage storage rectangle r i persistent obj if n card set branch n r obj return null else return split page storage r obj rtreepage addbranch ipersistent setbranch splitpage final rtree page split page storage storage rectangle r i persistent obj int i j seed0 0 seed1 0 long rect area new long card 1 long waste long worst waste long min value as the seeds for the two groups find two rectangles which waste the most area if covered by a single rectangle rect area 0 r area for i 0 i card i rect area i 1 b i area rectangle bp r for i 0 i card i for j i 1 j card j waste rectangle join area bp b j 1 rect area i rect area j if waste worst waste worst waste waste seed0 i seed1 j bp b i byte taken new byte card rectangle group0 group1 long group area0 group area1 int group card0 group card1 rtree page pg taken seed1 1 2 group1 new rectangle b seed1 1 if seed0 0 group0 new rectangle r pg new rtree page storage obj r else group0 new rectangle b seed0 1 pg new rtree page storage branch get raw seed0 1 group0 set branch seed0 1 r obj group card0 group card1 1 group area0 rect area seed0 group area1 rect area seed1 split remaining rectangles between two groups the one chosen is the one with the greatest difference in area expansion depending on which group the rect most strongly attracted to one group and repelled from the other while group card0 group card1 card 1 group card0 card 1 min fill group card1 card 1 min fill int better group 1 chosen 1 long biggest diff 1 for i 0 i card i if taken i 0 long diff rectangle join area group0 b i group area0 rectangle join area group1 b i group area1 if diff biggest diff diff biggest diff chosen i if diff 0 better group 0 biggest diff diff else better group 1 biggest diff diff assert that chosen 0 if better group 0 group0 join b chosen group area0 group0 area taken chosen 1 pg set branch group card0 b chosen branch get raw chosen else group card1 1 group1 join b chosen group area1 group1 area taken chosen 2 if one group gets too full then remaining rectangle are split between two groups in such way to balance cards of two groups if group card0 group card1 card 1 for i 0 i card i if taken i 0 if group card0 group card1 taken i 2 group card1 1 else taken i 1 pg set branch group card0 b i branch get raw i pg n group card0 n group card1 for i 0 j 0 i group card1 j if taken j 2 set branch i b j branch get raw j return pg rtreepage splitpage ipersistent rectarea worstwaste min_value rectarea rectarea joinarea rectarea rectarea worstwaste worstwaste grouparea0 grouparea1 groupcard0 groupcard1 rtreepage rtreepage rtreepage getraw setbranch groupcard0 groupcard1 grouparea0 rectarea grouparea1 rectarea groupcard0 groupcard1 groupcard0 minfill groupcard1 minfill bettergroup biggestdiff joinarea grouparea0 joinarea grouparea1 biggestdiff biggestdiff bettergroup biggestdiff bettergroup biggestdiff bettergroup grouparea0 setbranch groupcard0 getraw groupcard1 grouparea1 groupcard0 groupcard1 groupcard0 groupcard1 groupcard1 setbranch groupcard0 getraw groupcard0 groupcard1 groupcard1 setbranch getraw final rectangle cover rectangle r new rectangle b 0 for int i 1 i n i r join b i return r construct a stamp filter public stamp filter this 0 5f stampfilter stampfilter construct a stamp filter param threshold the threshold value public stamp filter float threshold set threshold threshold stampfilter stampfilter setthreshold set the radius of the effect param radius the radius min value 0 see get radius public void set radius float radius this radius radius getradius setradius get the radius of the effect return the radius see set radius public float get radius return radius setradius getradius set the threshold value param threshold the threshold value see get threshold public void set threshold float threshold this threshold threshold getthreshold setthreshold get the threshold value return the threshold value see set threshold public float get threshold return threshold setthreshold getthreshold set the softness of the effect in the range 0 1 param softness the softness min value 0 max value 1 see get softness public void set softness float softness this softness softness getsoftness setsoftness get the softness of the effect return the softness see set softness public float get softness return softness setsoftness getsoftness set the color to be used for pixels above the upper threshold param white the color see get white public void set white int white this white white getwhite setwhite get the color to be used for pixels above the upper threshold return the color see set white public int get white return white setwhite getwhite set the color to be used for pixels below the lower threshold param black the color see get black public void set black int black this black black getblack setblack set the color to be used for pixels below the lower threshold return the color see set black public int get black return black setblack getblack override public buffered image filter buffered image src buffered image dst dst new gaussian filter int radius filter src null lower threshold3 255 3 threshold softness 0 5f upper threshold3 255 3 threshold softness 0 5f return super filter dst dst bufferedimage bufferedimage bufferedimage gaussianfilter lowerthreshold3 upperthreshold3 override public int filterrgb int x int y int rgb int a rgb 0xff000000 int r rgb 16 0xff int g rgb 8 0xff int b rgb 0xff int l r g b float f image math smooth step lower threshold3 upper threshold3 l return image math mix colors f black white imagemath smoothstep lowerthreshold3 upperthreshold3 imagemath mixcolors override public string to string return stylize stamp tostring private boolean debug public config public config storage storage index dir myindex7 index max entries 4000 index subindex max size 4 1024 1024 index title xml spider index index owner freenet index owner email nil max shownur is 15 max parallel requests working 100 max parallel requests non working 100 begin working period 23 end working period 7 badlisted extensions new string ico bmp png jpg jpeg gif image zip jar gz bz2 rar archive 7z rar arj rpm deb xpi ace cab lza lzh ace exe iso binary mpg ogg ogv mp3 avi wv swf wmv mkv flac ogm media css sig gml df cbr gf pdf other request priority request starter immediate splitfile priority class storage make persistent this indexdir indexmaxentries indexsubindexmaxsize indextitle xmlspider indexowner indexowneremail maxshownuris maxparallelrequestsworking maxparallelrequestsnonworking beginworkingperiod endworkingperiod badlistedextensions requestpriority requeststarter immediate_splitfile_priority_class makepersistent public synchronized config clone try config config config super clone assert config is persistent return config catch clone not supported exception e logger error this impossible exception e throw new runtime exception e ispersistent clonenotsupportedexception runtimeexception public synchronized void set index dir string index dir assert is persistent this index dir index dir setindexdir indexdir ispersistent indexdir indexdir public synchronized string get index dir return index dir getindexdir indexdir public synchronized void set index max entries int index max entries assert is persistent this index max entries index max entries setindexmaxentries indexmaxentries ispersistent indexmaxentries indexmaxentries public synchronized int get index max entries return index max entries getindexmaxentries indexmaxentries public synchronized void set index subindex max size int index subindex max size assert is persistent this index subindex max size index subindex max size setindexsubindexmaxsize indexsubindexmaxsize ispersistent indexsubindexmaxsize indexsubindexmaxsize public synchronized int get index subindex max size return index subindex max size getindexsubindexmaxsize indexsubindexmaxsize public synchronized void set index title string index title assert is persistent this index title index title setindextitle indextitle ispersistent indextitle indextitle public synchronized string get index title return index title getindextitle indextitle public synchronized void set index owner string index owner assert is persistent this index owner index owner setindexowner indexowner ispersistent indexowner indexowner public synchronized string get index owner return index owner getindexowner indexowner public synchronized void set index owner email string index owner email assert is persistent this index owner email index owner email setindexowneremail indexowneremail ispersistent indexowneremail indexowneremail public synchronized void set max shownur is int max shownur is assert is persistent this max shownur is max shownur is setmaxshownuris maxshownuris ispersistent maxshownuris maxshownuris public synchronized int get max shownur is return max shownur is getmaxshownuris maxshownuris public synchronized string get index owner email return index owner email getindexowneremail indexowneremail public synchronized void set max parallel requests working int max parallel requests assert is persistent this max parallel requests working max parallel requests setmaxparallelrequestsworking maxparallelrequests ispersistent maxparallelrequestsworking maxparallelrequests public synchronized int get max parallel requests working return max parallel requests working getmaxparallelrequestsworking maxparallelrequestsworking public synchronized void set max parallel requests non working int max parallel requests assert is persistent this max parallel requests non working max parallel requests setmaxparallelrequestsnonworking maxparallelrequests ispersistent maxparallelrequestsnonworking maxparallelrequests public synchronized int get max parallel requests non working return max parallel requests non working getmaxparallelrequestsnonworking maxparallelrequestsnonworking public synchronized int get max parallel requests int actual hour calendar get instance get calendar hour of day boolean is working true if this get begin working period this get end working period midnight isn t in the interval m m 0 24 is working actual hour this get begin working period actual hour this get end working period else midnight is in the interval m m 0 24 is working actual hour this get begin working period actual hour this get end working period if is working return this get max parallel requests working else return this get max parallel requests non working getmaxparallelrequests actualhour getinstance hour_of_day isworking getbeginworkingperiod getendworkingperiod isworking actualhour getbeginworkingperiod actualhour getendworkingperiod isworking actualhour getbeginworkingperiod actualhour getendworkingperiod isworking getmaxparallelrequestsworking getmaxparallelrequestsnonworking public synchronized void set begin working period int begin working period assert is persistent this begin working period begin working period setbeginworkingperiod beginworkingperiod ispersistent beginworkingperiod beginworkingperiod public synchronized int get begin working period return begin working period getbeginworkingperiod beginworkingperiod public synchronized void set end working period int end working period assert is persistent this end working period end working period setendworkingperiod endworkingperiod ispersistent endworkingperiod endworkingperiod public synchronized int get end working period return end working period getendworkingperiod endworkingperiod public synchronized void set badlisted extensions string badlisted extensions assert is persistent this badlisted extensions badlisted extensions setbadlistedextensions badlistedextensions ispersistent badlistedextensions badlistedextensions public synchronized string get badlisted extensions return badlisted extensions getbadlistedextensions badlistedextensions public synchronized void set request priority short request priority assert is persistent this request priority request priority setrequestpriority requestpriority ispersistent requestpriority requestpriority public synchronized short get request priority return request priority getrequestpriority requestpriority public synchronized boolean is debug return debug isdebug public synchronized void debug boolean debug assert is persistent this debug debug ispersistent protected constructor to be called by factory implementations protected xml pull parser factory xmlpullparserfactory set the features to be set when xml pull parser is created by this factory p b note b factory features are not used for xml serializer param name string with uri identifying feature param state if true feature will be set if false will be ignored public void set feature string name boolean state throws xml pull parser exception features put name new boolean state setfeature xmlpullparserexception return the current value of the feature with given name p b note b factory features are not used for xml serializer param name the name of feature to be retrieved return the value of named feature unknown features are string always strong returned as false public boolean get feature string name boolean value boolean features get name return value null value boolean value false getfeature booleanvalue specifies that the parser produced by this factory will provide support for xml namespaces by default the value of this is set to false param awareness true if the parser produced by this code will provide support for xml namespaces false otherwise public void set namespace aware boolean awareness features put xml pull parser feature process namespaces new boolean awareness setnamespaceaware xmlpullparser feature_process_namespaces indicates whether or not the factory is configured to produce parsers which are namespace aware it simply set feature xml pull parser feature process namespaces to true or false return true if the factory is configured to produce parsers which are namespace aware false otherwise public boolean is namespace aware return get feature xml pull parser feature process namespaces xmlpullparser feature_process_namespaces isnamespaceaware getfeature xmlpullparser feature_process_namespaces specifies that the parser produced by this factory will be validating it simply set feature xml pull parser feature validation to true or false by default the value of this is set to false param validating if true the parsers created by this factory must be validating public void set validating boolean validating features put xml pull parser feature validation new boolean validating xmlpullparser feature_validation setvalidating xmlpullparser feature_validation indicates whether or not the factory is configured to produce parsers which validate the xml content during parse return true if the factory is configured to produce parsers which validate the xml content during parse false otherwise public boolean is validating return get feature xml pull parser feature validation isvalidating getfeature xmlpullparser feature_validation creates a new instance of a xml pull parser using the currently configured factory features return a new instance of a xml pull parser throws xml pull parser exception if a parser cannot be created which satisfies the requested configuration public xml pull parser new pull parser throws xml pull parser exception if parser classes null throw new xml pull parser exception factory initialization was incomplete has not tried class names location if parser classes size 0 throw new xml pull parser exception no valid parser classes found in class names location final string builder issues new string builder for int i 0 i parser classes size i final class pp class class parser classes element at i try final xml pull parser pp xml pull parser pp class new instance if features is empty enumeration keys features keys while keys has more elements for enumeration e features keys e has more elements final string key string e next element final boolean value boolean features get key if value null value boolean value pp set feature key true return pp catch exception ex issues append pp class get name ex to string throw new xml pull parser exception could not create parser issues xmlpullparserexception xmlpullparser newpullparser xmlpullparserexception parserclasses xmlpullparserexception classnameslocation parserclasses xmlpullparserexception classnameslocation stringbuilder stringbuilder parserclasses ppclass parserclasses elementat xmlpullparser xmlpullparser ppclass newinstance isempty hasmoreelements hasmoreelements nextelement booleanvalue setfeature ppclass getname tostring xmlpullparserexception creates a new instance of a xml serializer p b note b factory features are not used for xml serializer return a new instance of a xml serializer throws xml pull parser exception if a parser cannot be created which satisfies the requested configuration public xml serializer new serializer throws xml pull parser exception if serializer classes null throw new xml pull parser exception factory initialization incomplete has not tried class names location if serializer classes size 0 throw new xml pull parser exception no valid serializer classes found in class names location final string builder issues new string builder for int i 0 i serializer classes size i final class pp class class serializer classes element at i try final xml serializer ser xml serializer pp class new instance for enumeration e features keys e has more elements string key string e next element boolean value boolean features get key if value null value boolean value ser set feature key true return ser catch exception ex issues append pp class get name ex to string throw new xml pull parser exception could not create serializer issues xmlpullparserexception xmlserializer newserializer xmlpullparserexception serializerclasses xmlpullparserexception classnameslocation serializerclasses xmlpullparserexception classnameslocation stringbuilder stringbuilder serializerclasses ppclass serializerclasses elementat xmlserializer xmlserializer ppclass newinstance hasmoreelements nextelement booleanvalue setfeature ppclass getname tostring xmlpullparserexception create a new instance of a pull parser factory that can be used to create xml pull parsers see class description for more details return a new instance of a pull parser factory as returned by new instance null null public static xml pull parser factory new instance throws xml pull parser exception return new instance null null pullparserfactory pullparserfactory newinstance xmlpullparserfactory newinstance xmlpullparserexception newinstance public static xml pull parser factory new instance string class names class context throws xml pull parser exception if context null note make sure context uses the same class loader as api classes this is the best we can do without having access to context classloader in j2me if api is in the same classloader as implementation then this will work context reference context class string class names location null if class names null class names length 0 default equals class names try input stream is context get resource as stream resource name if is null throw new xml pull parser exception resource not found resource name make sure that parser implementing xml pull api is available final string builder sb new string builder while true final int ch is read if ch 0 break else if ch sb append char ch is close class names sb to string catch exception e throw new xml pull parser exception null null e class names location resource resource name that contained class names else class names location parameter class names to new instance that contained class names xml pull parser factory factory null final vector parser classes new vector final vector serializer classes new vector int pos 0 while pos class names length int cut class names index of pos if cut 1 cut class names length final string name class names substring pos cut class candidate null object instance null try candidate class for name name necessary because of j2me class issue instance candidate new instance catch exception e if candidate null boolean recognized false if instance instanceof xml pull parser parser classes add element candidate recognized true if instance instanceof xml serializer serializer classes add element candidate recognized true if instance instanceof xml pull parser factory if factory null factory xml pull parser factory instance recognized true if recognized throw new xml pull parser exception incompatible class name pos cut 1 if factory null factory new xml pull parser factory factory parser classes parser classes factory serializer classes serializer classes factory class names location class names location return factory xmlpullparserfactory newinstance classnames xmlpullparserexception referencecontextclass classnameslocation classnames classnames classnames inputstream getresourceasstream resource_name xmlpullparserexception resource_name xmlpull stringbuilder stringbuilder classnames tostring xmlpullparserexception classnameslocation resource_name classnames classnameslocation classnames newinstance classnames xmlpullparserfactory parserclasses serializerclasses classnames classnames indexof classnames classnames forname newinstance xmlpullparser parserclasses addelement xmlserializer serializerclasses addelement xmlpullparserfactory xmlpullparserfactory xmlpullparserexception xmlpullparserfactory parserclasses parserclasses serializerclasses serializerclasses classnameslocation classnameslocation final boolean remove with producer public event dumper print writer writer boolean remove with producer this pw writer this remove with producer remove with producer removewithproducer eventdumper printwriter removewithproducer removewithproducer removewithproducer public void receive client event ce object container container client context context pw println ce get description clientevent objectcontainer clientcontext getdescription public void on remove event producer object container container if remove with producer container delete this onremoveeventproducer objectcontainer removewithproducer public string descr public int compare to uri wrapper o return uri compare to o uri compareto uriwrapper compareto public boolean equals object o if o null o get class get class return false return uri equals uri wrapper o uri getclass getclass uriwrapper public int hash code return uri hash code hashcode hashcode private synchronized void refill buffer override protected void refill buffer encrypt feedback into result rijndael c encipher feedback register feedback register a t register pointer 0 refillbuffer refillbuffer feedback_register feedback_register registerpointer public rijndaelpcfb mode rijndael c super c int temp size c get temp array size a new int temp size t new int temp size rijndaelpcfbmode tempsize gettemparraysize tempsize tempsize public rijndaelpcfb mode rijndael c byte iv super c iv int temp size c get temp array size a new int temp size t new int temp size rijndaelpcfbmode tempsize gettemparraysize tempsize tempsize public class binary bloom filter extends bloom filter constructor param length length in bits protected binary bloom filter int length int k super length k filter byte buffer allocate this length 8 binarybloomfilter bloomfilter binarybloomfilter bytebuffer constructor param file disk file param length length in bits throws io exception protected binary bloom filter file file int length int k throws io exception super length k if file exists file length length 8 need rebuild true random access file raf new random access file file rw raf set length length 8 filter raf get channel map map mode read write 0 length 8 load ioexception binarybloomfilter ioexception needrebuild randomaccessfile randomaccessfile setlength getchannel mapmode read_write public binary bloom filter byte buffer slice int length int k super length k filter slice binarybloomfilter bytebuffer override public void remove key byte key ignore removekey override protected boolean get bit int offset return filter get offset 8 1 offset 8 0 getbit override protected void set bit int offset byte b filter get offset 8 b 1 offset 8 filter put offset 8 b setbit override protected void unset bit int offset no op unsetbit override public void fork int k lock write lock lock try file temp file file create temp file bloom tmp temp file delete on exit forked filter new binary bloom filter temp file length k catch io exception e forked filter new binary bloom filter length k finally lock write lock unlock writelock tempfile createtempfile tempfile deleteonexit forkedfilter binarybloomfilter tempfile ioexception forkedfilter binarybloomfilter writelock construct a rotate filter public rotate filter this image math pi rotatefilter rotatefilter imagemath construct a rotate filter param angle the angle to rotate public rotate filter float angle this angle true rotatefilter rotatefilter construct a rotate filter param angle the angle to rotate param resize true if the output image should be resized public rotate filter float angle boolean resize set angle angle this resize resize rotatefilter rotatefilter setangle specifies the angle of rotation param angle the angle of rotation angle see get angle public void set angle float angle this angle angle cos float math cos this angle sin float math sin this angle getangle setangle returns the angle of rotation return the angle of rotation see set angle public float get angle return angle setangle getangle override protected void transform space rectangle rect if resize point out new point 0 0 int minx integer max value int miny integer max value int maxx integer min value int maxy integer min value int w rect width int h rect height int x rect x int y rect y for int i 0 i 4 i switch i case 0 transform x y out break case 1 transform x w y out break case 2 transform x y h out break case 3 transform x w y h out break minx math min minx out x miny math min miny out y maxx math max maxx out x maxy math max maxy out y rect x minx rect y miny rect width maxx rect x rect height maxy rect y transformspace max_value max_value min_value min_value private void transform int x int y point out out x int x cos y sin out y int y cos x sin override protected void transform inverse int x int y float out out 0 x cos y sin out 1 y cos x sin transforminverse override public string to string return rotate int angle 180 math pi tostring public persistent get string identifier freeneturi uri int verbosity short priority class short return type short persistence type file target file file temp file string client token boolean global boolean started int max retries boolean binary blob long max size this identifier identifier this uri uri this verbosity verbosity this priority class priority class this return type return type this persistence type persistence type this target file target file this temp file temp file this client token client token this global global this started started this max retries max retries this binary blob binary blob this max size max size persistentget priorityclass returntype persistencetype targetfile tempfile clienttoken maxretries binaryblob maxsize priorityclass priorityclass returntype returntype persistencetype persistencetype targetfile targetfile tempfile tempfile clienttoken clienttoken maxretries maxretries binaryblob binaryblob maxsize maxsize override public simple field set get field set simple field set fs new simple field set true fs put single identifier identifier fs put single uri uri to string false false fs put verbosity verbosity fs put single return type client get message return type string return type fs put single persistence client request persistence type string persistence type fixme persistence type is backward compatibility cruft everything else uses persistence fs put single persistence type client request persistence type string persistence type if return type client get message return type disk fs put single filename target file get absolute path fs put single temp filename temp file get absolute path fs put priority class priority class if client token null fs put single client token client token fs put global global fs put started started fs put max retries max retries fs put binary blob binary blob fs put max size max size return fs simplefieldset getfieldset simplefieldset simplefieldset putsingle putsingle tostring putsingle returntype clientgetmessage returntypestring returntype putsingle clientrequest persistencetypestring persistencetype persistencetype putsingle persistencetype clientrequest persistencetypestring persistencetype returntype clientgetmessage return_type_disk putsingle targetfile getabsolutepath putsingle tempfilename tempfile getabsolutepath priorityclass priorityclass clienttoken putsingle clienttoken clienttoken maxretries maxretries binaryblob binaryblob maxsize maxsize override public string get name return name getname override public void run fcp connection handler handler node node throws message invalid exception throw new message invalid exception protocol error message invalid message persistent get goes from server to client not the other way around identifier global fcpconnectionhandler messageinvalidexception messageinvalidexception protocolerrormessage invalid_message persistentget override public void remove from object container container container activate uri 5 uri remove from container container activate target file 5 container delete target file container activate temp file 5 container delete temp file container delete this removefrom objectcontainer removefrom targetfile targetfile tempfile tempfile public final class multiply composite extends rgb composite public multiply composite float alpha super alpha multiplycomposite rgbcomposite multiplycomposite public composite context create context color model src color model color model dst color model rendering hints hints return new context extra alpha src color model dst color model compositecontext createcontext colormodel srccolormodel colormodel dstcolormodel renderinghints extraalpha srccolormodel dstcolormodel static class context extends rgb composite context public context float alpha color model src color model color model dst color model super alpha src color model dst color model rgbcompositecontext colormodel srccolormodel colormodel dstcolormodel srccolormodel dstcolormodel override public void composergb int src int dst float alpha int w src length for int i 0 i w i 4 int sr src i int dir dst i int sg src i 1 int dig dst i 1 int sb src i 2 int dib dst i 2 int sa src i 3 int dia dst i 3 int dor dog dob int t dir sr 0x80 dor t 8 t 8 t dig sg 0x80 dog t 8 t 8 t dib sb 0x80 dob t 8 t 8 float a alpha sa 255f float ac 1 a dst i int a dor ac dir dst i 1 int a dog ac dig dst i 2 int a dob ac dib dst i 3 int sa alpha dia ac public final long expected size public expected file size event long size expected size size expectedsize expectedfilesizeevent expectedsize static final int code 0x0c public int get code return code getcode public string get description return expected file size expected size getdescription expectedsize public int last good version 0 public build old age user alert super false null null null null user alert error true l10n get string user alert hide false null lastgoodversion buildoldageuseralert useralert getstring useralert override public string get title return l10n too old title gettitle toooldtitle private string l10n string key return l10n get string build old age user alert key getstring buildoldageuseralert private string l10n string key string pattern string value return l10n get string build old age user alert key pattern value getstring buildoldageuseralert override public string get text if last good version 0 throw new illegal argument exception not valid string s l10n too old lastgood integer to string last good version return s gettext lastgoodversion illegalargumentexception tooold tostring lastgoodversion override public html node gethtml text return new html node div get text htmlnode gethtmltext htmlnode gettext override public boolean is valid if last good version 0 return false return super is valid isvalid lastgoodversion isvalid override public string get short text return l10n too old short lastgood integer to string last good version getshorttext toooldshort tostring lastgoodversion public final long estimated size compression output size exception estimated size 1 estimatedsize compressionoutputsizeexception estimatedsize compression output size exception long sz estimated size sz compressionoutputsizeexception estimatedsize construct a gradient public gradient rebuild gradient rebuildgradient construct a gradient with the given colors param rgb the colors public gradient int rgb this null rgb null construct a gradient with the given colors and knot positions param x the knot positions param rgb the colors public gradient int x int rgb this x rgb null construct a gradient with the given colors knot positions and interpolation types param x the knot positions param rgb the colors param types interpolation types public gradient int x int rgb byte types set knots x rgb types setknots override public object clone gradient g gradient super clone g map int map clone g x knots int x knots clone g y knots int y knots clone g knot types byte knot types clone return g xknots xknots yknots yknots knottypes knottypes copy one gradient into another param g the gradient to copy into public void copy to gradient g g num knots num knots g map int map clone g x knots int x knots clone g y knots int y knots clone g knot types byte knot types clone copyto numknots numknots xknots xknots yknots yknots knottypes knottypes set a knot color param n the knot index param color the color override public void set color int n int color int first color map 0 int last color map 256 1 if n 0 for int i 0 i n i map i image math mix colors float i n first color color if n 256 1 for int i n i 256 i map i image math mix colors float i n 256 n color last color setcolor firstcolor lastcolor imagemath mixcolors firstcolor imagemath mixcolors lastcolor get the number of knots in the gradient return the number of knots public int get num knots return num knots getnumknots numknots set a knot color param n the knot index param color the color see get knot public void set knot int n int color y knots n color rebuild gradient getknot setknot yknots rebuildgradient get a knot color param n the knot index return the knot color see set knot public int get knot int n return y knots n setknot getknot yknots set a knot type param n the knot index param type the type see get knot type public void set knot type int n int type knot types n byte knot types n color mask type rebuild gradient getknottype setknottype knottypes knottypes color_mask rebuildgradient get a knot type param n the knot index return the knot type see set knot type public int get knot type int n return byte knot types n color mask setknottype getknottype knottypes color_mask set a knot blend type param n the knot index param type the knot blend type see get knot blend public void set knot blend int n int type knot types n byte knot types n blend mask type rebuild gradient getknotblend setknotblend knottypes knottypes blend_mask rebuildgradient get a knot blend type param n the knot index return the knot blend type see set knot blend public byte get knot blend int n return byte knot types n blend mask setknotblend getknotblend knottypes blend_mask add a new knot param x the knot position param color the color param type the knot type see remove knot public void add knot int x int color int type int nx new int num knots 1 int ny new int num knots 1 byte nt new byte num knots 1 system arraycopy x knots 0 nx 0 num knots system arraycopy y knots 0 ny 0 num knots system arraycopy knot types 0 nt 0 num knots x knots nx y knots ny knot types nt insert one position before the end so the sort works correctly x knots num knots x knots num knots 1 y knots num knots y knots num knots 1 knot types num knots knot types num knots 1 x knots num knots 1 x y knots num knots 1 color knot types num knots 1 byte type num knots sort knots rebuild gradient removeknot addknot numknots numknots numknots xknots numknots yknots numknots knottypes numknots xknots yknots knottypes xknots numknots xknots numknots yknots numknots yknots numknots knottypes numknots knottypes numknots xknots numknots yknots numknots knottypes numknots numknots sortknots rebuildgradient remove a knot param n the knot index see add knot public void remove knot int n if num knots 4 return if n num knots 1 system arraycopy x knots n 1 x knots n num knots n 1 system arraycopy y knots n 1 y knots n num knots n 1 system arraycopy knot types n 1 knot types n num knots n 1 num knots if x knots 1 0 x knots 1 0 rebuild gradient addknot removeknot numknots numknots xknots xknots numknots yknots yknots numknots knottypes knottypes numknots numknots xknots xknots rebuildgradient set the values of all the knots this version does not require the extra knots at 1 and 256 param x the knot positions param rgb the knot colors param types the knot types public void set knots int x int rgb byte types num knots rgb length 2 x knots new int num knots y knots new int num knots knot types new byte num knots if x null system arraycopy x 0 x knots 1 num knots 2 else for int i 1 i num knots 1 i x knots i 255 i num knots 2 system arraycopy rgb 0 y knots 1 num knots 2 if types null system arraycopy types 0 knot types 1 num knots 2 else for int i 0 i num knots i knot types i rgb spline sort knots rebuild gradient setknots numknots xknots numknots yknots numknots knottypes numknots xknots numknots numknots xknots numknots yknots numknots knottypes numknots numknots knottypes sortknots rebuildgradient set the values of a set of knots param x the knot positions param y the knot colors param types the knot types param offset the first knot to set param count the number of knots public void set knots int x int y byte types int offset int count num knots count x knots new int num knots y knots new int num knots knot types new byte num knots system arraycopy x offset x knots 0 num knots system arraycopy y offset y knots 0 num knots system arraycopy types offset knot types 0 num knots sort knots rebuild gradient setknots numknots xknots numknots yknots numknots knottypes numknots xknots numknots yknots numknots knottypes numknots sortknots rebuildgradient split a span into two by adding a knot in the middle param n the span index public void split span int n int x x knots n x knots n 1 2 add knot x get color x 256 0f knot types n rebuild gradient splitspan xknots xknots addknot getcolor knottypes rebuildgradient set a knot position param n the knot index param x the knot position see set knot position public void set knot position int n int x x knots n image math clamp x 0 255 sort knots rebuild gradient setknotposition setknotposition xknots imagemath sortknots rebuildgradient get a knot position param n the knot index return the knot position see set knot position public int get knot position int n return x knots n setknotposition getknotposition xknots return the knot at a given position param x the position return the knot number or 1 if no knot found public int knot at int x for int i 1 i num knots 1 i if x knots i 1 x return i return 1 knotat numknots xknots private void rebuild gradient x knots 0 1 x knots num knots 1 256 y knots 0 y knots 1 y knots num knots 1 y knots num knots 2 int knot 0 for int i 1 i num knots 1 i float span length x knots i 1 x knots i int end x knots i 1 if i num knots 2 end for int j x knots i j end j int rgb1 y knots i int rgb2 y knots i 1 float hsb1 color rg btohsb rgb1 16 0xff rgb1 8 0xff rgb1 0xff null float hsb2 color rg btohsb rgb2 16 0xff rgb2 8 0xff rgb2 0xff null float t float j x knots i span length int type get knot type i int blend get knot blend i if j 0 j 255 switch blend case constant t 0 break case linear break case spline map i image math color spline j num knots x knots y knots t image math smooth step 0 15f 0 85f t break case circle up t t 1 t float math sqrt 1 t t break case circle down t 1 float math sqrt 1 t t break if blend spline switch type case rgb map j image math mix colors t rgb1 rgb2 break case hue cw case hue ccw if type hue cw if hsb2 0 hsb1 0 hsb2 0 1 0f else if hsb1 0 hsb2 1 hsb1 0 1 0f float h image math lerp t hsb1 0 hsb2 0 image math two pi float s image math lerp t hsb1 1 hsb2 1 float b image math lerp t hsb1 2 hsb2 2 map j 0xff000000 color hs btorgb float h float s float b fixme alpha break rebuildgradient xknots xknots numknots yknots yknots yknots numknots yknots numknots numknots spanlength xknots xknots xknots numknots xknots yknots yknots rgbtohsb rgbtohsb xknots spanlength getknottype getknotblend imagemath colorspline numknots xknots yknots imagemath smoothstep circle_up circle_down imagemath mixcolors hue_cw hue_ccw hue_cw imagemath imagemath two_pi imagemath imagemath hsbtorgb private void sort knots for int i 1 i num knots 1 i for int j 1 j i j if x knots i x knots j int t x knots i x knots i x knots j x knots j t t y knots i y knots i y knots j y knots j t byte bt knot types i knot types i knot types j knot types j bt sortknots numknots xknots xknots xknots xknots xknots xknots yknots yknots yknots yknots knottypes knottypes knottypes knottypes private void rebuild sort knots rebuild gradient sortknots rebuildgradient randomize the gradient public void randomize num knots 4 int 6 math random x knots new int num knots y knots new int num knots knot types new byte num knots for int i 0 i num knots i x knots i int 255 math random y knots i 0xff000000 int 255 math random 16 int 255 math random 8 int 255 math random knot types i rgb spline x knots 0 1 x knots 1 0 x knots num knots 2 255 x knots num knots 1 256 sort knots rebuild gradient numknots xknots numknots yknots numknots knottypes numknots numknots xknots yknots knottypes xknots xknots xknots numknots xknots numknots sortknots rebuildgradient mutate the gradient param amount the amount in the range zero to one public void mutate float amount for int i 0 i num knots i int rgb y knots i int r rgb 16 0xff int g rgb 8 0xff int b rgb 0xff r pixel utils clamp int r amount 255 math random 0 5 g pixel utils clamp int g amount 255 math random 0 5 b pixel utils clamp int b amount 255 math random 0 5 y knots i 0xff000000 r 16 g 8 b knot types i rgb spline sort knots rebuild gradient numknots yknots pixelutils pixelutils pixelutils yknots knottypes sortknots rebuildgradient build a random gradient return the new gradient public static gradient random gradient gradient g new gradient g randomize return g randomgradient private static final long serial versionuid 1 override public final object clone return new bootstrapping decaying running average this serialversionuid bootstrappingdecayingrunningaverage constructor param default value default value param min minimum value of input data param max maxumum value of input data param max reports param fs link simple field set parameter for this object will override other parameters public bootstrapping decaying running average double default value double min double max int max reports simple field set fs this min min this max max reports 0 current value default value this max reports max reports if fs null current value fs get double current value current value reports fs get long reports reports defaultvalue maxreports simplefieldset bootstrappingdecayingrunningaverage defaultvalue maxreports simplefieldset currentvalue defaultvalue maxreports maxreports currentvalue getdouble currentvalue currentvalue getlong inherit doc public synchronized double current value return current value inheritdoc currentvalue currentvalue strong not a public method strong changes the internally stored code current value code and return the old one used by link decaying keyspace average to normalize the stored averages calling this function may purposefully destroy the utility of the average being kept see decaying keyspace average protected synchronized double set current value double d double old current value current value d return old currentvalue decayingkeyspaceaverage decayingkeyspaceaverage setcurrentvalue currentvalue currentvalue inherit doc public synchronized void report double d if d min if logger should log logger debug this logger debug this too low d new exception debug d min if d max if logger should log logger debug this logger debug this too high d new exception debug d max reports double decay factor 1 0 math min reports max reports current value d decay factor current value 1 decay factor inheritdoc shouldlog shouldlog decayfactor maxreports currentvalue decayfactor currentvalue decayfactor inherit doc public void report long d report double d inheritdoc inherit doc public synchronized double value if reported double d if d min logger error this too low d new exception debug d min if d max logger error this too high d new exception debug d max double decay factor 1 0 math min reports 1 max reports return d decay factor current value 1 decay factor inheritdoc valueifreported decayfactor maxreports decayfactor currentvalue decayfactor change code max reports code param max reports public synchronized void change max reports int max reports this max reports max reports maxreports maxreports changemaxreports maxreports maxreports maxreports copy constructor private bootstrapping decaying running average bootstrapping decaying running average a synchronized a this current value a current value this max a max this max reports a max reports this min a min this reports a reports bootstrappingdecayingrunningaverage bootstrappingdecayingrunningaverage currentvalue currentvalue maxreports maxreports inherit doc public synchronized long count reports return reports inheritdoc countreports export this object as link simple field set param short lived see link simple field set simple field set boolean public synchronized simple field set export field set boolean short lived simple field set fs new simple field set short lived fs put single type bootstrapping decaying running average fs put current value current value fs put reports reports return fs simplefieldset shortlived simplefieldset simplefieldset simplefieldset exportfieldset shortlived simplefieldset simplefieldset shortlived putsingle bootstrappingdecayingrunningaverage currentvalue currentvalue private random random numbers public dissolve filter randomnumbers dissolvefilter set the density of the image in the range 0 1 param density the density min value 0 max value 1 see get density public void set density float density this density density getdensity setdensity get the density of the image return the density see set density public float get density return density setdensity getdensity set the softness of the dissolve in the range 0 1 param softness the softness min value 0 max value 1 see get softness public void set softness float softness this softness softness getsoftness setsoftness get the softness of the dissolve return the softness see set softness public float get softness return softness setsoftness getsoftness override public buffered image filter buffered image src buffered image dst float d 1 density 1 softness min density d softness max density d random numbers new random 0 return super filter src dst bufferedimage bufferedimage bufferedimage mindensity maxdensity randomnumbers override public int filterrgb int x int y int rgb int a rgb 24 0xff float v random numbers next float float f image math smooth step min density max density v return int a f 24 rgb 0x00ffffff randomnumbers nextfloat imagemath smoothstep mindensity maxdensity override public string to string return stylize dissolve tostring public class null int callback extends int callback override public integer get return 0 nullintcallback intcallback override public void set integer val throws invalid config value exception ignore invalidconfigvalueexception public void terminate logger normal this stopping snmp snmp agent stopsnmp agent goon false snmpagent stopsnmpagent public int get port return port getport public string get bindto return bindto getbindto public void run plugin plugin respirator pr this pr pr snmp agent stopsnmp agent try fixme sort out config c pr get node config sub config sc new sub config plugins snmp c sc register port 4000 2 true false snmp port number snmp port number new snmp port number callback sc register bindto 127 0 0 1 2 true false ip address to bind to ip address to bind the snmp server to new snmp bindto callback bindto sc get string bindto port sc get int port sc finished initialization port 4000 bindto 127 0 0 1 snmp agent setsnmp port port system out println starting snmp server on bindto port snmp starter initialize pr get node logger normal this starting snmp server on bindto port while goon try thread sleep 10000 catch interrupted exception e ignore catch illegal argument exception e logger error this error loading snmp server runplugin pluginrespirator snmpagent stopsnmpagent getnode subconfig subconfig snmpportnumbercallback snmpbindtocallback getstring getint finishedinitialization snmpagent setsnmpport snmpstarter getnode interruptedexception illegalargumentexception user alerts toadlet high level simple client client node node node client core core super client this node node this alerts core alerts useralertstoadlet highlevelsimpleclient nodeclientcore private node node override public string supported methods return get supportedmethods override public void handle get uri uri http request request toadlet context ctx throws toadlet context closed exception io exception if ctx is allowed full access super send error page ctx 403 l10n get string toadlet unauthorized title l10n get string toadlet unauthorized return html node page node ctx get page maker get page node l10n title with name name node get my name ctx html node content node ctx get page maker get content node page node content node add child alerts create alerts writehtml reply ctx 200 ok page node generate handleget httprequest toadletcontext toadletcontextclosedexception ioexception isallowedfullaccess senderrorpage getstring unauthorizedtitle getstring htmlnode pagenode getpagemaker getpagenode titlewithname getmyname htmlnode contentnode getpagemaker getcontentnode pagenode contentnode addchild createalerts writehtmlreply pagenode protected string l10n string name string pattern string value return l10n get string user alerts toadlet name pattern value getstring useralertstoadlet private static final long serial versionuid 1l public no such message list exception string message listid super message listid serialversionuid nosuchmessagelistexception messagelistid messagelistid private final boolean null at start public simple int numbered item comparator boolean null at start this null at start null at start nullatstart simpleintnumbereditemcomparator nullatstart nullatstart nullatstart public int compare object o1 object o2 int x ocompare o1 o2 logger debug this compare o1 o2 x return x public int ocompare object o1 object o2 nulls at the end of the list if o1 null o2 null return 0 null null if o1 null o2 null return null at start 1 1 anything null if o2 null o1 null return null at start 1 1 long i1 i2 if o1 instanceof int numbered item i1 int numbered item o1 get number else if o1 instanceof integer i1 integer o1 int value else throw new class cast exception o1 to string if o2 instanceof int numbered item i2 int numbered item o2 get number else if o2 instanceof integer i2 integer o2 int value else throw new class cast exception o2 to string if i1 i2 return 0 if i1 i2 return 1 else return 1 nullatstart nullatstart intnumbereditem intnumbereditem getnumber intvalue classcastexception tostring intnumbereditem intnumbereditem getnumber intvalue classcastexception tostring logger register log threshold callback new log threshold callback override public void should update logminor logger should log logger minor this logdebug logger should log logger debug this registerlogthresholdcallback logthresholdcallback shouldupdate shouldlog shouldlog override public synchronized int hash code if has hash code return hash code int x key type hash code if doc name null x doc name hash code if meta str null for int i 0 i meta str length i x meta str i hash code if routing key null x fields hash code routing key if crypto key null x fields hash code crypto key if extra null x fields hash code extra if key type equals usk x suggested edition hash code x has hash code true return x hashcode hashashcode hashcode keytype hashcode docname docname hashcode metastr metastr metastr hashcode routingkey hashcode routingkey cryptokey hashcode cryptokey hashcode keytype suggestededition hashcode hashashcode override public boolean equals object o if o instanceof freeneturi return false else freeneturi f freeneturi o if key type equals f key type return false if key type equals usk if suggested edition f suggested edition return false if doc name null f doc name null return false if meta str null f meta str null return false if routing key null f routing key null return false if crypto key null f crypto key null return false if extra null f extra null return false if doc name null doc name equals f doc name return false if meta str null arrays equals meta str f meta str return false if routing key null arrays equals routing key f routing key return false if crypto key null arrays equals crypto key f crypto key return false if extra null arrays equals extra f extra return false return true keytype keytype keytype suggestededition suggestededition docname docname metastr metastr routingkey routingkey cryptokey cryptokey docname docname docname metastr metastr metastr routingkey routingkey routingkey cryptokey cryptokey cryptokey public boolean equals keypair freeneturi u2 if routing key null crypto key null return arrays equals routing key u2 routing key arrays equals crypto key u2 crypto key return false equalskeypair routingkey cryptokey routingkey routingkey cryptokey cryptokey override public final freeneturi clone return new freeneturi this public freeneturi freeneturi uri this unique hash code super hash code key type uri key type doc name uri doc name if uri meta str null meta str new string uri meta str length system arraycopy uri meta str 0 meta str 0 meta str length else meta str null if uri routing key null routing key new byte uri routing key length system arraycopy uri routing key 0 routing key 0 routing key length else routing key null if uri crypto key null crypto key new byte uri crypto key length system arraycopy uri crypto key 0 crypto key 0 crypto key length else crypto key null if uri extra null extra new byte uri extra length system arraycopy uri extra 0 extra 0 extra length else extra null this suggested edition uri suggested edition if logminor logger minor this copied to string from uri to string new exception debug uniquehashcode hashcode keytype keytype docname docname metastr metastr metastr metastr metastr metastr metastr routingkey routingkey routingkey routingkey routingkey routingkey routingkey cryptokey cryptokey cryptokey cryptokey cryptokey cryptokey cryptokey suggestededition suggestededition tostring tostring public freeneturi string key type string doc name this key type doc name string null null null null keytype docname keytype docname public freeneturi string key type string doc name byte routing key byte crypto key byte extra2 this key type doc name string null routing key crypto key extra2 keytype docname routingkey cryptokey keytype docname routingkey cryptokey public freeneturi string key type string doc name string meta str byte routing key byte crypto key this key type doc name meta str null string null new string meta str routing key crypto key null keytype docname metastr routingkey cryptokey keytype docname metastr metastr routingkey cryptokey public freeneturi string key type string doc name string meta str byte routing key byte crypto key byte extra2 this unique hash code super hash code this key type key type trim to upper case intern this doc name doc name this meta str meta str this routing key routing key this crypto key crypto key this extra extra2 this suggested edition 1 if logdebug logger minor this created from components to string new exception debug keytype docname metastr routingkey cryptokey uniquehashcode hashcode keytype keytype touppercase docname docname metastr metastr routingkey routingkey cryptokey cryptokey suggestededition tostring public freeneturi string key type string doc name string meta str byte routing key byte crypto key byte extra2 long suggested edition this unique hash code super hash code this key type key type trim to upper case intern this doc name doc name this meta str meta str this routing key routing key this crypto key crypto key this extra extra2 this suggested edition suggested edition if logdebug logger minor this created from components b to string new exception debug keytype docname metastr routingkey cryptokey suggestededition uniquehashcode hashcode keytype keytype touppercase docname docname metastr metastr routingkey routingkey cryptokey cryptokey suggestededition suggestededition tostring public freeneturi string uri throws malformedurl exception this unique hash code super hash code if uri null throw new malformedurl exception no uri specified uri uri trim if uri index of 0 uri index of 0 encoded url try uri url decoder decode uri false catch url encoded format exception e throw new malformedurl exception invalid uri no or or or is escaped but there are invalid escapes uri uri prefix matcher uri replace first decode key type int atchar uri index of if atchar 1 throw new malformedurl exception there is no in that uri uri string keytype uri substring 0 atchar to upper case uri uri substring atchar 1 boolean valid key type false for int i 0 i valid key types length i if keytype equals valid key types i valid key type true keytype valid key types i break key type keytype if valid key type throw new malformedurl exception invalid key type key type boolean isssk ssk equals key type boolean isusk usk equals key type boolean isksk ksk equals key type decode meta string array list string sv null int slash2 sv new array list string if isksk uri uri ensure that ksk doc names are decoded while slash2 uri last index of 1 string s try s url decoder decode uri substring slash2 1 length true catch url encoded format exception e malformedurl exception ue new malformedurl exception e to string ue init cause e throw ue if s null sv add s uri uri substring 0 slash2 sv is backwards this makes for more efficient handling if isssk isusk isksk if sv is empty throw new malformedurl exception no docname for key type doc name sv remove sv size 1 if isusk if sv is empty throw new malformedurl exception no suggested edition number for usk try suggested edition long parse long sv remove sv size 1 catch number format exception e malformedurl exception e1 new malformedurl exception invalid suggested edition e e1 init cause e throw e1 else suggested edition 1 else doc name not necessary nor is it supported for ch ks doc name null suggested edition 1 if sv is empty meta str new string sv size for int i 0 i meta str length i meta str i sv get meta str length 1 i intern if meta str i null throw new null pointer exception else meta str null if isksk routing key extra crypto key null return strip file extensions from ch ks added by aum david rebirthing co nz if chk equals key type uri uri split 0 uri now contains routing key crypto key meta info string tokenizer st new string tokenizer uri try if st has more tokens routing key base64 decode st next token else routing key crypto key extra null return if st has more tokens crypto key extra null return can be cryptokey or name value pair string t st next token crypto key base64 decode t if st has more tokens extra null return extra base64 decode st next token catch illegal base64 exception e throw new malformedurl exception invalid base64 quantity e if logdebug logger minor this created from parse to string from uri new exception debug malformedurlexception uniquehashcode hashcode malformedurlexception indexof indexof urldecoder urlencodedformatexception malformedurlexception uri_prefix replacefirst keytype indexof malformedurlexception _keytype touppercase validkeytype valid_key_types _keytype valid_key_types validkeytype _keytype valid_key_types keytype _keytype validkeytype malformedurlexception keytype keytype keytype keytype metastring arraylist arraylist docnames lastindexof urldecoder urlencodedformatexception malformedurlexception malformedurlexception tostring initcause isempty malformedurlexception keytype docname isempty malformedurlexception suggestededition parselong numberformatexception malformedurlexception malformedurlexception initcause suggestededition docname chks docname suggestededition isempty metastr metastr metastr metastr metastr nullpointerexception metastr routingkey cryptokey chks keytype routingkey cryptokey metainfo stringtokenizer stringtokenizer hasmoretokens routingkey nexttoken routingkey cryptokey hasmoretokens cryptokey nexttoken cryptokey hasmoretokens nexttoken illegalbase64exception malformedurlexception tostring usk constructor from components public freeneturi byte pub key hash byte crypto key byte extra string site name long suggested edition2 this unique hash code super hash code this key type usk this routing key pub key hash this crypto key crypto key this extra extra this doc name site name this suggested edition suggested edition2 meta str null if logdebug logger minor this created from components usk to string new exception debug pubkeyhash cryptokey sitename suggestededition2 uniquehashcode hashcode keytype routingkey pubkeyhash cryptokey cryptokey docname sitename suggestededition suggestededition2 metastr tostring public void decompose string r routing key null none hex util bytes to hex routing key string k crypto key null none hex util bytes to hex crypto key string e extra null none hex util bytes to hex extra system out println freeneturi this system out println key type key type system out println routing key r system out println crypto key k system out println extra e system out println doc name doc name null none doc name system out print meta strings if meta str null system err println none else for int i 0 i meta str length i system err print meta str i if i meta str length 1 system err println else system err print routingkey hexutil bytestohex routingkey cryptokey hexutil bytestohex cryptokey hexutil bytestohex keytype docname docname metastr metastr metastr metastr public string get guessable key return get doc name getguessablekey getdocname public string get doc name return doc name getdocname docname public string get meta string return meta str null meta str length 0 null meta str 0 getmetastring metastr metastr metastr public string last meta string return meta str null meta str length 0 null meta str meta str length 1 lastmetastring metastr metastr metastr metastr public string get all meta strings return meta str getallmetastrings metastr public boolean has meta strings return meta str null meta str length 0 hasmetastrings metastr metastr public byte get routing key return routing key getroutingkey routingkey public byte get crypto key return crypto key getcryptokey cryptokey public string get key type return key type getkeytype keytype returns a copy of this uri with the first meta string removed public freeneturi pop meta string string new meta str null if meta str null final int meta str length meta str length if meta str length 1 new meta str new string meta str length 1 system arraycopy meta str 1 new meta str 0 new meta str length return set meta string new meta str popmetastring newmetastr metastr metastrlength metastr metastrlength newmetastr metastrlength metastr newmetastr newmetastr setmetastring newmetastr public freeneturi drop last meta strings int i string new meta str null if meta str null meta str length 1 if i meta str length i meta str length new meta str new string meta str length i system arraycopy meta str 0 new meta str 0 new meta str length return set meta string new meta str droplastmetastrings newmetastr metastr metastr metastr metastr newmetastr metastr metastr newmetastr newmetastr setmetastring newmetastr returns a copy of this uri with the given string added as a new meta string public freeneturi push meta string string name string new meta str if name null throw new null pointer exception if meta str null new meta str new string name else new meta str new string meta str length 1 system arraycopy meta str 0 new meta str 0 meta str length new meta str meta str length name intern return set meta string new meta str pushmetastring newmetastr nullpointerexception metastr newmetastr newmetastr metastr metastr newmetastr metastr newmetastr metastr setmetastring newmetastr returns a copy of this uri with the those meta strings appended public freeneturi add meta strings string strs if strs null return this legal noop since get meta strings can return null for int i 0 i strs length i if strs i null throw new null pointer exception element i of strs length is null string new meta str if meta str null return set meta string strs else new meta str new string meta str length strs length if meta str null system arraycopy meta str 0 new meta str 0 meta str length system arraycopy strs 0 new meta str meta str length strs length return set meta string strs addmetastrings getmetastrings nullpointerexception newmetastr metastr setmetastring newmetastr metastr metastr metastr newmetastr metastr newmetastr metastr setmetastring public freeneturi add meta strings list string meta strings return add meta strings meta strings to array new string meta strings size addmetastrings metastrings addmetastrings metastrings toarray metastrings returns a copy of this uri with a new document name set public freeneturi set doc name string name return new freeneturi key type name meta str routing key crypto key extra suggested edition setdocname keytype metastr routingkey cryptokey suggestededition public freeneturi set meta string string new meta str return new freeneturi key type doc name new meta str routing key crypto key extra suggested edition setmetastring newmetastr keytype docname newmetastr routingkey cryptokey suggestededition override public string to string if to string cache null to string cache to string false false super to string unique hash code return to string cache tostring tostringcache tostringcache tostring tostring uniquehashcode tostringcache deprecated use link toascii string instead deprecated public string toacii string return toascii string toasciistring toaciistring toasciistring public string toascii string return to string true true toasciistring tostring public string to string boolean prefix boolean pure ascii if key type null not activated or something if logminor logger minor this not activated in to string prefix pure ascii return null string builder b if prefix b new string builder freenet else b new string builder b append key type append if ksk equals key type if routing key null b append base64 encode routing key if crypto key null b append append base64 encode crypto key if extra null b append append base64 encode extra if doc name null b append if doc name null b append url encoder encode doc name pure ascii if key type equals usk b append b append suggested edition if meta str null for int i 0 i meta str length i b append append url encoder encode meta str i pure ascii return b to string tostring pureascii keytype tostring pureascii stringbuilder stringbuilder stringbuilder keytype keytype routingkey routingkey cryptokey cryptokey docname docname urlencoder docname pureascii keytype suggestededition metastr metastr urlencoder metastr pureascii tostring public string to short string string builder b new string builder b append key type append if ksk equals key type b append if doc name null b append if doc name null b append url encoder encode doc name false if key type equals usk b append b append suggested edition if meta str null for int i 0 i meta str length i b append append url encoder encode meta str i false return b to string toshortstring stringbuilder stringbuilder keytype keytype docname docname urlencoder docname keytype suggestededition metastr metastr urlencoder metastr tostring public static void main string args throws exception new freeneturi args 0 decompose public byte get extra return extra getextra public array list string list meta strings if meta str null array list string l new array list string meta str length for int i 0 i meta str length i l add meta str i return l else return new array list string 0 arraylist listmetastrings metastr arraylist arraylist metastr metastr metastr arraylist public static freeneturi read full binary key with length data input stream dis throws io exception int len dis read short byte buf new byte len dis read fully buf if logminor logger minor freeneturi class read len bytes for key return from full binary key buf readfullbinarykeywithlength datainputstream ioexception readshort readfully fromfullbinarykey public static freeneturi from full binary key byte buf throws io exception byte array input stream bais new byte array input stream buf data input stream dis new data input stream bais return read full binary key dis fromfullbinarykey ioexception bytearrayinputstream bytearrayinputstream datainputstream datainputstream readfullbinarykey public static freeneturi read full binary key data input stream dis throws io exception byte type dis read byte string key type if type chk key type chk else if type ssk key type ssk else if type ksk key type ksk else throw new malformedurl exception unrecognized type type byte routing key null byte crypto key null byte extra null if type chk type ssk routing key is a hash so is exactly 32 bytes routing key new byte 32 dis read fully routing key crypto key is a 256 bit aes key so likewise crypto key new byte 32 dis read fully crypto key number of bytes of extra depends on key type int extra len extra len type chk clientchk extra length clientssk extra length extra new byte extra len dis read fully extra string doc name null if type chk doc name dis readutf int count dis read int string meta strings new string count for int i 0 i meta strings length i meta strings i dis readutf return new freeneturi key type doc name meta strings routing key crypto key extra readfullbinarykey datainputstream ioexception readbyte keytype keytype keytype keytype malformedurlexception routingkey cryptokey routingkey routingkey readfully routingkey cryptokey cryptokey readfully cryptokey extralen extralen extra_length extra_length extralen readfully docname docname readint metastrings metastrings metastrings keytype docname metastrings routingkey cryptokey write a binary representation of this uri with a short length so it can be passed over if necessary param dos the stream to write to throws malformedurl exception if the key could not be written because of inconsistencies or other problems in the key itself throws io exception if an error occurred while writing the key public void write full binary key with length data output stream dos throws io exception byte array output stream baos new byte array output stream data output stream ndos new data output stream baos write full binary key ndos ndos close byte data baos to byte array if data length short max value throw new malformedurl exception full key too long data length this dos write short short data length if logminor logger minor this written data length bytes dos write data malformedurlexception ioexception writefullbinarykeywithlength dataoutputstream ioexception bytearrayoutputstream bytearrayoutputstream dataoutputstream dataoutputstream writefullbinarykey tobytearray max_value malformedurlexception writeshort write a binary representation of this uri param dos the stream to write to throws malformedurl exception if the key could not be written because of inconsistencies or other problems in the key itself throws io exception if an error occurred while writing the key private void write full binary key data output stream dos throws io exception if key type equals chk dos write byte chk else if key type equals ssk dos write byte ssk else if key type equals ksk dos write byte ksk else if key type equals usk throw new malformedurl exception cannot write us ks as binary keys else throw new malformedurl exception cannot write key of type key type do not know how if key type equals ksk if routing key length 32 throw new malformedurl exception routing key must be of length 32 dos write routing key if crypto key length 32 throw new malformedurl exception crypto key must be of length 32 dos write crypto key if key type equals chk extra length clientchk extra length throw new malformedurl exception wrong number of extra bytes for chk if key type equals ssk extra length clientssk extra length throw new malformedurl exception wrong number of extra bytes for ssk dos write extra if key type equals chk dos writeutf doc name if meta str null dos write int meta str length for int i 0 i meta str length i dos writeutf meta str i else dos write int 0 malformedurlexception ioexception writefullbinarykey dataoutputstream ioexception keytype writebyte keytype writebyte keytype writebyte keytype malformedurlexception usks malformedurlexception keytype keytype routingkey malformedurlexception routingkey cryptokey malformedurlexception cryptokey keytype extra_length malformedurlexception keytype extra_length malformedurlexception keytype docname metastr writeint metastr metastr metastr writeint get suggested edition only valid for us ks public long get suggested edition if key type equals usk return suggested edition else throw new illegal argument exception not a usk requesting suggested edition usks getsuggestededition keytype suggestededition illegalargumentexception public string get preferred filename if logminor logger minor this getting preferred filename for this array list string names new array list string if key type null key type equals ksk key type equals ssk key type equals usk if logminor logger minor this adding doc name doc name names add doc name if key type equals usk names add long to string suggested edition if meta str null for int i 0 i meta str length i if logminor logger minor this adding meta string i meta str i names add meta str i string builder out new string builder for int i 0 i names size i string s names get i if logminor logger minor this name i s s file util sanitize s if logminor logger minor this sanitized name i s if s length 0 if out length 0 out append out append s if logminor logger minor this out out to string if out length 0 if routing key null if logminor logger minor this returning base64 encoded routing key return base64 encode routing key return unknown return out to string getpreferredfilename arraylist arraylist keytype keytype keytype keytype docname docname docname keytype tostring suggestededition metastr metastr metastring metastr metastr stringbuilder stringbuilder fileutil tostring routingkey routingkey tostring public freeneturi set suggested edition long new edition return new freeneturi key type doc name meta str routing key crypto key extra new edition setsuggestededition newedition keytype docname metastr routingkey cryptokey newedition public freeneturi set key type string new key type return new freeneturi new key type doc name meta str routing key crypto key extra suggested edition setkeytype newkeytype newkeytype docname metastr routingkey cryptokey suggestededition public freeneturi set routing key byte new routing key return new freeneturi key type doc name meta str new routing key crypto key extra suggested edition setroutingkey newroutingkey keytype docname metastr newroutingkey cryptokey suggestededition public void check inserturi throws insert exception if meta str null meta str length 0 throw new insert exception insert exception meta strings not supported this checkinserturi insertexception metastr metastr insertexception insertexception meta_strings_not_supported public static void check inserturi freeneturi uri throws insert exception uri check inserturi checkinserturi insertexception checkinserturi public uri to relativeuri throws uri syntax exception single argument constructor used because it preserves encoded es in path hence we can have slashes question marks etc in the path but they are encoded return new uri to string false false torelativeuri urisyntaxexception tostring public uri touri string base path throws uri syntax exception return new uri base path to string false false basepath urisyntaxexception basepath tostring public boolean isssk return ssk equals key type keytype public void remove from object container container all members are inline arrays ints etc treated as values so we can happily just call delete this container delete this removefrom objectcontainer public boolean object can new object container container if this freeneturi empty chk uri throw new runtime exception storing static chk to database can t remove it return true objectcannew objectcontainer empty_chk_uri runtimeexception public boolean object can update object container container if container ext is active this logger error this updating but not active new exception error return false return true objectcanupdate objectcontainer isactive public void object on delete object container container if logger should log logger debug this logger debug this deleting uri new exception debug objectondelete objectcontainer shouldlog public boolean isusk return usk equals key type keytype public boolean ischk return chk equals key type keytype public freeneturi ssk forusk if key type equals ignore case usk throw new illegal state exception return new freeneturi ssk doc name suggested edition meta str routing key crypto key extra 0 sskforusk keytype equalsignorecase illegalstateexception docname suggestededition metastr routingkey cryptokey public boolean isssk forusk return key type equals ignore case ssk doc name matches 0 9 issskforusk keytype equalsignorecase docname public freeneturi usk forssk if key type equals ignore case ssk throw new illegal state exception if doc name matches 0 9 throw new illegal state exception int offset doc name last index of string site name doc name substring 0 offset long edition long value of doc name substring offset 1 doc name length return new freeneturi usk site name meta str routing key crypto key extra edition uskforssk keytype equalsignorecase illegalstateexception docname illegalstateexception docname lastindexof sitename docname valueof docname docname sitename metastr routingkey cryptokey public long get edition if key type equals ignore case usk return suggested edition else if key type equals ignore case ssk if doc name matches 0 9 taken from usk forssk also modify there if necessary throw new illegal state exception return long value of doc name substring doc name last index of 1 doc name length else throw new illegal state exception getedition keytype equalsignorecase suggestededition keytype equalsignorecase docname uskforssk illegalstateexception valueof docname docname lastindexof docname illegalstateexception ttree page pg page reference ttree page p pg p ttreepage pagereference ttreepage public boolean recursive loading return false recursiveloading ttree page ttreepage ttree page i persistent mbr n items 1 item new i persistent max items item 0 mbr ttreepage ipersistent nitems ipersistent maxitems final i persistent load item int i i persistent mbr item i mbr load return mbr ipersistent loaditem ipersistent final boolean find persistent comparator comparator object min value int min inclusive object max value int max inclusive array list selection int l r m n load n n items if min value null if comparator compare member with key load item 0 min value min inclusive if comparator compare member with key load item n 1 min value min inclusive if right null return right find comparator min value min inclusive max value max inclusive selection return true for l 0 r n l r m l r 1 if comparator compare member with key load item m min value min inclusive l m 1 else r m while r n if max value null comparator compare member with key load item r max value max inclusive return false selection add load item r r 1 if right null return right find comparator min value min inclusive max value max inclusive selection return true if left null if left find comparator min value min inclusive max value max inclusive selection return false for l 0 l n l if max value null comparator compare member with key load item l max value max inclusive return false selection add load item l if right null return right find comparator min value min inclusive max value max inclusive selection return true persistentcomparator minvalue mininclusive maxvalue maxinclusive arraylist nitems minvalue comparememberwithkey loaditem minvalue mininclusive comparememberwithkey loaditem minvalue mininclusive minvalue mininclusive maxvalue maxinclusive comparememberwithkey loaditem minvalue mininclusive maxvalue comparememberwithkey loaditem maxvalue maxinclusive loaditem minvalue mininclusive maxvalue maxinclusive minvalue mininclusive maxvalue maxinclusive maxvalue comparememberwithkey loaditem maxvalue maxinclusive loaditem minvalue mininclusive maxvalue maxinclusive final boolean contains persistent comparator comparator i persistent key int l r m n load n n items if comparator compare members load item 0 key 0 if comparator compare members load item n 1 key 0 if right null return right contains comparator key return false for l 0 r n l r m l r 1 if comparator compare members load item m key 0 l m 1 else r m while r n if key equals load item r return true if comparator compare members item r key 0 return false r 1 if right null return right contains comparator key return false if left null if left contains comparator key return true for l 0 l n l if key equals load item l return true if comparator compare members item l key 0 return false if right null return right contains comparator key return false persistentcomparator ipersistent nitems comparemembers loaditem comparemembers loaditem comparemembers loaditem loaditem comparemembers loaditem comparemembers final boolean contains key persistent comparator comparator object key int l r m n load n n items if comparator compare member with key load item 0 key 0 if comparator compare member with key load item n 1 key 0 if right null return right contains key comparator key return false for l 0 r n l r m l r 1 if comparator compare member with key load item m key 0 l m 1 else r m while r n int diff comparator compare member with key load item r key if diff 0 return true else if diff 0 return false r 1 if right null return right contains key comparator key return false if left null if left contains key comparator key return true for l 0 l n l int diff comparator compare member with key load item l key if diff 0 return true else if diff 0 return false if right null return right contains key comparator key return false containskey persistentcomparator nitems comparememberwithkey loaditem comparememberwithkey loaditem containskey comparememberwithkey loaditem comparememberwithkey loaditem containskey containskey comparememberwithkey loaditem containskey final boolean contains object persistent comparator comparator i persistent mbr int l r m n load n n items if comparator compare members load item 0 mbr 0 if comparator compare members load item n 1 mbr 0 if right null return right contains object comparator mbr return false for l 0 r n l r m l r 1 if comparator compare members load item m mbr 0 l m 1 else r m while r n if mbr item r return true if comparator compare members item r mbr 0 return false r 1 if right null return right contains object comparator mbr return false if left null if left contains object comparator mbr return true for l 0 l n l if mbr item l return true if comparator compare members item l mbr 0 return false if right null return right contains object comparator mbr return false containsobject persistentcomparator ipersistent nitems comparemembers loaditem comparemembers loaditem containsobject comparemembers loaditem comparemembers containsobject containsobject comparemembers containsobject final int insert persistent comparator comparator i persistent mbr boolean unique page reference ref load int n n items ttree page pg int diff comparator compare members mbr load item 0 if diff 0 if unique diff 0 return not unique if left null diff 0 n max items modify for int i n i 0 i item i item i 1 system arraycopy item 0 item 1 n item 0 mbr n items 1 return ok if left null modify left new ttree page mbr else pg ref pg ref pg left int result left insert comparator mbr unique ref if result not unique return not unique modify left ref pg ref pg pg if result ok return ok if balance 0 balance 0 return ok else if balance 0 balance 1 return overflow else ttree page left this left left load left modify if left balance 0 single ll turn this left left right left right this balance 0 left balance 0 ref pg left else double lr turn ttree page right left right right load right modify left right right left right left left this left right right right right this balance right balance 0 1 0 left balance right balance 0 1 0 right balance 0 ref pg right return ok diff comparator compare members mbr load item n 1 if diff 0 if unique diff 0 return not unique if right null diff 0 n max items modify item n mbr n items 1 return ok if right null modify right new ttree page mbr else pg ref pg ref pg right int result right insert comparator mbr unique ref if result not unique return not unique modify right ref pg ref pg pg if result ok return ok if balance 0 balance 0 return ok else if balance 0 balance 1 return overflow else ttree page right this right right load right modify if right balance 0 single rr turn this right right left right left this balance 0 right balance 0 ref pg right else double rl turn ttree page left right left left load left modify right left left right left right right this right left left left left this balance left balance 0 1 0 right balance left balance 0 1 0 left balance 0 ref pg left return ok int l 1 r n 1 while l r int i l r 1 diff comparator compare members mbr load item i if diff 0 l i 1 else r i if diff 0 if unique return not unique break insert before item r modify if n max items system arraycopy item r item r 1 n r for int i n i r i item i item i 1 item r mbr n items 1 return ok else i persistent reinsert item if balance 0 reinsert item load item 0 system arraycopy item 1 item 0 r 1 for int i 1 i r i item i 1 item i item r 1 mbr else reinsert item load item n 1 system arraycopy item r item r 1 n r 1 for int i n 1 i r i item i item i 1 item r mbr return insert comparator reinsert item unique ref persistentcomparator ipersistent pagereference nitems ttreepage comparemembers loaditem not_unique maxitems nitems ttreepage not_unique not_unique ttreepage ttreepage comparemembers loaditem not_unique maxitems nitems ttreepage not_unique not_unique ttreepage ttreepage comparemembers loaditem not_unique maxitems nitems ipersistent reinsertitem reinsertitem loaditem reinsertitem loaditem reinsertitem final int balance left branch page reference ref if balance 0 balance 0 return underflow else if balance 0 balance 1 return ok else ttree page right this right right load right modify if right balance 0 single rr turn this right right left right left this if right balance 0 this balance 1 right balance 1 ref pg right return ok else balance 0 right balance 0 ref pg right return underflow else double rl turn ttree page left right left left load left modify right left left right left right right this right left left left left this balance left balance 0 1 0 right balance left balance 0 1 0 left balance 0 ref pg left return underflow balanceleftbranch pagereference ttreepage ttreepage final int balance right branch page reference ref if balance 0 balance 0 return underflow else if balance 0 balance 1 return ok else ttree page left this left left load left modify if left balance 0 single ll turn this left left right left right this if left balance 0 balance 1 left balance 1 ref pg left return ok else balance 0 left balance 0 ref pg left return underflow else double lr turn ttree page right left right right load right modify left right right left right left left this left right right right right this balance right balance 0 1 0 left balance right balance 0 1 0 right balance 0 ref pg right return underflow balancerightbranch pagereference ttreepage ttreepage final int remove persistent comparator comparator i persistent mbr page reference ref load ttree page pg int n n items int diff comparator compare members mbr load item 0 if diff 0 if left null modify pg ref pg ref pg left int h left remove comparator mbr ref left ref pg ref pg pg if h underflow return balance left branch ref else if h ok return ok diff comparator compare members mbr load item n 1 if diff 0 for int i 0 i n i if item i mbr if n 1 if right null deallocate ref pg left return underflow else if left null deallocate ref pg right return underflow modify if n min items if left null balance 0 ttree page prev left prev load while prev right null prev prev right prev load system arraycopy item 0 item 1 i while i 0 item i 1 item i item 0 prev item prev n items 1 pg ref pg ref pg left int h left remove comparator load item 0 ref left ref pg ref pg pg if h underflow h balance left branch ref return h else if right null ttree page next right next load while next left null next next left next load system arraycopy item i 1 item i n i 1 while i n item i 1 item i item n 1 next item 0 pg ref pg ref pg right int h right remove comparator load item n 1 ref right ref pg ref pg pg if h underflow h balance right branch ref return h system arraycopy item i 1 item i n i 1 while i n item i 1 item i item n 1 null n items 1 return ok if right null modify pg ref pg ref pg right int h right remove comparator mbr ref right ref pg ref pg pg if h underflow return balance right branch ref else return h return not found persistentcomparator ipersistent pagereference ttreepage nitems comparemembers loaditem balanceleftbranch comparemembers loaditem minitems ttreepage nitems loaditem balanceleftbranch ttreepage loaditem balancerightbranch nitems balancerightbranch not_found final int to array i persistent arr int index load if left null index left to array arr index for int i 0 n n items i n i arr index load item i if right null index right to array arr index return index toarray ipersistent toarray nitems loaditem toarray final void prune load if left null left prune if right null right prune deallocate private static final long serial versionuid 1 public incoming packet filter exception string string super string serialversionuid incomingpacketfilterexception public incoming packet filter exception super incomingpacketfilterexception private float s c public caustics filter causticsfilter specifies the scale of the texture param scale the scale of the texture min value 1 max value 300 see get scale public void set scale float scale this scale scale getscale setscale returns the scale of the texture return the scale of the texture see set scale public float get scale return scale setscale getscale set the brightness param brightness the brightness min value 0 max value 1 see get brightness public void set brightness int brightness this brightness brightness getbrightness setbrightness get the brightness return the brightness see set brightness public int get brightness return brightness setbrightness getbrightness specifies the turbulence of the texture param turbulence the turbulence of the texture min value 0 max value 1 see get turbulence public void set turbulence float turbulence this turbulence turbulence getturbulence setturbulence returns the turbulence of the effect return the turbulence of the effect see set turbulence public float get turbulence return turbulence setturbulence getturbulence set the amount of effect param amount the amount min value 0 max value 1 see get amount public void set amount float amount this amount amount getamount setamount get the amount of effect return the amount see set amount public float get amount return amount setamount getamount set the dispersion param dispersion the dispersion min value 0 max value 1 see get dispersion public void set dispersion float dispersion this dispersion dispersion getdispersion setdispersion get the dispersion return the dispersion see set dispersion public float get dispersion return dispersion setdispersion getdispersion set the time use this to animate the effect param time the time see get time public void set time float time this time time gettime settime set the time return the time see set time public float get time return time settime gettime set the number of samples per pixel more samples means better quality but slower rendering param samples the number of samples see get samples public void set samples int samples this samples samples getsamples setsamples get the number of samples per pixel return the number of samples see set samples public int get samples return samples setsamples getsamples set the background color param c the color see get bg color public void set bg color int c bg color c getbgcolor setbgcolor bgcolor get the background color return the color see set bg color public int get bg color return bg color setbgcolor getbgcolor bgcolor override protected int filter pixels int width int height int in pixels rectangle transformed space random random new random 0 s float math sin 0 1 c float math cos 0 1 int src width original space width int src height original space height int out width transformed space width int out height transformed space height int index 0 int pixels new int out width out height for int y 0 y out height y for int x 0 x out width x pixels index bg color int v brightness samples if v 0 v 1 float rs 1 0f scale float d 0 95f index 0 for int y 0 y out height y for int x 0 x out width x for int s 0 s samples s float sx x random next float float sy y random next float float nx sx rs float ny sy rs float x displacement y displacement float focus 0 1f amount x displacement evaluate nx d ny evaluate nx d ny y displacement evaluate nx ny d evaluate nx ny d if dispersion 0 for int c 0 c 3 c float ca 1 c dispersion float srcx sx scale focus x displacement ca float srcy sy scale focus y displacement ca if srcx 0 srcx out width 1 srcy 0 srcy out height 1 else int i int srcy out width int srcx int rgb pixels i int r rgb 16 0xff int g rgb 8 0xff int b rgb 0xff if c 2 r v else if c 1 g v else b v if r 255 r 255 if g 255 g 255 if b 255 b 255 pixels i 0xff000000 r 16 g 8 b else float srcx sx scale focus x displacement float srcy sy scale focus y displacement if srcx 0 srcx out width 1 srcy 0 srcy out height 1 else int i int srcy out width int srcx int rgb pixels i int r rgb 16 0xff int g rgb 8 0xff int b rgb 0xff r v g v b v if r 255 r 255 if g 255 g 255 if b 255 b 255 pixels i 0xff000000 r 16 g 8 b return pixels filterpixels inpixels transformedspace srcwidth originalspace srcheight originalspace outwidth transformedspace outheight transformedspace outwidth outheight outheight outwidth bgcolor outheight outwidth nextfloat nextfloat xdisplacement ydisplacement xdisplacement ydisplacement xdisplacement ydisplacement outwidth outheight outwidth xdisplacement ydisplacement outwidth outheight outwidth private static int add int rgb float brightness int r rgb 16 0xff int g rgb 8 0xff int b rgb 0xff r brightness g brightness b brightness if r 255 r 255 if g 255 g 255 if b 255 b 255 return 0xff000000 r 16 g 8 b private static int add int rgb float brightness int c int r rgb 16 0xff int g rgb 8 0xff int b rgb 0xff if c 2 r brightness else if c 1 g brightness else b brightness if r 255 r 255 if g 255 g 255 if b 255 b 255 return 0xff000000 r 16 g 8 b private static float turbulence2 float x float y float time float octaves float value 0 0f float remainder float lacunarity 2 0f float f 1 0f int i to prevent cascading effects x 371 y 529 for i 0 i int octaves i value noise noise3 x y time f x lacunarity y lacunarity f 2 remainder octaves int octaves if remainder 0 value remainder noise noise3 x y time f return value private float evaluate float x float y float xt s x c time float tt c x c time float f turbulence 0 0 noise noise3 xt y tt turbulence2 xt y tt turbulence return f override public string to string return texture caustics tostring final long created time uid tag created time system current time millis createdtime uidtag createdtime currenttimemillis public abstract void log still present long uid logstillpresent public abstract void log still present long uid long age return system current time millis created time logstillpresent currenttimemillis createdtime construct a flip filter which flips horizontally and vertically public flip filter this flip hv flipfilter flipfilter flip_hv construct a flip filter param operation the filter operation public flip filter int operation this operation operation flipfilter flipfilter set the filter operation param operation the filter operation see get operation public void set operation int operation this operation operation getoperation setoperation get the filter operation return the filter operation see set operation public int get operation return operation setoperation getoperation public buffered image filter buffered image src buffered image dst int width src get width int height src get height int type src get type writable raster src raster src get raster int in pixels getrgb src 0 0 width height null int x 0 y 0 int w width int h height int newx 0 int newy 0 int neww w int newh h switch operation case flip h newx width x w break case flip v newy height y h break case flip hv neww h newh w newx y newy x break case flip 90cw neww h newh w newx height y h newy x break case flip 90ccw neww h newh w newx y newy width x w break case flip 180 newx width x w newy height y h break int new pixels new int neww newh for int row 0 row h row for int col 0 col w col int index row width col int new row row int new col col switch operation case flip h new col w col 1 break case flip v new row h row 1 break case flip hv new row col new col row break case flip 90cw new row col new col h row 1 break case flip 90ccw new row w col 1 new col row break case flip 180 new row h row 1 new col w col 1 break int new index new row neww new col new pixels new index in pixels index if dst null color model dstcm src get color model dst new buffered image dstcm dstcm create compatible writable raster neww newh dstcm is alpha premultiplied null writable raster dst raster dst get raster setrgb dst 0 0 neww newh new pixels return dst bufferedimage bufferedimage bufferedimage getwidth getheight gettype writableraster srcraster getraster inpixels flip_h flip_v flip_hv flip_90cw flip_90ccw flip_180 newpixels newrow newcol flip_h newcol flip_v newrow flip_hv newrow newcol flip_90cw newrow newcol flip_90ccw newrow newcol flip_180 newrow newcol newindex newrow newcol newpixels newindex inpixels colormodel getcolormodel bufferedimage createcompatiblewritableraster isalphapremultiplied writableraster dstraster getraster newpixels override public string to string switch operation case flip h return flip horizontal case flip v return flip vertical case flip hv return flip diagonal case flip 90cw return rotate 90 case flip 90ccw return rotate 90 case flip 180 return rotate 180 return flip tostring flip_h flip_v flip_hv flip_90cw flip_90ccw flip_180 logger register log threshold callback new log threshold callback override public void should update logminor logger should log logger minor this registerlogthresholdcallback logthresholdcallback shouldupdate shouldlog do the request blocking called by request starter also responsible for deleting it return true if a request was executed false if caller should try to find another request and remove this one from the queue public boolean send node client core core final request scheduler sched client context context chosen block req object key num req token client key key req ckey if key null logger error sendable get class key is null in send key num key num for req return false if logminor logger minor sendable get class sending get for key key num key if req is cancelled if logminor logger minor sendable get class cancelled req req on failure new low level get exception low level get exception cancelled context return false try try core real get key key req local request only req cache local requests req ignore store catch final low level get exception e req on failure e context return true catch throwable t logger error this caught t t req on failure new low level get exception low level get exception internal error context return true req on fetch success context catch throwable t logger error this caught t t req on failure new low level get exception low level get exception internal error context return true return true requeststarter nodeclientcore requestscheduler clientcontext chosenblock keynum clientkey sendableget keynum keynum sendableget keynum iscancelled sendableget onfailure lowlevelgetexception lowlevelgetexception realgetkey localrequestonly cachelocalrequests ignorestore lowlevelgetexception onfailure onfailure lowlevelgetexception lowlevelgetexception internal_error onfetchsuccess onfailure lowlevelgetexception lowlevelgetexception internal_error public void run plugin plugin respirator mypr try logger debug this start catpcha generation needs headless mode on linux system set property java awt headless true mpr mypr mdb initdb database filename fixme change before release m config config load or create this if m config get int config database format version wot database format version throw new runtime exception the wot plugin s database format is newer than the wot plugin which is being used upgradedb delete duplicate objects delete orphan objects mxml transformer new xml transformer this m puzzle store new introduction puzzle store this m request client new request client public boolean persistent return false public void remove from object container container throw new unsupported operation exception create seed identities m inserter new identity inserter this m fetcher new identity fetcher this m introduction server new introduction server this m fetcher m introduction client new introduction client this m web interface new web interface this self uri mfcp interface new fcp interface this logger debug this starting fetches of all identities synchronized this for identity identity get all identities m fetcher fetch identity true logger debug this wot startup completed catch exception e logger error this error during startup e we call it so the database is properly closed terminate runplugin pluginrespirator setproperty database_filename mconfig loadorcreate mconfig getint database_format_version database_format_version runtimeexception deleteduplicateobjects deleteorphanobjects mxmltransformer xmltransformer mpuzzlestore introductionpuzzlestore mrequestclient requestclient removefrom objectcontainer unsupportedoperationexception createseedidentities minserter identityinserter mfetcher identityfetcher mintroductionserver introductionserver mfetcher mintroductionclient introductionclient mwebinterface webinterface self_uri mfcpinterface fcpinterface getallidentities mfetcher m request client new request client public boolean persistent return false mrequestclient requestclient public void remove from object container container throw new unsupported operation exception removefrom objectcontainer unsupportedoperationexception public wot for use by the unit tests to be able to run wot without a node param database filename the filename of the database public wot string database filename mdb initdb database filename m config config load or create this if m config get int config database format version wot database format version throw new runtime exception the wot plugin s database format is newer than the wot plugin which is being used databasefilename databasefilename databasefilename mconfig loadorcreate mconfig getint database_format_version database_format_version runtimeexception initializes the plugin s db4o database return a db4o code object container code private ext object container initdb string filename configuration cfg db4o new configuration cfg reflect with new jdk reflector m class loader cfg activation depth 5 fixme change to 1 and add explicit activation everywhere cfg exceptions on not storable true for string field identity get indexed fields cfg object class identity class object field field indexed true for string field own identity get indexed fields cfg object class own identity class object field field indexed true for string field trust get indexed fields cfg object class trust class object field field indexed true for string field score get indexed fields cfg object class score class object field field indexed true cfg object class introduction puzzle puzzle type class persist static field values needed to be able to store enums for string field introduction puzzle get indexed fields cfg object class introduction puzzle class object field field indexed true return db4o open file cfg filename ext objectcontainer extobjectcontainer newconfiguration reflectwith jdkreflector mclassloader activationdepth exceptionsonnotstorable getindexedfields objectclass objectfield ownidentity getindexedfields objectclass ownidentity objectfield getindexedfields objectclass objectfield getindexedfields objectclass objectfield objectclass introductionpuzzle puzzletype persiststaticfieldvalues introductionpuzzle getindexedfields objectclass introductionpuzzle objectfield openfile private synchronized void upgradedb int old version m config get int config database format version if old version wot database format version return if old version 100 logger normal this found old database 100 adding last fetched date to all identities for identity identity get all identities identity m last fetched date new date 0 store and commit identity m config set config database format version wot database format version m config store and commit else throw new runtime exception your database is too outdated to be upgraded automatically please create a new one by deleting database filename contact the developers if you really need your old data oldversion mconfig getint database_format_version oldversion database_format_version oldversion getallidentities mlastfetcheddate storeandcommit mconfig database_format_version database_format_version mconfig storeandcommit runtimeexception database_filename debug function for deleting duplicate identities etc which might have been created due to bugs suppress warnings unchecked private synchronized void delete duplicate objects synchronized mdb try object set identity identities get all identities hash set string deleted new hash set string for identity identity identities query q mdb query q constrain identity class q descend mid constrain identity getid q constrain identity identity not object set identity duplicates q execute for identity duplicate duplicates if deleted contains duplicate getid false logger error duplicate deleting duplicate identity duplicate get requesturi for trust trust get received trusts duplicate mdb delete trust for trust trust get given trusts duplicate mdb delete trust for score score get scores duplicate mdb delete score mdb delete duplicate deleted add identity getid mdb commit catch runtime exception e mdb rollback logger error this error while deleting duplicate identities e try for own identity tree owner get all own identities hash set string given to new hash set string for trust trust get given trusts tree owner if given to contains trust get trustee getid false given to add trust get trustee getid else identity trustee trust get trustee logger error this deleting duplicate given trust from tree owner get nickname to trustee get nickname mdb delete trust try update score without commit tree owner trustee catch exception e maybe another duplicate prevents it from working logger error this updating score of trustee get nickname failed e mdb commit catch runtime exception e mdb rollback logger error this error while deleting duplicate trusts e fixme also delete duplicate trust score etc suppresswarnings deleteduplicateobjects objectset getallidentities hashset hashset objectset getrequesturi getreceivedtrusts getgiventrusts getscores runtimeexception ownidentity treeowner getallownidentities hashset givento hashset getgiventrusts treeowner givento gettrustee givento gettrustee gettrustee treeowner getnickname getnickname updatescorewithoutcommit treeowner getnickname runtimeexception debug function for deleting trusts or scores of which one of the involved partners is missing suppress warnings unchecked private synchronized void delete orphan objects synchronized mdb try query q mdb query q constrain trust class q descend m truster constrain null identity or q descend m trustee constrain null identity object set trust orphan trusts q execute for trust trust orphan trusts logger error trust deleting orphan trust truster trust get truster trustee trust get trustee mdb delete trust catch exception e logger error this deleting orphan trusts failed e mdb rollback no need to do so here try query q mdb query q constrain score class q descend m tree owner constrain null identity or q descend m target constrain null identity object set score orphan scores q execute for score score orphan scores logger error score deleting orphan score tree owner score get tree owner target score get target mdb delete score mdb commit catch exception e logger error this deleting orphan trusts failed e mdb rollback no need to do so here suppresswarnings deleteorphanobjects mtruster mtrustee objectset orphantrusts orphantrusts gettruster gettrustee mtreeowner mtarget objectset orphanscores orphanscores treeowner gettreeowner gettarget private synchronized void create seed identities for string seeduri seed identities identity seed try seed get identity byuri seeduri if seed instanceof own identity own identity own seed own identity seed fixme does the cast make that necessary i m adding it to make sure that we do not lose information when storing mdb activate own seed 5 own seed add context introduction puzzle introduction context own seed set property introduction server puzzle count property integer to string introduction server seed identity puzzle count store and commit own seed try seed set edition new freeneturi seeduri get edition catch exception e we already have the latest edition stored catch unknown identity exception uie try seed new identity seeduri null true store and commit seed catch exception e logger error this seed identity creation error e catch exception e logger error this seed identity loading error e createseedidentities seed_identities getidentitybyuri ownidentity ownidentity ownseed ownidentity ownseed ownseed addcontext introductionpuzzle introduction_context ownseed setproperty introductionserver puzzle_count_property tostring introductionserver seed_identity_puzzle_count storeandcommit ownseed setedition getedition unknownidentityexception storeandcommit public void terminate logger debug this wot plugin terminating we use single try catch blocks so that failure of termination of one service does not prevent termination of the others try if m introduction client null m introduction client terminate catch exception e logger error this error during termination e try if m introduction server null m introduction server terminate catch exception e logger error this error during termination e try if m inserter null m inserter terminate catch exception e logger error this error during termination e try if m fetcher null m fetcher stop catch exception e logger error this error during termination e try if mdb null fixme is it possible to ask db4o whether a transaction is pending if the plugin s synchronization works correctly none should be pending here and we should log an error if there are any pending transactions at this point synchronized mdb lock mdb rollback mdb close catch exception e logger error this error during termination e logger debug this wot plugin terminated mintroductionclient mintroductionclient mintroductionserver mintroductionserver minserter minserter mfetcher mfetcher inherited event handler from fred pluginhttp handled in code class web interface code public string handlehttp get http request request throws pluginhttp exception return m web interface handlehttp get request fredpluginhttp webinterface handlehttpget httprequest pluginhttpexception mwebinterface handlehttpget inherited event handler from fred pluginhttp handled in code class web interface code public string handlehttp post http request request throws pluginhttp exception return m web interface handlehttp post request fredpluginhttp webinterface handlehttppost httprequest pluginhttpexception mwebinterface handlehttppost inherited event handler from fred pluginhttp handled in code class web interface code public string handlehttp put http request request throws pluginhttp exception return m web interface handlehttp put request fredpluginhttp webinterface handlehttpput httprequest pluginhttpexception mwebinterface handlehttpput inherited event handler from fred pluginfcp handled in code class fcp interface code public void handle plugin reply sender replysender simple field set params bucket data int accesstype mfcp interface handle replysender params data accesstype fredpluginfcp fcpinterface pluginreplysender simplefieldset mfcpinterface loads an own or normal identity from the database querying on its id param id the id of the identity to load return the identity matching the supplied id throws duplicate identity exception if there are more than one identity with this id in the database throws unknown identity exception if there is no identity with this id in the database suppress warnings unchecked public synchronized identity get identity byid string id throws unknown identity exception query query mdb query query constrain identity class query descend mid constrain id object set identity result query execute if result size 0 throw new unknown identity exception id if result size 1 throw new duplicate identity exception id return result next duplicateidentityexception unknownidentityexception suppresswarnings getidentitybyid unknownidentityexception objectset unknownidentityexception duplicateidentityexception gets an own identity by its id param id the unique identifier to query an own identity return the requested own identity throws unknown identity exception if there is now own identity with that id suppress warnings unchecked public synchronized own identity get own identity byid string id throws unknown identity exception query query mdb query query constrain own identity class query descend mid constrain id object set own identity result query execute if result size 0 throw new unknown identity exception id if result size 1 throw new duplicate identity exception id return result next ownidentity ownidentity ownidentity unknownidentityexception ownidentity suppresswarnings ownidentity getownidentitybyid unknownidentityexception ownidentity objectset ownidentity unknownidentityexception duplicateidentityexception loads an identity from the database querying on its requesturi a valid link freeneturi param uri the requesturi of the identity return the identity matching the supplied requesturi throws unknown identity exception if there is no identity with this id in the database throws duplicate identity exception if there are more than one identity with this id in the database public identity get identity byuri freeneturi uri throws unknown identity exception return get identity byid identity getid fromuri uri unknownidentityexception duplicateidentityexception getidentitybyuri unknownidentityexception getidentitybyid getidfromuri loads an identity from the database querying on its requesturi as string param uri the requesturi of the identity which will be converted to link freeneturi return the identity matching the supplied requesturi throws unknown identity exception if there is no identity with this id in the database throws duplicate identity exception if there are more than one identity with this id in the database throws malformedurl exception if the requesturi isn t a valid freeneturi public identity get identity byuri string uri throws unknown identity exception malformedurl exception return get identity byuri new freeneturi uri unknownidentityexception duplicateidentityexception malformedurlexception getidentitybyuri unknownidentityexception malformedurlexception getidentitybyuri gets an own identity by its requesturi a link freeneturi the own identity s unique identifier is extracted from the supplied requesturi param uri the requesturi of the desired own identity return the requested own identity throws unknown identity exception if the own identity isn t in the database public own identity get own identity byuri freeneturi uri throws unknown identity exception return get own identity byid own identity getid fromuri uri ownidentity ownidentity ownidentity ownidentity unknownidentityexception ownidentity ownidentity getownidentitybyuri unknownidentityexception getownidentitybyid ownidentity getidfromuri gets an own identity by its requesturi as string the given string is converted to link freeneturi in order to extract a unique id param db a reference to the database param uri the requesturi as string of the desired own identity return the requested own identity throws unknown identity exception if the own identity isn t in the database throws duplicate identity exception if the own identity is present more that once in the database should never happen throws malformedurl exception if the supplied requesturi is not a valid freeneturi public own identity get own identity byuri string uri throws unknown identity exception malformedurl exception return get own identity byuri new freeneturi uri ownidentity ownidentity ownidentity unknownidentityexception ownidentity duplicateidentityexception ownidentity malformedurlexception ownidentity getownidentitybyuri unknownidentityexception malformedurlexception getownidentitybyuri returns all identities that are in the database you have to synchronize on this wot when calling the function and processing the returned list return an link object set containing all identities present in the database public synchronized object set identity get all identities return mdb query by example identity class objectset objectset getallidentities querybyexample returns all non own identities that are in the database you have to synchronize on this wot when calling the function and processing the returned list suppress warnings unchecked public synchronized object set identity get all non own identities query q mdb query q constrain identity class q constrain own identity class not return q execute suppresswarnings objectset getallnonownidentities ownidentity returns all non own identities that are in the database sorted descending by their date of modification i e recently modified identities will be at the beginning of the list you have to synchronize on this wot when calling the function and processing the returned list used by the introduction client for fetching puzzles from recently modified identities suppress warnings unchecked public synchronized object set identity get all non own identities sorted by modification query q mdb query q constrain identity class q constrain own identity class not fixme as soon as identities announce that they were online every day uncomment the following line q descend m last changed date constrain new date current timeutc get in millis 1 24 60 60 1000 greater q descend m last fetched date order descending return q execute introductionclient suppresswarnings objectset getallnonownidentitiessortedbymodification ownidentity mlastchangeddate currenttimeutc getinmillis mlastfetcheddate orderdescending returns all own identities that are in the database you have to synchronize on this wot when calling the function and processing the returned list return an link object set containing all identities present in the database public synchronized object set own identity get all own identities return mdb query by example own identity class objectset objectset ownidentity getallownidentities querybyexample ownidentity public synchronized void store and commit identity identity synchronized identity synchronized mdb lock if mdb ext is stored identity mdb ext is active identity throw new runtime exception trying to store an inactive identity object fixme we also need to check whether the member objects are active here try if identity instanceof own identity own identity own id own identity identity mdb store own id m inserturi mdb store own id m creation date not stored because db4o considers it as a primitive and automatically stores it mdb store own id m last insert date not stored because db4o considers it as a primitive and automatically stores it mdb store mid not stored because db4o considers it as a primitive and automatically stores it mdb store identity m requesturi mdb store m first fetched date not stored because db4o considers it as a primitive and automatically stores it mdb store m last fetched date not stored because db4o considers it as a primitive and automatically stores it mdb store m last changed date not stored because db4o considers it as a primitive and automatically stores it mdb store m nickname not stored because db4o considers it as a primitive and automatically stores it mdb store m does publish trust list not stored because db4o considers it as a primitive and automatically stores it mdb store identity m properties mdb store identity m contexts mdb store identity mdb commit logger debug identity commited catch runtime exception e mdb rollback throw e storeandcommit isstored isactive runtimeexception ownidentity ownidentity ownid ownidentity ownid minserturi ownid mcreationdate ownid mlastinsertdate mrequesturi mfirstfetcheddate mlastfetcheddate mlastchangeddate mnickname mdoespublishtrustlist mproperties mcontexts runtimeexception gets the score of this identity in a trust tree each link own identity has its own trust tree param tree owner the owner of the trust tree param db a reference to the database return the link score of this identity in the required trust tree throws not in trust tree exception if this identity is not in the required trust tree suppress warnings unchecked public synchronized score get score own identity tree owner identity target throws not in trust tree exception query query mdb query query constrain score class query descend m tree owner constrain tree owner identity query descend m target constrain target identity object set score result query execute if result size 0 throw new not in trust tree exception target get requesturi is not in that trust tree if result size 1 throw new duplicate score exception target get requesturi target get nickname has result size scores in tree owner get nickname s trust tree return result next ownidentity treeowner notintrusttreeexception suppresswarnings getscore ownidentity treeowner notintrusttreeexception mtreeowner treeowner mtarget objectset notintrusttreeexception getrequesturi duplicatescoreexception getrequesturi getnickname treeowner getnickname gets a list of all this identity s scores you have to synchronize on this wot around the call to this function and the processing of the returned list param db a reference to the database return an link object set containing all link score this identity has suppress warnings unchecked public synchronized object set score get scores identity identity query query mdb query query constrain score class query descend m target constrain identity identity return query execute objectset suppresswarnings objectset getscores mtarget gets the best score this identity has in existing trust trees 0 if it is not in the trust tree return the best score this identity has public synchronized int get best score identity identity int best score 0 object set score scores get scores identity todo use a db4o native query for this loop maybe use an index indexes should be sorted so maximum search will be o 1 but i guess indexes cannot be done for the target value pair so we might just cache the best score ourselves otoh the number of own identies will be small so the maximum search will probably be fast while scores has next score score scores next best score math max score get score best score return best score getbestscore bestscore objectset getscores hasnext bestscore getscore bestscore bestscore get all scores in the database you have to synchronize on this wot when calling the function and processing the returned list public synchronized object set score get all scores return mdb query by example score class objectset getallscores querybyexample gets identities matching a specified score criteria you have to synchronize on this wot when calling the function and processing the returned list param owner requesturi of the owner of the trust tree null if you want the trusted identities of all owners param select score criteria can be 0 or return an link object set containing identities that match the criteria throws invalid parameter exception if the criteria is not recognised suppress warnings unchecked public synchronized object set score get identities by score own identity tree owner int select query query mdb query query constrain score class if tree owner null query descend m tree owner constrain tree owner identity query descend m target constrain own identity class not we include 0 in the list of identities with positive score because solving captchas gives no points to score if select 0 query descend m value constrain 0 smaller not else if select 0 query descend m value constrain 0 smaller else query descend m value constrain 0 return query execute objectset invalidparameterexception suppresswarnings objectset getidentitiesbyscore ownidentity treeowner treeowner mtreeowner treeowner mtarget ownidentity mvalue mvalue mvalue gets link trust from a specified truster to a specified trustee param truster the identity that gives trust to this identity param trustee the identity which receives the trust return the trust given to the trustee by the specified truster throws not trusted exception if the truster doesn t trust the trustee suppress warnings unchecked public synchronized trust get trust identity truster identity trustee throws not trusted exception duplicate trust exception query query mdb query query constrain trust class query descend m truster constrain truster identity query descend m trustee constrain trustee identity object set trust result query execute if result size 0 throw new not trusted exception truster get nickname does not trust trustee get nickname if result size 1 throw new duplicate trust exception trust from truster get nickname to trustee get nickname exists result size times in the database return result next nottrustedexception suppresswarnings gettrust nottrustedexception duplicatetrustexception mtruster mtrustee objectset nottrustedexception getnickname getnickname duplicatetrustexception getnickname getnickname gets all trusts given by the given truster you have to synchronize on this wot when calling the function and processing the returned list return an link object set containing all link trust the passed identity has given suppress warnings unchecked public synchronized object set trust get given trusts identity truster query query mdb query query constrain trust class query descend m truster constrain truster identity return query execute objectset suppresswarnings objectset getgiventrusts mtruster gets all trusts given by the given truster in a trust list older than the given edition number you have to synchronize on this wot when calling the function and processing the returned list suppress warnings unchecked protected synchronized object set trust get given trusts older than identity truster long edition query q mdb query q constrain trust class q descend m truster constrain truster identity q descend m truster trust list edition constrain edition smaller return q execute suppresswarnings objectset getgiventrustsolderthan mtruster mtrustertrustlistedition gets all trusts received by the given trustee you have to synchronize on this wot when calling the function and processing the returned list return an link object set containing all link trust the passed identity has received suppress warnings unchecked public synchronized object set trust get received trusts identity trustee query query mdb query query constrain trust class query descend m trustee constrain trustee identity return query execute objectset suppresswarnings objectset getreceivedtrusts mtrustee gets all trusts you have to synchronize on this wot when calling the function and processing the returned list return an link object set containing all link trust the passed identity has received suppress warnings unchecked public synchronized object set trust get all trusts query query mdb query query constrain trust class return query execute objectset suppresswarnings objectset getalltrusts gives some link trust to another identity it creates or updates an existing trust object and make the trustee compute its link score this function does neither lock the database nor commit the transaction you have to surround it with synchronized mdb lock try set trust without commit store and commit truster catch runtime exception e mdb rollback throw e param truster the identity that gives the trust param trustee the identity that receives the trust param new value numeric value of the trust param new comment a comment to explain the given value throws invalid parameter exception if a given parameter isn t valid see trust for details on accepted values protected synchronized void set trust without commit identity truster identity trustee byte new value string new comment throws invalid parameter exception trust trust try check if we are updating an existing trust value trust get trust truster trustee trust truster edition updated trust set comment new comment mdb store trust if trust get value new value trust set value new value mdb store trust logger debug this updated trust value trust now updating score update score without commit trustee catch not trusted exception e trust new trust truster trustee new value new comment mdb store trust logger debug this new trust value trust now updating score update score without commit trustee truster updated settrustwithoutcommit storeandcommit runtimeexception newvalue newcomment invalidparameterexception settrustwithoutcommit newvalue newcomment invalidparameterexception gettrust trustereditionupdated setcomment newcomment getvalue newvalue setvalue newvalue updatescorewithoutcommit nottrustedexception newvalue newcomment updatescorewithoutcommit only for being used by wot internally and by unit tests public synchronized void set trust identity truster identity trustee byte new value string new comment throws invalid parameter exception fixme throw if we are no unit test and the truster is no own identity assert truster instanceof own identity unit tests may ignore this synchronized mdb lock try set trust without commit truster trustee new value new comment store and commit truster catch runtime exception e mdb rollback throw e settrust newvalue newcomment invalidparameterexception ownidentity settrustwithoutcommit newvalue newcomment storeandcommit runtimeexception deletes a trust object param truster param trustee protected synchronized void remove trust own identity truster identity trustee synchronized mdb lock try try trust trust get trust truster trustee mdb delete trust update score without commit trustee catch not trusted exception e logger error this cannot remove trust there is none from truster get nickname to trustee get nickname catch runtime exception e mdb rollback throw e removetrust ownidentity gettrust updatescorewithoutcommit nottrustedexception getnickname getnickname runtimeexception this function does neither lock the database nor commit the transaction you have to surround it with synchronized mdb lock try set trust without commit store and commit truster catch runtime exception e mdb rollback throw e protected synchronized void remove trust without commit trust trust mdb delete trust update score without commit trust get trustee settrustwithoutcommit storeandcommit runtimeexception removetrustwithoutcommit updatescorewithoutcommit gettrustee initializes this own identity s trust tree meaning it creates a score object for this own identity in its own trust tree so it gets a rank and a capacity and can give trust to other identities param db a reference to the database throws duplicate score exception if there already is more than one score for this identity should never happen private synchronized void init trust tree own identity identity throws duplicate score exception synchronized mdb lock try get score identity identity logger error this init trus tree called even though there is already one for identity return catch not in trust tree exception e try mdb store new score identity identity 100 0 100 mdb commit catch runtime exception ex mdb rollback throw ex ownidentity ownidentity duplicatescoreexception inittrusttree ownidentity duplicatescoreexception getscore inittrustree notintrusttreeexception runtimeexception updates this identity s link score in every trust tree this function does neither lock the database nor commit the transaction you have to surround it with synchronized mdb lock try set trust without commit store and commit truster catch runtime exception e mdb rollback throw e private synchronized void update score without commit identity trustee object set own identity tree owners get all own identities if tree owners size 0 logger debug this can t update trustee get nickname s score there is no own identity yet while tree owners has next update score without commit tree owners next trustee settrustwithoutcommit storeandcommit runtimeexception updatescorewithoutcommit objectset ownidentity treeowners getallownidentities treeowners getnickname treeowners hasnext updatescorewithoutcommit treeowners updates this identity s link score in one trust tree makes this identity s trustees update their score if its capacity has changed this function does neither lock the database nor commit the transaction you have to surround it with synchronized mdb lock try set trust without commit store and commit truster catch runtime exception e mdb rollback throw e param db a reference to the database param tree owner the own identity that owns the trust tree private synchronized void update score without commit own identity tree owner identity target if target tree owner return boolean changed capacity false logger debug target updating target get nickname s score in tree owner get nickname s trust tree score score int value compute score value tree owner target int rank compute rank tree owner target if rank 1 1 value means the identity is not in the trust tree try if he had a score we delete it score get score tree owner target mdb delete score he had a score we delete it changed capacity true logger debug target target get nickname is not in tree owner get nickname s trust tree anymore catch not in trust tree exception e else the identity is in the trust tree we must detect if an identity had a null or negative score which has changed to positive if we download the trust list of someone who has no or negative score we do not create the identities in his trust list if the identity now gets a positive score we must re download his current trust list boolean score was negative false try get existing score or create one if needed score get score tree owner target score was negative score get score 0 catch not in trust tree exception e score new score tree owner target 0 1 0 score was negative true if score was negative score get score 0 target decrease edition logger debug this score changed from negative null to positive refetchting target get requesturi m fetcher fetch target score set value value score set rank rank 1 int old capacity score get capacity boolean has negative trust false does the tree owner personally distrust this identity try if get trust tree owner target get value 0 has negative trust true logger debug target target get nickname received negative trust from tree owner get nickname and therefore has no capacity in his trust tree catch not trusted exception e if has negative trust score set capacity 0 else score set capacity score get rank score capacities length 1 score capacities score get rank if score get capacity old capacity changed capacity true mdb store score logger debug target new score score to string if changed capacity we have to update trustees score object set trust given trusts get given trusts target logger debug target target get nickname s capacity has changed in tree owner get nickname s trust tree updating his given trusts size trustees for trust given trust given trusts update score without commit tree owner given trust get trustee settrustwithoutcommit storeandcommit runtimeexception treeowner ownidentity updatescorewithoutcommit ownidentity treeowner treeowner changedcapacity getnickname treeowner getnickname computescorevalue treeowner computerank treeowner getscore treeowner changedcapacity getnickname treeowner getnickname notintrusttreeexception scorewasnegative getscore treeowner scorewasnegative getscore notintrusttreeexception treeowner scorewasnegative scorewasnegative getscore decreaseedition getrequesturi mfetcher setvalue setrank oldcapacity getcapacity hasnegativetrust treeowner gettrust treeowner getvalue hasnegativetrust getnickname treeowner getnickname nottrustedexception hasnegativetrust setcapacity setcapacity getrank getrank getcapacity oldcapacity changedcapacity tostring changedcapacity objectset giventrusts getgiventrusts getnickname treeowner getnickname giventrusts giventrust giventrusts updatescorewithoutcommit treeowner giventrust gettrustee computes the target s score value according to the trusts it has received and the capacity of its trusters in the specified trust tree param db a reference to the database param tree owner the own identity that owns the trust tree return the new score if this identity throws duplicate score exception if there already exist more than one link score objects for the trustee should never happen private synchronized int compute score value own identity tree owner identity target throws duplicate score exception int value 0 object set trust received trusts get received trusts target while received trusts has next trust trust received trusts next try value trust get value get score tree owner trust get truster get capacity 100 catch not in trust tree exception e return value treeowner ownidentity duplicatescoreexception computescorevalue ownidentity treeowner duplicatescoreexception objectset receivedtrusts getreceivedtrusts receivedtrusts hasnext receivedtrusts getvalue getscore treeowner gettruster getcapacity notintrusttreeexception computes the target s rank in the trust tree it gets its best ranked truster s rank plus one or 1 if none of its trusters are in the trust tree param db a reference to the database param tree owner the own identity that owns the trust tree return the new rank if this identity throws duplicate score exception if there already exist more than one link score objects for the trustee should never happen private synchronized int compute rank own identity tree owner identity target throws duplicate score exception int rank 1 object set trust received trusts get received trusts target while received trusts has next trust trust received trusts next try score score get score tree owner trust get truster if score get capacity 0 if the truster has no capacity he can t give his rank if rank 1 score get rank rank if the truster s rank is better than ours or if we have not rank score get rank catch not in trust tree exception e return rank treeowner ownidentity duplicatescoreexception computerank ownidentity treeowner duplicatescoreexception objectset receivedtrusts getreceivedtrusts receivedtrusts hasnext receivedtrusts getscore treeowner gettruster getcapacity getrank getrank notintrusttreeexception public synchronized identity add identity string requesturi throws malformedurl exception invalid parameter exception identity identity try identity get identity byuri requesturi logger debug this tried to manually add an identity we already know ignored throw new invalid parameter exception we already have this identity catch unknown identity exception e identity new identity new freeneturi requesturi null false store and commit identity logger debug this trying to fetch manually added identity identity get requesturi m fetcher fetch identity return identity addidentity malformedurlexception invalidparameterexception getidentitybyuri invalidparameterexception unknownidentityexception storeandcommit getrequesturi mfetcher public synchronized void delete identity identity identity synchronized mdb lock try for score score get scores identity mdb delete score for trust trust get received trusts identity mdb delete trust for trust given trust get given trusts identity mdb delete given trust update score without commit given trust get trustee mdb delete identity mdb commit catch runtime exception e mdb rollback throw e deleteidentity getscores getreceivedtrusts giventrust getgiventrusts giventrust updatescorewithoutcommit giventrust gettrustee runtimeexception public synchronized void delete identity string id throws unknown identity exception synchronized mdb lock identity identity get identity byid id delete identity identity deleteidentity unknownidentityexception getidentitybyid deleteidentity public own identity create own identity string nick name boolean publish trust list string context throws malformedurl exception invalid parameter exception freeneturi keypair get plugin respirator gethl simple client generate key pair wot return create own identity keypair 0 to string keypair 1 to string nick name publish trust list context ownidentity createownidentity nickname publishtrustlist malformedurlexception invalidparameterexception getpluginrespirator gethlsimpleclient generatekeypair createownidentity tostring tostring nickname publishtrustlist public synchronized own identity create own identity string inserturi string requesturi string nick name boolean publish trust list string context throws malformedurl exception invalid parameter exception synchronized mdb lock own identity identity try identity get own identity byuri requesturi logger debug this tried to create an own identity with an already existing request uri throw new invalid parameter exception the uri you specified is already used by the own identity identity get nickname catch unknown identity exception uie identity new own identity new freeneturi inserturi new freeneturi requesturi nick name publish trust list identity add context context identity add context introduction puzzle introduction context fixme make configureable identity set property introduction server puzzle count property integer to string introduction server default puzzle count try mdb store identity init trust tree identity for string seeduri seed identities try set trust without commit identity get identity byuri seeduri byte 100 i trust the freenet developers catch unknown identity exception e logger error this should not happen seed identity not known e mdb commit logger debug this successfully created a new own identity identity get nickname return identity catch runtime exception e mdb rollback throw e ownidentity createownidentity nickname publishtrustlist malformedurlexception invalidparameterexception ownidentity getownidentitybyuri invalidparameterexception getnickname unknownidentityexception ownidentity nickname publishtrustlist addcontext addcontext introductionpuzzle introduction_context setproperty introductionserver puzzle_count_property tostring introductionserver default_puzzle_count inittrusttree seed_identities settrustwithoutcommit getidentitybyuri unknownidentityexception ownidentity getnickname runtimeexception public synchronized void restore identity string requesturi string inserturi throws malformedurl exception invalid parameter exception own identity identity synchronized mdb lock try try identity old get identity byuri requesturi if old instanceof own identity throw new invalid parameter exception there is already an own identity with the given uri pair we already have fetched this identity as a stranger s one we need to update the database identity new own identity inserturi requesturi old get nickname old does publish trust list we re fetch the current edition to make sure all trustees are imported identity set edition old get edition 1 identity set contexts old get contexts identity set properties old get properties update all received trusts for trust old received trust get received trusts old trust new received trust new trust old received trust get truster identity old received trust get value old received trust get comment mdb delete old received trust fixme is this allowed by db4o in a for each loop mdb store new received trust update all received scores for score old score get scores old score new score new score old score get tree owner identity old score get score old score get rank old score get capacity mdb delete old score mdb store new score mdb store identity init trust tree identity update all given trusts for trust given trust get given trusts old set trust without commit identity given trust get trustee given trust get value given trust get comment fixme the old code would just delete the old trust value here instead of doing the following is the following line correct remove trust without commit given trust remove the old identity mdb delete old store and commit identity logger debug this successfully restored an already known identity from freenet identity get nickname catch unknown identity exception e identity new own identity new freeneturi inserturi new freeneturi requesturi null false store the new identity mdb store identity init trust tree identity store and commit identity logger debug this successfully restored not yet known identity from freenet identity get requesturi catch runtime exception e mdb rollback throw e m fetcher fetch identity restoreidentity malformedurlexception invalidparameterexception ownidentity getidentitybyuri ownidentity invalidparameterexception ownidentity getnickname doespublishtrustlist setedition getedition setcontexts getcontexts setproperties getproperties oldreceivedtrust getreceivedtrusts newreceivedtrust oldreceivedtrust gettruster oldreceivedtrust getvalue oldreceivedtrust getcomment oldreceivedtrust newreceivedtrust oldscore getscores newscore oldscore gettreeowner oldscore getscore oldscore getrank oldscore getcapacity oldscore newscore inittrusttree giventrust getgiventrusts settrustwithoutcommit giventrust gettrustee giventrust getvalue giventrust getcomment removetrustwithoutcommit giventrust storeandcommit getnickname unknownidentityexception ownidentity inittrusttree storeandcommit getrequesturi runtimeexception mfetcher public synchronized void set trust string own trusterid string trusteeid byte value string comment throws unknown identity exception number format exception invalid parameter exception own identity truster get own identity byid own trusterid identity trustee get identity byid trusteeid set trust truster trustee value comment settrust owntrusterid unknownidentityexception numberformatexception invalidparameterexception ownidentity getownidentitybyid owntrusterid getidentitybyid settrust public synchronized void remove trust string own trusterid string trusteeid throws unknown identity exception own identity truster get own identity byid own trusterid identity trustee get identity byid trusteeid remove trust truster trustee removetrust owntrusterid unknownidentityexception ownidentity getownidentitybyid owntrusterid getidentitybyid removetrust public synchronized void add context string own identityid string new context throws unknown identity exception invalid parameter exception identity identity get own identity byid own identityid identity add context new context store and commit identity logger debug this added context new context to identity identity get nickname addcontext ownidentityid newcontext unknownidentityexception invalidparameterexception getownidentitybyid ownidentityid addcontext newcontext storeandcommit newcontext getnickname public synchronized void remove context string own identityid string context throws unknown identity exception invalid parameter exception identity identity get own identity byid own identityid identity remove context context store and commit identity logger debug this removed context context from identity identity get nickname removecontext ownidentityid unknownidentityexception invalidparameterexception getownidentitybyid ownidentityid removecontext storeandcommit getnickname public synchronized string get property string identityid string property throws invalid parameter exception unknown identity exception return get identity byid identityid get property property getproperty invalidparameterexception unknownidentityexception getidentitybyid getproperty public synchronized void set property string own identityid string property string value throws unknown identity exception invalid parameter exception identity identity get own identity byid own identityid identity set property property value store and commit identity logger debug this added property property value to identity identity get nickname setproperty ownidentityid unknownidentityexception invalidparameterexception getownidentitybyid ownidentityid setproperty storeandcommit getnickname public void remove property string own identityid string property throws unknown identity exception invalid parameter exception identity identity get own identity byid own identityid identity remove property property store and commit identity logger debug this removed property property from identity identity get nickname removeproperty ownidentityid unknownidentityexception invalidparameterexception getownidentitybyid ownidentityid removeproperty storeandcommit getnickname public string get version return version get marketing version getversion getmarketingversion public long get real version return version get real version getrealversion getrealversion public string get string string key return key getstring public void set class loader class loader my class loader m class loader my class loader setclassloader classloader myclassloader mclassloader myclassloader public void set language language new language setlanguage newlanguage public plugin respirator get plugin respirator return mpr pluginrespirator getpluginrespirator public ext object container getdb return mdb extobjectcontainer public config get config return m config getconfig mconfig public identity fetcher get identity fetcher return m fetcher identityfetcher getidentityfetcher mfetcher public xml transformer getxml transformer return mxml transformer xmltransformer getxmltransformer mxmltransformer public introduction puzzle store get introduction puzzle store return m puzzle store introductionpuzzlestore getintroductionpuzzlestore mpuzzlestore public introduction client get introduction client return m introduction client introductionclient getintroductionclient mintroductionclient public request client get request client return m request client requestclient getrequestclient mrequestclient final bucket data public fetch result client metadata dm bucket fetched metadata dm data fetched fetchresult clientmetadata create a fetch result with a new bucket of data but everything else the same as the old one public fetch result fetch result fr bucket output this data output this metadata fr metadata fetchresult fetchresult fetchresult get the mime type of the fetched data if unknown returns application octet stream public string get mime type return metadata getmime type getmimetype getmimetype public client metadata get metadata return metadata clientmetadata getmetadata return the size of the data fetched in bytes public long size return data size get the result as a simple byte array even if we don t have it as one throws out of memory error throws io exception if it was not possible to read the data public byte as byte array throws io exception return bucket tools to byte array data outofmemoryerror ioexception asbytearray ioexception buckettools tobytearray get the result as a bucket public bucket as bucket return data asbucket public bucket read filter bucket bucket bucket factory bf string charset hash map string string other params filter callback cb throws data filter exception io exception logminor logger should log logger minor this logdebug logger should log logger debug this if logminor logger minor this read filter charset charset input stream strm bucket get input stream buffered input stream bis new buffered input stream strm 4096 bucket temp bf make bucket 1 output stream os temp get output stream buffered output stream bos new buffered output stream os 4096 reader r null writer w null input stream reader isr null output stream writer osw null try try isr new input stream reader bis charset osw new output stream writer bos charset r new buffered reader isr 4096 w new buffered writer osw 4096 catch unsupported encoding exception e throw unknown charset exception create e charset html parse context pc new html parse context r w charset cb false pc run temp w close os null finally closer close os closer close strm return temp readfilter bucketfactory hashmap otherparams filtercallback datafilterexception ioexception shouldlog shouldlog readfilter inputstream getinputstream bufferedinputstream bufferedinputstream makebucket outputstream getoutputstream bufferedoutputstream bufferedoutputstream inputstreamreader outputstreamwriter inputstreamreader outputstreamwriter bufferedreader bufferedwriter unsupportedencodingexception unknowncharsetexception htmlparsecontext htmlparsecontext public bucket write filter bucket bucket bucket factory bf string charset hash map string string other params filter callback cb throws data filter exception io exception throw new unsupported operation exception writefilter bucketfactory hashmap otherparams filtercallback datafilterexception ioexception unsupportedoperationexception public string get charset bucket bucket string parse charset throws data filter exception io exception logminor logger should log logger minor this if logminor logger minor this get charset default parse charset input stream strm bucket get input stream buffered input stream bis new buffered input stream strm 4096 writer w new null writer reader r try r new buffered reader new input stream reader bis parse charset 4096 catch unsupported encoding exception e strm close throw e html parse context pc new html parse context r w null new null filter callback true try pc run null catch malformed input exception e not this charset return null catch io exception e throw e catch throwable t ignore all errors if logminor logger minor this caught t trying to detect mime type with parse charset try r close catch io exception e throw e catch throwable t if logminor logger minor this caught t closing stream after trying to detect mime type with parse charset if logminor logger minor this returning charset pc detected charset return pc detected charset getcharset parsecharset datafilterexception ioexception shouldlog getcharset parsecharset inputstream getinputstream bufferedinputstream bufferedinputstream nullwriter bufferedreader inputstreamreader parsecharset unsupportedencodingexception htmlparsecontext htmlparsecontext nullfiltercallback malformedinputexception ioexception parsecharset ioexception parsecharset detectedcharset detectedcharset html parse context reader r writer w string charset filter callback cb boolean no output this r r this w w this charset charset this cb cb this no output no output htmlparsecontext filtercallback nooutput nooutput nooutput bucket run bucket temp throws io exception data filter exception tokenize modes p 0 in text transitions 1 1 in tag not in quotes comment whitespace transitions whitespace 4 save current element 2 at beginning of tag 3 process whole tag 2 in tag in quotes transitions 1 grumble about markup in quotes in tag might confuse older user agents stay in current state 3 in tag in comment transitions save ignore comment go to 0 or grumble about markup in comments 4 in tag in whitespace transitions 2 save tag 0 anything else not whitespace 1 p string builder b new string builder 100 string builder balt new string builder 4000 list string split tag new array list string string current tag null char pprevc 0 char prevc 0 char c 0 mode intext while true int x try x r read libgcj up to at least 4 2 2 has a bug input stream reader refill throws this exception when buffered input reader refill returns false for eof see line 299 at input stream reader java in refill http www koders com java fidd8f7e2eb1e4c22da90ebe0130306ae30f876ab00 aspx s refill l279 line 355 at buffered input stream java in refill http www koders com java fid1949641524fac0083432d79793f554cd85f46759 aspx s refill l355 todo remove this when the gcj bug is fixed and the affected gcj versions are outdated catch java io char conversion exception cce if freenet node node check forgcj char conversion bug only ignore the exception on affected libgcj x 1 else throw cce if x 1 switch mode case intext save text b current tag w this break default dump unfinished tag break break else pprevc prevc prevc c c char x switch mode case intext if c save text b current tag w this b set length 0 balt set length 0 mode intag else b append c break case intag balt append c if html decoder is whitespace c split tag add b to string mode intagwhitespace b set length 0 else if c character is whitespace balt char at 0 previous was an un escaped in a script save text b current tag w this balt set length 0 b set length 0 split tag clear else if c split tag add b to string b set length 0 process tag split tag w this current tag split tag get 0 split tag clear balt set length 0 mode intext else if b length 2 c prevc pprevc mode intagcomment b append c else if c mode intagquotes b append c else if c mode intagsquotes b append c else if c probable end tag current tag null we didn t remember what was the last tag so b append c else b append c break case intagquotes inside double quotes single quotes are just another character perfectly legal in a url if c mode intag b append c part of the element else if c b append gt else if c b append lt else b append c break case intagsquotes if c mode intag b append c part of the element else if c b append lt else if c b append gt else b append c break comments are often used to temporarily disable markup i shall allow it avian white space is not permitted between the markup declaration open delimiter and the comment open delimiter but is permitted between the comment close delimiter and the markup declaration close delimiter a common error is to include a string of hyphens within a comment authors should avoid putting two or more adjacent hyphens inside comments however the only browser that actually gets it right is ie others either don t allow it or allow other chars as well the only safe course of action is to allow any and all chars but eat them avian case intagcomment if b length 4 c prevc b append c mode intagcommentclosing else b append c break case intagcommentclosing if c save comment b w this b set length 0 mode intext else b append c if c mode intagcomment break case intagwhitespace if c mode intagquotes b append c else if c e g div align center avian this will be converted automatically to double quotes note that single quotes are legal in urls if we have single quotes inside single quotes we could get into a major mess here but that s really malformed code and it will still be safe it will just be unreadable mode intagsquotes b append c else if c if kill tag process tag split tag w this kill tag false current tag split tag get 0 split tag clear b set length 0 balt set length 0 mode intext else if c character is whitespace balt char at 0 previous was an un escaped in a script save text balt current tag w this balt set length 0 b set length 0 split tag clear mode intag else if html decoder is whitespace c more whitespace what fun else mode intag b append c return temp ioexception datafilterexception stringbuilder stringbuilder stringbuilder stringbuilder splittag arraylist currenttag inputstreamreader bufferedinputreader inputstreamreader bufferedinputstream charconversionexception checkforgcjcharconversionbug savetext currenttag savetext currenttag setlength setlength htmldecoder iswhitespace splittag tostring setlength iswhitespace charat savetext currenttag setlength setlength splittag splittag tostring setlength processtag splittag currenttag splittag splittag setlength currenttag savecomment setlength killtag processtag splittag killtag currenttag splittag splittag setlength setlength iswhitespace charat savetext currenttag setlength setlength splittag htmldecoder iswhitespace void save text string builder s string tag name writer w html parse context pc throws io exception if pc no output return if logdebug logger debug this saving text s to string if pc kill text return for int i 0 i s length i char c s char at i if c 32 c t c n c r not a real character strongly suggests somebody is using a bogus charset this could be in order to break the filter s delete char at i if logdebug logger debug this removing c from the output stream string style s to string if pc in style pc in script pc current style script chunk style return is parsed and written elsewhere string builder out new string builder s length 2 for int i 0 i s length i char c s char at i if c out append lt else out append c string sout out to string if pc cb null pc cb on text html decoder decode sout tag name tag name is given as type for the text w write sout savetext stringbuilder tagname htmlparsecontext ioexception nooutput tostring killtext charat deletecharat tostring instyle inscript currentstylescriptchunk stringbuilder stringbuilder charat tostring ontext htmldecoder tagname void process tag list string split tag writer w html parse context pc throws io exception data filter exception first check that it is a recognized tag if logdebug for int i 0 i split tag size i logger debug this tag i split tag get i parsed tag t new parsed tag split tag if pc kill tag t t sanitize pc if pc no output return sanitize has done all the work we are interested in if t null if pc write style script with tag pc write style script with tag false string style pc current style script chunk if style null style length 0 pc write after tag append l10n deleted unknown style else w write style pc current style script chunk t write w if pc write after tag length 0 w write pc write after tag to string pc write after tag new string builder 1024 else pc write style script with tag false else pc kill tag false pc write style script with tag false processtag splittag htmlparsecontext ioexception datafilterexception splittag splittag parsedtag parsedtag splittag killtag nooutput writestylescriptwithtag writestylescriptwithtag currentstylescriptchunk writeaftertag deletedunknownstyle currentstylescriptchunk writeaftertag writeaftertag tostring writeaftertag stringbuilder writestylescriptwithtag killtag writestylescriptwithtag void save comment string builder s writer w html parse context pc throws io exception if pc no output return if s length 3 s char at 0 s char at 1 s char at 2 s delete 0 3 if s char at s length 1 s set length s length 1 if s char at s length 1 s set length s length 1 if logdebug logger debug this saving comment s to string if pc expecting bad comment return ignore it if pc in style pc in script pc current style script chunk s return style handler should write if pc kill tag pc kill tag false return string builder sb new string builder for int i 0 i s length i char c s char at i if c sb append lt else if c sb append gt else sb append c s sb w write w write s to string w write savecomment stringbuilder htmlparsecontext ioexception nooutput charat charat charat charat setlength charat setlength tostring expectingbadcomment instyle inscript currentstylescriptchunk killtag killtag stringbuilder stringbuilder charat tostring static void throw filter exception string msg throws data filter exception fixme string longer l10n failed to parse label throw new data filter exception longer longer msg new html node div msg throwfilterexception datafilterexception failedtoparselabel datafilterexception htmlnode public parsed tag parsed tag t string out attrs this element t element this unparsed attrs out attrs this start slash t start slash this end slash t end slash parsedtag parsedtag outattrs unparsedattrs outattrs startslash startslash endslash endslash public parsed tag list string v int len v size if len 0 element null unparsed attrs new string 0 start slash end slash false return string s v get len 1 if len 1 0 s length 1 s ends with s s substring 0 s length 1 v set len 1 s if s length 0 len end slash true don t need to set it back because everything is an i value else end slash false s v get 0 if s length 1 s starts with s s substring 1 v set 0 s start slash true else start slash false element v get 0 if len 1 unparsed attrs new string len 1 for int x 1 x len x unparsed attrs x 1 v get x else unparsed attrs new string 0 if logdebug logger debug this element element parsedtag unparsedattrs startslash endslash endswith endslash endslash startswith startslash startslash unparsedattrs unparsedattrs unparsedattrs public parsed tag sanitize html parse context pc throws data filter exception tag verifier tv allowed tags verifiers get element to lower case if logdebug logger debug this got verifier tv for element if tv null if delete wierd stuff return null else string err html encoder encode l10n unknown tag tag element if delete errors throw filter exception l10n unknown tag label err return null return tv sanitize this pc parsedtag htmlparsecontext datafilterexception tagverifier allowedtagsverifiers tolowercase deletewierdstuff htmlencoder unknowntag deleteerrors throwfilterexception unknowntaglabel override public string to string if element null return string builder sb new string builder if start slash sb append sb append element if unparsed attrs null int n unparsed attrs length for int i 0 i n i sb append append unparsed attrs i if end slash sb append sb append return sb to string tostring stringbuilder stringbuilder startslash unparsedattrs unparsedattrs unparsedattrs endslash tostring public void write writer w throws io exception string s to string if s null w write s ioexception tostring final hash set string inlineuri attrs tag verifier string tag string allowed attrs this tag allowed attrs null null hashset inlineuriattrs tagverifier allowedattrs allowedattrs tag verifier string tag string allowed attrs string uri attrs string inlineuri attrs this tag tag this allowed attrs new hash set string if allowed attrs null for int x 0 x allowed attrs length x this allowed attrs add allowed attrs x this uri attrs new hash set string if uri attrs null for int x 0 x uri attrs length x this uri attrs add uri attrs x this inlineuri attrs new hash set string if inlineuri attrs null for int x 0 x inlineuri attrs length x this inlineuri attrs add inlineuri attrs x tagverifier allowedattrs uriattrs inlineuriattrs allowedattrs hashset allowedattrs allowedattrs allowedattrs allowedattrs uriattrs hashset uriattrs uriattrs uriattrs uriattrs inlineuriattrs hashset inlineuriattrs inlineuriattrs inlineuriattrs inlineuriattrs parsed tag sanitize parsed tag t html parse context pc throws data filter exception map string object h new hash map string object boolean equals false string prevx if t unparsed attrs null for int i 0 i t unparsed attrs length i string s t unparsed attrs i if equals equals false s strip quotes s h remove prevx h put prevx s prevx else int idx s index of if idx s length 1 equals true if idx 0 prevx already set else prevx s substring 0 s length 1 prevx prevx to lower case else if idx 1 string x s substring 0 idx if x length 0 x prevx x x to lower case string y if idx s length 1 y else y s substring idx 1 s length y strip quotes y h remove x h put x y prevx x else h remove s h put s new object prevx s h sanitize hash h t pc if h null return null if t start slash return new parsed tag t null string out attrs new string h size int i 0 for map entry string object entry h entry set string x entry get key object o entry get value string y if o instanceof string y string o else y null string builder out new string builder x if y null out append append y append out attrs i out to string return new parsed tag t out attrs parsedtag parsedtag htmlparsecontext datafilterexception hashmap unparsedattrs unparsedattrs unparsedattrs stripquotes indexof tolowercase tolowercase stripquotes sanitizehash startslash parsedtag outattrs entryset getkey getvalue stringbuilder stringbuilder outattrs tostring parsedtag outattrs map string object sanitize hash map string object h parsed tag p html parse context pc throws data filter exception map string object hn new hash map string object for map entry string object entry h entry set string x entry get key object o entry get value straight attribs if allowed attrs contains x hn put x o continue if uri attrs contains x if logminor logger minor this non inline uri attribute x uri if o instanceof string java s url handling doesn t seem suitable string uri string o uri html decoder decode uri uri html sanitizeuri uri null null pc cb pc false if uri null uri html encoder encode uri hn put x uri fixme rewrite absolute ur ls handle date etc if inlineuri attrs contains x if logminor logger minor this inline uri attribute x uri if o instanceof string java s url handling doesn t seem suitable string uri string o uri html decoder decode uri uri html sanitizeuri uri null null pc cb pc true if uri null uri html encoder encode uri hn put x uri fixme rewrite absolute ur ls handle date etc lang xml lang and dir can go on anything lang or xml lang language country variant the variant can be just about anything no way to test avian string s get hash string h lang if s null hn put lang s s get hash string h xml lang if s null hn put xml lang s s get hash string h dir if s null s equals ignore case ltr s equals ignore case rtl hn put dir s return hn sanitizehash parsedtag htmlparsecontext datafilterexception hashmap entryset getkey getvalue allowedattrs uriattrs htmldecoder htmlsanitizeuri htmlencoder urls inlineuriattrs htmldecoder htmlsanitizeuri htmlencoder urls gethashstring gethashstring gethashstring equalsignorecase equalsignorecase static string strip quotes string s final string quotes if s length 2 int n quotes length for int x 0 x n x char cc quotes char at x if s char at 0 cc s char at s length 1 cc if s length 2 s s substring 1 s length 1 else s break return s stripquotes charat charat charat static abstract class script style tag verifier extends tag verifier script style tag verifier string tag string allowed attrs string uri attrs super tag allowed attrs uri attrs null scriptstyletagverifier tagverifier scriptstyletagverifier allowedattrs uriattrs allowedattrs uriattrs abstract void set style boolean b html parse context pc setstyle htmlparsecontext abstract void set style boolean b html parse context pc abstract boolean get style html parse context pc setstyle htmlparsecontext getstyle htmlparsecontext abstract boolean get style html parse context pc abstract void process style html parse context pc getstyle htmlparsecontext processstyle htmlparsecontext override map string object sanitize hash map string object h parsed tag p html parse context pc throws data filter exception map string object hn super sanitize hash h p pc if p start slash return finish h hn pc else return start h hn pc sanitizehash parsedtag htmlparsecontext datafilterexception sanitizehash startslash map string object finish map string object h map string object hn html parse context pc throws data filter exception if logdebug logger debug this finishing script style finishing set style false pc pc style script recurse count if pc style script recurse count 0 if delete errors pc write after tag append l10n too many nested style or script tags else throw filter exception l10n too many nested style or script tags long return null if pc kill style process style pc pc write style script with tag true else pc kill style false pc current style script chunk pc expecting bad comment false pass it on no params for style return hn htmlparsecontext datafilterexception setstyle stylescriptrecursecount stylescriptrecursecount deleteerrors writeaftertag toomanynestedstyleorscripttags throwfilterexception toomanynestedstyleorscripttagslong killstyle processstyle writestylescriptwithtag killstyle currentstylescriptchunk expectingbadcomment map string object start map string object h map string object hn html parse context pc throws data filter exception if logdebug logger debug this starting script style pc style script recurse count if pc style script recurse count 1 if delete errors pc write after tag append l10n too many nested style or script tags else throw filter exception l10n too many nested style or script tags long return null set style true pc string type get hash string h type if type null if type equals ignore case text css fixme pc kill style true pc expecting bad comment true return null kill the tag hn put type text css return hn htmlparsecontext datafilterexception stylescriptrecursecount stylescriptrecursecount deleteerrors writeaftertag toomanynestedstyleorscripttags throwfilterexception toomanynestedstyleorscripttagslong setstyle gethashstring equalsignorecase killstyle expectingbadcomment static class style tag verifier extends script style tag verifier style tag verifier super style new string id media title xml space empty string array styletagverifier scriptstyletagverifier styletagverifier emptystringarray override void set style boolean b html parse context pc pc in style b setstyle htmlparsecontext instyle override boolean get style html parse context pc return pc in style getstyle htmlparsecontext instyle override void process style html parse context pc try pc current style script chunk sanitize style pc current style script chunk pc cb pc catch data filter exception e logger error this error parsing style e e pc current style script chunk processstyle htmlparsecontext currentstylescriptchunk sanitizestyle currentstylescriptchunk datafilterexception currentstylescriptchunk static class script tag verifier extends script style tag verifier script tag verifier super script new string id charset type language defer xml space new string src fixme src not supported type ignored we will need to check this when if when we support scripts charset ignored scripttagverifier scriptstyletagverifier scripttagverifier override map string object sanitize hash map string object hn parsed tag p html parse context pc throws data filter exception call parent so we swallow the scripting super sanitize hash hn p pc return null lose the tags sanitizehash parsedtag htmlparsecontext datafilterexception sanitizehash override void set style boolean b html parse context pc pc in script b setstyle htmlparsecontext inscript override boolean get style html parse context pc return pc in script getstyle htmlparsecontext inscript override void process style html parse context pc pc current style script chunk sanitize scripting pc current style script chunk processstyle htmlparsecontext currentstylescriptchunk sanitizescripting currentstylescriptchunk static class base core tag verifier extends tag verifier base core tag verifier string tag string allowed attrs string uri attrs string inlineuri attrs super tag allowed attrs uri attrs inlineuri attrs basecoretagverifier tagverifier basecoretagverifier allowedattrs uriattrs inlineuriattrs allowedattrs uriattrs inlineuriattrs override map string object sanitize hash map string object h parsed tag p html parse context pc throws data filter exception map string object hn super sanitize hash h p pc i18n dealt with by tag verifier coreattrs string id get hash string h id if id null hn put id id hopefully nobody will be stupid enough to encode ur ls into the unique id string class names get hash string h class if class names null hn put class class names ditto string style get hash string h style if style null style sanitize style style pc cb pc if style null style escape quotes style if style null hn put style style string title get hash string h title if title null paranoia title is plain text right in all user agents hn put title title return hn sanitizehash parsedtag htmlparsecontext datafilterexception sanitizehash tagverifier gethashstring urls classnames gethashstring classnames classnames gethashstring sanitizestyle escapequotes gethashstring core tag verifier string tag string allowed attrs string uri attrs string inlineuri attrs string event attrs this tag allowed attrs uri attrs inlineuri attrs event attrs true coretagverifier allowedattrs uriattrs inlineuriattrs eventattrs allowedattrs uriattrs inlineuriattrs eventattrs core tag verifier string tag string allowed attrs string uri attrs string inlineuri attrs string event attrs boolean add std events super tag allowed attrs uri attrs inlineuri attrs this event attrs new hash set string if event attrs null for int x 0 x event attrs length x this event attrs add event attrs x if add std events for int x 0 x std events length x this event attrs add std events x coretagverifier allowedattrs uriattrs inlineuriattrs eventattrs addstdevents allowedattrs uriattrs inlineuriattrs eventattrs hashset eventattrs eventattrs eventattrs eventattrs addstdevents stdevents eventattrs stdevents override map string object sanitize hash map string object h parsed tag p html parse context pc throws data filter exception map string object hn super sanitize hash h p pc events default and added for iterator string e event attrs iterator e has next string name e next string arg get hash string h name if arg null arg sanitize scripting arg if arg null hn put name arg return hn sanitizehash parsedtag htmlparsecontext datafilterexception sanitizehash eventattrs hasnext gethashstring sanitizescripting static class link tag verifier extends core tag verifier link tag verifier string tag string allowed attrs string uri attrs string inlineuri attrs string event attrs super tag allowed attrs uri attrs inlineuri attrs event attrs linktagverifier coretagverifier linktagverifier allowedattrs uriattrs inlineuriattrs eventattrs allowedattrs uriattrs inlineuriattrs eventattrs override map string object sanitize hash map string object h parsed tag p html parse context pc throws data filter exception map string object hn super sanitize hash h p pc string hreflang get hash string h hreflang string charset null string type get hash string h type if type null string typesplit split type type type typesplit 0 if typesplit 1 null typesplit 1 length 0 charset typesplit 1 if logdebug logger debug this processing link tag type type charset charset string c get hash string h charset if c null charset c string href get hash string h href if href null final string rels new string rel rev for int x 0 x rels length x string reltype rels x string rel get hash string h reltype if rel null string tokenizer tok new string tokenizer rel while tok has more tokens string t tok next token if t equals ignore case alternate t equals ignore case stylesheet fixme hardcoding text css type text css fixme do we want to do anything with the other possible rel s hn put reltype rel core logger log this sanitizing uri href with type type and charset charset logger debug href html decoder decode href href html sanitizeuri href type charset pc cb pc false if href null href html encoder encode href hn put href href if type null hn put type type if charset null hn put charset charset if charset null hreflang null hn put hreflang hreflang fixme allow these if the charset and encoding are encoded into the url fixme link types http www w3 org tr html4 types html type links the stylesheet stuff primarily rel and rev properties parse these use same fix as above browser may assume text css for anything linked as a stylesheet return hn sanitizehash parsedtag htmlparsecontext datafilterexception sanitizehash gethashstring gethashstring splittype gethashstring gethashstring gethashstring stringtokenizer stringtokenizer hasmoretokens nexttoken equalsignorecase equalsignorecase htmldecoder htmlsanitizeuri htmlencoder static class form tag verifier extends core tag verifier form tag verifier string tag string allowed attrs string uri attrs string event attrs super tag allowed attrs uri attrs null event attrs formtagverifier coretagverifier formtagverifier allowedattrs uriattrs eventattrs allowedattrs uriattrs eventattrs override map string object sanitize hash map string object h parsed tag p html parse context pc throws data filter exception map string object hn super sanitize hash h p pc if p start slash allow but only with standard elements return hn string method string h get method string action string h get action string final action try final action pc cb process form method action catch comment exception e pc write after tag append append html encoder encode e to string append return null if final action null return null hn put method method hn put action final action force enctype and accept charset to acceptable values hn put enctype multipart form data hn put accept charset utf 8 return hn sanitizehash parsedtag htmlparsecontext datafilterexception sanitizehash startslash finalaction finalaction processform commentexception writeaftertag htmlencoder tostring finalaction finalaction input tag verifier string tag string allowed attrs string uri attrs string inlineuri attrs string event attrs super tag allowed attrs uri attrs inlineuri attrs event attrs this allowed types new hash set string if types null for int x 0 x types length x this allowed types add types x inputtagverifier allowedattrs uriattrs inlineuriattrs eventattrs allowedattrs uriattrs inlineuriattrs eventattrs allowedtypes hashset allowedtypes override map string object sanitize hash map string object h parsed tag p html parse context pc throws data filter exception map string object hn super sanitize hash h p pc we drop the whole input if type isn t allowed if allowed types contains hn get type return null return hn sanitizehash parsedtag htmlparsecontext datafilterexception sanitizehash allowedtypes static class meta tag verifier extends tag verifier meta tag verifier super meta new string id metatagverifier tagverifier metatagverifier override map string object sanitize hash map string object h parsed tag p html parse context pc throws data filter exception map string object hn super sanitize hash h p pc several possibilities a meta http equiv x content y b meta name x content y string http equiv get hash string h http equiv string name get hash string h name string content get hash string h content string scheme get hash string h scheme if logminor logger minor this meta name name content content http equiv http equiv scheme scheme if content null if name null http equiv null if name equals ignore case author hn put name name hn put content content else if name equals ignore case keywords hn put name name hn put content content else if name equals ignore case description hn put name name hn put content content else if http equiv null name null if http equiv equals ignore case expires hn put http equiv http equiv hn put content content else if http equiv equals ignore case content script type we don t support script at this time else if http equiv equals ignore case content style type fixme charsets if content equals ignore case text css fixme selectable style languages only matters when we have implemented more than one fixme if we ever do allow it the spec http www w3 org tr html4 present styles html h 14 2 1 says only the last definition counts but it only counts if it s in the head section so we dont need to parse the whole doc hn put http equiv http equiv hn put content content fixme add some more headers dublin core else if http equiv equals ignore case content type if logminor logger minor this found http equiv content type content string typesplit split type content if logdebug for int i 0 i typesplit length i logger debug this i typesplit i if typesplit 0 equals ignore case text html typesplit 1 null typesplit 1 equals ignore case pc charset hn put http equiv http equiv hn put content typesplit 0 typesplit 1 null charset typesplit 1 if typesplit 1 null pc detected charset typesplit 1 trim else if http equiv equals ignore case content language hn put http equiv content language hn put content content return hn sanitizehash parsedtag htmlparsecontext datafilterexception sanitizehash http_equiv gethashstring gethashstring gethashstring gethashstring http_equiv http_equiv equalsignorecase equalsignorecase equalsignorecase http_equiv http_equiv equalsignorecase http_equiv http_equiv equalsignorecase http_equiv equalsignorecase equalsignorecase http_equiv http_equiv equalsignorecase splittype equalsignorecase equalsignorecase http_equiv detectedcharset http_equiv equalsignorecase static class doc type tag verifier extends tag verifier doc type tag verifier string tag super tag null doctypetagverifier tagverifier doctypetagverifier override parsed tag sanitize parsed tag t html parse context pc if t unparsed attrs length 3 t unparsed attrs length 4 return null if t unparsed attrs 0 equals ignore case html return null if t unparsed attrs 1 equals ignore case public return null string s strip quotes t unparsed attrs 2 if dt ds contains key s return null if t unparsed attrs length 4 string ss strip quotes t unparsed attrs 3 string spec get hash string dt ds s if spec null spec equals ss return null return t parsedtag parsedtag htmlparsecontext unparsedattrs unparsedattrs unparsedattrs equalsignorecase unparsedattrs equalsignorecase stripquotes unparsedattrs dtds containskey unparsedattrs stripquotes unparsedattrs gethashstring dtds static class xml tag verifier extends tag verifier xml tag verifier super xml null xmltagverifier tagverifier xmltagverifier override parsed tag sanitize parsed tag t html parse context pc if t unparsed attrs length 2 return null if t unparsed attrs 0 equals version 1 0 return null if t unparsed attrs 1 starts with encoding t unparsed attrs 1 ends with return null if t unparsed attrs 1 substring 10 t unparsed attrs 1 length 2 equals ignore case pc charset return null return t parsedtag parsedtag htmlparsecontext unparsedattrs unparsedattrs unparsedattrs startswith unparsedattrs endswith unparsedattrs unparsedattrs equalsignorecase static class html tag verifier extends tag verifier html tag verifier super html new string id version htmltagverifier tagverifier htmltagverifier override map string object sanitize hash map string object h parsed tag p html parse context pc throws data filter exception map string object hn super sanitize hash h p pc string xmlns get hash string h xmlns if xmlns null xmlns equals http www w3 org 1999 xhtml hn put xmlns xmlns return hn sanitizehash parsedtag htmlparsecontext datafilterexception sanitizehash gethashstring static class base href tag verifier extends tag verifier base href tag verifier string string string strings string strings2 super string strings strings2 null basehreftagverifier tagverifier basehreftagverifier override map string object sanitize hash map string object h parsed tag p html parse context pc throws data filter exception map string object hn super sanitize hash h p pc get the already sanitized version string base href get hash string hn href if base href null string ref pc cb on base href base href if ref null hn put href ref return hn sanitizehash parsedtag htmlparsecontext datafilterexception sanitizehash basehref gethashstring basehref onbasehref basehref static string sanitize style string style filter callback cb html parse context hpc throws data filter exception if style null return null if hpc no output return null reader r new string reader style writer w new string writer style style trim if logminor logger minor html filter class sanitizing style style css parser pc new css parser r w false cb try pc parse catch io exception e logger error html filter class io exception parsing inline css catch error e if e get message equals error could not match input this sucks it should be a proper exception logger normal html filter class css parse error e return l10n could not parse style else throw e string s w to string if s null s length 0 return null core logger log safer filter class style now s logger debug if logminor logger minor html filter class style finally s return s sanitizestyle filtercallback htmlparsecontext datafilterexception nooutput stringreader stringwriter htmlfilter cssparser cssparser ioexception htmlfilter ioexception getmessage htmlfilter couldnotparsestyle tostring saferfilter htmlfilter static string escape quotes string s string builder buf new string builder s length for int x 0 x s length x char c s char at x if c buf append quot else buf append c return buf to string escapequotes stringbuilder stringbuilder charat tostring static string sanitize scripting string script kill it at some point we may want to allow certain recipes fixme return null sanitizescripting static string sanitizeuri string uri filter callback cb boolean inline throws comment exception return sanitizeuri uri null null cb inline filtercallback commentexception static string split type string type string field parser sfp string charset null param name value int x sfp new string field parser type type sfp next field trim while sfp has more fields param sfp next field x param index of if x 1 name param substring 0 x trim value param substring x 1 trim if name equals charset charset value return new string type charset splittype stringfieldparser stringfieldparser nextfield hasmorefields nextfield indexof private char c public string field parser string str this str t stringfieldparser public string field parser string str char c this str str this max pos str length this cur pos 0 this c c stringfieldparser maxpos curpos public boolean has more fields return cur pos max pos hasmorefields curpos maxpos public string next field int start end if cur pos max pos return null start cur pos while cur pos max pos str char at cur pos c cur pos end cur pos cur pos return str substring start end nextfield curpos maxpos curpos curpos maxpos charat curpos curpos curpos curpos static string html sanitizeuri string suri string override type string override charset filter callback cb html parse context pc boolean inline try return sanitizeuri suri override type override charset cb inline catch comment exception e pc write after tag append append html encoder encode e to string append return null htmlsanitizeuri overridetype overridecharset filtercallback htmlparsecontext overridetype overridecharset commentexception writeaftertag htmlencoder tostring static string sanitizeuri string suri string override type string override charset filter callback cb boolean inline throws comment exception if logminor logger minor html filter class sanitizing uri suri override type override type override charset override charset inline inline new exception debug if override charset null override charset length 0 override type charset override charset return cb processuri suri override type false inline overridetype overridecharset filtercallback commentexception htmlfilter overridetype overridecharset overridecharset overridecharset overridetype overridecharset overridetype static string get hash string map string object h string key object o h get key if o null return null if o instanceof string return string o else return null gethashstring private static string l10n string key return l10n get string html filter key getstring htmlfilter private static string l10n string key string pattern string value return l10n get string html filter key pattern value getstring htmlfilter public dsa private key big integer x dsa group g this x x if x signum 1 x compare to g getq 1 x compare to big integer zero 1 throw new illegal argument exception dsaprivatekey biginteger dsagroup compareto compareto biginteger illegalargumentexception public dsa private key dsa group g random r big integer tempx do tempx new native big integer 256 r while tempx compare to g getq 1 tempx compare to big integer zero 1 this x tempx dsaprivatekey dsagroup biginteger nativebiginteger compareto compareto biginteger override public string key type return dsa s keytype public big integer getx return x biginteger public static crypto key read input stream i dsa group g throws io exception return new dsa private key util readmpi i g cryptokey inputstream dsagroup ioexception dsaprivatekey public string to long string return x hex util bi to hex x tolongstring hexutil bitohex override public byte as bytes return util mp ibytes x asbytes mpibytes override public byte fingerprint return fingerprint new big integer x biginteger public simple field set as field set simple field set fs new simple field set true fs put single x base64 encode x to byte array return fs simplefieldset asfieldset simplefieldset simplefieldset putsingle tobytearray public static dsa private key create simple field set fs dsa group group throws illegal base64 exception native big integer y new native big integer 1 base64 decode fs get x if y bit length 512 throw new illegal base64 exception probably a pubkey return new dsa private key y group dsaprivatekey simplefieldset dsagroup illegalbase64exception nativebiginteger nativebiginteger bitlength illegalbase64exception dsaprivatekey public void remove from object container container container delete x container delete this removefrom objectcontainer final public bucket data result simple field set my params bucket my data params my params data my data simplefieldset myparams mydata myparams mydata public plugin talker blocking plugin respirator mypr throws plugin not found exception m talker mypr get plugin talker this freetalk wot name freetalk plugin title plugintalkerblocking pluginrespirator pluginnotfoundexception mtalker getplugintalker wot_name plugin_title sends a fcp message and blocks execution until the answer was received and then returns the answer this can be used to simplify code which uses fcp very much especially ui code which needs the result of fcp calls directly when using send blocking please make sure that you only ever call it for fcp functions which only send a single result public synchronized result send blocking simple field set params bucket data throws plugin not found exception assert m result null m talker send params data while m result null todo or timeout try wait catch interrupted exception e result result m result m result null return result sendblocking sendblocking simplefieldset pluginnotfoundexception mresult mtalker mresult interruptedexception mresult mresult synchronized because notify all will otherwise throw illegal monitor state exception public synchronized void on reply string pluginname string indentifier simple field set params bucket data if m result null logger error this send blocking called for a fcp function which sends more than 1 reply return m result new result params data notify all notifyall illegalmonitorstateexception onreply simplefieldset mresult sendblocking mresult notifyall public uptime estimator file node dir ticker ticker byte bs this ticker ticker log file new file node dir uptime dat prev file new file node dir uptime old dat time offset int double math abs fields hash code bs bs length 2 bs length bs length 2 integer max value 5 60 1000 uptimeestimator nodedir logfile nodedir prevfile nodedir timeoffset hashcode max_value public void start long now system current time millis int five minutes since epoch int now period int base five minutes since epoch was online length read both files read data prev file base read data log file base schedule system current time millis system out println created uptime estimator time offset is time offset uptime at startup is new decimal format 0 00 format get uptime currenttimemillis fiveminutessinceepoch fiveminutessinceepoch wasonline readdata prevfile readdata logfile currenttimemillis timeoffset decimalformat getuptime private void read data file file int base file input stream fis null try fis new file input stream file data input stream dis new data input stream fis try while true int offset dis read int if offset base continue int slot no offset base if slot no was online length break reached the end restarted within the same timeslot if slot no was online length slot no 0 logger error this corrupt data read from uptime file file 5 minutes from epoch is now base was online length but read slot no break was online slot no true catch eof exception e finished finally closer close dis catch io exception e logger error this unable to read old uptime file file we will assume we weren t online during that period finally closer close fis readdata fileinputstream fileinputstream datainputstream datainputstream readint slotno slotno wasonline slotno wasonline slotno wasonline slotno wasonline slotno eofexception ioexception public void run synchronized this was online slot true slot slot 1 was online length long now system current time millis if log file length was online length 4l prev file delete log file rename to prev file file output stream fos null data output stream dos null int five minutes since epoch int now period try fos new file output stream log file true dos new data output stream fos dos write int five minutes since epoch catch file not found exception e logger error this unable to create or access log file e e catch io exception e logger error this unable to write to uptime estimator log file log file finally closer close dos closer close fos schedule next time schedule now wasonline wasonline currenttimemillis logfile wasonline prevfile logfile renameto prevfile fileoutputstream dataoutputstream fiveminutessinceepoch fileoutputstream logfile dataoutputstream writeint fiveminutessinceepoch filenotfoundexception logfile ioexception logfile private void schedule long now long next time now period period time offset if next time now next time period ticker queue timed job this next time system current time millis nexttime timeoffset nexttime nexttime queuetimedjob nexttime currenttimemillis get the node s uptime fraction over the last 48 hours public synchronized double get uptime int up count 0 for int i 0 i was online length i if was online i up count return double up count double was online length getuptime upcount wasonline wasonline upcount upcount wasonline public icon list iconlist public icon get icon int n return icon get n geticon a debugging method which prints the tree out public void list print stream s int level for int i 0 i level i system out print if count 0 system out println index count count else system out println index count count red total red count green total green count blue total blue count for int i 0 i 8 i if leaf i null leaf i list s level 2 printstream totalred totalgreen totalblue public oct tree quantizer setup 256 color list new vector max level 1 for int i 0 i max level 1 i color list i new vector root new oct tree node octtreequantizer colorlist max_level max_level colorlist octtreenode initialize the quantizer this should be called before adding any pixels param num colors the number of colors we re quantizing to public void setup int num colors maximum colors num colors reduce colors math max 512 num colors 2 numcolors numcolors maximumcolors numcolors reducecolors numcolors add pixels to the quantizer param pixels the array of argb pixels param offset the offset into the array param count the count of pixels public void add pixels int pixels int offset int count for int i 0 i count i insert color pixels i offset if colors reduce colors reduce tree reduce colors addpixels insertcolor reducecolors reducetree reducecolors get the color table index for a color param rgb the color return the index public int get index for color int rgb int red rgb 16 0xff int green rgb 8 0xff int blue rgb 0xff oct tree node node root for int level 0 level max level level oct tree node child int bit 0x80 level int index 0 if red bit 0 index 4 if green bit 0 index 2 if blue bit 0 index 1 child node leaf index if child null return node index else if child is leaf return child index else node child system out println get index for color failed return 0 getindexforcolor octtreenode max_level octtreenode isleaf getindexforcolor private void insert color int rgb int red rgb 16 0xff int green rgb 8 0xff int blue rgb 0xff oct tree node node root system out println insert color integer to hex string rgb for int level 0 level max level level oct tree node child int bit 0x80 level int index 0 if red bit 0 index 4 if green bit 0 index 2 if blue bit 0 index 1 child node leaf index if child null node children child new oct tree node child parent node node leaf index child node is leaf false nodes color list level add element child if level max level child is leaf true child count 1 child total red red child total green green child total blue blue child level level colors return node child else if child is leaf child count child total red red child total green green child total blue blue return else node child system out println insert color failed insertcolor octtreenode insertcolor tohexstring max_level octtreenode octtreenode isleaf colorlist addelement max_level isleaf totalred totalgreen totalblue isleaf totalred totalgreen totalblue insertcolor private void reduce tree int num colors for int level max level 1 level 0 level vector v color list level if v null v size 0 for int j 0 j v size j oct tree node node oct tree node v element at j if node children 0 for int i 0 i 8 i oct tree node child node leaf i if child null if child is leaf system out println not a leaf node count child count node total red child total red node total green child total green node total blue child total blue node leaf i null node children colors nodes color list level 1 remove element child node is leaf true colors if colors num colors return system out println unable to reduce the oct tree reducetree numcolors max_level colorlist octtreenode octtreenode elementat octtreenode isleaf totalred totalred totalgreen totalgreen totalblue totalblue colorlist removeelement isleaf numcolors octtree build the color table return the color table public int build color table int table new int colors build color table root table 0 return table buildcolortable buildcolortable a quick way to use the quantizer just create a table the right size and pass in the pixels param in pixels the input colors param table the output color table public void build color table int in pixels int table int count in pixels length maximum colors table length for int i 0 i count i insert color in pixels i if colors reduce colors reduce tree reduce colors if colors maximum colors reduce tree maximum colors build color table root table 0 inpixels buildcolortable inpixels inpixels maximumcolors insertcolor inpixels reducecolors reducetree reducecolors maximumcolors reducetree maximumcolors buildcolortable private int build color table oct tree node node int table int index if colors maximum colors reduce tree maximum colors if node is leaf int count node count table index 0xff000000 node total red count 16 node total green count 8 node total blue count node index index else for int i 0 i 8 i if node leaf i null node index index index build color table node leaf i table index return index buildcolortable octtreenode maximumcolors reducetree maximumcolors isleaf totalred totalgreen totalblue buildcolortable public class generic sort static void sort generic sort array arr sort1 arr 0 arr size genericsort genericsortarray private static void sort1 generic sort array x int off int len insertion sort on smallest arrays if len 7 for int i off i len off i for int j i j off x compare j 1 j 0 j x swap j j 1 return choose a partition element v int m off len 1 small arrays middle element if len 7 int l off int n off len 1 if len 40 big arrays pseudomedian of 9 int s len 8 l med3 x l l s l 2 s m med3 x m s m m s n med3 x n 2 s n s n m med3 x l m n mid size med of 3 establish invariant v v v v int a off b a c off len 1 d c diff while true while b c diff x compare b m 0 if diff 0 x swap a b b while c b diff x compare c m 0 if diff 0 x swap c d c if b c break x swap b c swap partition elements back to middle int s n off len s math min a off b a vecswap x off b s s s math min d c n d 1 vecswap x b n s s recursively sort non partition elements if s b a 1 sort1 x off s if s d c 1 sort1 x n s s genericsortarray private static void vecswap generic sort array x int a int b int n for int i 0 i n i a b x swap a b genericsortarray private static int med3 generic sort array x int a int b int c return x compare a b 0 x compare b c 0 b x compare a c 0 c a x compare b c 0 b x compare a c 0 c a genericsortarray param jmdns impl socket listener jmdns impl jmdns impl this jmdns impl jmdns impl jmdnsimpl socketlistener jmdnsimpl jmdnsimpl jmdnsimpl jmdnsimpl public void run try byte buf new byte dns constants max msg absolute datagram packet packet new datagram packet buf buf length while this jmdns impl get state dns state canceled packet set length buf length this jmdns impl get socket receive packet if this jmdns impl get state dns state canceled break try if this jmdns impl get local host should ignore packet packet continue dns incoming msg new dns incoming packet logger finest socket listener run jmdns in msg print true synchronized this jmdns impl get io lock if msg is query if packet get port dns constants mdns port this jmdns impl handle query msg packet get address packet get port this jmdns impl handle query msg this jmdns impl get group dns constants mdns port else this jmdns impl handle response msg catch io exception e logger log level warning run exception e catch io exception e if this jmdns impl get state dns state canceled logger log level warning run exception e this jmdns impl recover dnsconstants max_msg_absolute datagrampacket datagrampacket jmdnsimpl getstate dnsstate setlength jmdnsimpl getsocket jmdnsimpl getstate dnsstate jmdnsimpl getlocalhost shouldignorepacket dnsincoming dnsincoming socketlistener jmdnsimpl getiolock isquery getport dnsconstants mdns_port jmdnsimpl handlequery getaddress getport jmdnsimpl handlequery jmdnsimpl getgroup dnsconstants mdns_port jmdnsimpl handleresponse ioexception ioexception jmdnsimpl getstate dnsstate jmdnsimpl return the time at which this object was last used public synchronized long last used time return last used time lastusedtime lastusedtime static logger register log threshold callback new log threshold callback override public void should update logminor logger should log logger minor this registerlogthresholdcallback logthresholdcallback shouldupdate shouldlog private final request tag tag override public string to string return super to string for uid requesttag tostring tostring public request handler message m peer node source long id node n short htl key key request tag tag req m node n uid id this source source this htl htl this tag tag if htl 0 htl 1 this key key if key instanceof nodessk needs pub key m get boolean dmt need pub key received bytes m received byte count requesthandler peernode requesttag needspubkey getboolean need_pub_key receivedbytes receivedbytecount public void run freenet support logger os thread logpid this try real run the last thing that real run does is register as a request sender listener so any exception here is the end catch not connected exception e logger normal this requestor gone could not start request handler wait node remove transferring request handler uid tag handler threw e node unlockuid uid key instanceof nodessk false false false false tag catch throwable t logger error this caught t t node remove transferring request handler uid tag handler threw t node unlockuid uid key instanceof nodessk false false false false tag osthread realrun realrun notconnectedexception removetransferringrequesthandler handlerthrew removetransferringrequesthandler handlerthrew private void apply byte counts if disconnected logger normal this not applying byte counts as request source disconnected during receive return if applied byte counts logger error this apply byte counts already called new exception error logger error this first called here previous apply byte count call return previous apply byte count call new exception first call to apply byte counts applied byte counts true if final transfer failed rs null status request sender timed out status request sender generated rejected overload status request sender internal error int sent rcvd synchronized bytes sync sent sent bytes rcvd received bytes sent rs get total sent bytes rcvd rs get total received bytes if key instanceof nodessk if logminor logger minor this remote ssk fetch cost sent rcvd bytes status node node stats remote ssk fetch bytes sent average report sent node node stats remote ssk fetch bytes received average report rcvd if status request sender success can report both parts because we had both a handler and a sender node node stats successful ssk fetch bytes sent average report sent node node stats successful ssk fetch bytes received average report rcvd else if logminor logger minor this remote chk fetch cost sent rcvd bytes status node node stats remote chk fetch bytes sent average report sent node node stats remote chk fetch bytes received average report rcvd if status request sender success can report both parts because we had both a handler and a sender node node stats successful chk fetch bytes sent average report sent node node stats successful chk fetch bytes received average report rcvd applybytecounts appliedbytecounts applybytecounts previousapplybytecountcall previousapplybytecountcall applybytecounts appliedbytecounts finaltransferfailed requestsender timed_out requestsender generated_rejected_overload requestsender internal_error bytessync sentbytes receivedbytes gettotalsentbytes gettotalreceivedbytes nodestats remotesskfetchbytessentaverage nodestats remotesskfetchbytesreceivedaverage requestsender nodestats successfulsskfetchbytessentaverage nodestats successfulsskfetchbytesreceivedaverage nodestats remotechkfetchbytessentaverage nodestats remotechkfetchbytesreceivedaverage requestsender nodestats successfulchkfetchbytessentaverage nodestats successfulchkfetchbytesreceivedaverage private void real run throws not connected exception if logminor logger minor this handling a request uid message accepted dmt createfnp accepted uid source send async accepted null this object o node make request sender key htl uid source false true false false if o instanceof key block tag set served from datastore return local data key block o return if o null ran out of htl message dnf dmt createfnp data not found uid status request sender data not found for byte logging node failure table on final failure key null htl failure table reject time source send terminal dnf return else long queue time source get probable send queue time synchronized this rs request sender o if we cannot respond before this time the source node has already fatally timed out and we need not return packets which will not be claimed search start time system current time millis response deadline search start time request sender fetch timeout queue time rs add listener this realrun notconnectedexception createfnpaccepted sendasync makerequestsender keyblock setservedfromdatastore returnlocaldata keyblock createfnpdatanotfound requestsender data_not_found failuretable onfinalfailure failuretable reject_time sendterminal queuetime getprobablesendqueuetime requestsender searchstarttime currenttimemillis responsedeadline searchstarttime requestsender fetch_timeout queuetime addlistener public void on received reject overload try if sent rejected overload forward rejected overload note this message is only decernable from the terminal messages by the is local flag being false is local terminal message msg dmt createfnp rejected overload uid false source send async msg null this if the status changes e g to success there is little need to send yet another reject overload sent rejected overload true catch not connected exception e logger normal this requestor is gone can t forward reject overload onreceivedrejectoverload sentrejectedoverload rejectedoverload is_local is_local createfnprejectedoverload sendasync sentrejectedoverload notconnectedexception public void onchk transfer begins try is a chk message df dmt createfnpchk data found uid rs get headers source send async df null this partially received block prb rs getprb bt new block transmitter node usm source uid prb this node add transferring request handler uid bt send async node executor catch not connected exception e synchronized this disconnected true tag handler disconnected logger normal this requestor is gone can t begin chk transfer onchktransferbegins createfnpchkdatafound getheaders sendasync partiallyreceivedblock blocktransmitter addtransferringrequesthandler sendasync notconnectedexception handlerdisconnected public void on abort downstream transfers int reason string desc if bt null logger error this no downstream transfer to abort on this return if logminor logger minor this aborting downstream transfer on this tag on abort downstream transfers reason desc try bt abort send reason desc catch not connected exception e ignore onabortdownstreamtransfers onabortdownstreamtransfers abortsend notconnectedexception private void wait and finishchk transfer off thread node executor execute new runnable public void run try wait and finishchk transfer catch not connected exception e for byte logging since the block is the terminal message apply byte counts unregister request handler with node finish chk transfer for key for this waitandfinishchktransferoffthread waitandfinishchktransfer notconnectedexception applybytecounts unregisterrequesthandlerwithnode public void run try wait and finishchk transfer catch not connected exception e for byte logging since the block is the terminal message apply byte counts unregister request handler with node waitandfinishchktransfer notconnectedexception applybytecounts unregisterrequesthandlerwithnode private void wait and finishchk transfer throws not connected exception if logminor logger minor this waiting for chk transfer to finish if bt get async exit status status rs get status successful chk transfer maybe path fold finish opennet checked else final transfer failed true status rs get status for byte logging since the block is the terminal message apply byte counts unregister request handler with node waitandfinishchktransfer notconnectedexception getasyncexitstatus getstatus finishopennetchecked finaltransferfailed getstatus applybytecounts unregisterrequesthandlerwithnode public void on request sender finished int status if logminor logger minor this on request sender finished status on this long now system current time millis this status status boolean too late synchronized this too late response deadline 0 now response deadline if too late offer the data if there is any node failure table on final failure key null htl 1 source peer node routed last rs null null rs routed last a certain number of these are normal logger normal this requestsender took too long to respond to requestor time util format time now search start time 2 true rs null null rs get status string routed to routed last null null routed last short to string apply byte counts unregister request handler with node return if status request sender not finished logger error this on finished but not finished try switch status case request sender not finished case request sender data not found message dnf dmt createfnp data not found uid send terminal dnf return case request sender recently failed message rf dmt createfnp recently failed uid rs get recently failed time left send terminal rf return case request sender generated rejected overload case request sender timed out case request sender internal error locally generated propagate back to source who needs to reduce send rate bug we may not want to translate fatal timeouts into non fatal timeouts message reject dmt createfnp rejected overload uid true send terminal reject return case request sender route not found tell source message rnf dmt createfnp route not found uid rs gethtl send terminal rnf return case request sender success if key instanceof nodessk sendssk rs get headers rs getssk data needs pub key nodessk rs getssk block get key get pub key else if bt null disconnected bug this is impossible logger error this status is success but we never started a transfer on uid obviously this node is confused send a terminal reject to make sure the requestor is not waiting forever reject dmt createfnp rejected overload uid true send terminal reject else if disconnected wait and finishchk transfer off thread else unregister request handler with node return case request sender verify failure case request sender get offer verify failure if key instanceof nodechk if bt null disconnected bug this is impossible logger error this status is verify failure but we never started a transfer on uid obviously this node is confused send a terminal reject to make sure the requestor is not waiting forever reject dmt createfnp rejected overload uid true send terminal reject else if disconnected verify fails after receive is complete so we might as well propagate it wait and finishchk transfer off thread else unregister request handler with node return reject dmt createfnp rejected overload uid true send terminal reject return case request sender transfer failed case request sender get offer transfer failed if key instanceof nodechk if bt null disconnected bug this is impossible logger error this status is transfer failed but we never started a transfer on uid obviously this node is confused send a terminal reject to make sure the requestor is not waiting forever reject dmt createfnp rejected overload uid true send terminal reject else if disconnected wait and finishchk transfer off thread else unregister request handler with node return logger error this finish transfer failed should not be called on ssk new exception error return default treat as internal error reject dmt createfnp rejected overload uid true send terminal reject throw new illegal state exception unknown status code status catch not connected exception e logger normal this requestor is gone can t send terminal message apply byte counts unregister request handler with node onrequestsenderfinished onrequestsenderfinished currenttimemillis toolate toolate responsedeadline responsedeadline toolate failuretable onfinalfailure peernode routedlast routedlast timeutil formattime searchstarttime getstatusstring routedlast routedlast shorttostring applybytecounts unregisterrequesthandlerwithnode requestsender not_finished onfinished requestsender not_finished requestsender data_not_found createfnpdatanotfound sendterminal requestsender recently_failed createfnprecentlyfailed getrecentlyfailedtimeleft sendterminal requestsender generated_rejected_overload requestsender timed_out requestsender internal_error createfnprejectedoverload sendterminal requestsender route_not_found createfnproutenotfound sendterminal requestsender getheaders getsskdata needspubkey getsskblock getkey getpubkey createfnprejectedoverload sendterminal waitandfinishchktransferoffthread unregisterrequesthandlerwithnode requestsender verify_failure requestsender get_offer_verify_failure verify_failure createfnprejectedoverload sendterminal waitandfinishchktransferoffthread unregisterrequesthandlerwithnode createfnprejectedoverload sendterminal requestsender transfer_failed requestsender get_offer_transfer_failed transfer_failed createfnprejectedoverload sendterminal waitandfinishchktransferoffthread unregisterrequesthandlerwithnode transfer_failed createfnprejectedoverload sendterminal illegalstateexception notconnectedexception applybytecounts unregisterrequesthandlerwithnode private void sendssk byte headers final byte data boolean needs pub key2 dsa public key pub key throws not connected exception success requires that both the pubkey and the data headers have been received the pub key will have been set on the ssk key and the ssk block will have been constructed message headers msg dmt createfnpssk data found headers uid headers source send async headers msg null this final message data msg dmt createfnpssk data found data uid data node executor execute new prio runnable public int get priority return request handler this get priority public void run try source send throttled message data msg data length request handler this 60 1000 true null apply byte counts catch not connected exception e okay catch waited too long exception e grrrr logger error this waited too long to send ssk data on request handler this because of bwlimiting catch sync send waited too long exception e logger error this waited too long to send ssk data on request handler this because of peer finally unregister request handler with node send throttled ssk data for request handler this if needs pub key message pk dmt createfnpssk pub key uid pub key source send async pk null this needspubkey2 dsapublickey pubkey notconnectedexception pubkey sskblock headersmsg createfnpsskdatafoundheaders sendasync headersmsg datamsg createfnpsskdatafounddata priorunnable getpriority requesthandler getpriority sendthrottledmessage datamsg requesthandler applybytecounts notconnectedexception waitedtoolongexception requesthandler syncsendwaitedtoolongexception requesthandler unregisterrequesthandlerwithnode requesthandler needspubkey createfnpsskpubkey pubkey sendasync node executor execute new prio runnable public int get priority return request handler this get priority priorunnable getpriority requesthandler getpriority public void run try source send throttled message data msg data length request handler this 60 1000 true null apply byte counts catch not connected exception e okay catch waited too long exception e grrrr logger error this waited too long to send ssk data on request handler this because of bwlimiting catch sync send waited too long exception e logger error this waited too long to send ssk data on request handler this because of peer finally unregister request handler with node sendthrottledmessage datamsg requesthandler applybytecounts notconnectedexception waitedtoolongexception requesthandler syncsendwaitedtoolongexception requesthandler unregisterrequesthandlerwithnode static void sendssk byte headers byte data boolean needs pub key dsa public key pub key final peer node source long uid byte counter ctr throws not connected exception waited too long exception success requires that both the pubkey and the data headers have been received the pub key will have been set on the ssk key and the ssk block will have been constructed message headers msg dmt createfnpssk data found headers uid headers source send async headers msg null ctr final message data msg dmt createfnpssk data found data uid data try source send throttled message data msg data length ctr 60 1000 false null catch sync send waited too long exception e impossible throw new error e if needs pub key message pk dmt createfnpssk pub key uid pub key source send async pk null ctr needspubkey dsapublickey pubkey peernode bytecounter notconnectedexception waitedtoolongexception pubkey sskblock headersmsg createfnpsskdatafoundheaders sendasync headersmsg datamsg createfnpsskdatafounddata sendthrottledmessage datamsg syncsendwaitedtoolongexception needspubkey createfnpsskpubkey pubkey sendasync return data from the datastore param block the block we found in the datastore throws not connected exception if we lose the connected to the request source private void return local data key block block throws not connected exception if key instanceof nodessk sendssk block get raw headers block get raw data needs pub key ssk block block get pub key status request sender success for byte logging else if block instanceof chk block message df dmt createfnpchk data found uid block get raw headers partially received block prb new partially received block node packets in block node packet size block get raw data block transmitter bt new block transmitter node usm source uid prb this node add transferring request handler uid source send async df null this if bt send node executor for byte logging status request sender success we ve fetched it from our datastore so there won t be a downstream noderef but we want to send at least an fnp opennet completed ack otherwise the request source may have to timeout waiting for one that will be the terminal message finish opennet no relay else also for byte logging since the block is the terminal message apply byte counts unregister request handler with node else throw new illegal state exception notconnectedexception returnlocaldata keyblock notconnectedexception getrawheaders getrawdata needspubkey sskblock getpubkey requestsender chkblock createfnpchkdatafound getrawheaders partiallyreceivedblock partiallyreceivedblock packets_in_block packet_size getrawdata blocktransmitter blocktransmitter addtransferringrequesthandler sendasync requestsender fnpopennetcompletedack finishopennetnorelay applybytecounts unregisterrequesthandlerwithnode illegalstateexception private void unregister request handler with node node remove transferring request handler uid node unlockuid uid key instanceof nodessk false false false false tag unregisterrequesthandlerwithnode removetransferringrequesthandler sends the final packet of a request in such a way that the thread can be freed made non runnable exit and the byte counter will still be accurate private void send terminal message msg throws not connected exception if logminor logger minor this send terminal msg new exception debug if send terminal called throw new illegal state exception send terminal should only be called once else send terminal called true source send async msg new terminal message byte count collector this sendterminal notconnectedexception sendterminal sendterminalcalled illegalstateexception sendterminal sendterminalcalled sendasync terminalmessagebytecountcollector public void acknowledged if logminor logger minor this acknowledged terminal message request handler this terminal message ack d by remote peer complete requesthandler terminalmessage public void disconnected if logminor logger minor this peer disconnected before terminal message sent for request handler this complete requesthandler public void fatal error logger error this error sending terminal message for request handler this complete fatalerror requesthandler public void sent if logminor logger minor this sent terminal message request handler this complete requesthandler private void complete synchronized this if completed return completed true if logminor logger minor this completing request handler this for byte counting this relies on the fact that the callback will only be excuted once apply byte counts unregister request handler with node requesthandler applybytecounts unregisterrequesthandlerwithnode either send an ack indicating we ve finished and aren t interested in opennet or wait for a noderef and relay it and wait for a response and relay that or send our own noderef and wait for a response and add that private void finish opennet checked throws not connected exception opennet manager om node get opennet if om null node pass opennet refs through darknet source is opennet finish opennet inner om apply byte counts unregister request handler with node return message msg dmt createfnp opennet completed ack uid send terminal msg finishopennetchecked notconnectedexception opennetmanager getopennet passopennetrefsthroughdarknet isopennet finishopennetinner applybytecounts unregisterrequesthandlerwithnode createfnpopennetcompletedack sendterminal there is no noderef to pass downstream if we want a connection send our noderef and wait for a reply otherwise just send an ack private void finish opennet no relay throws not connected exception opennet manager om node get opennet if om null source is opennet node pass opennet refs through darknet finish opennet no relay inner om apply byte counts unregister request handler with node return otherwise just ack it message msg dmt createfnp opennet completed ack uid send terminal msg finishopennetnorelay notconnectedexception opennetmanager getopennet isopennet passopennetrefsthroughdarknet finishopennetnorelayinner applybytecounts unregisterrequesthandlerwithnode createfnpopennetcompletedack sendterminal private boolean finish opennet inner opennet manager om byte noderef rs wait for opennet noderef if noderef null return finish opennet no relay inner om if node random next int opennet manager reset path folding prob 0 return finish opennet no relay inner om finish opennet relay noderef om return true finishopennetinner opennetmanager waitforopennetnoderef finishopennetnorelayinner nextint opennetmanager reset_path_folding_prob finishopennetnorelayinner finishopennetrelay send our noderef to the request source wait for a reply if we get one add it called when either the request wasn t routed or the node it was routed to didn t return a noderef return true if success or lost connection false if we need to send an ack private boolean finish opennet no relay inner opennet manager om if logminor logger minor this finishing opennet sending own reference if om want peer null false false false return false don t want a reference try om send opennet ref false uid source om crypto my compressed full ref this catch not connected exception e logger normal this can t send opennet ref because node disconnected on this oh well return true wait for response byte noderef om wait for opennet noderef true source uid this if noderef null return false simple field set ref om validate noderef noderef 0 noderef length source false if ref null return false try if node add new opennet node ref null logger normal this asked for opennet ref but didn t want it for this n ref else logger normal this added opennet noderef in this catch fs parse exception e logger error this could not parse opennet noderef for this from source e catch peer parse exception e logger error this could not parse opennet noderef for this from source e catch reference signature verification exception e logger error this bad signature on opennet noderef for this from source e e return true finishopennetnorelayinner opennetmanager wantpeer sendopennetref mycompressedfullref notconnectedexception waitforopennetnoderef simplefieldset validatenoderef addnewopennetnode fsparseexception peerparseexception referencesignatureverificationexception called when the node we routed the request to returned a valid noderef and we don t want it so we relay it downstream to somebody who does and wait to relay the response back upstream param noderef param om private void finish opennet relay byte noderef opennet manager om if logminor logger minor this finishing opennet relaying reference from rs success from send it back to the handler then wait for the connect reply peer node data source rs success from try om send opennet ref false uid source noderef this catch not connected exception e lost contact with request source nothing we can do return now wait for reply from the request source byte new noderef om wait for opennet noderef true source uid this if new noderef null already sent a ref no way to tell upstream that we didn t receive one return send it forward to the data source if it is valid if om validate noderef new noderef 0 new noderef length source false null try om send opennet ref true uid data source new noderef this catch not connected exception e how sad return finishopennetrelay opennetmanager successfrom connectreply peernode datasource successfrom sendopennetref notconnectedexception newnoderef waitforopennetnoderef newnoderef validatenoderef newnoderef newnoderef sendopennetref datasource newnoderef notconnectedexception public void sent bytes int x synchronized bytes sync sent bytes x node node stats request sent bytes key instanceof nodessk x if logminor logger minor this sent bytes x on this sentbytes bytessync sentbytes nodestats requestsentbytes sentbytes public void received bytes int x synchronized bytes sync received bytes x node node stats request received bytes key instanceof nodessk x receivedbytes bytessync receivedbytes nodestats requestreceivedbytes public void sent payload int x do not add payload to sent bytes sent bytes is called with the actual sent bytes and we do not deduct the already reported bytes which are only used for accounting for the bandwidth throttle node sent payload x node node stats request sent bytes key instanceof nodessk x if logminor logger minor this sent payload x on this sentpayload sentbytes sentbytes alreadyreportedbytes sentpayload nodestats requestsentbytes sentpayload public int get priority return native thread high priority getpriority nativethread high_priority public abstract class messageuri public abstract freeneturi get freeneturi getfreeneturi public abstract freeneturi get freeneturi public abstract string get messageid getfreeneturi getmessageid public abstract string get messageid override public abstract boolean equals object obj getmessageid public abstract boolean equals object obj override public abstract string to string tostring public class black function implements binary function public boolean is black int rgb return rgb 0xff000000 blackfunction binaryfunction isblack private string value new string public attribute public attribute string name string value set name name set value value setname setvalue public void set name string name this name name setname public string get name return name getname public void set value string value this value value setvalue public string get value return value getvalue public final class saturation composite extends rgb composite public saturation composite float alpha super alpha saturationcomposite rgbcomposite saturationcomposite public composite context create context color model src color model color model dst color model rendering hints hints return new context extra alpha src color model dst color model compositecontext createcontext colormodel srccolormodel colormodel dstcolormodel renderinghints extraalpha srccolormodel dstcolormodel private float dhsb new float 3 public context float alpha color model src color model color model dst color model super alpha src color model dst color model colormodel srccolormodel colormodel dstcolormodel srccolormodel dstcolormodel override public void composergb int src int dst float alpha int w src length for int i 0 i w i 4 int sr src i int dir dst i int sg src i 1 int dig dst i 1 int sb src i 2 int dib dst i 2 int sa src i 3 int dia dst i 3 int dor dog dob color rg btohsb sr sg sb shsb color rg btohsb dir dig dib dhsb dhsb 1 shsb 1 int dorgb color hs btorgb dhsb 0 dhsb 1 dhsb 2 dor dorgb 0xff0000 16 dog dorgb 0xff00 8 dob dorgb 0xff float a alpha sa 255f float ac 1 a dst i int a dor ac dir dst i 1 int a dog ac dig dst i 2 int a dob ac dib dst i 3 int sa alpha dia ac rgbtohsb rgbtohsb hsbtorgb get a list of fields which the database should create an index on public static string get indexed fields return new string mid m last fetched date getindexedfields mlastfetcheddate creates an identity param new requesturi a link freeneturi to fetch this identity param new nickname the nickname of this identity param does publish trust list whether this identity publishes its trust list or not throws invalid parameter exception if a supplied parameter is invalid protected identity freeneturi new requesturi string new nickname boolean does publish trust list throws invalid parameter exception set requesturi new requesturi mid getid fromuri get requesturi m added date current timeutc get m first fetched date new date 0 m last fetched date new date 0 m last changed date new date 0 set nickname new nickname set publish trust list does publish trust list m contexts new array list string 4 currently we have introduction freetalk m properties new hash map string string logger debug this new identity get nickname uri new requesturi newrequesturi newnickname doespublishtrustlist trustlist invalidparameterexception newrequesturi newnickname doespublishtrustlist invalidparameterexception setrequesturi newrequesturi getidfromuri getrequesturi maddeddate currenttimeutc mfirstfetcheddate mlastfetcheddate mlastchangeddate setnickname newnickname setpublishtrustlist doespublishtrustlist mcontexts arraylist mproperties hashmap getnickname newrequesturi creates an identity only for being used by the wot package and unit tests not for user interfaces param new requesturi a string that will be converted to link freeneturi before creating the identity param new nickname the nickname of this identity param does publish trust list whether this identity publishes its trust list or not throws invalid parameter exception if a supplied parameter is invalid throws malformedurl exception if the supplied requesturi isn t a valid freeneturi public identity string new requesturi string new nickname boolean does publish trust list throws invalid parameter exception malformedurl exception this new freeneturi new requesturi new nickname does publish trust list newrequesturi newnickname doespublishtrustlist trustlist invalidparameterexception malformedurlexception newrequesturi newnickname doespublishtrustlist invalidparameterexception malformedurlexception newrequesturi newnickname doespublishtrustlist gets this identity s id which is the routing key of the author encoded with the freenet variant of base64 we use this to identify identities and perform requests on the database return a unique identifier for this identity public string getid return mid generates a unique i dfrom a link freeneturi which is the routing key of the author encoded with the freenet variant of base64 we use this to identify identities and perform requests on the database param uri the requesturi of the identity return a string to uniquely identify the identity public static final string getid fromuri freeneturi uri warning when changing this also update freetalk wot wot identity getuid fromuri return base64 encode uri get routing key idfrom getidfromuri wotidentity getuidfromuri getroutingkey return the requesturi link freeneturi to fetch this identity public synchronized freeneturi get requesturi return m requesturi getrequesturi mrequesturi sets the requesturi of this identity the given link freeneturi is converted to usk and the document name is forced to wot param new requesturi the freeneturi used to fetch this identity throws illegal argument exception if the given freeneturi is neither a ssk nor a usk or if the keypair does not match the old one protected synchronized void set requesturi freeneturi new requesturi if m requesturi null new requesturi equals keypair m requesturi throw new illegal argument exception cannot change the request uri of an existing identity if new requesturi isusk new requesturi isssk throw new illegal argument exception identity uri keytype not supported new requesturi m requesturi new requesturi set key type usk set doc name wot set meta string null updated newrequesturi illegalargumentexception setrequesturi newrequesturi mrequesturi newrequesturi equalskeypair mrequesturi illegalargumentexception newrequesturi newrequesturi illegalargumentexception newrequesturi mrequesturi newrequesturi setkeytype setdocname setmetastring get the edition number of the request uri of this identity public synchronized long get edition return get requesturi get suggested edition getedition getrequesturi getsuggestededition sets the edition of the last fetched version of this identity that number is published in trust lists to limit the number of editions a newbie has to fetch before he actually gets ans identity param new edition a long representing the last fetched version of this identity throws invalid parameter exception if the new edition is less than the current one protected synchronized void set edition long new edition throws invalid parameter exception long current edition m requesturi get edition if new edition current edition throw new invalid parameter exception the edition of an identity cannot be lowered if new edition current edition m requesturi m requesturi set suggested edition new edition updated trustlists newedition invalidparameterexception setedition newedition invalidparameterexception currentedition mrequesturi getedition newedition currentedition invalidparameterexception newedition currentedition mrequesturi mrequesturi setsuggestededition newedition decrease the current edition by one called by the wot when the score of an identity changes from negative or 0 to 0 to make the identity fetcher re download it s current trust list this is necessary because we do not create the trusted identities of someone if he has a negative score protected synchronized void decrease edition long new edition get edition 1 if new edition 0 new edition 0 if the edition is 0 the fetcher decides via last fetched date whether to fetch current or next m last fetched date new date 0 m requesturi m requesturi set suggested edition new edition currentedition identityfetcher decreaseedition newedition getedition newedition newedition mlastfetcheddate mrequesturi mrequesturi setsuggestededition newedition return the date when this identity was first seen in a trust list of someone public date get added date return date m added date clone getaddeddate maddeddate return the date when the identity was fetched successfully for the first time equal to new date 0 if it was never fetched public date get first fetched date return date m first fetched date clone getfirstfetcheddate mfirstfetcheddate return the date of this identity s last modification public synchronized date get last fetched date return date m last fetched date clone getlastfetcheddate mlastfetcheddate return the date of this identity s last modification public synchronized date get last change date return date m last changed date clone getlastchangedate mlastchangeddate has to be called when the identity was fetched protected synchronized void on fetched if m first fetched date equals new date 0 m first fetched date current timeutc get m last fetched date current timeutc get updated onfetched mfirstfetcheddate mfirstfetcheddate currenttimeutc mlastfetcheddate currenttimeutc return the identity s nick name public synchronized string get nickname return m nickname nickname getnickname mnickname important this code is duplicated in plugins freetalk wot wot identity validate nickname please also modify it there if you modify it here public boolean is nickname valid string new nickname return new nickname length 0 new nickname length 50 string validity checker contains noidn blacklist characters new nickname wotidentity validatenickname isnicknamevalid newnickname newnickname newnickname stringvaliditychecker containsnoidnblacklistcharacters newnickname sets the nick name of this identity param m nickname a string containing this identity s nick name setting it to null means that it was not retrieved yet throws invalid parameter exception if the nick name s length is bigger than 50 or if it empty public synchronized void set nickname string new nickname throws invalid parameter exception if new nickname null new nickname new nickname trim if new nickname null if new nickname length 0 throw new invalid parameter exception blank nickname if new nickname length 50 throw new invalid parameter exception nickname is too long 50 chars max if is nickname valid new nickname throw new invalid parameter exception nickname contains illegal characters if m nickname null m nickname equals new nickname throw new invalid parameter exception changing the nickname of an identity is not allowed m nickname new nickname updated nickname mnickname nickname invalidparameterexception nickname setnickname newnickname invalidparameterexception newnickname newnickname newnickname newnickname newnickname invalidparameterexception newnickname invalidparameterexception isnicknamevalid newnickname invalidparameterexception mnickname mnickname newnickname invalidparameterexception mnickname newnickname checks whether this identity publishes a trust list return whether this identity publishes its trust list or not public synchronized boolean does publish trust list return m does publish trust list trustlist doespublishtrustlist mdoespublishtrustlist sets if this identity publishes its trust list or not public synchronized void set publish trust list boolean does publish trust list if m does publish trust list does publish trust list return m does publish trust list does publish trust list updated setpublishtrustlist doespublishtrustlist mdoespublishtrustlist doespublishtrustlist mdoespublishtrustlist doespublishtrustlist checks whether this identity offers the given contexts param context the context we want to know if this identity has it or not return whether this identity has that context or not public synchronized boolean has context string context return m contexts contains context trim hascontext mcontexts gets all this identity s contexts return a copy of the array list string of all contexts of this identity suppress warnings unchecked public synchronized array list string get contexts todo if this is used often which it probably is we might verify that no code corrupts the hash map and return the original one instead of a copy return array list string m contexts clone arraylist suppresswarnings arraylist getcontexts hashmap arraylist mcontexts adds a context to this identity a context is a string the identities contexts are a set of strings no context will be added more than once contexts are used by client applications to identify what identities are relevant for their use currently known contexts wot adds the introduction context if an identity publishes catpchas to allow other to get on it s trust list freetalk the messaging system for freenet adds the freetalk context to identities which use it param db a reference to the database param context name of the context throws invalid parameter exception if the context name is empty public synchronized void add context string new context throws invalid parameter exception new context new context trim if new context length 0 throw new invalid parameter exception a blank context cannot be added to an identity fixme limit the length of a context if m contexts contains new context fixme limit the amount of contexts m contexts add new context updated invalidparameterexception addcontext newcontext invalidparameterexception newcontext newcontext newcontext invalidparameterexception mcontexts newcontext mcontexts newcontext clears the list of contexts and sets it to the new list of contexts which was passed to the function duplicate contexts are ignored for invalid contexts an error is logged all valid ones will be added important this always marks the identity as updated so it should not be used on own identities because it would result in a re insert even if nothing was changed protected synchronized void set contexts list string new contexts m contexts clear for string context new contexts try add context context catch invalid parameter exception e logger error this set contexts add context failed e m contexts trim to size ownidentities setcontexts newcontexts mcontexts newcontexts addcontext invalidparameterexception setcontexts addcontext mcontexts trimtosize removes a context from this identity does nothing if it does not exist if this identity is no longer used by a client application the user can tell it and others won t try to fetch it anymore param db a reference to the database param context name of the context public synchronized void remove context string context throws invalid parameter exception context context trim if m contexts contains context m contexts remove context updated removecontext invalidparameterexception mcontexts mcontexts gets the value of one of this identity s properties param key the name of the requested custom property return the value of the requested custom property throws invalid parameter exception if this identity doesn t have the required property public synchronized string get property string key throws invalid parameter exception key key trim if m properties contains key key throw new invalid parameter exception the property key isn t set on this identity return m properties get key invalidparameterexception getproperty invalidparameterexception mproperties containskey invalidparameterexception mproperties gets all custom properties from this identity return a copy of the hash map string string referencing all this identity s custom properties suppress warnings unchecked public synchronized hash map string string get properties todo if this is used often we might verify that no code corrupts the hash map and return the original one instead of a copy return hash map string string m properties clone hashmap suppresswarnings hashmap getproperties hashmap hashmap mproperties sets a custom property on this identity custom properties keys have to be unique this can be used by client applications that need to store additional informations on their identities crypto keys avatar whatever the key is always trimmed before storage the value is stored as passed param db a reference to the database param key name of the custom property param value value of the custom property throws invalid parameter exception if the key or the value is empty public synchronized void set property string key string value throws invalid parameter exception key key trim if key length 0 value length 0 throw new invalid parameter exception blank key or value in this property fixme limit the length of key and value string old value m properties get key if old value null old value equals value false fixme limit the amount of properties m properties put key value updated invalidparameterexception setproperty invalidparameterexception invalidparameterexception oldvalue mproperties oldvalue oldvalue mproperties clears the list of properties and sets it to the new list of properties which was passed to the function for invalid properties an error is logged all valid ones will be added important this always marks the identity as updated so it should not be used on own identities because it would result in a re insert even if nothing was changed protected synchronized void set properties hash map string string new properties m properties new hash map string string for entry string string property new properties entry set try set property property get key property get value catch invalid parameter exception e logger error this set properties set property failed e ownidentities setproperties hashmap newproperties mproperties hashmap newproperties entryset setproperty getkey getvalue invalidparameterexception setproperties setproperty removes a custom property from this identity does nothing if it does not exist param db a reference to the database param key name of the custom property public synchronized void remove property string key throws invalid parameter exception key key trim if m properties remove key null updated removeproperty invalidparameterexception mproperties tell that this identity has been updated updated own identities will be reinserted by the identity inserter automatically public synchronized void updated m last changed date current timeutc get ownidentities identityinserter mlastchangeddate currenttimeutc static final byte db database format version byte 2 final int get bitmap page id int i return i db bitmap pages db bitmap id i header root 1 curr index bitmap extent i bitmap extent base dbdatabaseformatversion getbitmappageid dbbitmappages dbbitmapid currindex bitmapextent bitmapextentbase final long get pos int oid synchronized object cache if oid 0 oid curr index size throw new storage error storage error invalid oid page pg pool get page header root 1 curr index index long oid db handles per page bits page page size log long pos bytes unpack8 pg data oid db handles per page 1 3 pool unfix pg return pos getpos objectcache currindexsize storageerror storageerror invalid_oid getpage currindex dbhandlesperpagebits pagesizelog dbhandlesperpage final void set pos int oid long pos synchronized object cache dirty pages map oid db handles per page bits 5 1 oid db handles per page bits 31 page pg pool put page header root 1 curr index index long oid db handles per page bits page page size log bytes pack8 pg data oid db handles per page 1 3 pos pool unfix pg setpos objectcache dirtypagesmap dbhandlesperpagebits dbhandlesperpagebits putpage currindex dbhandlesperpagebits pagesizelog dbhandlesperpage final byte get int oid long pos get pos oid if pos db free handle flag db page object flag 0 throw new storage error storage error invalid oid return pool get pos db flags mask getpos dbfreehandleflag dbpageobjectflag storageerror storageerror invalid_oid dbflagsmask final page get page int oid long pos get pos oid if pos db free handle flag db page object flag db page object flag throw new storage error storage error deleted object return pool get page pos db flags mask getpage getpos dbfreehandleflag dbpageobjectflag dbpageobjectflag storageerror storageerror deleted_object getpage dbflagsmask final page put page int oid synchronized object cache long pos get pos oid if pos db free handle flag db page object flag db page object flag throw new storage error storage error deleted object if pos db modified flag 0 dirty pages map oid db handles per page bits 5 1 oid db handles per page bits 31 allocate page page size oid clone bitmap pos db flags mask page page size pos get pos oid modified true return pool put page pos db flags mask putpage objectcache getpos dbfreehandleflag dbpageobjectflag dbpageobjectflag storageerror storageerror deleted_object dbmodifiedflag dirtypagesmap dbhandlesperpagebits dbhandlesperpagebits pagesize clonebitmap dbflagsmask pagesize getpos putpage dbflagsmask int allocate page int oid allocate id set pos oid allocate page page size 0 db page object flag db modified flag return oid allocatepage allocateid setpos pagesize dbpageobjectflag dbmodifiedflag public protected synchronized void deallocate object i persistent obj synchronized object cache if obj get oid 0 return if use serializable transactions thread transaction context ctx get transaction context if ctx nested 0 serializable transaction ctx deleted add obj return deallocate object0 obj deallocateobject ipersistent objectcache getoid useserializabletransactions threadtransactioncontext gettransactioncontext deallocateobject0 public void throw object i persistent obj object cache remove obj get oid throwobject ipersistent objectcache getoid private void deallocate object0 i persistent obj int oid obj get oid long pos get pos oid object cache remove oid int offs int pos page page size 1 if offs db free handle flag db page object flag 0 throw new storage error storage error deleted object page pg pool get page pos offs offs db flags mask int size object header get size pg data offs pool unfix pg free id oid custom allocator allocator custom allocator map null get custom allocator obj get class null if allocator null allocator free pos db flags mask size else if pos db modified flag 0 free pos db flags mask size else clone bitmap pos size obj assign oid null 0 false deallocateobject0 ipersistent getoid getpos objectcache pagesize dbfreehandleflag dbpageobjectflag storageerror storageerror deleted_object getpage dbflagsmask objectheader getsize freeid customallocator customallocatormap getcustomallocator getclass dbflagsmask dbmodifiedflag dbflagsmask clonebitmap assignoid final void free page int oid long pos get pos oid assert that pos db free handle flag db page object flag db page object flag if pos db modified flag 0 free pos db flags mask page page size else clone bitmap pos db flags mask page page size free id oid freepage getpos dbfreehandleflag dbpageobjectflag dbpageobjectflag dbmodifiedflag dbflagsmask pagesize clonebitmap dbflagsmask pagesize freeid int allocate id synchronized object cache int oid int curr 1 curr index set dirty if oid header root curr free list 0 header root curr free list int get pos oid db flags bits assert that header root curr free list 0 dirty pages map oid db handles per page bits 5 1 oid db handles per page bits 31 return oid if curr index size db max object oid throw new storage error storage error too much objects if curr index size header root curr index size int old index size header root curr index size int new index size old index size 1 if new index size old index size new index size integer max value db handles per page 1 if new index size old index size throw new storage error storage error not enough space long new index allocate new index size 8l 0 if curr index size header root curr index size long old index header root curr index pool copy new index old index curr index size 8l header root curr index new index header root curr index size new index size free old index old index size 8l else index was already reallocated free new index new index size 8l oid curr index size header root curr index used curr index size return oid allocateid objectcache currindex setdirty freelist freelist getpos dbflagsbits freelist dirtypagesmap dbhandlesperpagebits dbhandlesperpagebits currindexsize dbmaxobjectoid storageerror storageerror too_much_objects currindexsize indexsize oldindexsize indexsize newindexsize oldindexsize newindexsize oldindexsize newindexsize max_value dbhandlesperpage newindexsize oldindexsize storageerror storageerror not_enough_space newindex newindexsize currindexsize indexsize oldindex newindex oldindex currindexsize newindex indexsize newindexsize oldindex oldindexsize newindex newindexsize currindexsize indexused currindexsize void free id int oid synchronized object cache set pos oid long header root 1 curr index free list db flags bits db free handle flag header root 1 curr index free list oid freeid objectcache setpos currindex freelist dbflagsbits dbfreehandleflag currindex freelist static final void memset page pg int offs int pattern int len byte arr pg data byte pat byte pattern while len 0 arr offs pat final void extend long size if size header root 1 curr index size header root 1 curr index size size currindex currindex public long get used size return used size getusedsize usedsize public long get database size return header root 1 curr index size getdatabasesize currindex final boolean was reserved long pos long size for location location reserved chain location null location location next if pos location pos pos location pos location size pos location pos location pos pos size return true return false wasreserved reservedchain final void reserve location long pos long size location location new location location pos pos location size size location next reserved chain reserved chain location reservelocation reservedchain reservedchain final void commit location reserved chain reserved chain next commitlocation reservedchain reservedchain final void set dirty modified true if header dirty header dirty true page pg pool put page 0 header pack pg data pool flush pool unfix pg setdirty putpage protected boolean is dirty return header dirty isdirty final page put bitmap page int i return put page get bitmap page id i putbitmappage putpage getbitmappageid final page get bitmap page int i return get page get bitmap page id i getbitmappage getpage getbitmappageid final long allocate long size int oid synchronized object cache set dirty size size db allocation quantum 1 db allocation quantum 1 assert that size 0 allocated delta size if allocated delta gc threshold gc0 int obj bit size int size db allocation quantum bits assert that obj bit size size db allocation quantum bits long pos int hole bit size 0 int alignment int size page page size 1 int offs first page last page i j int hole before free page 0 int free bitmap page 0 int curr 1 curr index page pg last page header root curr bitmap end db bitmap id used size size if alignment 0 first page currp bitmap page offs currp bitmap offs inc 1 inc 1 else first page currr bitmap page offs currr bitmap offs while true if alignment 0 allocate page object for i first page i last page i int space needed obj bit size hole bit size page bits obj bit size hole bit size page bits if bitmap page available space i space needed hole bit size 0 offs 0 continue pg get bitmap page i int start offs offs while offs page page size if pg data offs 0 offs offs inc 1 inc 1 hole bit size 0 else if hole bit size 8 obj bit size pos long i page page size offs 8 hole bit size db allocation quantum bits if was reserved pos size start offs offs offs inc 1 inc 1 hole bit size 0 continue reserve location pos size currp bitmap page i currp bitmap offs offs extend pos size if oid 0 long prev get pos oid int marker int prev db flags mask pool copy pos prev marker size set pos oid pos marker db modified flag pool unfix pg pg put bitmap page i int hole bytes hole bit size 3 if hole bytes offs memset pg 0 0xff offs hole bytes offs pool unfix pg pg put bitmap page i offs page page size while hole bytes page page size memset pg 0 0xff page page size hole bytes page page size bitmap page available space i 0 pool unfix pg pg put bitmap page i memset pg offs hole bytes 0xff hole bytes commit location pool unfix pg return pos if start offs 0 hole bit size 0 space needed bitmap page available space i bitmap page available space i space needed offs 0 pool unfix pg else for i first page i last page i int space needed obj bit size hole bit size page bits obj bit size hole bit size page bits if bitmap page available space i space needed hole bit size 0 offs 0 continue pg get bitmap page i int start offs offs while offs page page size int mask pg data offs 0xff if hole bit size bitmap first hole size mask obj bit size pos long i page page size offs 8 hole bit size db allocation quantum bits if was reserved pos size start offs offs 1 hole bit size 0 continue reserve location pos size currr bitmap page i currr bitmap offs offs extend pos size if oid 0 long prev get pos oid int marker int prev db flags mask pool copy pos prev marker size set pos oid pos marker db modified flag pool unfix pg pg put bitmap page i pg data offs byte 1 obj bit size hole bit size 1 if hole bit size 0 if hole bit size offs 8 memset pg 0 0xff offs hole bit size offs 8 pool unfix pg pg put bitmap page i offs page page size while hole bit size page bits memset pg 0 0xff page page size hole bit size page bits bitmap page available space i 0 pool unfix pg pg put bitmap page i while hole bit size 8 0 pg data offs byte 0xff pg data offs 1 byte 1 hole bit size 1 pool unfix pg commit location return pos else if bitmap max hole size mask obj bit size int hole bit offset bitmap max hole offset mask pos long i page page size offs 8 hole bit offset db allocation quantum bits if was reserved pos size start offs offs 1 hole bit size 0 continue reserve location pos size currr bitmap page i currr bitmap offs offs extend pos size if oid 0 long prev get pos oid int marker int prev db flags mask pool copy pos prev marker size set pos oid pos marker db modified flag pool unfix pg pg put bitmap page i pg data offs byte 1 obj bit size 1 hole bit offset pool unfix pg commit location return pos offs 1 if bitmap last hole size mask 8 hole bit size 8 else hole bit size bitmap last hole size mask if start offs 0 hole bit size 0 objectcache setdirty dballocationquantum dballocationquantum allocateddelta allocateddelta gcthreshold objbitsize dballocationquantumbits objbitsize dballocationquantumbits holebitsize pagesize firstpage lastpage holebeforefreepage freebitmappage currindex lastpage bitmapend dbbitmapid usedsize firstpage currpbitmappage currpbitmapoffs firstpage currrbitmappage currrbitmapoffs firstpage lastpage spaceneeded objbitsize holebitsize pagebits objbitsize holebitsize pagebits bitmappageavailablespace spaceneeded holebitsize getbitmappage startoffs pagesize holebitsize holebitsize objbitsize pagesize holebitsize dballocationquantumbits wasreserved startoffs holebitsize reservelocation currpbitmappage currpbitmapoffs getpos dbflagsmask setpos dbmodifiedflag putbitmappage holebytes holebitsize holebytes holebytes putbitmappage pagesize holebytes pagesize pagesize holebytes pagesize bitmappageavailablespace putbitmappage holebytes holebytes commitlocation startoffs holebitsize spaceneeded bitmappageavailablespace bitmappageavailablespace spaceneeded firstpage lastpage spaceneeded objbitsize holebitsize pagebits objbitsize holebitsize pagebits bitmappageavailablespace spaceneeded holebitsize getbitmappage startoffs pagesize holebitsize firstholesize objbitsize pagesize holebitsize dballocationquantumbits wasreserved startoffs holebitsize reservelocation currrbitmappage currrbitmapoffs getpos dbflagsmask setpos dbmodifiedflag putbitmappage objbitsize holebitsize holebitsize holebitsize holebitsize putbitmappage pagesize holebitsize pagebits pagesize holebitsize pagebits bitmappageavailablespace putbitmappage holebitsize holebitsize commitlocation maxholesize objbitsize holebitoffset maxholeoffset pagesize holebitoffset dballocationquantumbits wasreserved startoffs holebitsize reservelocation currrbitmappage currrbitmapoffs getpos dbflagsmask setpos dbmodifiedflag putbitmappage objbitsize holebitoffset commitlocation lastholesize holebitsize holebitsize lastholesize startoffs holebitsize final void fill bitmap long adr int len while true int off int adr page page size 1 page pg pool put page adr off if page page size off len memset pg off 0xff len pool unfix pg break else memset pg off 0xff page page size off pool unfix pg adr page page size off len page page size off fillbitmap pagesize putpage pagesize pagesize pagesize pagesize final void free long pos long size synchronized object cache assert that pos 0 pos db allocation quantum 1 0 long quant no pos db allocation quantum bits int obj bit size int size db allocation quantum 1 db allocation quantum bits int page id int quant no page page size log 3 int offs int quant no page page size 8 1 3 page pg put bitmap page page id int bit offs int quant no 7 allocated delta long obj bit size db allocation quantum bits used size long obj bit size db allocation quantum bits if pos page page size 1 0 size page page size if page id currp bitmap page offs currp bitmap offs currp bitmap offs offs if page id currr bitmap page offs currr bitmap offs currr bitmap offs offs bitmap page available space page id integer max value if obj bit size 8 bit offs obj bit size 8 bit offs pg data offs 1 bit offs 1 while obj bit size offs 8 page page size 8 memset pg offs 0 page page size offs pool unfix pg pg put bitmap page page id bitmap page available space page id integer max value obj bit size page page size offs 8 offs 0 while obj bit size 8 0 pg data offs byte 0 pg data offs byte 1 obj bit size 8 1 else pg data offs byte 1 obj bit size 1 bit offs pool unfix pg objectcache dballocationquantum quantno dballocationquantumbits objbitsize dballocationquantum dballocationquantumbits pageid quantno pagesizelog quantno pagesize putbitmappage pageid bitoffs quantno allocateddelta objbitsize dballocationquantumbits usedsize objbitsize dballocationquantumbits pagesize pagesize pageid currpbitmappage currpbitmapoffs currpbitmapoffs pageid currrbitmappage currrbitmapoffs currrbitmapoffs bitmappageavailablespace pageid max_value objbitsize bitoffs objbitsize bitoffs bitoffs objbitsize pagesize pagesize putbitmappage pageid bitmappageavailablespace pageid max_value objbitsize pagesize objbitsize objbitsize objbitsize bitoffs clone node next clone node long pos clone node list this pos pos this next list clonenode clonenode clonenode final void clone bitmap long pos long size synchronized object cache if inside clone bitmap assert that size page page size clone list new clone node pos clone list else inside clone bitmap true while true long quant no pos db allocation quantum bits int obj bit size int size db allocation quantum 1 db allocation quantum bits int page id int quant no page page size log 3 int offs int quant no page page size 8 1 3 int bit offs int quant no 7 int oid get bitmap page id page id pos get pos oid if pos db modified flag 0 dirty pages map oid db handles per page bits 5 1 oid db handles per page bits 31 allocate page page size oid clone bitmap pos db flags mask page page size if obj bit size 8 bit offs obj bit size 8 bit offs offs 1 while obj bit size offs 8 page page size 8 oid get bitmap page id page id pos get pos oid if pos db modified flag 0 dirty pages map oid db handles per page bits 5 1 oid db handles per page bits 31 allocate page page size oid clone bitmap pos db flags mask page page size obj bit size page page size offs 8 offs 0 if clone list null break pos clone list pos size page page size clone list clone list next inside clone bitmap false clonebitmap objectcache insideclonebitmap pagesize clonelist clonenode clonelist insideclonebitmap quantno dballocationquantumbits objbitsize dballocationquantum dballocationquantumbits pageid quantno pagesizelog quantno pagesize bitoffs quantno getbitmappageid pageid getpos dbmodifiedflag dirtypagesmap dbhandlesperpagebits dbhandlesperpagebits pagesize clonebitmap dbflagsmask pagesize objbitsize bitoffs objbitsize bitoffs objbitsize pagesize getbitmappageid pageid getpos dbmodifiedflag dirtypagesmap dbhandlesperpagebits dbhandlesperpagebits pagesize clonebitmap dbflagsmask pagesize objbitsize pagesize clonelist clonelist pagesize clonelist clonelist insideclonebitmap public void open string file path open file path default page pool size filepath filepath default_page_pool_size public void open i file file open file default page pool size ifile default_page_pool_size public synchronized void open string file path int page pool size i file file file path starts with i file new multi file file path substring 1 read only no flush i file new os file file path read only no flush try open file page pool size catch storage error ex file close throw ex filepath pagepoolsize ifile filepath startswith ifile multifile filepath readonly noflush ifile osfile filepath readonly noflush pagepoolsize storageerror public synchronized void open string file path int page pool size string crypt key rc4 file file new rc4 file file path read only no flush crypt key try open file page pool size catch storage error ex file close throw ex filepath pagepoolsize cryptkey rc4file rc4file filepath readonly noflush cryptkey pagepoolsize storageerror public void clear object cache object cache clear clearobjectcache objectcache protected oid hash table create object cache string kind int page pool size int object cache size if page pool size infinite page pool strong equals kind return new strong hash table object cache size if soft equals kind return new soft hash table object cache size if weak equals kind return new weak hash table object cache size if pinned equals kind return new pin weak hash table object cache size return new lru object cache object cache size oidhashtable createobjectcache pagepoolsize objectcachesize pagepoolsize infinite_page_pool stronghashtable objectcachesize softhashtable objectcachesize weakhashtable objectcachesize pinweakhashtable objectcachesize lruobjectcache objectcachesize protected void initialize i file file int page pool size this file file if lock file multiclient support if file try lock false throw new storage error storage error storage is used dirty pages map new int db dirty page bitmap size 4 1 gc threshold long max value background gc monitor new object background gc start monitor new object gc thread null gc active false gc done false allocated delta 0 reserved chain null clone list null inside clone bitmap false n nested transactions 0 n blocked transactions 0 n committed transactions 0 scheduled commit time long max value transaction monitor new object transaction lock new persistent resource modified false object cache create object cache cache kind page pool size object cache init size class desc map new hash map desc list null header new header pool new page pool page pool size page page size page pool lru limit pool open file ifile pagepoolsize lockfile multiclientsupport trylock storageerror storageerror storage_is_used dirtypagesmap dbdirtypagebitmapsize gcthreshold max_value backgroundgcmonitor backgroundgcstartmonitor gcthread gcactive gcdone allocateddelta reservedchain clonelist insideclonebitmap nnestedtransactions nblockedtransactions ncommittedtransactions scheduledcommittime max_value transactionmonitor transactionlock persistentresource objectcache createobjectcache cachekind pagepoolsize objectcacheinitsize classdescmap hashmap desclist pagepool pagepoolsize pagesize pagepoollrulimit public synchronized void open i file file int page pool size page pg int i if opened throw new storage error storage error storage already opened initialize file page pool size if multiclient support begin thread transaction read write transaction byte buf new byte header sizeof int rc file read 0 buf if rc 0 rc header sizeof throw new storage error storage error database corrupted header unpack buf if header curr 0 header curr 1 throw new storage error storage error database corrupted transaction id header transaction id if header database format version 0 database not initialized int index size init index size if index size db first user id index size db first user id index size index size db handles per page 1 db handles per page 1 bitmap extent base db bitmap pages header curr curr index 0 long used page page size header root 0 index used header root 0 index size index size header root 0 index used db first user id header root 0 free list 0 used index size 8l header root 1 index used header root 1 index size index size header root 1 index used db first user id header root 1 free list 0 used index size 8l header root 0 shadow index header root 1 index header root 1 shadow index header root 0 index header root 0 shadow index size index size header root 1 shadow index size index size int bitmap pages int used page page size db allocation quantum 8 1 1 page page size db allocation quantum 8 1 long bitmap size long bitmap pages page page size int used bitmap size int used bitmap size db allocation quantum bits 3 for i 0 i bitmap pages i pg pool put page used long i page page size byte bitmap pg data int n used bitmap size page page size page page size used bitmap size for int j 0 j n j bitmap j byte 0xff used bitmap size page page size pool unfix pg int bitmap index size db bitmap id db bitmap pages 8 page page size 1 page page size 1 byte index new byte bitmap index size bytes pack8 index db invalid id 8 db free handle flag for i 0 i bitmap pages i bytes pack8 index db bitmap id i 8 used db page object flag used page page size header root 0 bitmap end db bitmap id i header root 1 bitmap end db bitmap id i while i db bitmap pages bytes pack8 index db bitmap id i 8 db free handle flag i 1 header root 0 size used header root 1 size used used size used committed index size curr index size db first user id pool write header root 1 index index pool write header root 0 index index header dirty true header root 0 size header root 1 size pg pool put page 0 header pack pg data pool flush pool modify pg header database format version db database format version header pack pg data pool unfix pg pool flush else int curr header curr curr index curr if header root curr index size header root curr shadow index size throw new storage error storage error database corrupted bitmap extent base header database format version 2 0 db bitmap pages if is dirty if listener null listener database corrupted system err println database was not normally closed start recovery header root 1 curr size header root curr size header root 1 curr index used header root curr index used header root 1 curr free list header root curr free list header root 1 curr index header root curr shadow index header root 1 curr index size header root curr shadow index size header root 1 curr shadow index header root curr index header root 1 curr shadow index size header root curr index size header root 1 curr bitmap end header root curr bitmap end header root 1 curr root object header root curr root object header root 1 curr class desc list header root curr class desc list header root 1 curr bitmap extent header root curr bitmap extent pg pool put page 0 header pack pg data pool unfix pg pool copy header root 1 curr index header root curr index header root curr index used 8l page page size 1 page page size 1 if listener null listener recovery completed system err println recovery completed curr index size header root 1 curr index used committed index size curr index size used size header root curr size int bitmap size header root 1 curr index bitmap extent 0 db bitmap pages db large bitmap pages bitmap page available space new int bitmap size for i 0 i bitmap page available space length i bitmap page available space i integer max value currr bitmap page currp bitmap page 0 currr bitmap offs currp bitmap offs 0 opened true reload scheme if multiclient support end thread transaction ifile pagepoolsize storageerror storageerror storage_already_opened pagepoolsize multiclientsupport beginthreadtransaction read_write_transaction storageerror storageerror database_corrupted storageerror storageerror database_corrupted transactionid transactionid databaseformatversion indexsize initindexsize indexsize dbfirstuserid indexsize dbfirstuserid indexsize indexsize dbhandlesperpage dbhandlesperpage bitmapextentbase dbbitmappages currindex pagesize indexsize indexsize indexused dbfirstuserid freelist indexsize indexsize indexsize indexused dbfirstuserid freelist indexsize shadowindex shadowindex shadowindexsize indexsize shadowindexsize indexsize bitmappages pagesize dballocationquantum pagesize dballocationquantum bitmapsize bitmappages pagesize usedbitmapsize bitmapsize dballocationquantumbits bitmappages putpage pagesize usedbitmapsize pagesize pagesize usedbitmapsize usedbitmapsize pagesize bitmapindexsize dbbitmapid dbbitmappages pagesize pagesize bitmapindexsize dbinvalidid dbfreehandleflag bitmappages dbbitmapid dbpageobjectflag pagesize bitmapend dbbitmapid bitmapend dbbitmapid dbbitmappages dbbitmapid dbfreehandleflag usedsize committedindexsize currindexsize dbfirstuserid putpage databaseformatversion dbdatabaseformatversion currindex indexsize shadowindexsize storageerror storageerror database_corrupted bitmapextentbase databaseformatversion dbbitmappages isdirty databasecorrupted indexused indexused freelist freelist shadowindex indexsize shadowindexsize shadowindex shadowindexsize indexsize bitmapend bitmapend rootobject rootobject classdesclist classdesclist bitmapextent bitmapextent putpage indexused pagesize pagesize recoverycompleted currindexsize indexused committedindexsize currindexsize usedsize bitmapsize currindex bitmapextent dbbitmappages dblargebitmappages bitmappageavailablespace bitmapsize bitmappageavailablespace bitmappageavailablespace max_value currrbitmappage currpbitmappage currrbitmapoffs currpbitmapoffs reloadscheme multiclientsupport endthreadtransaction public boolean is opened return opened isopened static void check if final class descriptor desc class cls desc cls if cls null for class descriptor next desc next next null next next next next load if cls is assignable from next cls desc has subclasses true else if next cls is assignable from cls next has subclasses true checkiffinal classdescriptor classdescriptor isassignablefrom hassubclasses isassignablefrom hassubclasses void reload scheme class desc map clear custom allocator map null custom allocator list null default allocator new default allocator this int desc list oid header root 1 curr index class desc list class desc map put class descriptor class new class descriptor this class descriptor class class desc map put class descriptor field descriptor class new class descriptor this class descriptor field descriptor class if desc list oid 0 class descriptor desc desc list find class descriptor desc list oid for desc desc list desc null desc desc next desc load for desc desc list desc null desc desc next if find class descriptor desc cls desc desc resolve if desc allocator null if custom allocator map null custom allocator map new hash map custom allocator list new array list desc allocator load custom allocator map put desc cls desc allocator custom allocator list add desc allocator check if final desc else desc list null reloadscheme classdescmap customallocatormap customallocatorlist defaultallocator defaultallocator desclistoid currindex classdesclist classdescmap classdescriptor classdescriptor classdescriptor classdescmap classdescriptor fielddescriptor classdescriptor classdescriptor fielddescriptor desclistoid classdescriptor desclist findclassdescriptor desclistoid desclist desclist findclassdescriptor customallocatormap customallocatormap hashmap customallocatorlist arraylist customallocatormap customallocatorlist checkiffinal desclist final void assign oid i persistent obj int oid obj assign oid this oid false assignoid ipersistent assignoid final void register class descriptor class descriptor desc class desc map put desc cls desc desc next desc list desc list desc check if final desc store object0 desc false header root 1 curr index class desc list desc get oid modified true registerclassdescriptor classdescriptor classdescmap desclist desclist checkiffinal storeobject0 currindex classdesclist getoid final class descriptor find class descriptor class cls return class descriptor class desc map get cls classdescriptor findclassdescriptor classdescriptor classdescmap final class descriptor get class descriptor class cls class descriptor desc find class descriptor cls if desc null desc new class descriptor this cls register class descriptor desc return desc classdescriptor getclassdescriptor classdescriptor findclassdescriptor classdescriptor registerclassdescriptor public synchronized i persistent get root if opened throw new storage error storage error storage not opened int root oid header root 1 curr index root object return root oid 0 null lookup object root oid null ipersistent getroot storageerror storageerror storage_not_opened rootoid currindex rootobject rootoid lookupobject rootoid public synchronized void set root i persistent root if opened throw new storage error storage error storage not opened if root null header root 1 curr index root object 0 else if root is persistent store object0 root false header root 1 curr index root object root get oid modified true setroot ipersistent storageerror storageerror storage_not_opened currindex rootobject ispersistent storeobject0 currindex rootobject getoid public void commit synchronized background gc monitor synchronized this if opened throw new storage error storage error storage not opened object cache flush if custom allocator list null iterator iterator custom allocator list iterator while iterator has next custom allocator alloc custom allocator iterator next if alloc is modified alloc store alloc commit if modified return commit0 modified false backgroundgcmonitor storageerror storageerror storage_not_opened objectcache customallocatorlist customallocatorlist hasnext customallocator customallocator ismodified private final void commit0 int i j n int curr curr index int map dirty pages map int old index size header root curr index size int new index size header root 1 curr index size int n pages committed index size db handles per page bits page pg if new index size old index size clone bitmap header root curr index old index size 8l long new index while true new index allocate new index size 8l 0 if new index size header root 1 curr index size break free new index new index size 8l new index size header root 1 curr index size header root 1 curr shadow index new index header root 1 curr shadow index size new index size free header root curr index old index size 8l long curr size header root 1 curr size for i 0 i n pages i if map i 5 1 i 31 0 page src index pool get page header root 1 curr index long i page page size page dst index pool get page header root curr index long i page page size for j 0 j page page size j 8 long pos bytes unpack8 dst index data j if bytes unpack8 src index data j pos pos curr size if pos db free handle flag 0 if pos db page object flag 0 free pos db flags mask page page size else if pos 0 int offs int pos page page size 1 pg pool get page pos offs free pos object header get size pg data offs pool unfix pg pool unfix src index pool unfix dst index n committed index size db handles per page 1 if n 0 map i 5 1 i 31 0 page src index pool get page header root 1 curr index long i page page size page dst index pool get page header root curr index long i page page size j 0 do long pos bytes unpack8 dst index data j if bytes unpack8 src index data j pos pos curr size if pos db free handle flag 0 if pos db page object flag 0 free pos db flags mask page page size else if pos 0 int offs int pos page page size 1 pg pool get page pos offs free pos object header get size pg data offs pool unfix pg j 8 while n 0 pool unfix src index pool unfix dst index for i 0 i n pages i if map i 5 1 i 31 0 pg pool put page header root 1 curr index long i page page size for j 0 j page page size j 8 bytes pack8 pg data j bytes unpack8 pg data j db modified flag pool unfix pg if curr index size committed index size long page header root 1 curr index committed index size 8l page page size 1 long end header root 1 curr index page page size 1 curr index size 8l page page size 1 while page end pg pool put page page for j 0 j page page size j 8 bytes pack8 pg data j bytes unpack8 pg data j db modified flag pool unfix pg page page page size header root 1 curr used size used size pg pool put page 0 header pack pg data pool flush pool modify pg assert that header transaction id transaction id header transaction id transaction id header curr curr 1 header dirty true header pack pg data pool unfix pg pool flush header root 1 curr size header root curr size header root 1 curr index used curr index size header root 1 curr free list header root curr free list header root 1 curr bitmap end header root curr bitmap end header root 1 curr root object header root curr root object header root 1 curr class desc list header root curr class desc list header root 1 curr bitmap extent header root curr bitmap extent if curr index size 0 new index size old index size header root 1 curr index header root curr shadow index header root 1 curr index size header root curr shadow index size header root 1 curr shadow index header root curr index header root 1 curr shadow index size header root curr index size pool copy header root 1 curr index header root curr index curr index size 8l i curr index size db handles per page 32 1 db handles per page bits 5 while i 0 map i 0 else for i 0 i n pages i if map i 5 1 i 31 0 map i 5 1 i 31 pool copy header root 1 curr index long i page page size header root curr index long i page page size page page size if curr index size i db handles per page map i 5 1 i 31 0 curr index size committed index size pool copy header root 1 curr index long i page page size header root curr index long i page page size 8l curr index size long i page page size j i 5 n curr index size db handles per page 32 1 db handles per page bits 5 while j n map j 0 gc done false curr index curr committed index size curr index size if multiclient support pool flush pg pool put page 0 header dirty false header pack pg data pool unfix pg pool flush currindex dirtypagesmap oldindexsize indexsize newindexsize indexsize npages committedindexsize dbhandlesperpagebits newindexsize oldindexsize clonebitmap oldindexsize newindex newindex newindexsize newindexsize indexsize newindex newindexsize newindexsize indexsize shadowindex newindex shadowindexsize newindexsize oldindexsize currsize npages srcindex getpage pagesize dstindex getpage pagesize pagesize dstindex srcindex currsize dbfreehandleflag dbpageobjectflag dbflagsmask pagesize pagesize getpage objectheader getsize srcindex dstindex committedindexsize dbhandlesperpage srcindex getpage pagesize dstindex getpage pagesize dstindex srcindex currsize dbfreehandleflag dbpageobjectflag dbflagsmask pagesize pagesize getpage objectheader getsize srcindex dstindex npages putpage pagesize pagesize dbmodifiedflag currindexsize committedindexsize committedindexsize pagesize pagesize currindexsize pagesize putpage pagesize dbmodifiedflag pagesize usedsize usedsize putpage transactionid transactionid transactionid transactionid indexused currindexsize freelist freelist bitmapend bitmapend rootobject rootobject classdesclist classdesclist bitmapextent bitmapextent currindexsize newindexsize oldindexsize shadowindex indexsize shadowindexsize shadowindex shadowindexsize indexsize currindexsize currindexsize dbhandlesperpage dbhandlesperpagebits npages pagesize pagesize pagesize currindexsize dbhandlesperpage currindexsize committedindexsize pagesize pagesize currindexsize pagesize currindexsize dbhandlesperpage dbhandlesperpagebits gcdone currindex committedindexsize currindexsize multiclientsupport putpage public synchronized void rollback if opened throw new storage error storage error storage not opened object cache invalidate synchronized object cache if modified return rollback0 modified false storageerror storageerror storage_not_opened objectcache objectcache private final void rollback0 int curr curr index int map dirty pages map if header root 1 curr index header root curr shadow index pool copy header root curr shadow index header root curr index 8l committed index size else int n pages committed index size db handles per page 1 db handles per page bits for int i 0 i n pages i if map i 5 1 i 31 0 pool copy header root curr shadow index long i page page size header root curr index long i page page size page page size for int j curr index size db handles per page 32 1 db handles per page bits 5 j 0 map j 0 header root 1 curr index header root curr shadow index header root 1 curr index size header root curr shadow index size header root 1 curr index used committed index size header root 1 curr free list header root curr free list header root 1 curr bitmap end header root curr bitmap end header root 1 curr size header root curr size header root 1 curr root object header root curr root object header root 1 curr class desc list header root curr class desc list header root 1 curr bitmap extent header root curr bitmap extent used size header root curr size curr index size committed index size currr bitmap page currp bitmap page 0 currr bitmap offs currp bitmap offs 0 reload scheme currindex dirtypagesmap shadowindex shadowindex committedindexsize npages committedindexsize dbhandlesperpage dbhandlesperpagebits npages shadowindex pagesize pagesize pagesize currindexsize dbhandlesperpage dbhandlesperpagebits shadowindex indexsize shadowindexsize indexused committedindexsize freelist freelist bitmapend bitmapend rootobject rootobject classdesclist classdesclist bitmapextent bitmapextent usedsize currindexsize committedindexsize currrbitmappage currpbitmappage currrbitmapoffs currpbitmapoffs reloadscheme public synchronized void backup output stream out throws java io io exception if opened throw new storage error storage error storage not opened object cache flush int curr 1 curr index final int n objects header root curr index used long index offs header root curr index int i j k int n used index pages n objects db handles per page 1 db handles per page int n index pages int header root curr index size db handles per page 1 db handles per page long total records size 0 long n paged objects 0 int bitmap extent header root curr bitmap extent final long index new long n objects final int oids new int n objects if bitmap extent 0 bitmap extent integer max value for i 0 j 0 i n used index pages i page pg pool get page index offs long i page page size for k 0 k db handles per page j n objects k j long pos bytes unpack8 pg data k 8 index j pos oids j j if pos db free handle flag 0 if pos db page object flag 0 n paged objects 1 else if pos 0 int offs int pos page page size 1 page op pool get page pos offs int size object header get size op data offs db flags mask size size db allocation quantum 1 db allocation quantum 1 total records size size pool unfix op pool unfix pg header new header new header new header curr 0 new header dirty false new header database format version header database format version long new file size long n paged objects n index pages 2 1 page page size total records size new file size new file size page page size 1 page page size 1 new header root new root page 2 new header root 0 new root page new header root 1 new root page new header root 0 size new header root 1 size new file size new header root 0 index new header root 1 shadow index page page size new header root 0 shadow index new header root 1 index page page size long n index pages page page size new header root 0 shadow index size new header root 0 index size new header root 1 shadow index size new header root 1 index size n index pages db handles per page new header root 0 index used new header root 1 index used n objects new header root 0 free list new header root 1 free list header root curr free list new header root 0 bitmap end new header root 1 bitmap end header root curr bitmap end new header root 0 root object new header root 1 root object header root curr root object new header root 0 class desc list new header root 1 class desc list header root curr class desc list new header root 0 bitmap extent new header root 1 bitmap extent header root curr bitmap extent byte page new byte page page size new header pack page out write page long page offs long n index pages 2 1 page page size long rec offs long n paged objects n index pages 2 1 page page size generic sort sort new generic sort array public int size return n objects public int compare int i int j return index i index j 1 index i index j 0 1 public void swap int i int j long t1 index i index i index j index j t1 int t2 oids i oids i oids j oids j t2 byte new index new byte n index pages db handles per page 8 for i 0 i n objects i long pos index i int oid oids i if pos db free handle flag 0 if pos db page object flag 0 bytes pack8 new index oid 8 page offs db page object flag page offs page page size else if pos 0 bytes pack8 new index oid 8 rec offs int offs int pos page page size 1 page op pool get page pos offs int size object header get size op data offs db flags mask size size db allocation quantum 1 db allocation quantum 1 rec offs size pool unfix op else bytes pack8 new index oid 8 pos out write new index out write new index for i 0 i n objects i long pos index i if int pos db free handle flag db page object flag db page object flag if oids i db bitmap id db bitmap pages oids i bitmap extent oids i bitmap extent db large bitmap pages db bitmap pages int page id oids i db bitmap id db bitmap pages oids i db bitmap id oids i bitmap extent bitmap extent base long mapped space long page id page page size 8 db allocation quantum if mapped space new file size arrays fill page byte 0 else if mapped space page page size 8 db allocation quantum new file size arrays fill page byte 1 else int n bits int new file size mapped space db allocation quantum bits arrays fill page 0 n bits 3 byte 1 page n bits 3 byte 1 n bits 7 1 arrays fill page n bits 3 1 page page size byte 0 out write page else page pg pool get page pos db flags mask out write pg data pool unfix pg for i 0 i n objects i long pos index i if pos 0 int pos db free handle flag db page object flag 0 pos db flags mask int offs int pos page page size 1 page pg pool get page pos offs int size object header get size pg data offs size size db allocation quantum 1 db allocation quantum 1 while true if page page size offs size out write pg data offs size break out write pg data offs page page size offs size page page size offs pos page page size offs offs 0 pool unfix pg pg pool get page pos pool unfix pg if rec offs new file size assert that new file size rec offs page page size int align int new file size rec offs arrays fill page 0 align byte 0 out write page 0 align outputstream ioexception storageerror storageerror storage_not_opened objectcache currindex nobjects indexused indexoffs nusedindexpages nobjects dbhandlesperpage dbhandlesperpage nindexpages indexsize dbhandlesperpage dbhandlesperpage totalrecordssize npagedobjects bitmapextent bitmapextent nobjects nobjects bitmapextent bitmapextent max_value nusedindexpages getpage indexoffs pagesize dbhandlesperpage nobjects dbfreehandleflag dbpageobjectflag npagedobjects pagesize getpage objectheader getsize dbflagsmask dballocationquantum dballocationquantum totalrecordssize newheader newheader newheader newheader databaseformatversion databaseformatversion newfilesize npagedobjects nindexpages pagesize totalrecordssize newfilesize newfilesize pagesize pagesize newheader rootpage newheader rootpage newheader rootpage newheader newheader newfilesize newheader newheader shadowindex pagesize newheader shadowindex newheader pagesize nindexpages pagesize newheader shadowindexsize newheader indexsize newheader shadowindexsize newheader indexsize nindexpages dbhandlesperpage newheader indexused newheader indexused nobjects newheader freelist newheader freelist freelist newheader bitmapend newheader bitmapend bitmapend newheader rootobject newheader rootobject rootobject newheader classdesclist newheader classdesclist classdesclist newheader bitmapextent newheader bitmapextent bitmapextent pagesize newheader pageoffs nindexpages pagesize recoffs npagedobjects nindexpages pagesize genericsort genericsortarray nobjects newindex nindexpages dbhandlesperpage nobjects dbfreehandleflag dbpageobjectflag newindex pageoffs dbpageobjectflag pageoffs pagesize newindex recoffs pagesize getpage objectheader getsize dbflagsmask dballocationquantum dballocationquantum recoffs newindex newindex newindex nobjects dbfreehandleflag dbpageobjectflag dbpageobjectflag dbbitmapid dbbitmappages bitmapextent bitmapextent dblargebitmappages dbbitmappages pageid dbbitmapid dbbitmappages dbbitmapid bitmapextent bitmapextentbase mappedspace pageid pagesize dballocationquantum mappedspace newfilesize mappedspace pagesize dballocationquantum newfilesize nbits newfilesize mappedspace dballocationquantumbits nbits nbits nbits nbits pagesize getpage dbflagsmask nobjects dbfreehandleflag dbpageobjectflag dbflagsmask pagesize getpage objectheader getsize dballocationquantum dballocationquantum pagesize pagesize pagesize pagesize getpage recoffs newfilesize newfilesize recoffs pagesize newfilesize recoffs long rec offs long n paged objects n index pages 2 1 page page size generic sort sort new generic sort array public int size return n objects recoffs npagedobjects nindexpages pagesize genericsort genericsortarray nobjects return n objects public int compare int i int j return index i index j 1 index i index j 0 1 nobjects public void swap int i int j long t1 index i index i index j index j t1 int t2 oids i oids i oids j oids j t2 public t query t create query return new query impl t this createquery queryimpl public synchronized t extends i persistent i persistent set t create scalable set return create scalable set 8 ipersistent ipersistentset createscalableset createscalableset public synchronized t extends i persistent i persistent set t create scalable set int initial size if opened throw new storage error storage error storage not opened return new scalable set this initial size ipersistent ipersistentset createscalableset initialsize storageerror storageerror storage_not_opened scalableset initialsize public t extends i persistent i persistent list t create list if opened throw new storage error storage error storage not opened return new persistent list impl t this ipersistent ipersistentlist createlist storageerror storageerror storage_not_opened persistentlistimpl public t extends i persistent i persistent list t create scalable list return create scalable list 8 ipersistent ipersistentlist createscalablelist createscalablelist public t extends i persistent i persistent list t create scalable list int initial size if opened throw new storage error storage error storage not opened return new scalable list t this initial size ipersistent ipersistentlist createscalablelist initialsize storageerror storageerror storage_not_opened scalablelist initialsize public k extends comparable v extends i persistent i persistent map k v create map class key type return create map key type 4 ipersistent ipersistentmap createmap keytype createmap keytype public k extends comparable v extends i persistent i persistent map k v create map class key type int initial size if opened throw new storage error storage error storage not opened return new persistent map impl k v this key type initial size ipersistent ipersistentmap createmap keytype initialsize storageerror storageerror storage_not_opened persistentmapimpl keytype initialsize public synchronized t extends i persistent i persistent set t create set if opened throw new storage error storage error storage not opened i persistent set t set alternative btree i persistent set t new alt persistent set t i persistent set t new persistent set t set assign oid this 0 false return set ipersistent ipersistentset createset storageerror storageerror storage_not_opened ipersistentset alternativebtree ipersistentset altpersistentset ipersistentset persistentset assignoid public synchronized t extends i persistent bit index t create bit index if opened throw new storage error storage error storage not opened bit index index new bit index impl t index assign oid this 0 false return index ipersistent bitindex createbitindex storageerror storageerror storage_not_opened bitindex bitindeximpl assignoid public synchronized t extends i persistent index t create index class key type boolean unique if opened throw new storage error storage error storage not opened index t index alternative btree index t new alt btree t key type unique index t new btree t key type unique index assign oid this 0 false return index ipersistent createindex keytype storageerror storageerror storage_not_opened alternativebtree altbtree keytype keytype assignoid public synchronized t extends i persistent index t create index class key types boolean unique if opened throw new storage error storage error storage not opened index t index alternative btree index t new alt btree compound index t key types unique index t new btree compound index t key types unique index assign oid this 0 false return index ipersistent createindex keytypes storageerror storageerror storage_not_opened alternativebtree altbtreecompoundindex keytypes btreecompoundindex keytypes assignoid public synchronized t extends i persistent multidimensional index t create multidimensional index multidimensional comparator t comparator if opened throw new storage error storage error storage not opened return new kd tree t this comparator ipersistent multidimensionalindex createmultidimensionalindex multidimensionalcomparator storageerror storageerror storage_not_opened kdtree public synchronized t extends i persistent multidimensional index t create multidimensional index class type string field names boolean treate zero as undefined value if opened throw new storage error storage error storage not opened return new kd tree t this type field names treate zero as undefined value ipersistent multidimensionalindex createmultidimensionalindex fieldnames treatezeroasundefinedvalue storageerror storageerror storage_not_opened kdtree fieldnames treatezeroasundefinedvalue public synchronized t extends i persistent index t create thick index class key type if opened throw new storage error storage error storage not opened return new thick index t key type this ipersistent createthickindex keytype storageerror storageerror storage_not_opened thickindex keytype public synchronized t extends i persistent spatial index t create spatial index if opened throw new storage error storage error storage not opened return new rtree t ipersistent spatialindex createspatialindex storageerror storageerror storage_not_opened public synchronized t extends i persistent spatial indexr2 t create spatial indexr2 if opened throw new storage error storage error storage not opened return new rtreer2 t this ipersistent spatialindexr2 createspatialindexr2 storageerror storageerror storage_not_opened public t extends i persistent field index t create field index class type string field name boolean unique return this t create field index type field name unique false ipersistent fieldindex createfieldindex fieldname createfieldindex fieldname public synchronized t extends i persistent field index t create field index class type string field name boolean unique boolean case insensitive if opened throw new storage error storage error storage not opened field index t index case insensitive alternative btree field index t new alt btree case insensitive field index t type field name unique field index t new btree case insensitive field index t type field name unique alternative btree field index t new alt btree field index t type field name unique field index t new btree field index t type field name unique index assign oid this 0 false return index ipersistent fieldindex createfieldindex fieldname caseinsensitive storageerror storageerror storage_not_opened fieldindex caseinsensitive alternativebtree fieldindex altbtreecaseinsensitivefieldindex fieldname fieldindex btreecaseinsensitivefieldindex fieldname alternativebtree fieldindex altbtreefieldindex fieldname fieldindex btreefieldindex fieldname assignoid public t extends i persistent field index t create field index class type string field names boolean unique return this t create field index type field names unique false ipersistent fieldindex createfieldindex fieldnames createfieldindex fieldnames public synchronized t extends i persistent field index t create field index class type string field names boolean unique boolean case insensitive if opened throw new storage error storage error storage not opened field index t index case insensitive alternative btree field index t new alt btree case insensitive multi field index type field names unique field index t new btree case insensitive multi field index type field names unique alternative btree field index t new alt btree multi field index type field names unique field index t new btree multi field index type field names unique index assign oid this 0 false return index ipersistent fieldindex createfieldindex fieldnames caseinsensitive storageerror storageerror storage_not_opened fieldindex caseinsensitive alternativebtree fieldindex altbtreecaseinsensitivemultifieldindex fieldnames fieldindex btreecaseinsensitivemultifieldindex fieldnames alternativebtree fieldindex altbtreemultifieldindex fieldnames fieldindex btreemultifieldindex fieldnames assignoid public synchronized t extends i persistent index t create random access index class key type boolean unique if opened throw new storage error storage error storage not opened index t index new rnd btree t key type unique index assign oid this 0 false return index ipersistent createrandomaccessindex keytype storageerror storageerror storage_not_opened rndbtree keytype assignoid public synchronized t extends i persistent index t create random access index class key types boolean unique if opened throw new storage error storage error storage not opened index t index new rnd btree compound index t key types unique index assign oid this 0 false return index ipersistent createrandomaccessindex keytypes storageerror storageerror storage_not_opened rndbtreecompoundindex keytypes assignoid public t extends i persistent field index t create random access field index class type string field name boolean unique return this t create random access field index type field name unique false ipersistent fieldindex createrandomaccessfieldindex fieldname createrandomaccessfieldindex fieldname public synchronized t extends i persistent field index t create random access field index class type string field name boolean unique boolean case insensitive if opened throw new storage error storage error storage not opened field index t index case insensitive field index new rnd btree case insensitive field index t type field name unique field index new rnd btree field index t type field name unique index assign oid this 0 false return index ipersistent fieldindex createrandomaccessfieldindex fieldname caseinsensitive storageerror storageerror storage_not_opened fieldindex caseinsensitive fieldindex rndbtreecaseinsensitivefieldindex fieldname fieldindex rndbtreefieldindex fieldname assignoid public t extends i persistent field index t create random access field index class type string field names boolean unique return this t create random access field index type field names unique false ipersistent fieldindex createrandomaccessfieldindex fieldnames createrandomaccessfieldindex fieldnames public synchronized t extends i persistent field index t create random access field index class type string field names boolean unique boolean case insensitive if opened throw new storage error storage error storage not opened field index t index case insensitive field index new rnd btree case insensitive multi field index type field names unique field index new rnd btree multi field index type field names unique index assign oid this 0 false return index ipersistent fieldindex createrandomaccessfieldindex fieldnames caseinsensitive storageerror storageerror storage_not_opened fieldindex caseinsensitive fieldindex rndbtreecaseinsensitivemultifieldindex fieldnames fieldindex rndbtreemultifieldindex fieldnames assignoid public t extends i persistent sorted collection t create sorted collection persistent comparator t comparator boolean unique if opened throw new storage error storage error storage not opened return new ttree t comparator unique ipersistent sortedcollection createsortedcollection persistentcomparator storageerror storageerror storage_not_opened public t extends i persistent comparable sorted collection t create sorted collection boolean unique if opened throw new storage error storage error storage not opened return new ttree t new default persistent comparator t unique ipersistent sortedcollection createsortedcollection storageerror storageerror storage_not_opened defaultpersistentcomparator public t extends i persistent link t create link return create link 8 ipersistent createlink createlink public t extends i persistent link t create link int initial size return new link impl t initial size ipersistent createlink initialsize linkimpl initialsize public m extends i persistent o extends i persistent relation m o create relation o owner return new relation impl m o owner ipersistent ipersistent createrelation relationimpl public blob create blob return new blob impl this page page size blob impl header size createblob blobimpl pagesize blobimpl headersize public blob create random access blob return new random access blob impl this createrandomaccessblob randomaccessblobimpl public t extends time series tick time series t create time series class block class long max block time interval return new time series impl t this block class max block time interval timeseries timeseries createtimeseries blockclass maxblocktimeinterval timeseriesimpl blockclass maxblocktimeinterval public t extends i persistent patricia trie t create patricia trie return new p trie t ipersistent patriciatrie createpatriciatrie ptrie public full text index create full text index full text search helper helper return new full text index impl this helper fulltextindex createfulltextindex fulltextsearchhelper fulltextindeximpl public full text index create full text index return create full text index new full text search helper this fulltextindex createfulltextindex createfulltextindex fulltextsearchhelper final long getgc pos int oid page pg pool get page header root curr index index long oid db handles per page bits page page size log long pos bytes unpack8 pg data oid db handles per page 1 3 pool unfix pg return pos getgcpos getpage currindex dbhandlesperpagebits pagesizelog dbhandlesperpage final void mark oid int oid if oid 0 long pos getgc pos oid if pos db free handle flag db page object flag 0 throw new storage error storage error invalid oid if pos header root curr index size object was not allocated by custom allocator int bit int pos db allocation quantum bits if black bitmap bit 5 1 bit 31 0 grey bitmap bit 5 1 bit 31 markoid getgcpos dbfreehandleflag dbpageobjectflag storageerror storageerror invalid_oid currindex dballocationquantumbits blackbitmap greybitmap final page getgc page int oid return pool get page getgc pos oid db flags mask getgcpage getpage getgcpos dbflagsmask public void set gc threshold long max allocated delta gc threshold max allocated delta setgcthreshold maxallocateddelta gcthreshold maxallocateddelta private void mark int bitmap size int header root curr index size db allocation quantum bits 5 1 boolean exists not marked objects long pos int i j if listener null listener gc started grey bitmap new int bitmap size black bitmap new int bitmap size int root oid header root curr index root object if root oid 0 mark oid root oid do exists not marked objects false for i 0 i bitmap size i if grey bitmap i 0 exists not marked objects true for j 0 j 32 j if grey bitmap i 1 j 0 pos long i 5 j db allocation quantum bits grey bitmap i 1 j black bitmap i 1 j int offs int pos page page size 1 page pg pool get page pos offs int type oid object header get type pg data offs if type oid 0 class descriptor desc find class descriptor type oid if btree class is assignable from desc cls btree btree new btree pg data object header sizeof offs btree assign oid this 0 false btree mark tree else if desc has references mark object pool get pos object header sizeof desc pool unfix pg while exists not marked objects bitmapsize currindex dballocationquantumbits existsnotmarkedobjects gcstarted greybitmap bitmapsize blackbitmap bitmapsize rootoid currindex rootobject rootoid markoid rootoid existsnotmarkedobjects bitmapsize greybitmap existsnotmarkedobjects greybitmap dballocationquantumbits greybitmap blackbitmap pagesize getpage typeoid objectheader gettype typeoid classdescriptor findclassdescriptor typeoid isassignablefrom objectheader assignoid marktree hasreferences markobject objectheader existsnotmarkedobjects private int sweep int n deallocated 0 long pos gc done true for int i db first user id j committed index size i j i pos getgc pos i if pos 0 int pos db page object flag db free handle flag 0 int bit int pos db allocation quantum bits if black bitmap bit 5 1 bit 31 0 object is not accessible if get pos i pos int offs int pos page page size 1 page pg pool get page pos offs int type oid object header get type pg data offs if type oid 0 class descriptor desc find class descriptor type oid n deallocated 1 if btree class is assignable from desc cls btree btree new btree pg data object header sizeof offs pool unfix pg btree assign oid this i false btree deallocate else int size object header get size pg data offs pool unfix pg free id i object cache remove i clone bitmap pos size if listener null listener deallocate object desc cls i grey bitmap null black bitmap null allocated delta 0 gc active false if listener null listener gc completed n deallocated return n deallocated ndeallocated gcdone dbfirstuserid committedindexsize getgcpos dbpageobjectflag dbfreehandleflag dballocationquantumbits blackbitmap getpos pagesize getpage typeoid objectheader gettype typeoid classdescriptor findclassdescriptor typeoid ndeallocated isassignablefrom objectheader assignoid objectheader getsize freeid objectcache clonebitmap deallocateobject greybitmap blackbitmap allocateddelta gcactive gccompleted ndeallocated ndeallocated private boolean go gc thread start gcthread void activate synchronized background gc start monitor go true background gc start monitor notify backgroundgcstartmonitor backgroundgcstartmonitor public void run try while true synchronized background gc start monitor while go opened background gc start monitor wait if opened return go false synchronized background gc monitor if opened return mark synchronized storage impl this synchronized object cache sweep catch interrupted exception x backgroundgcstartmonitor backgroundgcstartmonitor backgroundgcmonitor storageimpl objectcache interruptedexception public synchronized int gc return gc0 private int gc0 synchronized object cache if opened throw new storage error storage error storage not opened if gc done gc active return 0 gc active true if background gc if gc thread null gc thread new gc thread gc thread activate return 0 system out println start gc allocated delta allocated delta header curr index size header root curr index size gc treshold gc threshold mark return sweep objectcache storageerror storageerror storage_not_opened gcdone gcactive gcactive backgroundgc gcthread gcthread gcthread gcthread allocateddelta allocateddelta currindex currindex gctreshold gcthreshold public synchronized hash map get memory dump synchronized object cache if opened throw new storage error storage error storage not opened int bitmap size int header root curr index size db allocation quantum bits 5 1 boolean exists not marked objects long pos int i j n mark grey bitmap new int bitmap size black bitmap new int bitmap size int root oid header root curr index root object hash map map new hash map if root oid 0 memory usage index usage new memory usage index class memory usage field index usage new memory usage field index class memory usage class usage new memory usage class class mark oid root oid do exists not marked objects false for i 0 i bitmap size i if grey bitmap i 0 exists not marked objects true for j 0 j 32 j if grey bitmap i 1 j 0 pos long i 5 j db allocation quantum bits grey bitmap i 1 j black bitmap i 1 j int offs int pos page page size 1 page pg pool get page pos offs int type oid object header get type pg data offs int obj size object header get size pg data offs int aligned size obj size db allocation quantum 1 db allocation quantum 1 if type oid 0 mark oid type oid class descriptor desc find class descriptor type oid if btree class is assignable from desc cls btree btree new btree pg data object header sizeof offs btree assign oid this 0 false int n pages btree mark tree if field index class is assignable from desc cls field index usage n instances 1 field index usage total size long n pages page page size obj size field index usage allocated size long n pages page page size aligned size else index usage n instances 1 index usage total size long n pages page page size obj size index usage allocated size long n pages page page size aligned size else memory usage usage memory usage map get desc cls if usage null usage new memory usage desc cls map put desc cls usage usage n instances 1 usage total size obj size usage allocated size aligned size if desc has references mark object pool get pos object header sizeof desc else class usage n instances 1 class usage total size obj size class usage allocated size aligned size pool unfix pg while exists not marked objects if index usage n instances 0 map put index class index usage if field index usage n instances 0 map put field index class field index usage if class usage n instances 0 map put class class class usage memory usage system new memory usage storage class system total size header root 0 index size 8l system total size header root 1 index size 8l system total size long header root curr index bitmap end db bitmap id page page size system total size page page size root page if header root curr index bitmap extent 0 system allocated size get bitmap used space db bitmap id db bitmap id db bitmap pages get bitmap used space header root curr index bitmap extent db bitmap pages bitmap extent base header root curr index bitmap extent header root curr index bitmap end db bitmap id bitmap extent base else system allocated size get bitmap used space db bitmap id header root curr index bitmap end system n instances header root curr index index size map put storage class system return map hashmap getmemorydump objectcache storageerror storageerror storage_not_opened bitmapsize currindex dballocationquantumbits existsnotmarkedobjects greybitmap bitmapsize blackbitmap bitmapsize rootoid currindex rootobject hashmap hashmap rootoid memoryusage indexusage memoryusage memoryusage fieldindexusage memoryusage fieldindex memoryusage classusage memoryusage markoid rootoid existsnotmarkedobjects bitmapsize greybitmap existsnotmarkedobjects greybitmap dballocationquantumbits greybitmap blackbitmap pagesize getpage typeoid objectheader gettype objsize objectheader getsize alignedsize objsize dballocationquantum dballocationquantum typeoid markoid typeoid classdescriptor findclassdescriptor typeoid isassignablefrom objectheader assignoid npages marktree fieldindex isassignablefrom fieldindexusage ninstances fieldindexusage totalsize npages pagesize objsize fieldindexusage allocatedsize npages pagesize alignedsize indexusage ninstances indexusage totalsize npages pagesize objsize indexusage allocatedsize npages pagesize alignedsize memoryusage memoryusage memoryusage ninstances totalsize objsize allocatedsize alignedsize hasreferences markobject objectheader classusage ninstances classusage totalsize objsize classusage allocatedsize alignedsize existsnotmarkedobjects indexusage ninstances indexusage fieldindexusage ninstances fieldindex fieldindexusage classusage ninstances classusage memoryusage memoryusage totalsize indexsize totalsize indexsize totalsize currindex bitmapend dbbitmapid pagesize totalsize pagesize currindex bitmapextent allocatedsize getbitmapusedspace dbbitmapid dbbitmapid dbbitmappages getbitmapusedspace currindex bitmapextent dbbitmappages bitmapextentbase currindex bitmapextent currindex bitmapend dbbitmapid bitmapextentbase allocatedsize getbitmapusedspace dbbitmapid currindex bitmapend ninstances currindex indexsize final long get bitmap used space int from int till long allocated 0 while from till page pg getgc page from for int j 0 j page page size j int mask pg data j 0xff while mask 0 if mask 1 0 allocated db allocation quantum mask 1 pool unfix pg from 1 return allocated getbitmapusedspace getgcpage pagesize dballocationquantum final int mark object byte obj int offs class descriptor desc class descriptor field descriptor all desc all fields for int i 0 n all length i n i class descriptor field descriptor fd all i switch fd type case class descriptor tp boolean case class descriptor tp byte offs 1 continue case class descriptor tp char case class descriptor tp short offs 2 continue case class descriptor tp int case class descriptor tp enum case class descriptor tp float offs 4 continue case class descriptor tp long case class descriptor tp double case class descriptor tp date offs 8 continue case class descriptor tp string int strlen bytes unpack4 obj offs offs 4 if strlen 0 offs strlen 2 else if strlen 1 offs strlen 2 continue case class descriptor tp object mark oid bytes unpack4 obj offs offs 4 continue case class descriptor tp value offs mark object obj offs fd value desc continue case class descriptor tp raw int len bytes unpack4 obj offs offs 4 if len 0 offs len else if len 2 class descriptor tp object mark oid bytes unpack4 obj offs offs 4 else if len 1 offs class descriptor sizeof 2 len continue case class descriptor tp custom try byte array input stream in new byte array input stream obj offs obj length offs serializer unpack in offs obj length in available catch io exception x throw new storage error storage error access violation x continue case class descriptor tp array of byte case class descriptor tp array of boolean int len bytes unpack4 obj offs offs 4 if len 0 offs len continue case class descriptor tp array of short case class descriptor tp array of char int len bytes unpack4 obj offs offs 4 if len 0 offs len 2 continue case class descriptor tp array of int case class descriptor tp array of enum case class descriptor tp array of float int len bytes unpack4 obj offs offs 4 if len 0 offs len 4 continue case class descriptor tp array of long case class descriptor tp array of double case class descriptor tp array of date int len bytes unpack4 obj offs offs 4 if len 0 offs len 8 continue case class descriptor tp array of string int len bytes unpack4 obj offs offs 4 while len 0 int strlen bytes unpack4 obj offs offs 4 if strlen 0 offs strlen 2 else if strlen 1 offs strlen 2 continue case class descriptor tp array of object case class descriptor tp link int len bytes unpack4 obj offs offs 4 while len 0 mark oid bytes unpack4 obj offs offs 4 continue case class descriptor tp array of value int len bytes unpack4 obj offs offs 4 class descriptor value desc fd value desc while len 0 offs mark object obj offs value desc continue case class descriptor tp array of raw int len bytes unpack4 obj offs offs 4 while len 0 int rawlen bytes unpack4 obj offs offs 4 if rawlen 0 offs rawlen else if rawlen 2 class descriptor tp object mark oid bytes unpack4 obj offs offs 4 else if rawlen 1 offs class descriptor sizeof 2 rawlen continue continue return offs markobject classdescriptor classdescriptor fielddescriptor allfields classdescriptor fielddescriptor classdescriptor tpboolean classdescriptor tpbyte classdescriptor tpchar classdescriptor tpshort classdescriptor tpint classdescriptor tpenum classdescriptor tpfloat classdescriptor tplong classdescriptor tpdouble classdescriptor tpdate classdescriptor tpstring classdescriptor tpobject markoid classdescriptor tpvalue markobject valuedesc classdescriptor tpraw classdescriptor tpobject markoid classdescriptor classdescriptor tpcustom bytearrayinputstream bytearrayinputstream ioexception storageerror storageerror access_violation classdescriptor tparrayofbyte classdescriptor tparrayofboolean classdescriptor tparrayofshort classdescriptor tparrayofchar classdescriptor tparrayofint classdescriptor tparrayofenum classdescriptor tparrayoffloat classdescriptor tparrayoflong classdescriptor tparrayofdouble classdescriptor tparrayofdate classdescriptor tparrayofstring classdescriptor tparrayofobject classdescriptor tplink markoid classdescriptor tparrayofvalue classdescriptor valuedesc valuedesc markobject valuedesc classdescriptor tparrayofraw classdescriptor tpobject markoid classdescriptor this method is used internally by perst to get transaction context associated with current thread but it can be also used by application to get transaction context store it in some variable and use in another thread i will make it possible to share one transaction between multiple threads return transaction context associated with current thread public thread transaction context get transaction context return thread transaction context transaction context get threadtransactioncontext gettransactioncontext threadtransactioncontext transactioncontext associate transaction context with the thread this method can be used by application to share the same transaction between multiple threads param ctx new transaction context return transaction context previously associated with this thread public thread transaction context set transaction context thread transaction context ctx thread transaction context old ctx thread transaction context transaction context get transaction context set ctx return old ctx threadtransactioncontext settransactioncontext threadtransactioncontext threadtransactioncontext oldctx threadtransactioncontext transactioncontext transactioncontext oldctx public void begin thread transaction int mode switch mode case serializable transaction if multiclient support throw new illegal argument exception illegal transaction mode use serializable transactions true get transaction context nested 1 break case exclusive transaction case cooperative transaction if multiclient support if mode exclusive transaction transaction lock exclusive lock else transaction lock shared lock synchronized transaction monitor if n nested transactions 0 file lock mode read only transaction byte buf new byte header sizeof int rc file read 0 buf if rc 0 rc header sizeof throw new storage error storage error database corrupted header unpack buf int curr header curr curr index curr curr index size header root 1 curr index used committed index size curr index size used size header root curr size if header transaction id transaction id if bitmap page available space null for int i 0 i bitmap page available space length i bitmap page available space i integer max value object cache clear pool clear transaction id header transaction id else synchronized transaction monitor if scheduled commit time long max value n blocked transactions 1 while system current time millis scheduled commit time try transaction monitor wait catch interrupted exception x n blocked transactions 1 n nested transactions 1 if mode exclusive transaction transaction lock exclusive lock else transaction lock shared lock break default throw new illegal argument exception illegal transaction mode beginthreadtransaction serializable_transaction multiclientsupport illegalargumentexception useserializabletransactions gettransactioncontext exclusive_transaction cooperative_transaction multiclientsupport exclusive_transaction transactionlock exclusivelock transactionlock sharedlock transactionmonitor nnestedtransactions read_only_transaction storageerror storageerror database_corrupted currindex currindexsize indexused committedindexsize currindexsize usedsize transactionid transactionid bitmappageavailablespace bitmappageavailablespace bitmappageavailablespace max_value objectcache transactionid transactionid transactionmonitor scheduledcommittime max_value nblockedtransactions currenttimemillis scheduledcommittime transactionmonitor interruptedexception nblockedtransactions nnestedtransactions exclusive_transaction transactionlock exclusivelock transactionlock sharedlock illegalargumentexception public void end thread transaction end thread transaction integer max value endthreadtransaction endthreadtransaction max_value public void end thread transaction int max delay if multiclient support if max delay integer max value throw new illegal argument exception delay is not supported for global transactions synchronized transaction monitor transaction lock unlock if n nested transactions 0 may be everything is already aborted if n nested transactions 0 commit pool flush file unlock return thread transaction context ctx get transaction context if ctx nested 0 serializable transaction if ctx nested 0 array list modified ctx modified array list deleted ctx deleted map locked ctx locked synchronized background gc monitor synchronized this synchronized object cache for int i modified size i 0 i persistent modified get i store for int i deleted size i 0 deallocate object0 i persistent deleted get i if modified size deleted size 0 commit0 iterator iterator locked values iterator while iterator has next i resource iterator next reset modified clear deleted clear locked clear else exclusive or cooperative transaction synchronized transaction monitor transaction lock unlock if n nested transactions 0 may be everything is already aborted if n nested transactions 0 n committed transactions 1 commit scheduled commit time long max value if n blocked transactions 0 transaction monitor notify all else if max delay integer max value long next commit system current time millis max delay if next commit scheduled commit time scheduled commit time next commit if max delay 0 int n n committed transactions n blocked transactions 1 do try transaction monitor wait catch interrupted exception x while n committed transactions n n blocked transactions 1 endthreadtransaction maxdelay multiclientsupport maxdelay max_value illegalargumentexception transactionmonitor transactionlock nnestedtransactions nnestedtransactions threadtransactioncontext gettransactioncontext arraylist arraylist backgroundgcmonitor objectcache ipersistent deallocateobject0 ipersistent hasnext iresource transactionmonitor transactionlock nnestedtransactions nnestedtransactions ncommittedtransactions scheduledcommittime max_value nblockedtransactions transactionmonitor notifyall maxdelay max_value nextcommit currenttimemillis maxdelay nextcommit scheduledcommittime scheduledcommittime nextcommit maxdelay ncommittedtransactions nblockedtransactions transactionmonitor interruptedexception ncommittedtransactions nblockedtransactions public void rollback thread transaction if multiclient support synchronized transaction monitor transaction lock reset n nested transactions 0 rollback file unlock return thread transaction context ctx get transaction context if ctx nested 0 serializable transaction array list modified ctx modified map locked ctx locked synchronized this synchronized object cache int i modified size while i 0 i persistent obj i persistent modified get i int oid obj get oid if get pos oid 0 free id oid obj invalidate object cache clear dirty obj iterator iterator locked values iterator while iterator has next i resource iterator next reset ctx nested 0 modified clear ctx deleted clear locked clear else synchronized transaction monitor transaction lock reset n nested transactions 0 if n blocked transactions 0 transaction monitor notify all rollback rollbackthreadtransaction multiclientsupport transactionmonitor transactionlock nnestedtransactions threadtransactioncontext gettransactioncontext arraylist objectcache ipersistent ipersistent getoid getpos freeid objectcache cleardirty hasnext iresource transactionmonitor transactionlock nnestedtransactions nblockedtransactions transactionmonitor notifyall public protected boolean lock object i persistent obj if use serializable transactions thread transaction context ctx get transaction context if ctx nested 0 serializable transaction return ctx locked put obj obj null return true lockobject ipersistent useserializabletransactions threadtransactioncontext gettransactioncontext public void close synchronized background gc monitor commit opened false if gc thread null gc thread activate try gc thread join catch interrupted exception x if is dirty page pg pool put page 0 header pack pg data pool flush pool modify pg header dirty false header pack pg data pool unfix pg pool flush pool close make gc easier pool null object cache null class desc map null bitmap page available space null dirty pages map null desc list null backgroundgcmonitor gcthread gcthread gcthread interruptedexception isdirty putpage objectcache classdescmap bitmappageavailablespace dirtypagesmap desclist public synchronized void exportxml java io writer writer throws java io io exception if opened throw new storage error storage error storage not opened object cache flush int root oid header root 1 curr index root object if root oid 0 xml exporter xml exporter new xml exporter this writer xml exporter export database root oid ioexception storageerror storageerror storage_not_opened objectcache rootoid currindex rootobject rootoid xmlexporter xmlexporter xmlexporter xmlexporter exportdatabase rootoid public synchronized void importxml java io reader reader throws xml import exception if opened throw new storage error storage error storage not opened xml importer xml importer new xml importer this reader xml importer import database xmlimportexception storageerror storageerror storage_not_opened xmlimporter xmlimporter xmlimporter xmlimporter importdatabase private boolean get boolean value object value if value instanceof boolean return boolean value boolean value else if value instanceof string string s string value if true equals ignore case s t equals ignore case s 1 equals s return true else if false equals ignore case s f equals ignore case s 0 equals s return false throw new storage error storage error bad property value getbooleanvalue booleanvalue equalsignorecase equalsignorecase equalsignorecase equalsignorecase storageerror storageerror bad_property_value private long get integer value object value if value instanceof number return number value long value else if value instanceof string try return long parse long string value 10 catch number format exception x throw new storage error storage error bad property value getintegervalue longvalue parselong numberformatexception storageerror storageerror bad_property_value public void set properties properties props string value properties put all props if value props get property perst implicit values null class descriptor treate any non persistent object as value get boolean value value if value props get property perst serialize transient objects null class descriptor serialize non persistent objects get boolean value value if value props get property perst object cache init size null object cache init size int get integer value value if object cache init size 0 throw new illegal argument exception initial object cache size should be positive if value props get property perst object cache kind null cache kind value if value props get property perst object index init size null init index size int get integer value value if value props get property perst extension quantum null extension quantum get integer value value if value props get property perst gc threshold null gc threshold get integer value value if value props get property perst file readonly null read only get boolean value value if value props get property perst file noflush null no flush get boolean value value if value props get property perst alternative btree null alternative btree get boolean value value if value props get property perst background gc null background gc get boolean value value if value props get property perst string encoding null encoding value if value props get property perst lock file null lock file get boolean value value if value props get property perst replication ack null replication ack get boolean value value if value props get property perst concurrent iterator null concurrent iterator get boolean value value if value props get property perst slave connection timeout null slave connection timeout int get integer value value if value props get property perst force store null force store get boolean value value if value props get property perst page pool lru limit null page pool lru limit get integer value value if value props get property perst multiclient support null multiclient support get boolean value value if multiclient support background gc throw new illegal argument exception in mutliclient access mode bachround gc is not supported setproperties putall getproperty classdescriptor treateanynonpersistentobjectasvalue getbooleanvalue getproperty classdescriptor serializenonpersistentobjects getbooleanvalue getproperty objectcacheinitsize getintegervalue objectcacheinitsize illegalargumentexception getproperty cachekind getproperty initindexsize getintegervalue getproperty extensionquantum getintegervalue getproperty gcthreshold getintegervalue getproperty readonly getbooleanvalue getproperty noflush getbooleanvalue getproperty alternativebtree getbooleanvalue getproperty backgroundgc getbooleanvalue getproperty getproperty lockfile getbooleanvalue getproperty replicationack getbooleanvalue getproperty concurrentiterator getbooleanvalue getproperty slaveconnectiontimeout getintegervalue getproperty forcestore getbooleanvalue getproperty pagepoollrulimit getintegervalue getproperty multiclientsupport getbooleanvalue multiclientsupport backgroundgc illegalargumentexception public void set property string name object value properties put name value if name equals perst implicit values class descriptor treate any non persistent object as value get boolean value value else if name equals perst serialize transient objects class descriptor serialize non persistent objects get boolean value value else if name equals perst object cache init size object cache init size int get integer value value if object cache init size 0 throw new illegal argument exception initial object cache size should be positive else if name equals perst object cache kind cache kind string value else if name equals perst object index init size init index size int get integer value value else if name equals perst extension quantum extension quantum get integer value value else if name equals perst gc threshold gc threshold get integer value value else if name equals perst file readonly read only get boolean value value else if name equals perst file noflush no flush get boolean value value else if name equals perst alternative btree alternative btree get boolean value value else if name equals perst background gc background gc get boolean value value else if name equals perst string encoding encoding value null null value to string else if name equals perst lock file lock file get boolean value value else if name equals perst replication ack replication ack get boolean value value else if name equals perst concurrent iterator concurrent iterator get boolean value value else if name equals perst slave connection timeout slave connection timeout int get integer value value else if name equals perst force store force store get boolean value value else if name equals perst page pool lru limit page pool lru limit get integer value value else if name equals perst multiclient support multiclient support get boolean value value else throw new storage error storage error no such property if multiclient support background gc throw new illegal argument exception in mutliclient access mode bachround gc is not supported setproperty classdescriptor treateanynonpersistentobjectasvalue getbooleanvalue classdescriptor serializenonpersistentobjects getbooleanvalue objectcacheinitsize getintegervalue objectcacheinitsize illegalargumentexception cachekind initindexsize getintegervalue extensionquantum getintegervalue gcthreshold getintegervalue readonly getbooleanvalue noflush getbooleanvalue alternativebtree getbooleanvalue backgroundgc getbooleanvalue tostring lockfile getbooleanvalue replicationack getbooleanvalue concurrentiterator getbooleanvalue slaveconnectiontimeout getintegervalue forcestore getbooleanvalue pagepoollrulimit getintegervalue multiclientsupport getbooleanvalue storageerror storageerror no_such_property multiclientsupport backgroundgc illegalargumentexception public object get property string name return properties get name getproperty public properties get properties return properties getproperties public storage listener set listener storage listener listener storage listener prev listener this listener this listener listener return prev listener storagelistener setlistener storagelistener storagelistener prevlistener prevlistener public synchronized i persistent get object byoid int oid return oid 0 null lookup object oid null ipersistent getobjectbyoid lookupobject public protected synchronized void modify object i persistent obj synchronized object cache if obj is modified if use serializable transactions thread transaction context ctx get transaction context if ctx nested 0 serializable transaction ctx modified add obj return object cache set dirty obj modifyobject ipersistent objectcache ismodified useserializabletransactions threadtransactioncontext gettransactioncontext objectcache setdirty public protected synchronized void store object i persistent obj if opened throw new storage error storage error storage not opened synchronized object cache store object0 obj false storeobject ipersistent storageerror storageerror storage_not_opened objectcache storeobject0 public protected void store finalized object i persistent obj if opened synchronized object cache if obj get oid 0 store object0 obj true storefinalizedobject ipersistent objectcache getoid storeobject0 public synchronized int make persistent i persistent obj if opened throw new storage error storage error storage not opened if obj null return 0 int oid obj get oid if oid 0 return oid if force store use serializable transactions get transaction context nested 0 synchronized object cache store object0 obj false return obj get oid else synchronized object cache oid allocate id obj assign oid this oid false set pos oid 0 object cache put oid obj obj modify return oid makepersistent ipersistent storageerror storageerror storage_not_opened getoid forcestore useserializabletransactions gettransactioncontext objectcache storeobject0 getoid objectcache allocateid assignoid setpos objectcache private final custom allocator get custom allocator class cls object a custom allocator map get cls if a null return a default allocator null custom allocator a class superclass cls get superclass if superclass null custom allocator alloc get custom allocator superclass if alloc null custom allocator map put cls alloc return alloc class interfaces cls get interfaces for int i 0 i interfaces length i custom allocator alloc get custom allocator interfaces i if alloc null custom allocator map put cls alloc return alloc custom allocator map put cls default allocator return null customallocator getcustomallocator customallocatormap defaultallocator customallocator getsuperclass customallocator getcustomallocator customallocatormap getinterfaces customallocator getcustomallocator customallocatormap customallocatormap defaultallocator private final void store object0 i persistent obj boolean finalized obj on store int oid obj get oid boolean new object false if oid 0 oid allocate id if finalized object cache put oid obj obj assign oid this oid false new object true else if obj is modified object cache clear dirty obj byte data pack object obj finalized long pos int new size object header get size data 0 custom allocator allocator custom allocator map null get custom allocator obj get class null if new object pos get pos oid 0 pos allocator null allocator allocate new size allocate new size 0 set pos oid pos db modified flag else int offs int pos page page size 1 if offs db free handle flag db page object flag 0 throw new storage error storage error deleted object page pg pool get page pos offs int size object header get size pg data offs db flags mask pool unfix pg if pos db modified flag 0 if allocator null allocator free pos db flags mask size pos allocator allocate new size else clone bitmap pos db flags mask size pos allocate new size 0 set pos oid pos db modified flag else pos db flags mask if new size size if allocator null long new pos allocator reallocate pos size new size if new pos pos pos new pos set pos oid pos db modified flag else if new size size object header set size data 0 size else if new size db allocation quantum 1 db allocation quantum 1 size db allocation quantum 1 db allocation quantum 1 long new pos allocate new size 0 clone bitmap pos size free pos size pos new pos set pos oid pos db modified flag else if new size size object header set size data 0 size modified true pool put pos data new size storeobject0 ipersistent onstore getoid newobject allocateid objectcache assignoid newobject ismodified objectcache cleardirty packobject newsize objectheader getsize customallocator customallocatormap getcustomallocator getclass newobject getpos newsize newsize setpos dbmodifiedflag pagesize dbfreehandleflag dbpageobjectflag storageerror storageerror deleted_object getpage objectheader getsize dbflagsmask dbmodifiedflag dbflagsmask newsize clonebitmap dbflagsmask newsize setpos dbmodifiedflag dbflagsmask newsize newpos newsize newpos newpos setpos dbmodifiedflag newsize objectheader setsize newsize dballocationquantum dballocationquantum dballocationquantum dballocationquantum newpos newsize clonebitmap newpos setpos dbmodifiedflag newsize objectheader setsize newsize public protected synchronized void load object i persistent obj if obj is raw load stub obj get oid obj obj get class loadobject ipersistent israw loadstub getoid getclass final synchronized i persistent lookup object int oid class cls i persistent obj object cache get oid if obj null obj is raw obj load stub oid obj cls return obj ipersistent lookupobject ipersistent objectcache israw loadstub protected int swizzle i persistent obj boolean finalized int oid 0 if obj null if obj is persistent store object0 obj finalized oid obj get oid return oid ipersistent ispersistent storeobject0 getoid final class descriptor find class descriptor int oid return class descriptor lookup object oid class descriptor class classdescriptor findclassdescriptor classdescriptor lookupobject classdescriptor protected i persistent unswizzle int oid class cls boolean recursive loading if oid 0 return null if recursive loading return lookup object oid cls i persistent stub object cache get oid if stub null return stub class descriptor desc if cls persistent class desc find class descriptor cls null desc has subclasses long pos get pos oid int offs int pos page page size 1 if offs db free handle flag db page object flag 0 throw new storage error storage error deleted object page pg pool get page pos offs int type oid object header get type pg data offs db flags mask pool unfix pg desc find class descriptor type oid stub i persistent desc new instance stub assign oid this oid true object cache put oid stub return stub ipersistent recursiveloading recursiveloading lookupobject ipersistent objectcache classdescriptor findclassdescriptor hassubclasses getpos pagesize dbfreehandleflag dbpageobjectflag storageerror storageerror deleted_object getpage typeoid objectheader gettype dbflagsmask findclassdescriptor typeoid ipersistent newinstance assignoid objectcache final i persistent load stub int oid i persistent obj class cls long pos get pos oid if pos db free handle flag db page object flag 0 throw new storage error storage error deleted object byte body pool get pos db flags mask class descriptor desc int type oid object header get type body 0 if type oid 0 desc find class descriptor cls else desc find class descriptor type oid if obj null obj i persistent desc new instance object cache put oid obj obj assign oid this oid false if obj instanceof fast serializable fast serializable obj unpack body object header sizeof encoding else try unpack object obj desc obj recursive loading body object header sizeof obj catch exception x throw new storage error storage error access violation x obj on load return obj ipersistent loadstub ipersistent getpos dbfreehandleflag dbpageobjectflag storageerror storageerror deleted_object dbflagsmask classdescriptor typeoid objectheader gettype typeoid findclassdescriptor findclassdescriptor typeoid ipersistent newinstance objectcache assignoid fastserializable fastserializable objectheader unpackobject recursiveloading objectheader storageerror storageerror access_violation onload class persistent object input stream extends object input stream persistent object input stream input stream in throws io exception super in enable resolve object true persistentobjectinputstream objectinputstream persistentobjectinputstream inputstream ioexception enableresolveobject protected object resolve object object obj throws io exception if obj instanceof i persistent int oid i persistent obj get oid if oid 0 return lookup object oid obj get class return obj resolveobject ioexception ipersistent ipersistent getoid lookupobject getclass protected class resolve class object stream class desc throws io exception class not found exception string class loader name null if loader map null class loader name string read object class loader cl class loader name null find class loader class loader name loader if cl null try return class for name desc get name false cl catch class not found exception x return super resolve class desc resolveclass objectstreamclass ioexception classnotfoundexception classloadername loadermap classloadername readobject classloader classloadername findclassloader classloadername forname getname classnotfoundexception resolveclass public class persistent object output stream extends object output stream persistent object output stream output stream out throws io exception super out persistentobjectoutputstream objectoutputstream persistentobjectoutputstream outputstream ioexception public storage get storage return storage impl this getstorage storageimpl public class annotated persistent object output stream extends persistent object output stream annotated persistent object output stream output stream out throws io exception super out annotatedpersistentobjectoutputstream persistentobjectoutputstream annotatedpersistentobjectoutputstream outputstream ioexception protected void annotate class class cls throws io exception class loader loader cls get class loader write object loader instanceof i named class loader i named class loader loader get name null annotateclass ioexception classloader getclassloader writeobject inamedclassloader inamedclassloader getname final int unpack object object obj class descriptor desc boolean recursive loading byte body int offs i persistent po throws exception class descriptor field descriptor all desc all fields reflection provider provider class descriptor get reflection provider int len for int i 0 n all length i n i class descriptor field descriptor fd all i field f fd field if f null obj null switch fd type case class descriptor tp boolean case class descriptor tp byte offs 1 continue case class descriptor tp char case class descriptor tp short offs 2 continue case class descriptor tp int case class descriptor tp float case class descriptor tp object case class descriptor tp enum offs 4 continue case class descriptor tp long case class descriptor tp double case class descriptor tp date offs 8 continue case class descriptor tp string len bytes unpack4 body offs offs 4 if len 0 offs len 2 else if len 1 offs len 2 continue case class descriptor tp value offs unpack object null fd value desc recursive loading body offs po continue case class descriptor tp raw case class descriptor tp array of byte case class descriptor tp array of boolean len bytes unpack4 body offs offs 4 if len 0 offs len else if len 1 offs class descriptor sizeof 2 len continue case class descriptor tp custom byte array input stream in new byte array input stream body offs body length offs serializer unpack in offs body length in available continue case class descriptor tp array of short case class descriptor tp array of char len bytes unpack4 body offs offs 4 if len 0 offs len 2 continue case class descriptor tp array of int case class descriptor tp array of enum case class descriptor tp array of float case class descriptor tp array of object case class descriptor tp link len bytes unpack4 body offs offs 4 if len 0 offs len 4 continue case class descriptor tp array of long case class descriptor tp array of double case class descriptor tp array of date len bytes unpack4 body offs offs 4 if len 0 offs len 8 continue case class descriptor tp array of string len bytes unpack4 body offs offs 4 if len 0 for int j 0 j len j int strlen bytes unpack4 body offs offs 4 if strlen 0 offs strlen 2 else if strlen 1 offs strlen 2 continue case class descriptor tp array of value len bytes unpack4 body offs offs 4 if len 0 class descriptor value desc fd value desc for int j 0 j len j offs unpack object null value desc recursive loading body offs po continue case class descriptor tp array of raw len bytes unpack4 body offs offs 4 if len 0 for int j 0 j len j int rawlen bytes unpack4 body offs offs 4 if rawlen 0 offs rawlen else if rawlen 1 offs class descriptor sizeof 2 rawlen continue else if offs body length switch fd type case class descriptor tp boolean provider set boolean f obj body offs 0 continue case class descriptor tp byte provider set byte f obj body offs continue case class descriptor tp char provider set char f obj char bytes unpack2 body offs offs 2 continue case class descriptor tp short provider set short f obj bytes unpack2 body offs offs 2 continue case class descriptor tp int provider set int f obj bytes unpack4 body offs offs 4 continue case class descriptor tp long provider set long f obj bytes unpack8 body offs offs 8 continue case class descriptor tp float provider set float f obj float int bits to float bytes unpack4 body offs offs 4 continue case class descriptor tp double provider set double f obj double long bits to double bytes unpack8 body offs offs 8 continue case class descriptor tp enum int index bytes unpack4 body offs if index 0 provider set f obj fd field get type get enum constants index else provider set f obj null offs 4 continue case class descriptor tp string len bytes unpack4 body offs offs 4 string str null if len 0 char chars new char len for int j 0 j len j chars j char bytes unpack2 body offs offs 2 str new string chars else if len 1 if encoding null str new string body offs 2 len encoding else str new string body offs 2 len offs 2 len provider set f obj str continue case class descriptor tp date long msec bytes unpack8 body offs offs 8 date date null if msec 0 date new date msec provider set f obj date continue case class descriptor tp object provider set f obj unswizzle bytes unpack4 body offs f get type recursive loading offs 4 continue case class descriptor tp value object value fd value desc new instance offs unpack object value fd value desc recursive loading body offs po provider set f obj value continue case class descriptor tp raw len bytes unpack4 body offs offs 4 if len 0 byte array input stream bin new byte array input stream body offs len object input stream in new persistent object input stream bin provider set f obj in read object in close offs len else if len 0 object unpackobject classdescriptor recursiveloading ipersistent classdescriptor fielddescriptor allfields reflectionprovider classdescriptor getreflectionprovider classdescriptor fielddescriptor classdescriptor tpboolean classdescriptor tpbyte classdescriptor tpchar classdescriptor tpshort classdescriptor tpint classdescriptor tpfloat classdescriptor tpobject classdescriptor tpenum classdescriptor tplong classdescriptor tpdouble classdescriptor tpdate classdescriptor tpstring classdescriptor tpvalue unpackobject valuedesc recursiveloading classdescriptor tpraw classdescriptor tparrayofbyte classdescriptor tparrayofboolean classdescriptor classdescriptor tpcustom bytearrayinputstream bytearrayinputstream classdescriptor tparrayofshort classdescriptor tparrayofchar classdescriptor tparrayofint classdescriptor tparrayofenum classdescriptor tparrayoffloat classdescriptor tparrayofobject classdescriptor tplink classdescriptor tparrayoflong classdescriptor tparrayofdouble classdescriptor tparrayofdate classdescriptor tparrayofstring classdescriptor tparrayofvalue classdescriptor valuedesc valuedesc unpackobject valuedesc recursiveloading classdescriptor tparrayofraw classdescriptor classdescriptor tpboolean setboolean classdescriptor tpbyte setbyte classdescriptor tpchar setchar classdescriptor tpshort setshort classdescriptor tpint setint classdescriptor tplong setlong classdescriptor tpfloat setfloat intbitstofloat classdescriptor tpdouble setdouble longbitstodouble classdescriptor tpenum gettype getenumconstants classdescriptor tpstring classdescriptor tpdate classdescriptor tpobject gettype recursiveloading classdescriptor tpvalue valuedesc newinstance unpackobject valuedesc recursiveloading classdescriptor tpraw bytearrayinputstream bytearrayinputstream objectinputstream persistentobjectinputstream readobject final byte pack object i persistent obj boolean finalized byte buffer buf new byte buffer int offs object header sizeof buf extend offs class descriptor desc get class descriptor obj get class if obj instanceof fast serializable offs fast serializable obj pack buf offs encoding else try offs pack object obj desc offs buf obj finalized catch exception x throw new storage error storage error access violation x object header set size buf arr 0 offs object header set type buf arr 0 desc get oid return buf arr packobject ipersistent bytebuffer bytebuffer objectheader classdescriptor getclassdescriptor getclass fastserializable fastserializable packobject storageerror storageerror access_violation objectheader setsize objectheader settype getoid final int pack value object value int offs byte buffer buf boolean finalized throws exception if value null buf extend offs 4 bytes pack4 buf arr offs 1 offs 4 else if value instanceof i persistent buf extend offs 8 bytes pack4 buf arr offs 2 class descriptor tp object bytes pack4 buf arr offs 4 swizzle i persistent value finalized offs 8 else class c value get class if c boolean class buf extend offs 5 bytes pack4 buf arr offs 2 class descriptor tp boolean buf arr offs 4 byte boolean value boolean value 1 0 offs 5 else if c character class buf extend offs 6 bytes pack4 buf arr offs 2 class descriptor tp char bytes pack2 buf arr offs 4 short character value char value offs 6 else if c byte class buf extend offs 5 bytes pack4 buf arr offs 2 class descriptor tp byte buf arr offs 4 byte value byte value offs 5 else if c short class buf extend offs 6 bytes pack4 buf arr offs 2 class descriptor tp short bytes pack2 buf arr offs 4 short value short value offs 6 else if c integer class buf extend offs 8 bytes pack4 buf arr offs 2 class descriptor tp int bytes pack4 buf arr offs 4 integer value int value offs 8 else if c long class buf extend offs 12 bytes pack4 buf arr offs 2 class descriptor tp long bytes pack8 buf arr offs 4 long value long value offs 12 else if c float class buf extend offs 8 bytes pack4 buf arr offs 2 class descriptor tp float bytes pack4 buf arr offs 4 float float to int bits float value float value offs 8 else if c double class buf extend offs 12 bytes pack4 buf arr offs 2 class descriptor tp double bytes pack8 buf arr offs 4 double double to long bits double value double value offs 12 else if c date class buf extend offs 12 bytes pack4 buf arr offs 2 class descriptor tp date bytes pack8 buf arr offs 4 date value get time offs 12 else byte array output stream bout new byte array output stream object output stream out loader map null object output stream new annotated persistent object output stream bout object output stream new persistent object output stream bout out write object value out close byte arr bout to byte array int len arr length buf extend offs 4 len bytes pack4 buf arr offs len offs 4 system arraycopy arr 0 buf arr offs len offs len return offs packvalue bytebuffer ipersistent classdescriptor tpobject ipersistent getclass classdescriptor tpboolean booleanvalue classdescriptor tpchar charvalue classdescriptor tpbyte bytevalue classdescriptor tpshort shortvalue classdescriptor tpint intvalue classdescriptor tplong longvalue classdescriptor tpfloat floattointbits floatvalue classdescriptor tpdouble doubletolongbits doublevalue classdescriptor tpdate gettime bytearrayoutputstream bytearrayoutputstream objectoutputstream loadermap objectoutputstream annotatedpersistentobjectoutputstream objectoutputstream persistentobjectoutputstream writeobject tobytearray final int pack object object obj class descriptor desc int offs byte buffer buf i persistent po boolean finalized throws exception class descriptor field descriptor flds desc all fields for int i 0 n flds length i n i class descriptor field descriptor fd flds i field f fd field switch fd type case class descriptor tp byte buf extend offs 1 buf arr offs f get byte obj continue case class descriptor tp boolean buf extend offs 1 buf arr offs byte f get boolean obj 1 0 continue case class descriptor tp short buf extend offs 2 bytes pack2 buf arr offs f get short obj offs 2 continue case class descriptor tp char buf extend offs 2 bytes pack2 buf arr offs short f get char obj offs 2 continue case class descriptor tp int buf extend offs 4 bytes pack4 buf arr offs f get int obj offs 4 continue case class descriptor tp long buf extend offs 8 bytes pack8 buf arr offs f get long obj offs 8 continue case class descriptor tp float buf extend offs 4 bytes pack4 buf arr offs float float to int bits f get float obj offs 4 continue case class descriptor tp double buf extend offs 8 bytes pack8 buf arr offs double double to long bits f get double obj offs 8 continue case class descriptor tp enum enum e enum f get obj buf extend offs 4 if e null bytes pack4 buf arr offs 1 else bytes pack4 buf arr offs e ordinal offs 4 continue case class descriptor tp date buf extend offs 8 date d date f get obj long msec d null 1 d get time bytes pack8 buf arr offs msec offs 8 continue case class descriptor tp string offs buf pack string offs string f get obj encoding continue case class descriptor tp object buf extend offs 4 bytes pack4 buf arr offs swizzle i persistent f get obj finalized offs 4 continue case class descriptor tp value object value f get obj if value null throw new storage error storage error null value fd field name else if value instanceof i persistent throw new storage error storage error serialize persistent offs pack object value fd value desc offs buf po finalized continue case class descriptor tp raw offs pack value f get obj offs buf finalized continue case class descriptor tp custom serializer pack custom serializable f get obj buf get output stream offs buf size continue case class descriptor tp array of byte byte arr byte f get obj if arr null buf extend offs 4 bytes pack4 buf arr offs 1 offs 4 else int len arr length buf extend offs 4 len bytes pack4 buf arr offs len offs 4 system arraycopy arr 0 buf arr offs len offs len continue case class descriptor tp array of boolean boolean arr boolean f get obj if arr null buf extend offs 4 bytes pack4 buf arr offs 1 offs 4 else int len arr length buf extend offs 4 len bytes pack4 buf arr offs len offs 4 for int j 0 j len j offs buf arr offs byte arr j 1 0 continue case class descriptor tp array of short short arr short f get obj if arr null buf extend offs 4 bytes pack4 buf arr offs 1 offs 4 else int len arr length buf extend offs 4 len 2 bytes pack4 buf arr offs len offs 4 for int j 0 j len j bytes pack2 buf arr offs arr j offs 2 continue case class descriptor tp array of char char arr char f get obj if arr null buf extend offs 4 bytes pack4 buf arr offs 1 offs 4 else int len arr length buf extend offs 4 len 2 bytes pack4 buf arr offs len offs 4 for int j 0 j len j bytes pack2 buf arr offs short arr j offs 2 continue case class descriptor tp array of int int arr int f get obj if arr null buf extend offs 4 bytes pack4 buf arr offs 1 offs 4 else int len arr length buf extend offs 4 len 4 bytes pack4 buf arr offs len offs 4 for int j 0 j len j bytes pack4 buf arr offs arr j offs 4 continue case class descriptor tp array of enum enum arr enum f get obj if arr null buf extend offs 4 bytes pack4 buf arr offs 1 offs 4 else int len arr length buf extend offs 4 len 4 bytes pack4 buf arr offs len offs 4 for int j 0 j len j if arr j null bytes pack4 buf arr offs 1 else bytes pack4 buf arr offs arr j ordinal offs 4 continue case class descriptor tp array of long long arr long f get obj if arr null buf extend offs 4 bytes pack4 buf arr offs 1 offs 4 else int len arr length buf extend offs 4 len 8 bytes pack4 buf arr offs len offs 4 for int j 0 j len j bytes pack8 buf arr offs arr j offs 8 continue case class descriptor packobject classdescriptor bytebuffer ipersistent classdescriptor fielddescriptor allfields classdescriptor fielddescriptor classdescriptor tpbyte getbyte classdescriptor tpboolean getboolean classdescriptor tpshort getshort classdescriptor tpchar getchar classdescriptor tpint getint classdescriptor tplong getlong classdescriptor tpfloat floattointbits getfloat classdescriptor tpdouble doubletolongbits getdouble classdescriptor tpenum classdescriptor tpdate gettime classdescriptor tpstring packstring classdescriptor tpobject ipersistent classdescriptor tpvalue storageerror storageerror null_value fieldname ipersistent storageerror storageerror serialize_persistent packobject valuedesc classdescriptor tpraw packvalue classdescriptor tpcustom customserializable getoutputstream classdescriptor tparrayofbyte classdescriptor tparrayofboolean classdescriptor tparrayofshort classdescriptor tparrayofchar classdescriptor tparrayofint classdescriptor tparrayofenum classdescriptor tparrayoflong classdescriptor public class loader set class loader class loader loader class loader prev loader this loader loader return prev classloader setclassloader classloader classloader public class loader get class loader return loader classloader getclassloader public void register class loader i named class loader loader if loader map null loader map new hash map loader map put loader get name loader registerclassloader inamedclassloader loadermap loadermap hashmap loadermap getname public class loader find class loader string name if loader map null return null return class loader loader map get name classloader findclassloader loadermap classloader loadermap public void set custom serializer custom serializer serializer this serializer serializer setcustomserializer customserializer iterator oids hash iterator hash set result oids result iterator hashiterator hashset public object next return lookup object next oid null lookupobject nextoid public int next oid return integer oids next int value nextoid intvalue public boolean has next return oids has next hasnext hasnext public void remove throw new unsupported operation exception unsupportedoperationexception public iterator merge iterator selections hash set result null for int i 0 i selections length i iterator iterator selections i hash set new result new hash set while iterator has next integer oid new integer persistent iterator iterator next oid if result null result contains oid new result add oid result new result if result size 0 break if result null result new hash set return new hash iterator result hashset hashset newresult hashset hasnext persistentiterator nextoid newresult newresult hashset hashiterator public iterator join iterator selections hash set result new hash set for int i 0 i selections length i iterator iterator selections i while iterator has next result add new integer persistent iterator iterator next oid return new hash iterator result hashset hashset hasnext persistentiterator nextoid hashiterator public synchronized void register custom allocator class cls custom allocator allocator synchronized object cache class descriptor desc get class descriptor cls desc allocator allocator store object0 desc false if custom allocator map null custom allocator map new hash map custom allocator list new array list custom allocator map put cls desc allocator custom allocator list add desc allocator registercustomallocator customallocator objectcache classdescriptor getclassdescriptor storeobject0 customallocatormap customallocatormap hashmap customallocatorlist arraylist customallocatormap customallocatorlist public custom allocator create bitmap allocator int quantum long base long extension long limit return new bitmap custom allocator this quantum base extension limit customallocator createbitmapallocator bitmapcustomallocator public int get database format version return header database format version getdatabaseformatversion databaseformatversion final thread local transaction context new thread local protected synchronized object initial value return new thread transaction context threadlocal transactioncontext threadlocal initialvalue threadtransactioncontext final void pack byte rec int offs 0 rec offs byte curr rec offs byte dirty 1 0 rec offs database format version for int i 0 i 2 i bytes pack8 rec offs root i size offs 8 bytes pack8 rec offs root i index offs 8 bytes pack8 rec offs root i shadow index offs 8 bytes pack8 rec offs root i used size offs 8 bytes pack4 rec offs root i index size offs 4 bytes pack4 rec offs root i shadow index size offs 4 bytes pack4 rec offs root i index used offs 4 bytes pack4 rec offs root i free list offs 4 bytes pack4 rec offs root i bitmap end offs 4 bytes pack4 rec offs root i root object offs 4 bytes pack4 rec offs root i class desc list offs 4 bytes pack4 rec offs root i bitmap extent offs 4 bytes pack8 rec offs transaction id offs 8 assert that offs sizeof databaseformatversion shadowindex usedsize indexsize shadowindexsize indexused freelist bitmapend rootobject classdesclist bitmapextent transactionid final void unpack byte rec int offs 0 curr rec offs dirty rec offs 0 database format version rec offs root new root page 2 for int i 0 i 2 i root i new root page root i size bytes unpack8 rec offs offs 8 root i index bytes unpack8 rec offs offs 8 root i shadow index bytes unpack8 rec offs offs 8 root i used size bytes unpack8 rec offs offs 8 root i index size bytes unpack4 rec offs offs 4 root i shadow index size bytes unpack4 rec offs offs 4 root i index used bytes unpack4 rec offs offs 4 root i free list bytes unpack4 rec offs offs 4 root i bitmap end bytes unpack4 rec offs offs 4 root i root object bytes unpack4 rec offs offs 4 root i class desc list bytes unpack4 rec offs offs 4 root i bitmap extent bytes unpack4 rec offs offs 4 transaction id bytes unpack8 rec offs offs 8 assert that offs sizeof databaseformatversion rootpage rootpage shadowindex usedsize indexsize shadowindexsize indexused freelist bitmapend rootobject classdesclist bitmapextent transactionid private final int interval private final nodeip detector detector public ip address detector int interval nodeip detector detector this interval interval this detector detector nodeipdetector ipaddressdetector nodeipdetector return our name public string get checkpoint name return autodetection of ip addresses getcheckpointname return next scheduling point public long next checkpoint return system current time millis interval we are pretty cheap nextcheckpoint currenttimemillis fetches the currently detected ip address if not detected yet a detection is forced return detected ip address public inet address get address return get address interval inetaddress getaddress getaddress get the ip address return detected ip address public inet address get address long recheck time if system current time millis last detected time recheck time checkpoint return last address list null new inet address 0 last address list inetaddress getaddress rechecktime currenttimemillis lastdetectedtime rechecktime lastaddresslist inetaddress lastaddresslist execute a checkpoint detect our internet ip address and log it param prefered address an address that for some reason is preferred above others might be null protected synchronized void checkpoint boolean logdebug logger should log logger debug this list inet address addrs new array list inet address enumeration java net network interface interfaces null try interfaces java net network interface get network interfaces catch socket exception e logger error this socket exception trying to detect network interfaces e e addrs add old detect old true if old while interfaces has more elements java net network interface iface interfaces next element if logdebug logger debug this scanning network interface iface get display name enumeration inet address ee iface get inet addresses while ee has more elements inet address addr ee next element addrs add addr if logdebug logger debug this adding address addr from iface get display name if logdebug logger debug this finished scanning interface iface get display name if logdebug logger debug this finished scanning interfaces fixme what are we doing here last inet address is always null inet address old address list last address list on get addresses addrs last detected time system current time millis if old address list last address list old address list null last address list null old address list null last address list null arrays equals old address list last address list something changed yes i know it could just have changed the order but this is unlikely hopefully fixme detector redetect address preferedaddress shouldlog inetaddress arraylist inetaddress networkinterface networkinterface getnetworkinterfaces socketexception socketexception networkinterfaces olddetect hasmoreelements networkinterface nextelement networkinterface getdisplayname inetaddress getinetaddresses hasmoreelements inetaddress nextelement getdisplayname getdisplayname lastinetaddress inetaddress oldaddresslist lastaddresslist ongetaddresses lastdetectedtime currenttimemillis oldaddresslist lastaddresslist oldaddresslist lastaddresslist oldaddresslist lastaddresslist oldaddresslist lastaddresslist redetectaddress protected inet address old detect boolean should log logger should log logger debug this if should log logger debug this running old style detection code datagram socket ds null try try ds new datagram socket catch socket exception e logger error this socket exception e return null this does not transfer any data the ip is a root servers net 53 is dns try ds connect inet address get by name 198 41 0 4 53 catch unknown host exception ex logger error this unknown host exception ex return null return ds get local address finally if ds null ds close inetaddress olddetect shouldlog shouldlog shouldlog datagramsocket datagramsocket socketexception socketexception inetaddress getbyname unknownhostexception unknownhostexception getlocaladdress do something with the list of detected ip addresses param addrs vector of inet addresses protected void on get addresses list inet address addrs list inet address output new array list inet address boolean logdebug logger should log logger debug this if logdebug logger debug this on get addresses found addrs size potential addresses if addrs size 0 logger error this no addresses found last address list null return else inet address last non valid address null for int x 0 x addrs size x if addrs get x null inet address i addrs get x if logdebug logger debug this address x i if i is any local address wildcard address 0 0 0 0 ignore else if i is link local address i is loopback address i is site local address will be filtered out later if necessary output add i else if i is multicast address ignore else ignore isatap addresses see http archives freenetproject org message 20071129 220955 ac2a2a36 en html if address identifier is anisatapi pv6 address i to string output add i last address list output to array new inet address output size inetaddresses ongetaddresses inetaddress inetaddress arraylist inetaddress shouldlog ongetaddresses lastaddresslist inetaddress lastnonvalidaddress inetaddress isanylocaladdress islinklocaladdress isloopbackaddress issitelocaladdress ismulticastaddress addressidentifier isanisatapipv6address tostring lastaddresslist toarray inetaddress public void run freenet support logger os thread logpid this while true try thread sleep interval catch interrupted exception e ignore try checkpoint catch throwable t logger error this caught t t osthread interruptedexception public void clear cached last address list null last detected time 1 clearcached lastaddresslist lastdetectedtime public class null bloom filter extends bloom filter protected null bloom filter int length int k super length k nullbloomfilter bloomfilter nullbloomfilter override public boolean check filter byte key return true checkfilter override public void add key byte key ignore addkey override public void remove key byte key ignore removekey override protected boolean get bit int offset ignore return true getbit override protected void set bit int offset ignore setbit override protected void unset bit int offset ignore unsetbit override public void fork int k return override public void discard return override public void merge return public class snmp bindto callback extends string callback public snmp bindto callback snmpbindtocallback stringcallback snmpbindtocallback public string get string bindto snmp agent getsnmp agent getsnm pbindto if bindto null return bindto return 127 0 0 1 snmpagent getsnmpagent getsnmpbindto public void set string val throws invalid config value exception if val equals get snmp agent setsnm pbindto val invalidconfigvalueexception snmpagent setsnmpbindto static logger register log threshold callback new log threshold callback override public void should update logminor logger should log logger minor this registerlogthresholdcallback logthresholdcallback shouldupdate shouldlog public announce sender message m long uid peer node source opennet manager om node node this source source this uid uid this msg m this om om this node node this only node null htl short math min m get short dmt htl node maxhtl target m get double dmt target location fixme validate cb null announcesender peernode opennetmanager onlynode getshort getdouble target_location public announce sender double target opennet manager om node node announcement callback cb peer node only node source null this uid node random next long msg null this om om this node node this htl node maxhtl this target target this cb cb this only node only node noderef buf om crypto my compressed full ref announcesender opennetmanager announcementcallback peernode onlynode nextlong onlynode onlynode noderefbuf mycompressedfullref public void run try real run catch throwable t logger error this caught t announcing uid from source t finally if source null source completed announce uid node completed uid if cb null cb completed realrun completedannounce private void real run boolean has forwarded false if source null try source send async dmt createfnp accepted uid null this catch not connected exception e return if transfer noderef return now route it hash set peer node nodes routed to new hash set peer node peer node next null while true if logminor logger minor this htl htl if we haven t routed to any node yet decrement according to the source if we have decrement according to the node which just failed because 1 if we always decrement according to source then we can be at max or min htl for a long time while we visit every peer node this is bad 2 the node which just failed can be seen as the requestor for our purposes decrement at this point so we can dnf immediately on reaching htl 0 htl node decrementhtl has forwarded next source htl if htl 0 no more nodes complete return if node is opennet enabled complete return if only node null route it next node peers closer peer source nodes routed to target true node is advanced mode enabled 1 null null else next only node if nodes routed to contains only node rnf only node return if next null backtrack rnf next return if logminor logger minor this routing request to next nodes routed to add next long xferuid send to next if xferuid 1 continue has forwarded true message msg null while true what are we waiting for fnp accepted continue fnp rejected loop go to another node fnp rejected overload go to another node message filter mf accepted message filter create set source next set field dmt uid uid set timeout accepted timeout set type dmt fnp accepted message filter mf rejected loop message filter create set source next set field dmt uid uid set timeout accepted timeout set type dmt fnp rejected loop message filter mf rejected overload message filter create set source next set field dmt uid uid set timeout accepted timeout set type dmt fnp rejected overload message filter mf opennet disabled message filter create set source next set field dmt uid uid set timeout accepted timeout set type dmt fnp opennet disabled mf rejected overload must be the last thing in the or so its or pointer remains null otherwise we need to recreate it below message filter mf mf accepted or mf rejected loop or mf rejected overload or mf opennet disabled try msg node usm wait for mf this if logminor logger minor this first part got msg catch disconnected exception e logger normal this disconnected from next while waiting for accepted on uid break if msg null if logminor logger minor this timeout waiting for accepted try next node msg null break if msg get spec dmt fnp rejected loop if logminor logger minor this rejected loop find another node to route to msg null break if msg get spec dmt fnp rejected overload if logminor logger minor this rejected overload give up on this one try another msg null break if msg get spec dmt fnp opennet disabled if logminor logger minor this opennet disabled msg null break if msg get spec dmt fnp accepted logger error this unrecognized message msg continue break if msg null msg get spec dmt fnp accepted try another node continue if logminor logger minor this got accepted send the rest try send rest next xferuid catch not connected exception e1 if logminor logger minor this not connected while sending noderef on next continue otherwise must be accepted so wait while true message filter mf announce completed message filter create set source next set field dmt uid uid set timeout announce timeout set type dmt fnp opennet announce completed message filter mf route not found message filter create set source next set field dmt uid uid set timeout announce timeout set type dmt fnp route not found message filter mf rejected overload message filter create set source next set field dmt uid uid set timeout announce timeout set type dmt fnp rejected overload message filter mf announce reply message filter create set source next set field dmt uid uid set timeout announce timeout set type dmt fnp opennet announce reply message filter mf opennet disabled message filter create set source next set field dmt uid uid set timeout announce timeout set type dmt fnp opennet disabled message filter mf not wanted message filter create set source next set field dmt uid uid set timeout announce timeout set type dmt fnp opennet announce node not wanted message filter mf opennet noderef rejected message filter create set source next set field dmt uid uid set timeout accepted timeout set type dmt fnp opennet noderef rejected message filter mf mf announce completed or mf route not found or mf rejected overload or mf announce reply or mf opennet disabled or mf not wanted or mf opennet noderef rejected try msg node usm wait for mf this catch disconnected exception e logger normal this disconnected from next while waiting for announcement break if logminor logger minor this second part got msg if msg null fatal timeout must be terminal is local true timed out next return if msg get spec dmt fnp opennet noderef rejected int reason msg get int dmt reject code logger normal this announce rejected by next dmt get opennet rejected code reason msg null break if msg get spec dmt fnp opennet announce completed send the completion on immediately we don t want to accumulate 30 seconds per hop complete mf announce reply set timeout end timeout set timeout relative to creation true mf not wanted set timeout end timeout set timeout relative to creation true mf announce reply clear or mf not wanted clear or mf mf announce reply or mf not wanted while true try msg node usm wait for mf this catch disconnected exception e return if msg null return if msg get spec dmt fnp opennet announce reply validate forward reply msg next continue if msg get spec dmt fnp opennet announce node not wanted if cb null cb node not wanted if source null try send not wanted catch not connected exception e logger error this lost connection to source return continue if msg get spec dmt fnp route not found backtrack within available hops short new htl msg get short dmt htl if new htl htl htl new htl break if msg get spec dmt fnp rejected overload give up on this one try another break if msg get spec dmt fnp opennet disabled logger minor this opennet disabled msg null break if msg get spec dmt fnp opennet announce reply validate forward reply msg next continue there may be more realrun hasforwarded sendasync createfnpaccepted notconnectedexception transfernoderef hashset peernode nodesroutedto hashset peernode peernode hasforwarded isopennetenabled onlynode closerpeer nodesroutedto isadvancedmodeenabled onlynode nodesroutedto onlynode onlynode nodesroutedto sendto hasforwarded fnpaccepted fnprejectedloop fnprejectedoverload messagefilter mfaccepted messagefilter setsource setfield settimeout accepted_timeout settype fnpaccepted messagefilter mfrejectedloop messagefilter setsource setfield settimeout accepted_timeout settype fnprejectedloop messagefilter mfrejectedoverload messagefilter setsource setfield settimeout accepted_timeout settype fnprejectedoverload messagefilter mfopennetdisabled messagefilter setsource setfield settimeout accepted_timeout settype fnpopennetdisabled mfrejectedoverload messagefilter mfaccepted mfrejectedloop mfrejectedoverload mfopennetdisabled waitfor disconnectedexception getspec fnprejectedloop getspec fnprejectedoverload getspec fnpopennetdisabled getspec fnpaccepted getspec fnpaccepted sendrest notconnectedexception messagefilter mfannouncecompleted messagefilter setsource setfield settimeout announce_timeout settype fnpopennetannouncecompleted messagefilter mfroutenotfound messagefilter setsource setfield settimeout announce_timeout settype fnproutenotfound messagefilter mfrejectedoverload messagefilter setsource setfield settimeout announce_timeout settype fnprejectedoverload messagefilter mfannouncereply messagefilter setsource setfield settimeout announce_timeout settype fnpopennetannouncereply messagefilter mfopennetdisabled messagefilter setsource setfield settimeout announce_timeout settype fnpopennetdisabled messagefilter mfnotwanted messagefilter setsource setfield settimeout announce_timeout settype fnpopennetannouncenodenotwanted messagefilter mfopennetnoderefrejected messagefilter setsource setfield settimeout accepted_timeout settype fnpopennetnoderefrejected messagefilter mfannouncecompleted mfroutenotfound mfrejectedoverload mfannouncereply mfopennetdisabled mfnotwanted mfopennetnoderefrejected waitfor disconnectedexception is_local timedout getspec fnpopennetnoderefrejected getint reject_code getopennetrejectedcode getspec fnpopennetannouncecompleted mfannouncereply settimeout end_timeout settimeoutrelativetocreation mfnotwanted settimeout end_timeout settimeoutrelativetocreation mfannouncereply clearor mfnotwanted clearor mfannouncereply mfnotwanted waitfor disconnectedexception getspec fnpopennetannouncereply validateforwardreply getspec fnpopennetannouncenodenotwanted nodenotwanted sendnotwanted notconnectedexception getspec fnproutenotfound newhtl getshort newhtl newhtl getspec fnprejectedoverload getspec fnpopennetdisabled getspec fnpopennetannouncereply validateforwardreply validate a reply and relay it back to the source param msg2 the announcement reply message return true unless we lost the connection to our request source private boolean validate forward reply message msg peer node next long xferuid msg get long dmt transfer uid int noderef length msg get int dmt noderef length int padded length msg get int dmt padded length byte noderef buf om inner wait for opennet noderef xferuid padded length noderef length next false uid true this if noderef buf null return true don t relay simple field set fs om validate noderef noderef buf 0 noderef length next false if fs null if cb null cb bogus noderef invalid noderef return true don t relay if source null now relay it try om send announcement reply uid source noderef buf this catch not connected exception e hmmm return false else add it try opennet peer node pn node add new opennet node fs if pn null cb added node pn else cb node not added catch fs parse exception e logger normal this failed to parse reply e e if cb null cb bogus noderef parse failed e catch peer parse exception e logger normal this failed to parse reply e e if cb null cb bogus noderef parse failed e catch reference signature verification exception e logger normal this failed to parse reply e e if cb null cb bogus noderef parse failed e return true announcementreply validateforwardreply peernode getlong transfer_uid nodereflength getint noderef_length paddedlength getint padded_length noderefbuf innerwaitforopennetnoderef paddedlength nodereflength noderefbuf simplefieldset validatenoderef noderefbuf nodereflength bogusnoderef sendannouncementreply noderefbuf notconnectedexception opennetpeernode addnewopennetnode addednode nodenotadded fsparseexception bogusnoderef peerparseexception bogusnoderef referencesignatureverificationexception bogusnoderef send an announcement request param next the node to send the announcement to return true if the announcement was successfully sent private long send to peer node next try return om start send announcement request uid next noderef buf this target htl catch not connected exception e if logminor logger minor this disconnected return 1 announcementrequest sendto peernode startsendannouncementrequest noderefbuf notconnectedexception send an announcement request param next the node to send the announcement to return true if the announcement was successfully sent throws not connected exception private void send rest peer node next long xferuid throws not connected exception om finish sent announcement request next noderef buf this xferuid announcementrequest notconnectedexception sendrest peernode notconnectedexception finishsentannouncementrequest noderefbuf private void timed out peer node next message msg dmt createfnp rejected overload uid true if source null try source send async msg null this catch not connected exception e ok if cb null cb node failed next timed out timedout peernode createfnprejectedoverload sendasync notconnectedexception nodefailed private void rnf peer node next message msg dmt createfnp route not found uid htl if source null try source send async msg null this catch not connected exception e ok if cb null if next null cb node failed next route not found else cb no more nodes peernode createfnproutenotfound sendasync notconnectedexception nodefailed nomorenodes private void complete message msg dmt createfnp opennet announce completed uid if source null try source send async msg null this catch not connected exception e oh well createfnpopennetannouncecompleted sendasync notconnectedexception return true unless the noderef is bogus private boolean transfer noderef long xferuid msg get long dmt transfer uid noderef length msg get int dmt noderef length int padded length msg get int dmt padded length noderef buf om inner wait for opennet noderef xferuid padded length noderef length source false uid true this if noderef buf null return false simple field set fs om validate noderef noderef buf 0 noderef length source false if fs null om reject ref uid source dmt noderef rejected invalid this return false if we want it add it and send it try if om add new opennet node fs null send our ref source om crypto my compressed full ref else if logminor logger minor this don t need the node send not wanted okay just route it catch fs parse exception e if logminor logger minor this rejecting noderef e e om reject ref uid source dmt noderef rejected invalid this return false catch peer parse exception e if logminor logger minor this rejecting noderef e e om reject ref uid source dmt noderef rejected invalid this return false catch reference signature verification exception e if logminor logger minor this rejecting noderef e e om reject ref uid source dmt noderef rejected invalid this return false catch not connected exception e logger normal this could not receive noderef disconnected return false return true transfernoderef getlong transfer_uid nodereflength getint noderef_length paddedlength getint padded_length noderefbuf innerwaitforopennetnoderef paddedlength nodereflength noderefbuf simplefieldset validatenoderef noderefbuf nodereflength rejectref noderef_rejected_invalid addnewopennetnode sendourref mycompressedfullref sendnotwanted fsparseexception rejectref noderef_rejected_invalid peerparseexception rejectref noderef_rejected_invalid referencesignatureverificationexception rejectref noderef_rejected_invalid notconnectedexception private void send not wanted throws not connected exception message msg dmt createfnp opennet announce node not wanted uid source send async msg null this sendnotwanted notconnectedexception createfnpopennetannouncenodenotwanted sendasync private void send our ref peer node next byte ref throws not connected exception om send announcement reply uid next ref this sendourref peernode notconnectedexception sendannouncementreply public void sent bytes int x node node stats announce byte counter sent bytes x sentbytes nodestats announcebytecounter sentbytes public void received bytes int x node node stats announce byte counter received bytes x receivedbytes nodestats announcebytecounter receivedbytes public void sent payload int x doesn t count sentpayload public int get priority return native thread high priority getpriority nativethread high_priority public class ip undetected user alert extends abstract user alert public ip undetected user alert node n super true null null null null short 0 true l10n get string user alert hide false null this node n ipundetecteduseralert abstractuseralert ipundetecteduseralert getstring useralert final node node override public string get title return l10n unknown address title gettitle unknownaddresstitle override public string get text if node ip detector no detect plugins return l10n no detector plugins if node ip detector is detecting return l10n detecting else return l10n unknown address port integer to string node get darknet port number text port forward suggestion gettext ipdetector nodetectplugins nodetectorplugins ipdetector isdetecting unknownaddress tostring getdarknetportnumber textportforwardsuggestion private string l10n string key return l10n get string ip undetected user alert key getstring ipundetecteduseralert private string l10n string key string pattern string value return l10n get string ip undetected user alert key pattern value getstring ipundetecteduseralert private string l10n string key string patterns string values return l10n get string ip undetected user alert key patterns values getstring ipundetecteduseralert override public html node gethtml text if node ip detector no detect plugins html node p new html node p l10n addl10n substitution p ip undetected user alert load detect plugins new string plugins plugins config config new string a href plugins a a href config a return p html node text node new html node div sub config sc node config get node option o sc get option tempip address hint l10n addl10n substitution text node ip undetected user alert node ip detector is detecting detecting with config link unknown address with config link new string link link new string a href config a add port forward suggestion text node html node form node text node add child form new string action method new string config post form node add child input new string type name value new string hidden form password node client core form password html node list node form node add child ul class config html node item node list node add child li item node add child span class configshortdesc l10n get string o get short desc add child input new string type name value new string text sc get prefix tempip address hint o get value string item node add child span class configlongdesc l10n get string o get long desc form node add child input new string type value new string submit l10n get string user alert apply form node add child input new string type value new string reset l10n get string user alert reset return text node htmlnode gethtmltext ipdetector nodetectplugins htmlnode htmlnode addl10nsubstitution ipundetecteduseralert loaddetectplugins htmlnode textnode htmlnode subconfig getoption tempipaddresshint addl10nsubstitution textnode ipundetecteduseralert ipdetector isdetecting detectingwithconfiglink unknownaddresswithconfiglink addportforwardsuggestion textnode htmlnode formnode textnode addchild formnode addchild formpassword clientcore formpassword htmlnode listnode formnode addchild htmlnode itemnode listnode addchild itemnode addchild getstring getshortdesc addchild getprefix tempipaddresshint getvaluestring itemnode addchild getstring getlongdesc formnode addchild getstring useralert formnode addchild getstring useralert textnode private void add port forward suggestion html node text node fixme we should support any number of ports udp or tcp and pick them up from the node as we do with the forwarding plugin that would be a bit of a pain for l10n though int darknet port node get darknet port number int opennet port node get opennetfnp port if opennet port 0 text node add child l10n suggest forward port port integer to string darknet port else text node add child l10n suggest forward two ports new string port1 port2 new string integer to string darknet port integer to string opennet port addportforwardsuggestion htmlnode textnode darknetport getdarknetportnumber opennetport getopennetfnpport opennetport textnode addchild suggestforwardport tostring darknetport textnode addchild suggestforwardtwoports tostring darknetport tostring opennetport private string text port forward suggestion fixme we should support any number of ports udp or tcp and pick them up from the node as we do with the forwarding plugin that would be a bit of a pain for l10n though int darknet port node get darknet port number int opennet port node get opennetfnp port if opennet port 0 return l10n suggest forward port port integer to string darknet port else return l10n suggest forward two ports new string port1 port2 new string integer to string darknet port integer to string opennet port textportforwardsuggestion darknetport getdarknetportnumber opennetport getopennetfnpport opennetport suggestforwardport tostring darknetport suggestforwardtwoports tostring darknetport tostring opennetport override public short get priority class if node ip detector is detecting return user alert warning else return user alert error getpriorityclass ipdetector isdetecting useralert useralert override public string get short text if node ip detector no detect plugins return l10n no detector plugins if node ip detector is detecting return l10n detecting short else return l10n unknown address short getshorttext ipdetector nodetectplugins nodetectorplugins ipdetector isdetecting detectingshort unknownaddressshort public class gray filter extends point filter public gray filter can filter index color model true grayfilter pointfilter grayfilter canfilterindexcolormodel override public int filterrgb int x int y int rgb int a rgb 0xff000000 int r rgb 16 0xff int g rgb 8 0xff int b rgb 0xff r r 255 2 g g 255 2 b b 255 2 return a r 16 g 8 b override public string to string return colors gray out tostring transient field field public int compare to object o return field name compare to field descriptor o field name compareto fieldname compareto fielddescriptor fieldname public boolean equals field descriptor fd return field name equals fd field name class name equals fd class name value desc fd value desc type fd type fielddescriptor fieldname fieldname classname classname valuedesc valuedesc static reflection provider get reflection provider if reflection provider null try class for name sun misc unsafe string cls plugins xml spider org garret perst impl sun14 sun14 reflection provider reflection provider reflection provider class for name cls new instance catch throwable x reflection provider new standard reflection provider return reflection provider reflectionprovider getreflectionprovider reflectionprovider forname xmlspider sun14reflectionprovider reflectionprovider reflectionprovider forname newinstance reflectionprovider standardreflectionprovider reflectionprovider public boolean equals class descriptor cd if cd null all fields length cd all fields length return false for int i 0 i all fields length i if all fields i equals cd all fields i return false return true classdescriptor allfields allfields allfields allfields allfields object new instance if factory null return factory create this else try return load constructor new instance constructor params catch exception x throw new storage error storage error constructor failure cls x newinstance loadconstructor newinstance constructorparams storageerror storageerror constructor_failure void build field list storage impl storage class cls array list list class superclass cls get superclass if superclass null build field list storage superclass list field flds cls get declared fields if storage get database format version 2 arrays sort flds new comparator field public int compare field f1 field f2 return f1 get name compare to f2 get name else preserve backward compatibility if class descriptor class equals cls for int i 0 i flds length i if flds i get modifiers modifier transient modifier static 0 if next equals flds i get name reverse members order true break if reverse members order for int i 0 n flds length i n 1 i field f flds i flds i flds n i 1 flds n i 1 f for int i 0 i flds length i field f flds i if f is synthetic f get modifiers modifier transient modifier static 0 try f set accessible true catch exception x field descriptor fd new field descriptor fd field f fd field name f get name fd class name cls get name int type get type code f get type switch type case tp object case tp link case tp array of object has references true break case tp value fd value desc storage get class descriptor f get type has references fd value desc has references break case tp array of value fd value desc storage get class descriptor f get type get component type has references fd value desc has references fd type type list add fd buildfieldlist storageimpl arraylist getsuperclass buildfieldlist getdeclaredfields getdatabaseformatversion getname compareto getname classdescriptor getmodifiers getname reversemembersorder reversemembersorder issynthetic getmodifiers setaccessible fielddescriptor fielddescriptor fieldname getname classname getname gettypecode gettype tpobject tplink tparrayofobject hasreferences tpvalue valuedesc getclassdescriptor gettype hasreferences valuedesc hasreferences tparrayofvalue valuedesc getclassdescriptor gettype getcomponenttype hasreferences valuedesc hasreferences field flds cls get declared fields if storage get database format version 2 arrays sort flds new comparator field public int compare field f1 field f2 return f1 get name compare to f2 get name getdeclaredfields getdatabaseformatversion getname compareto getname public static int get type code class c int type if c equals byte class type tp byte else if c equals short class type tp short else if c equals char class type tp char else if c equals int class type tp int else if c equals long class type tp long else if c equals float class type tp float else if c equals double class type tp double else if c equals string class type tp string else if c equals boolean class type tp boolean else if c is enum type tp enum else if c equals java util date class type tp date else if i persistent class is assignable from c type tp object else if i value class is assignable from c type tp value else if c equals link class type tp link else if c is array type get type code c get component type if type tp link throw new storage error storage error unsupported type c type tp array of boolean else if custom serializable class is assignable from c type tp custom else if c equals object class comparable class is assignable from c type tp raw else if serialize non persistent objects type tp raw else if treate any non persistent object as value if c equals object class throw new storage error storage error empty value type tp value else throw new storage error storage error unsupported type c return type gettypecode tpbyte tpshort tpchar tpint tplong tpfloat tpdouble tpstring tpboolean isenum tpenum tpdate ipersistent isassignablefrom tpobject ivalue isassignablefrom tpvalue tplink isarray gettypecode getcomponenttype tplink storageerror storageerror unsupported_type tparrayofboolean customserializable isassignablefrom tpcustom isassignablefrom tpraw serializenonpersistentobjects tpraw treateanynonpersistentobjectasvalue storageerror storageerror empty_value tpvalue storageerror storageerror unsupported_type static boolean serialize non persistent objects boolean get boolean perst serialize transient objects class descriptor serializenonpersistentobjects getboolean classdescriptor private static class load class string name throws class not found exception class loader loader thread current thread get context class loader if loader null return loader load class name else return class for name name loadclass classnotfoundexception classloader currentthread getcontextclassloader loadclass forname private void locate constructor try class c load class cls get name load factory factory load factory c new instance catch exception x1 try load constructor cls get declared constructor perst constructor profile constructor params new object this catch no such method exception x2 try load constructor get reflection provider get default constructor cls constructor params null catch exception x3 throw new storage error storage error descriptor failure cls x3 try load constructor set accessible true catch exception x locateconstructor loadclass getname loadfactory loadfactory newinstance loadconstructor getdeclaredconstructor perstconstructorprofile constructorparams nosuchmethodexception loadconstructor getreflectionprovider getdefaultconstructor constructorparams storageerror storageerror descriptor_failure loadconstructor setaccessible class descriptor storage impl storage class cls this cls cls name get class name cls array list list new array list build field list storage cls list all fields field descriptor list to array new field descriptor list size locate constructor resolved true classdescriptor storageimpl getclassname arraylist arraylist buildfieldlist allfields fielddescriptor toarray fielddescriptor locateconstructor protected static field locate field class scope string name try do try field fld scope get declared field name try fld set accessible true catch exception e return fld catch no such field exception x scope scope get superclass while scope null catch exception x throw new storage error storage error access violation scope get name name x return null locatefield getdeclaredfield setaccessible nosuchfieldexception getsuperclass storageerror storageerror access_violation getname public static string get class name class cls class loader loader cls get class loader return loader instanceof i named class loader i named class loader loader get name cls get name cls get name getclassname classloader getclassloader inamedclassloader inamedclassloader getname getname getname public static class load class storage storage string name if storage null int col name index of class loader loader if col 0 loader storage find class loader name substring 0 col if loader null just ignore this class return null name name substring col 1 else loader storage get class loader if loader null try return loader load class name catch class not found exception x try return load class name catch class not found exception x throw new storage error storage error class not found name x loadclass indexof classloader findclassloader getclassloader loadclass classnotfoundexception loadclass classnotfoundexception storageerror storageerror class_not_found public void on load cls load class get storage name class scope cls int n all fields length for int i n i 0 field descriptor fd all fields i fd load if fd class name equals scope get name for scope cls scope null scope scope get superclass if fd class name equals scope get name break if scope null try field f scope get declared field fd field name if f get modifiers modifier transient modifier static 0 try f set accessible true catch exception e fd field f catch no such field exception x else scope cls for int i n i 0 field descriptor fd all fields i if fd field null hierarchy loop for scope cls scope null scope scope get superclass try field f scope get declared field fd field name if f get modifiers modifier transient modifier static 0 for int j 0 j n j if all fields j field f continue hierarchy loop try f set accessible true catch exception e fd field f break catch no such field exception x locate constructor storage impl s storage impl get storage if s class desc map get cls null s class desc map put cls this onload loadclass getstorage allfields fielddescriptor allfields classname getname getsuperclass classname getname getdeclaredfield fieldname getmodifiers setaccessible nosuchfieldexception fielddescriptor allfields hierarchyloop getsuperclass getdeclaredfield fieldname getmodifiers allfields hierarchyloop setaccessible nosuchfieldexception locateconstructor storageimpl storageimpl getstorage classdescmap classdescmap void resolve if resolved storage impl class storage storage impl get storage class descriptor desc new class descriptor class storage cls resolved true if desc equals this class storage register class descriptor desc storageimpl classstorage storageimpl getstorage classdescriptor classdescriptor classstorage classstorage registerclassdescriptor public boolean recursive loading return false recursiveloading public static pcfb mode create block cipher c if c instanceof rijndael return new rijndaelpcfb mode rijndael c return new pcfb mode c pcfbmode blockcipher rijndaelpcfbmode pcfbmode public static pcfb mode create block cipher c byte iv if c instanceof rijndael return new rijndaelpcfb mode rijndael c iv return new pcfb mode c iv pcfbmode blockcipher rijndaelpcfbmode pcfbmode protected pcfb mode block cipher c this c c feedback register new byte c get block size 3 register pointer feedback register length pcfbmode blockcipher feedback_register getblocksize registerpointer feedback_register protected pcfb mode block cipher c byte iv this c system arraycopy iv 0 feedback register 0 feedback register length pcfbmode blockcipher feedback_register feedback_register resets the pcfb mode to an initial iv public final void reset byte iv system arraycopy iv 0 feedback register 0 feedback register length register pointer feedback register length pcfbmode feedback_register feedback_register registerpointer feedback_register resets the pcfb mode to an initial iv param iv the buffer containing the iv param offset the offset to start reading the iv at public final void reset byte iv int offset system arraycopy iv offset feedback register 0 feedback register length register pointer feedback register length pcfbmode feedback_register feedback_register registerpointer feedback_register writes the initialization vector to the stream though the iv is transmitted in the clear this gives the attacker no additional information because the register pointer is set so that the encrypted buffer is empty this causes an immediate encryption of the iv thus invalidating any information that the attacker had public void writeiv random source rs output stream out throws io exception rs next bytes feedback register out write feedback register registerpointer randomsource outputstream ioexception nextbytes feedback_register feedback_register reads the initialization vector from the given stream public void readiv input stream in throws io exception for int i 0 i feedback register length i feedback register i byte in read util read fully in feedback register inputstream ioexception feedback_register feedback_register readfully feedback_register returns the length of the iv public int lengthiv return feedback register length feedback_register deciphers one byte of data by xor ing the ciphertext byte with one byte from the encrypted buffer then places the received byte in the feedback register if no bytes are available in the encrypted buffer the feedback register is encrypted providing block size 8 new bytes for decryption public synchronized int decipher int b public int decipher int b if register pointer feedback register length refill buffer int rv feedback register register pointer byte b 0xff feedback register register pointer byte b return rv block_size registerpointer feedback_register refillbuffer feedback_register registerpointer feedback_register registerpointer note as a side effect this will decrypt the data in the array public synchronized byte block decipher byte buf int off int len public byte block decipher byte buf int off int len while len 0 if register pointer feedback register length refill buffer int n math min len feedback register length register pointer for int i off i off n i byte b buf i buf i feedback register register pointer feedback register register pointer b off n len n return buf blockdecipher blockdecipher registerpointer feedback_register refillbuffer feedback_register registerpointer feedback_register registerpointer feedback_register registerpointer enciphers one byte of data by xor ing the plaintext byte with one byte from the encrypted buffer then places the enciphered byte in the feedback register if no bytes are available in the encrypted buffer the feedback register is encrypted providing block size 8 new bytes for encryption public synchronized int encipher int b public int encipher int b if register pointer feedback register length refill buffer feedback register register pointer byte b return feedback register register pointer 0xff block_size registerpointer feedback_register refillbuffer feedback_register registerpointer feedback_register registerpointer note as a sideeffect this will encrypt the data in the array public synchronized byte block encipher byte buf int off int len public byte block encipher byte buf int off int len while len 0 if register pointer feedback register length refill buffer int n math min len feedback register length register pointer for int i off i off n i buf i feedback register register pointer buf i off n len n return buf blockencipher blockencipher registerpointer feedback_register refillbuffer feedback_register registerpointer feedback_register registerpointer private synchronized void refill buffer protected void refill buffer encrypt feedback into result c encipher feedback register feedback register register pointer 0 refillbuffer refillbuffer feedback_register feedback_register registerpointer public class chk encode exception extends key encode exception private static final long serial versionuid 1 public chk encode exception super chkencodeexception keyencodeexception serialversionuid chkencodeexception public chk encode exception string message super message chkencodeexception public chk encode exception string message throwable cause super message cause chkencodeexception public chk encode exception throwable cause super cause chkencodeexception final string encoded type public unknown content type exception string type name this type type name encoded type html encoder encode type encodedtype unknowncontenttypeexception typename typename encodedtype htmlencoder public string get type return type gettype override public string gethtml encoded title return l10n title type encoded type gethtmlencodedtitle encodedtype override public string get raw title return l10n title type type getrawtitle override public string get explanation return l10n explanation getexplanation override public html node gethtml explanation return new html node div l10n explanation htmlnode gethtmlexplanation htmlnode private static string l10n string key return l10n get string unknown content type exception key getstring unknowncontenttypeexception private static string l10n string key string pattern string value return l10n get string unknown content type exception key pattern value getstring unknowncontenttypeexception private int paint mode pixel utils normal public gradient filter paintmode pixelutils gradientfilter public gradient filter point p1 point p2 int color1 int color2 boolean repeat int type int interpolation this p1 p1 this p2 p2 this color1 color1 this color2 color2 this repeat repeat this type type this interpolation interpolation colormap new linear colormap color1 color2 gradientfilter linearcolormap public void set point1 point point1 this p1 point1 setpoint1 public point get point1 return p1 getpoint1 public void set point2 point point2 this p2 point2 setpoint2 public point get point2 return p2 getpoint2 public void set type int type this type type settype public int get type return type gettype public void set interpolation int interpolation this interpolation interpolation setinterpolation public int get interpolation return interpolation getinterpolation specifies the angle of the texture param angle the angle of the texture angle see get angle public void set angle float angle this angle angle p2 new point int 64 math cos angle int 64 math sin angle getangle setangle returns the angle of the texture return the angle of the texture see set angle public float get angle return angle setangle getangle set the colormap to be used for the filter param colormap the colormap see get colormap public void set colormap colormap colormap this colormap colormap getcolormap setcolormap get the colormap to be used for the filter return the colormap see set colormap public colormap get colormap return colormap setcolormap getcolormap public void set paint mode int paint mode this paint mode paint mode setpaintmode paintmode paintmode paintmode public int get paint mode return paint mode getpaintmode paintmode public buffered image filter buffered image src buffered image dst int width src get width int height src get height if dst null dst create compatible dest image src null int rgb1 rgb2 float x1 y1 x2 y2 x1 p1 x x2 p2 x if x1 x2 type radial y1 x1 x1 x2 x2 y1 y1 p2 y y2 p1 y rgb1 color2 rgb2 color1 else y1 p1 y y2 p2 y rgb1 color1 rgb2 color2 float dx x2 x1 float dy y2 y1 float len sq dx dx dy dy this x1 x1 this y1 y1 if len sq float min value dx dx len sq dy dy len sq if repeat dx dx 1 0f dy dy 1 0f this dx dx this dy dy int pixels new int width for int y 0 y height y getrgb src 0 y width 1 pixels switch type case linear case bilinear linear gradient pixels y width 1 break case radial radial gradient pixels y width 1 break case conical case biconical conical gradient pixels y width 1 break case square square gradient pixels y width 1 break setrgb dst 0 y width 1 pixels return dst bufferedimage bufferedimage bufferedimage getwidth getheight createcompatibledestimage lensq lensq min_value lensq lensq lineargradient radialgradient conicalgradient squaregradient private void repeat gradient int pixels int w int h float rowrel float dx float dy int off 0 for int y 0 y h y float colrel rowrel int j w int rgb while j 0 if type bilinear rgb colormap get color map image math triangle colrel else rgb colormap get color map image math mod colrel 1 0f pixels off pixel utils combine pixels rgb pixels off paint mode off colrel dx rowrel dy repeatgradient getcolor imagemath getcolor imagemath pixelutils combinepixels paintmode private void single gradient int pixels int w int h float rowrel float dx float dy int off 0 for int y 0 y h y float colrel rowrel int j w int rgb if colrel 0 0 rgb colormap get color 0 do pixels off pixel utils combine pixels rgb pixels off paint mode off colrel dx while j 0 colrel 0 0 while colrel 1 0 j 0 if type bilinear rgb colormap get color map image math triangle colrel else rgb colormap get color map colrel pixels off pixel utils combine pixels rgb pixels off paint mode off colrel dx if j 0 if type bilinear rgb colormap get color 0 0f else rgb colormap get color 1 0f do pixels off pixel utils combine pixels rgb pixels off paint mode off while j 0 rowrel dy singlegradient getcolor pixelutils combinepixels paintmode getcolor imagemath getcolor pixelutils combinepixels paintmode getcolor getcolor pixelutils combinepixels paintmode private void linear gradient int pixels int y int w int h int x 0 float rowrel x x1 dx y y1 dy if repeat repeat gradient pixels w h rowrel dx dy else single gradient pixels w h rowrel dx dy lineargradient repeatgradient singlegradient private void radial gradient int pixels int y int w int h int off 0 float radius distance p2 x p1 x p2 y p1 y for int x 0 x w x float distance distance x p1 x y p1 y float ratio distance radius if repeat ratio ratio 2 else if ratio 1 0 ratio 1 0f int rgb colormap get color map ratio pixels off pixel utils combine pixels rgb pixels off paint mode off radialgradient getcolor pixelutils combinepixels paintmode private void square gradient int pixels int y int w int h int off 0 float radius math max math abs p2 x p1 x math abs p2 y p1 y for int x 0 x w x float distance math max math abs x p1 x math abs y p1 y float ratio distance radius if repeat ratio ratio 2 else if ratio 1 0 ratio 1 0f int rgb colormap get color map ratio pixels off pixel utils combine pixels rgb pixels off paint mode off squaregradient getcolor pixelutils combinepixels paintmode private void conical gradient int pixels int y int w int h int off 0 float angle0 float math atan2 p2 x p1 x p2 y p1 y for int x 0 x w x float angle float math atan2 x p1 x y p1 y angle0 image math two pi angle 1 0f angle 1 0f if type biconical angle image math triangle angle int rgb colormap get color map angle pixels off pixel utils combine pixels rgb pixels off paint mode off conicalgradient imagemath two_pi imagemath getcolor pixelutils combinepixels paintmode private float map float v if repeat v v 1 0 2 0f v v switch interpolation case int circle up v image math circle up image math clamp v 0 0f 1 0f break case int circle down v image math circle down image math clamp v 0 0f 1 0f break case int smooth v image math smooth step 0 1 v break return v int_circle_up imagemath circleup imagemath int_circle_down imagemath circledown imagemath int_smooth imagemath smoothstep private float distance float a float b return float math sqrt a a b b override public string to string return other gradient fill tostring private boolean read only public byte array random access thing byte padded this data padded readonly bytearrayrandomaccessthing public void close do nothing public void pread long file offset byte buf int buf offset int length throws io exception if file offset 0 throw new io exception cannot read before zero if file offset length data length throw new io exception cannot read after end trying to read from file offset to file offset length on block length data length system arraycopy data int file offset buf buf offset length fileoffset bufoffset ioexception fileoffset ioexception fileoffset ioexception fileoffset fileoffset fileoffset bufoffset public void pwrite long file offset byte buf int buf offset int length throws io exception if file offset 0 throw new io exception cannot write before zero if file offset length data length throw new io exception cannot write after end trying to write from file offset to file offset length on block length data length if read only throw new io exception read only system arraycopy buf buf offset data int file offset length fileoffset bufoffset ioexception fileoffset ioexception fileoffset ioexception fileoffset fileoffset readonly ioexception bufoffset fileoffset public long size throws io exception return data length ioexception public void set read only read only true setreadonly readonly public final string charset private unknown charset exception string warning string warning2 string string html node explanation string charset super warning warning2 string explanation this charset charset unknowncharsetexception htmlnode public static unknown charset exception create unsupported encoding exception e string charset html node explanation new html node p string expl title l10ndf unknown charset title string expl l10ndf unknown charset explanation add child b expl title explanation add child expl string warning l10ndf warning unknown charset title charset charset return new unknown charset exception warning warning expl title expl explanation charset unknowncharsetexception unsupportedencodingexception htmlnode htmlnode expltitle unknowncharsettitle unknowncharset addchild expltitle addchild warningunknowncharsettitle unknowncharsetexception expltitle private static string l10ndf string key all the strings here are generic return l10n get string content data filter key getstring contentdatafilter private static string l10ndf string key string pattern string value all the strings here are generic return l10n get string content data filter key pattern value getstring contentdatafilter public announcer jmdns impl jmdns impl this jmdns impl jmdns impl associate host to this if it needs announcing if this jmdns impl get state dns state announcing 1 this jmdns impl set task this associate services to this if they need announcing synchronized this jmdns impl for iterator s this jmdns impl get services values iterator s has next service info impl info service info impl s next if info get state dns state announcing 1 info set task this jmdnsimpl jmdnsimpl jmdnsimpl jmdnsimpl jmdnsimpl getstate dnsstate announcing_1 jmdnsimpl settask jmdnsimpl jmdnsimpl getservices hasnext serviceinfoimpl serviceinfoimpl getstate dnsstate announcing_1 settask public void start timer timer timer schedule this dns constants announce wait interval dns constants announce wait interval dnsconstants announce_wait_interval dnsconstants announce_wait_interval public boolean cancel remove association from host to this if this jmdns impl get task this this jmdns impl set task null remove associations from services to this synchronized this jmdns impl for iterator i this jmdns impl get services values iterator i has next service info impl info service info impl i next if info get task this info set task null return super cancel jmdnsimpl gettask jmdnsimpl settask jmdnsimpl jmdnsimpl getservices hasnext serviceinfoimpl serviceinfoimpl gettask settask public void run dns outgoing out null try send probes for jmdns itself if this jmdns impl get state task state if out null out new dns outgoing dns constants flags qr response dns constants flags aa this jmdns impl get local host add address records out false this jmdns impl advance state send announces for services defensively copy the services into a local list to prevent race conditions with methods register service and unregister service list list synchronized this jmdns impl list new array list this jmdns impl get services values for iterator i list iterator i has next service info impl info service info impl i next synchronized info if info get state task state info get task this info advance state logger finer run jmdns announcing info get qualified name state info get state if out null out new dns outgoing dns constants flags qr response dns constants flags aa info add answers out dns constants dns ttl this jmdns impl get local host if out null logger finer run jmdns announcing task state this jmdns impl send out else if we have nothing to send another timer task state ahead of us has done the job for us we can cancel cancel catch throwable e logger log level warning run exception e this jmdns impl recover task state task state advance if task state is announcing cancel this jmdns impl start renewer dnsoutgoing jmdnsimpl getstate taskstate dnsoutgoing dnsconstants flags_qr_response dnsconstants flags_aa jmdnsimpl getlocalhost addaddressrecords jmdnsimpl advancestate registerservice unregisterservice jmdnsimpl arraylist jmdnsimpl getservices hasnext serviceinfoimpl serviceinfoimpl getstate taskstate gettask advancestate getqualifiedname getstate dnsoutgoing dnsconstants flags_qr_response dnsconstants flags_aa addanswers dnsconstants dns_ttl jmdnsimpl getlocalhost taskstate jmdnsimpl taskstate jmdnsimpl taskstate taskstate taskstate isannouncing jmdnsimpl startrenewer persistent blob temp bucket tag persistent blob temp bucket factory f long idx factory f index idx is free true persistentblobtempbuckettag persistentblobtempbucketfactory isfree static logger register log threshold callback new log threshold callback override public void should update logminor logger should log logger minor this registerlogthresholdcallback logthresholdcallback shouldupdate shouldlog public update over mandatory manager node update manager manager this update manager manager nodes say key revoked new hash set peer node nodes say key revoked failed transfer new hash set peer node nodes offered main jar new hash set peer node nodes offered ext jar new hash set peer node nodes asked send main jar new hash set peer node nodes asked send ext jar new hash set peer node nodes sending main jar new hash set peer node nodes sending ext jar new hash set peer node updateovermandatorymanager nodeupdatemanager updatemanager nodessaykeyrevoked hashset peernode nodessaykeyrevokedfailedtransfer hashset peernode nodesofferedmainjar hashset peernode nodesofferedextjar hashset peernode nodesaskedsendmainjar hashset peernode nodesaskedsendextjar hashset peernode nodessendingmainjar hashset peernode nodessendingextjar hashset peernode handle a uom announce message a node has sent us a message offering us use of its update over mandatory facilities in some way param m the message to handle param source the peer node which sent the message return true unless we don t want the message in this case always true public boolean handle announce message m final peer node source string main jar key m get string dmt main jar key string extra jar key m get string dmt extra jar key string revocation key m get string dmt revocation key boolean have revocation key m get boolean dmt have revocation key long main jar version m get long dmt main jar version long extra jar version m get long dmt extra jar version long revocation key last tried m get long dmt revocation key time last tried int revocation keydn fs m get int dmt revocation key dnf count long revocation key file length m get long dmt revocation key file length long main jar file length m get long dmt main jar file length long extra jar file length m get long dmt extra jar file length int ping time m get int dmt ping time int delay time m get int dmt bwlimit delay time log it if logminor logger minor this update over mandatory offer from node source get peer source user to string logger minor this main jar key main jar key version main jar version length main jar file length logger minor this extra jar key extra jar key version extra jar version length extra jar file length logger minor this revocation key revocation key found have revocation key length revocation key file length last had 3 dn fs revocation key last tried ms ago revocation keydn fs dn fs so far logger minor this load stats ping time ms ping delay time ms bwlimit delay time now the core logic first off if a node says it has the revocation key and its key is the same as ours we should 1 suspend any auto updates and tell the user 2 try to download it and 3 if the download fails move the notification if the download succeeds process it if have revocation key if update manager is blown return true we already know first is the key the same as ours try freeneturi revocationuri new freeneturi revocation key if revocationuri equals update manager revocationuri uh oh have to do this first to avoid race condition synchronized this nodes say key revoked add source disable the update update manager peer claims key blown source tell the user alert user system err println your peer source user to string says that the auto update key is blown system err println attempting to fetch it try to transfer it message msg dmt createuom request revocation update manager node random next long source send async msg new async message callback public void acknowledged ok public void disconnected system err println failed to send request for revocation key to source user to string because it disconnected synchronized update over mandatory manager this nodes say key revoked failed transfer add source public void fatal error not good system err println failed to send request for revocation key to source user to string because of a fatal error public void sent cool update manager ctr the reply message will start the transfer it includes the revocation uri so we can tell if anything wierd is happening else should probably also be a useralert logger normal this node source sent us a uom claiming that the auto update key was blown but it used a different key to us nour key update manager revocationuri nhis key revocationuri system err println node source user to string sent us a uom claiming that the revocation key was blown but it used a different key to us nour key update manager revocationuri nhis key revocationuri catch malformedurl exception e should maybe be a useralert logger error this node source sent us a uom announce claiming that the auto update key was blown but it had an invalid revocation uri revocation key e e system err println node source user to string sent us a uom announce claiming that the revocation key was blown but it had an invalid revocation uri revocation key e catch not connected exception e system err println node source says that the auto update key was blown but has now gone offline something bad may be happening logger error this node source says that the auto update key was blown but has now gone offline something bad may be happening synchronized update over mandatory manager this nodes say key revoked failed transfer add source if update manager is blown return true we already know if update manager is enabled return true don t care if not enabled except for the revocation uri long now system current time millis handle main jar offer now main jar file length main jar version source main jar key handle ext jar offer now extra jar file length extra jar version source extra jar key return true uomannounce peernode handleannounce peernode mainjarkey getstring main_jar_key extrajarkey getstring extra_jar_key revocationkey getstring revocation_key haverevocationkey getboolean have_revocation_key mainjarversion getlong main_jar_version extrajarversion getlong extra_jar_version revocationkeylasttried getlong revocation_key_time_last_tried revocationkeydnfs getint revocation_key_dnf_count revocationkeyfilelength getlong revocation_key_file_length mainjarfilelength getlong main_jar_file_length extrajarfilelength getlong extra_jar_file_length pingtime getint ping_time delaytime getint bwlimit_delay_time getpeer usertostring mainjarkey mainjarversion mainjarfilelength extrajarkey extrajarversion extrajarfilelength revocationkey haverevocationkey revocationkeyfilelength dnfs revocationkeylasttried revocationkeydnfs dnfs pingtime delaytime haverevocationkey updatemanager isblown revocationkey updatemanager nodessaykeyrevoked updatemanager peerclaimskeyblown alertuser usertostring createuomrequestrevocation updatemanager nextlong sendasync asyncmessagecallback usertostring updateovermandatorymanager nodessaykeyrevokedfailedtransfer fatalerror usertostring updatemanager updatemanager usertostring updatemanager malformedurlexception uomannounce revocationkey usertostring uomannounce revocationkey notconnectedexception updateovermandatorymanager nodessaykeyrevokedfailedtransfer updatemanager isblown updatemanager isenabled currenttimemillis handlemainjaroffer mainjarfilelength mainjarversion mainjarkey handleextjaroffer extrajarfilelength extrajarversion extrajarkey source send async msg new async message callback public void acknowledged ok sendasync asyncmessagecallback public void disconnected system err println failed to send request for revocation key to source user to string because it disconnected synchronized update over mandatory manager this nodes say key revoked failed transfer add source usertostring updateovermandatorymanager nodessaykeyrevokedfailedtransfer public void fatal error not good system err println failed to send request for revocation key to source user to string because of a fatal error fatalerror usertostring public void sent cool private void handle main jar offer long now long main jar file length long main jar version peer node source string jar key long started update manager get started fetching next main jar timestamp long when to take over the normal updater if started 0 when to take over the normal updater started grace time else when to take over the normal updater system current time millis grace time boolean is outdated update manager node is oudated if the new build is self mandatory or if the normal updater has been trying to update for more than one hour logger normal this we received a valid uom announce main is outdated is outdated version main jar version when to take over the normal updater time util format time when to take over the normal updater now file length main jar file length update manager version update manager new main jar version if main jar version version build number main jar file length 0 main jar version update manager new main jar version source set main jar offered version main jar version offer is valid if logminor logger minor this offer is valid if is outdated when to take over the normal updater now take up the offer subject to limits on number of simultaneous downloads if we have fetches running already then senduom request main will add the offer to nodes offered main jar so that if all our fetches fail we can fetch from this node if is outdated string how long time util format time now started logger error this the update process seems to have been stuck for how long let s switch to uom should not happen 1 system out println the update process seems to have been stuck for how long let s switch to uom should not happen 1 else if logminor logger minor this fetching via uom as our build is deprecated fetch it try freeneturi main jaruri new freeneturi jar key set suggested edition main jar version if main jaruri equals update manager updateuri set suggested edition main jar version senduom request source true false else system err println node source user to string offered us a new main jar version main jar version but his key was different to ours n our key update manager updateuri nhis key main jaruri catch malformedurl exception e should maybe be a useralert logger error this node source sent us a uom announce claiming to have a new ext jar but it had an invalid uri jar key e e system err println node source user to string sent us a uom announce claiming to have a new ext jar but it had an invalid uri jar key e else don t take up the offer add to nodes offered main jar so that we know where to fetch it from when we need it synchronized this nodes offered main jar add source update manager node get ticker queue timed job new runnable public void run if update manager is blown return if update manager is enabled return if update manager has new main jar return if update manager node is oudated logger error this the update process seems to have been stuck for too long let s switch to uom should not happen 2 ext system out println the update process seems to have been stuck for too long let s switch to uom should not happen 2 ext maybe request main jar when to take over the normal updater now handlemainjaroffer mainjarfilelength mainjarversion peernode jarkey updatemanager getstartedfetchingnextmainjartimestamp whentotakeoverthenormalupdater whentotakeoverthenormalupdater grace_time whentotakeoverthenormalupdater currenttimemillis grace_time isoutdated updatemanager isoudated uomannounce isoutdated isoutdated mainjarversion whentotakeoverthenormalupdater timeutil formattime whentotakeoverthenormalupdater mainjarfilelength updatemanager updatemanager newmainjarversion mainjarversion buildnumber mainjarfilelength mainjarversion updatemanager newmainjarversion setmainjarofferedversion mainjarversion isoutdated whentotakeoverthenormalupdater senduomrequestmain nodesofferedmainjar isoutdated howlong timeutil formattime howlong howlong mainjaruri jarkey setsuggestededition mainjarversion mainjaruri updatemanager setsuggestededition mainjarversion senduomrequest usertostring mainjarversion updatemanager mainjaruri malformedurlexception uomannounce jarkey usertostring uomannounce jarkey nodesofferedmainjar nodesofferedmainjar updatemanager getticker queuetimedjob updatemanager isblown updatemanager isenabled updatemanager hasnewmainjar updatemanager isoudated mayberequestmainjar whentotakeoverthenormalupdater public void run if update manager is blown return if update manager is enabled return if update manager has new main jar return if update manager node is oudated logger error this the update process seems to have been stuck for too long let s switch to uom should not happen 2 ext system out println the update process seems to have been stuck for too long let s switch to uom should not happen 2 ext maybe request main jar updatemanager isblown updatemanager isenabled updatemanager hasnewmainjar updatemanager isoudated mayberequestmainjar private void handle ext jar offer long now long ext jar file length long ext jar version peer node source string jar key long started update manager get started fetching next ext jar timestamp long when to take over the normal updater if started 0 when to take over the normal updater started grace time else when to take over the normal updater system current time millis grace time boolean is outdated update manager node is oudated if the new build is self mandatory or if the normal updater has been trying to update for more than one hour logger normal this we received a valid uom announce ext is outdated is outdated version ext jar version when to take over the normal updater time util format time when to take over the normal updater now file length ext jar file length update manager version update manager new ext jar version if ext jar version node starter ext build number ext jar file length 0 ext jar version update manager new ext jar version source set ext jar offered version ext jar version offer is valid if logminor logger minor this offer is valid if is outdated when to take over the normal updater now take up the offer subject to limits on number of simultaneous downloads if we have fetches running already then senduom request main will add the offer to nodes offered main jar so that if all our fetches fail we can fetch from this node if is outdated string how long time util format time now started logger error this the update process seems to have been stuck for how long let s switch to uom should not happen 1 ext system out println the update process seems to have been stuck for how long let s switch to uom should not happen 1 ext else if logminor logger minor this fetching via uom as our build is deprecated fetch it try freeneturi ext jaruri new freeneturi jar key set suggested edition ext jar version if ext jaruri equals update manager exturi set suggested edition ext jar version senduom request source true true else system err println node source user to string offered us a new ext jar version ext jar version but his key was different to ours n our key update manager exturi nhis key ext jaruri catch malformedurl exception e should maybe be a useralert logger error this node source sent us a uom announce claiming to have a new ext jar but it had an invalid uri jar key e e system err println node source user to string sent us a uom announce claiming to have a new jar but it had an invalid uri jar key e else don t take up the offer add to nodes offered main jar so that we know where to fetch it from when we need it synchronized this nodes offered ext jar add source update manager node get ticker queue timed job new runnable public void run if update manager is blown return if update manager is enabled return if update manager has new ext jar return if update manager node is oudated logger error this the update process seems to have been stuck for too long let s switch to uom should not happen 2 system out println the update process seems to have been stuck for too long let s switch to uom should not happen 2 maybe request ext jar when to take over the normal updater now handleextjaroffer extjarfilelength extjarversion peernode jarkey updatemanager getstartedfetchingnextextjartimestamp whentotakeoverthenormalupdater whentotakeoverthenormalupdater grace_time whentotakeoverthenormalupdater currenttimemillis grace_time isoutdated updatemanager isoudated uomannounce isoutdated isoutdated extjarversion whentotakeoverthenormalupdater timeutil formattime whentotakeoverthenormalupdater extjarfilelength updatemanager updatemanager newextjarversion extjarversion nodestarter extbuildnumber extjarfilelength extjarversion updatemanager newextjarversion setextjarofferedversion extjarversion isoutdated whentotakeoverthenormalupdater senduomrequestmain nodesofferedmainjar isoutdated howlong timeutil formattime howlong howlong extjaruri jarkey setsuggestededition extjarversion extjaruri updatemanager setsuggestededition extjarversion senduomrequest usertostring extjarversion updatemanager extjaruri malformedurlexception uomannounce jarkey usertostring uomannounce jarkey nodesofferedmainjar nodesofferedextjar updatemanager getticker queuetimedjob updatemanager isblown updatemanager isenabled updatemanager hasnewextjar updatemanager isoudated mayberequestextjar whentotakeoverthenormalupdater public void run if update manager is blown return if update manager is enabled return if update manager has new ext jar return if update manager node is oudated logger error this the update process seems to have been stuck for too long let s switch to uom should not happen 2 system out println the update process seems to have been stuck for too long let s switch to uom should not happen 2 maybe request ext jar updatemanager isblown updatemanager isenabled updatemanager hasnewextjar updatemanager isoudated mayberequestextjar private void senduom request final peer node source boolean add on fail final boolean is ext final string name is ext extra main string lname is ext ext main if logminor logger minor this senduom request name source add on fail if source is connected return final hash set peer node sending jar is ext nodes sending ext jar nodes sending main jar final hash set peer node asked send jar is ext nodes asked send ext jar nodes asked send main jar synchronized this long offered version is ext source get ext jar offered version source get main jar offered version long update version is ext update manager new ext jar version update manager new main jar version if offered version update version if offered version 0 logger error this not sending uom lname request to source because it hasn t offered anything else if logminor logger minor this not sending uom lname request to source because we already have its offered version offered version return int cur version is ext update manager get ext version update manager get main version if cur version offered version if logminor logger minor this not fetching from source because current lname jar version cur version is more recent than offered version return if asked send jar contains source if logminor logger minor this recently asked node source lname so not re asking yet return if add on fail asked send jar size sending jar size max nodes sending jar hash set peer node offered jar is ext nodes offered ext jar nodes offered main jar if offered jar add source system err println offered lname jar by source user to string already fetching from sending jar size but will use this offer if our current fetches fail return else if sending jar contains source if logminor logger minor this not fetching lname jar from source user to string because already fetching from that node return sending jar add source message msg is ext dmt createuom request extra update manager node random next long dmt createuom request main update manager node random next long try system err println fetching lname jar from source user to string source send async msg new async message callback public void acknowledged cool wait for the actual transfer public void disconnected logger normal this disconnected from source user to string after sending uom request name synchronized update over mandatory manager this sending jar remove source if is ext maybe request ext jar else maybe request main jar public void fatal error logger normal this fatal error from source user to string after sending uom request name synchronized update over mandatory manager this asked send jar remove source if is ext maybe request ext jar else maybe request main jar public void sent timeout update manager node ps queue timed job new runnable public void run synchronized update over mandatory manager this if asked send jar contains source return asked send jar remove source free up a slot if is ext maybe request ext jar else maybe request main jar request main jar timeout update manager ctr catch not connected exception e synchronized this asked send jar remove source if is ext maybe request ext jar else maybe request main jar senduomrequest peernode addonfail isext isext isext senduomrequest addonfail isconnected hashset peernode sendingjar isext nodessendingextjar nodessendingmainjar hashset peernode askedsendjar isext nodesaskedsendextjar nodesaskedsendmainjar offeredversion isext getextjarofferedversion getmainjarofferedversion updateversion isext updatemanager newextjarversion updatemanager newmainjarversion offeredversion updateversion offeredversion offeredversion curversion isext updatemanager getextversion updatemanager getmainversion curversion offeredversion curversion offeredversion askedsendjar addonfail askedsendjar sendingjar max_nodes_sending_jar hashset peernode offeredjar isext nodesofferedextjar nodesofferedmainjar offeredjar usertostring sendingjar sendingjar usertostring sendingjar isext createuomrequestextra updatemanager nextlong createuomrequestmain updatemanager nextlong usertostring sendasync asyncmessagecallback usertostring uomrequest updateovermandatorymanager sendingjar isext mayberequestextjar mayberequestmainjar fatalerror usertostring uomrequest updateovermandatorymanager askedsendjar isext mayberequestextjar mayberequestmainjar updatemanager queuetimedjob updateovermandatorymanager askedsendjar askedsendjar isext mayberequestextjar mayberequestmainjar request_main_jar_timeout updatemanager notconnectedexception askedsendjar isext mayberequestextjar mayberequestmainjar source send async msg new async message callback public void acknowledged cool wait for the actual transfer sendasync asyncmessagecallback public void disconnected logger normal this disconnected from source user to string after sending uom request name synchronized update over mandatory manager this sending jar remove source if is ext maybe request ext jar else maybe request main jar usertostring uomrequest updateovermandatorymanager sendingjar isext mayberequestextjar mayberequestmainjar public void fatal error logger normal this fatal error from source user to string after sending uom request name synchronized update over mandatory manager this asked send jar remove source if is ext maybe request ext jar else maybe request main jar fatalerror usertostring uomrequest updateovermandatorymanager askedsendjar isext mayberequestextjar mayberequestmainjar public void sent timeout update manager node ps queue timed job new runnable public void run synchronized update over mandatory manager this if asked send jar contains source return asked send jar remove source free up a slot if is ext maybe request ext jar else maybe request main jar request main jar timeout updatemanager queuetimedjob updateovermandatorymanager askedsendjar askedsendjar isext mayberequestextjar mayberequestmainjar request_main_jar_timeout public void run synchronized update over mandatory manager this if asked send jar contains source return asked send jar remove source free up a slot if is ext maybe request ext jar else maybe request main jar updateovermandatorymanager askedsendjar askedsendjar isext mayberequestextjar mayberequestmainjar protected void maybe request main jar peer node offers synchronized this if nodes asked send main jar size nodes sending main jar size max nodes sending jar return if nodes offered main jar is empty return offers nodes offered main jar to array new peer node nodes offered main jar size for int i 0 i offers length i if offers i is connected continue synchronized this if nodes asked send main jar size nodes sending main jar size max nodes sending jar return if nodes sending main jar contains offers i continue if nodes asked send main jar contains offers i continue senduom request offers i false false mayberequestmainjar peernode nodesaskedsendmainjar nodessendingmainjar max_nodes_sending_jar nodesofferedmainjar isempty nodesofferedmainjar toarray peernode nodesofferedmainjar isconnected nodesaskedsendmainjar nodessendingmainjar max_nodes_sending_jar nodessendingmainjar nodesaskedsendmainjar senduomrequest protected void maybe request ext jar peer node offers synchronized this if nodes asked send ext jar size nodes sending ext jar size max nodes sending jar return if nodes offered ext jar is empty return offers nodes offered ext jar to array new peer node nodes offered ext jar size for int i 0 i offers length i if offers i is connected continue synchronized this if nodes asked send ext jar size nodes sending ext jar size max nodes sending jar return if nodes sending ext jar contains offers i continue if nodes asked send ext jar contains offers i continue senduom request offers i false true mayberequestextjar peernode nodesaskedsendextjar nodessendingextjar max_nodes_sending_jar nodesofferedextjar isempty nodesofferedextjar toarray peernode nodesofferedextjar isconnected nodesaskedsendextjar nodessendingextjar max_nodes_sending_jar nodessendingextjar nodesaskedsendextjar senduomrequest private void alert user synchronized this if alert null return alert new peers say key blown alert update manager node client core alerts register alert alertuser peerssaykeyblownalert updatemanager clientcore private class peers say key blown alert extends abstract user alert public peers say key blown alert super false null null null null user alert critical error true null false null peerssaykeyblownalert abstractuseralert peerssaykeyblownalert useralert critical_error override public html node gethtml text html node div new html node div div add child p add child l10n intro peer node nodes get nodes say blown peer node nodes say blown connected nodes 0 peer node nodes say blown disconnected nodes 1 peer node nodes say blown failed transfer nodes 2 if nodes say blown connected length 0 div add child p add child l10n fetching else div add child p add child l10n failed fetch if nodes say blown connected length 0 div add child p add child l10n connected say blown label html node list div add child ul for int i 0 i nodes say blown connected length i list add child li nodes say blown connected i user to string nodes say blown connected i get peer if nodes say blown disconnected length 0 div add child p add child l10n disconnected say blown label html node list div add child ul for int i 0 i nodes say blown disconnected length i list add child li nodes say blown disconnected i user to string nodes say blown disconnected i get peer if nodes say blown failed transfer length 0 div add child p add child l10n failed transfer say blown label html node list div add child ul for int i 0 i nodes say blown failed transfer length i list add child li nodes say blown failed transfer i user to string nodes say blown failed transfer i get peer return div htmlnode gethtmltext htmlnode htmlnode addchild addchild peernode getnodessayblown peernode nodessayblownconnected peernode nodessayblowndisconnected peernode nodessayblownfailedtransfer nodessayblownconnected addchild addchild addchild addchild failedfetch nodessayblownconnected addchild addchild connectedsayblownlabel htmlnode addchild nodessayblownconnected addchild nodessayblownconnected usertostring nodessayblownconnected getpeer nodessayblowndisconnected addchild addchild disconnectedsayblownlabel htmlnode addchild nodessayblowndisconnected addchild nodessayblowndisconnected usertostring nodessayblowndisconnected getpeer nodessayblownfailedtransfer addchild addchild failedtransfersayblownlabel htmlnode addchild nodessayblownfailedtransfer addchild nodessayblownfailedtransfer usertostring nodessayblownfailedtransfer getpeer private string l10n string key return l10n get string peers say key blown alert key getstring peerssaykeyblownalert private string l10n string key string pattern string value return l10n get string peers say key blown alert key pattern value getstring peerssaykeyblownalert override public string get text string builder sb new string builder sb append l10n intro append n n peer node nodes get nodes say blown peer node nodes say blown connected nodes 0 peer node nodes say blown disconnected nodes 1 peer node nodes say blown failed transfer nodes 2 if nodes say blown connected length 0 sb append l10n fetching append n n else sb append l10n failed fetch append n n if nodes say blown connected length 0 sb append l10n connected say blown label append n n for int i 0 i nodes say blown connected length i sb append nodes say blown connected i user to string nodes say blown connected i get peer append n sb append n if nodes say blown disconnected length 0 sb append l10n disconnected say blown label for int i 0 i nodes say blown disconnected length i sb append nodes say blown disconnected i user to string nodes say blown disconnected i get peer append n sb append n if nodes say blown failed transfer length 0 sb append l10n failed transfer say blown label for int i 0 i nodes say blown failed transfer length i sb append nodes say blown failed transfer i user to string nodes say blown failed transfer i get peer append n sb append n return sb to string gettext stringbuilder stringbuilder peernode getnodessayblown peernode nodessayblownconnected peernode nodessayblowndisconnected peernode nodessayblownfailedtransfer nodessayblownconnected failedfetch nodessayblownconnected connectedsayblownlabel nodessayblownconnected nodessayblownconnected usertostring nodessayblownconnected getpeer nodessayblowndisconnected disconnectedsayblownlabel nodessayblowndisconnected nodessayblowndisconnected usertostring nodessayblowndisconnected getpeer nodessayblownfailedtransfer failedtransfersayblownlabel nodessayblownfailedtransfer nodessayblownfailedtransfer usertostring nodessayblownfailedtransfer getpeer tostring override public string get title return l10n title with count count integer to string nodes say key revoked size gettitle titlewithcount tostring nodessaykeyrevoked override public void is valid boolean validity do nothing isvalid override public string get short text return l10n short getshorttext public peer node get nodes say blown vector peer node nodes connected say revoked new vector peer node vector peer node nodes disconnected say revoked new vector peer node vector peer node nodes failed say revoked new vector peer node synchronized this peer node nodes say revoked nodes say key revoked to array new peer node nodes say key revoked size for int i 0 i nodes say revoked length i peer node pn nodes say revoked i if nodes say key revoked failed transfer contains pn nodes failed say revoked add pn else nodes connected say revoked add pn for int i 0 i nodes connected say revoked size i peer node pn nodes connected say revoked get i if pn is connected nodes disconnected say revoked add pn nodes connected say revoked remove i i continue return new peer node nodes connected say revoked to array new peer node nodes connected say revoked size nodes disconnected say revoked to array new peer node nodes disconnected say revoked size nodes failed say revoked to array new peer node nodes failed say revoked size peernode getnodessayblown peernode nodesconnectedsayrevoked peernode peernode nodesdisconnectedsayrevoked peernode peernode nodesfailedsayrevoked peernode peernode nodessayrevoked nodessaykeyrevoked toarray peernode nodessaykeyrevoked nodessayrevoked peernode nodessayrevoked nodessaykeyrevokedfailedtransfer nodesfailedsayrevoked nodesconnectedsayrevoked nodesconnectedsayrevoked peernode nodesconnectedsayrevoked isconnected nodesdisconnectedsayrevoked nodesconnectedsayrevoked peernode nodesconnectedsayrevoked toarray peernode nodesconnectedsayrevoked nodesdisconnectedsayrevoked toarray peernode nodesdisconnectedsayrevoked nodesfailedsayrevoked toarray peernode nodesfailedsayrevoked a peer node requests us to send the binary blob of the revocation key param m the message requesting the transfer param source the node requesting the transfer return true if we handled the message i e always public boolean handle request revocation message m final peer node source do we have the data file data update manager revocation checker get blob file if data null logger normal this peer source asked us for the blob file for the revocation key but we don t have it probably a race condition on reconnect hopefully we ll be asked again return true final long uid m get long dmt uid random access file wrapper raf try raf new random access file wrapper data r catch file not found exception e logger error this peer source asked us for the blob file for the revocation key we have downloaded it but don t have the file even though we did have it when we checked e e return true final partially received bulk prb long length try length raf size prb new partially received bulk update manager node getusm length node packet size raf true catch io exception e logger error this peer source asked us for the blob file for the revocation key we have downloaded it but we can t determine the file size e e return true final bulk transmitter bt try bt new bulk transmitter prb source uid false update manager ctr catch disconnected exception e logger error this peer source asked us for the blob file for the revocation key then disconnected e e return true final runnable r new runnable public void run if bt send logger error this failed to send revocation key blob to source user to string bt get cancel reason else logger normal this sent revocation key blob to source user to string message msg dmt createuom sending revocation uid length update manager revocationuri to string try source send async msg new async message callback public void acknowledged if logminor logger minor this sending data send the data update manager node executor execute r revocation key send for uid to source user to string public void disconnected argh logger error this peer source asked us for the blob file for the revocation key then disconnected when we tried to send the uom sending revocation public void fatal error argh logger error this peer source asked us for the blob file for the revocation key then got a fatal error when we tried to send the uom sending revocation public void sent if logminor logger minor this message sent data soon override public string to string return super to string uid source get peer update manager ctr catch not connected exception e logger error this peer source asked us for the blob file for the revocation key then disconnected when we tried to send the uom sending revocation e e return true return true handlerequestrevocation peernode updatemanager revocationchecker getblobfile getlong randomaccessfilewrapper randomaccessfilewrapper filenotfoundexception partiallyreceivedbulk partiallyreceivedbulk updatemanager packet_size ioexception bulktransmitter bulktransmitter updatemanager disconnectedexception usertostring getcancelreason usertostring createuomsendingrevocation updatemanager tostring sendasync asyncmessagecallback updatemanager usertostring uomsendingrevocation fatalerror uomsendingrevocation tostring tostring getpeer updatemanager notconnectedexception uomsendingrevocation public void run if bt send logger error this failed to send revocation key blob to source user to string bt get cancel reason else logger normal this sent revocation key blob to source user to string usertostring getcancelreason usertostring public void acknowledged if logminor logger minor this sending data send the data update manager node executor execute r revocation key send for uid to source user to string updatemanager usertostring public void disconnected argh logger error this peer source asked us for the blob file for the revocation key then disconnected when we tried to send the uom sending revocation uomsendingrevocation public void fatal error argh logger error this peer source asked us for the blob file for the revocation key then got a fatal error when we tried to send the uom sending revocation fatalerror uomsendingrevocation public void sent if logminor logger minor this message sent data soon override public string to string return super to string uid source get peer tostring tostring getpeer public boolean handle sending revocation message m final peer node source final long uid m get long dmt uid final long length m get long dmt file length string key m get string dmt revocation key freeneturi revocationuri try revocationuri new freeneturi key catch malformedurl exception e logger error this failed receiving recovation because uri not parsable e for key e system err println failed receiving recovation because uri not parsable e for key e print stack trace synchronized this wierd case of a failed transfer nodes say key revoked failed transfer add source cancel send source uid return true if revocationuri equals update manager revocationuri system err println node sending us a revocation certificate from the wrong uri n node source user to string n our uri update manager revocationuri n their uri revocationuri synchronized this wierd case of a failed transfer nodes say key revoked failed transfer add source cancel send source uid return true if update manager is blown if logminor logger minor this already blown so not receiving from source uid cancel send source uid return true if length node update manager max revocation key length system err println node source user to string offered us a revocation certificate size util format size length long this is unacceptably long so we have refused the transfer logger error this node source user to string offered us a revocation certificate size util format size length long this is unacceptably long so we have refused the transfer synchronized update over mandatory manager this nodes say key revoked failed transfer add source cancel send source uid return true okay we can receive it final file temp try temp file create temp file revocation fblob tmp update manager node client core get persistent temp dir temp delete on exit catch io exception e system err println cannot save revocation certificate to disk and therefore cannot fetch it from our peer e e print stack trace update manager blow cannot fetch the revocation certificate from our peer because we cannot write it to disk e cancel send source uid return true random access file wrapper raf try raf new random access file wrapper temp rw catch file not found exception e logger error this peer source asked us for the blob file for the revocation key we have downloaded it but don t have the file even though we did have it when we checked e e return true partially received bulk prb new partially received bulk update manager node getusm length node packet size raf false final bulk receiver br new bulk receiver prb source uid update manager ctr update manager node executor execute new runnable public void run if br receive success process revocation blob temp source else logger error this failed to transfer revocation certificate from source system err println failed to transfer revocation certificate from source synchronized update over mandatory manager this nodes say key revoked failed transfer add source revocation key receive for uid from source user to string return true handlesendingrevocation peernode getlong getlong file_length getstring revocation_key malformedurlexception printstacktrace nodessaykeyrevokedfailedtransfer cancelsend updatemanager usertostring updatemanager nodessaykeyrevokedfailedtransfer cancelsend updatemanager isblown cancelsend nodeupdatemanager max_revocation_key_length usertostring sizeutil formatsize usertostring sizeutil formatsize updateovermandatorymanager nodessaykeyrevokedfailedtransfer cancelsend createtempfile updatemanager clientcore getpersistenttempdir deleteonexit ioexception printstacktrace updatemanager cancelsend randomaccessfilewrapper randomaccessfilewrapper filenotfoundexception partiallyreceivedbulk partiallyreceivedbulk updatemanager packet_size bulkreceiver bulkreceiver updatemanager updatemanager processrevocationblob updateovermandatorymanager nodessaykeyrevokedfailedtransfer usertostring public void run if br receive success process revocation blob temp source else logger error this failed to transfer revocation certificate from source system err println failed to transfer revocation certificate from source synchronized update over mandatory manager this nodes say key revoked failed transfer add source processrevocationblob updateovermandatorymanager nodessaykeyrevokedfailedtransfer process a binary blob for a revocation certificate the revocation key param temp the file it was written to protected void process revocation blob final file temp final peer node source simple block set blocks new simple block set data input stream dis null try dis new data input stream new buffered input stream new file input stream temp binary blob read binary blob dis blocks true catch file not found exception e logger error this somebody deleted temp we lost the revocation certificate from source user to string system err println somebody deleted temp we lost the revocation certificate from source user to string update manager blow somebody deleted temp we lost the revocation certificate from source user to string return catch io exception e logger error this could not read revocation cert from temp file temp from node source user to string system err println could not read revocation cert from temp file temp from node source user to string update manager blow could not read revocation cert from temp file temp from node source user to string fixme will be kept until exit for debugging purposes return catch binary blob format exception e logger error this peer source user to string sent us an invalid revocation certificate e data in temp e system err println peer source user to string sent us an invalid revocation certificate e data in temp probably malicious might just be buggy either way it s not blown e print stack trace synchronized update over mandatory manager this nodes say key revoked failed transfer add source fixme file will be kept until exit for debugging purposes return finally if dis null try dis close catch io exception e ignore fetch our revocation key from the datastore plus the binary blob fetch context seed context update manager node client core make client short 0 true get fetch context fetch context temp context new fetch context seed context fetch context identical mask true blocks temp context local request only true file f file bucket b null try f file create temp file revocation fblob tmp update manager node client core get persistent temp dir b new file bucket f false false true true true catch io exception e logger error this cannot share revocation key from source user to string with our peers because cannot write the cleaned version to disk e e system err println cannot share revocation key from source user to string with our peers because cannot write the cleaned version to disk e e print stack trace b null f null final file bucket cleaned blob b final file cleaned blob file f client callback my callback new client callback public void on failure fetch exception e client getter state object container container if e mode fetch exception cancelled eh logger error this cancelled fetch from store blob of revocation certificate from source user to string system err println cancelled fetch from store blob of revocation certificate from source user to string to temp please report to developers probably best to keep files around for now else if e is fatal blown somebody inserted a revocation message but it was corrupt as inserted however it had valid signatures etc system err println got revocation certificate from source user to string fatal error i e someone with the key inserted bad data blow the update and propagate the revocation certificate update manager revocation checker on failure e state cleaned blob file temp delete insert blob update manager revocation checker get blob file revocation else logger error this failed to fetch revocation certificate from blob from source user to string system err println failed to fetch revocation certificate from blob from source user to string synchronized update over mandatory manager this nodes say key revoked failed transfer add source public void on failure insert exception e base client putter state object container container ignore not possible public void on fetchable base client putter state object container container irrelevant public void on generateduri freeneturi uri base client putter state object container container ignore not possible public void on major progress object container container ignore public void on success fetch result result client getter state object container container system err println got revocation certificate from source user to string update manager revocation checker on success result state cleaned blob file temp delete insert blob update manager revocation checker get blob file revocation public void on success base client putter state object container container ignore not possible client getter cg new client getter my callback update manager revocationuri temp context short 0 this null cleaned blob try update manager node client core client context start cg catch fetch exception e1 system err println failed to decode uom blob e1 e1 print stack trace my callback on failure e1 cg null processrevocationblob peernode simpleblockset simpleblockset datainputstream datainputstream bufferedinputstream fileinputstream binaryblob readbinaryblob filenotfoundexception usertostring usertostring updatemanager usertostring ioexception usertostring usertostring updatemanager usertostring binaryblobformatexception usertostring usertostring printstacktrace updateovermandatorymanager nodessaykeyrevokedfailedtransfer ioexception fetchcontext seedcontext updatemanager clientcore makeclient getfetchcontext fetchcontext tempcontext fetchcontext seedcontext fetchcontext identical_mask tempcontext localrequestonly filebucket createtempfile updatemanager clientcore getpersistenttempdir filebucket ioexception usertostring usertostring printstacktrace filebucket cleanedblob cleanedblobfile clientcallback mycallback clientcallback onfailure fetchexception clientgetter objectcontainer fetchexception usertostring usertostring isfatal usertostring updatemanager revocationchecker onfailure cleanedblobfile insertblob updatemanager revocationchecker getblobfile usertostring usertostring updateovermandatorymanager nodessaykeyrevokedfailedtransfer onfailure insertexception baseclientputter objectcontainer onfetchable baseclientputter objectcontainer ongenerateduri baseclientputter objectcontainer onmajorprogress objectcontainer onsuccess fetchresult clientgetter objectcontainer usertostring updatemanager revocationchecker onsuccess cleanedblobfile insertblob updatemanager revocationchecker getblobfile onsuccess baseclientputter objectcontainer clientgetter clientgetter mycallback updatemanager tempcontext cleanedblob updatemanager clientcore clientcontext fetchexception printstacktrace mycallback onfailure public void on failure fetch exception e client getter state object container container if e mode fetch exception cancelled eh logger error this cancelled fetch from store blob of revocation certificate from source user to string system err println cancelled fetch from store blob of revocation certificate from source user to string to temp please report to developers probably best to keep files around for now else if e is fatal blown somebody inserted a revocation message but it was corrupt as inserted however it had valid signatures etc system err println got revocation certificate from source user to string fatal error i e someone with the key inserted bad data blow the update and propagate the revocation certificate update manager revocation checker on failure e state cleaned blob file temp delete insert blob update manager revocation checker get blob file revocation else logger error this failed to fetch revocation certificate from blob from source user to string system err println failed to fetch revocation certificate from blob from source user to string synchronized update over mandatory manager this nodes say key revoked failed transfer add source onfailure fetchexception clientgetter objectcontainer fetchexception usertostring usertostring isfatal usertostring updatemanager revocationchecker onfailure cleanedblobfile insertblob updatemanager revocationchecker getblobfile usertostring usertostring updateovermandatorymanager nodessaykeyrevokedfailedtransfer public void on failure insert exception e base client putter state object container container ignore not possible onfailure insertexception baseclientputter objectcontainer public void on fetchable base client putter state object container container irrelevant onfetchable baseclientputter objectcontainer public void on generateduri freeneturi uri base client putter state object container container ignore not possible ongenerateduri baseclientputter objectcontainer public void on major progress object container container ignore onmajorprogress objectcontainer public void on success fetch result result client getter state object container container system err println got revocation certificate from source user to string update manager revocation checker on success result state cleaned blob file temp delete insert blob update manager revocation checker get blob file revocation onsuccess fetchresult clientgetter objectcontainer usertostring updatemanager revocationchecker onsuccess cleanedblobfile insertblob updatemanager revocationchecker getblobfile public void on success base client putter state object container container ignore not possible onsuccess baseclientputter objectcontainer protected void insert blob final file blob final string type client callback callback new client callback public void on failure fetch exception e client getter state object container container ignore can t happen public void on failure insert exception e base client putter state object container container logger error this failed to insert type binary blob e e public void on fetchable base client putter state object container container ignore public void on generateduri freeneturi uri base client putter state object container container ignore public void on major progress object container container ignore public void on success fetch result result client getter state object container container ignore can t happen public void on success base client putter state object container container all done cool logger normal this inserted type binary blob file bucket bucket new file bucket blob true false false false false client putter putter new client putter callback bucket freeneturi empty chk uri null update manager node client core make client request starter interactive priority class get insert context true request starter interactive priority class false false this null null true try update manager node client core client context start putter false catch insert exception e1 logger error this failed to start insert of type binary blob e1 e1 insertblob clientcallback clientcallback onfailure fetchexception clientgetter objectcontainer onfailure insertexception baseclientputter objectcontainer onfetchable baseclientputter objectcontainer ongenerateduri baseclientputter objectcontainer onmajorprogress objectcontainer onsuccess fetchresult clientgetter objectcontainer onsuccess baseclientputter objectcontainer filebucket filebucket clientputter clientputter empty_chk_uri updatemanager clientcore makeclient requeststarter interactive_priority_class getinsertcontext requeststarter interactive_priority_class updatemanager clientcore clientcontext insertexception client callback callback new client callback public void on failure fetch exception e client getter state object container container ignore can t happen clientcallback clientcallback onfailure fetchexception clientgetter objectcontainer public void on failure insert exception e base client putter state object container container logger error this failed to insert type binary blob e e onfailure insertexception baseclientputter objectcontainer public void on fetchable base client putter state object container container ignore onfetchable baseclientputter objectcontainer public void on generateduri freeneturi uri base client putter state object container container ignore ongenerateduri baseclientputter objectcontainer public void on major progress object container container ignore onmajorprogress objectcontainer public void on success fetch result result client getter state object container container ignore can t happen onsuccess fetchresult clientgetter objectcontainer public void on success base client putter state object container container all done cool logger normal this inserted type binary blob onsuccess baseclientputter objectcontainer private void cancel send peer node source long uid message msg dmt createfnp bulk receive aborted uid try source send async msg null update manager ctr catch not connected exception e1 ignore cancelsend peernode createfnpbulkreceiveaborted sendasync updatemanager notconnectedexception public void kill alert update manager node client core alerts unregister alert killalert updatemanager clientcore public boolean handle request jar message m final peer node source boolean is ext do we have the data int version is ext update manager new ext jar version update manager new main jar version file data is ext update manager get ext blob version update manager get main blob version final string name is ext ext main if data null logger normal this peer source asked us for the blob file for the name jar but we don t have it probably a race condition on reconnect hopefully we ll be asked again return true final long uid m get long dmt uid random access file wrapper raf try raf new random access file wrapper data r catch file not found exception e logger error this peer source asked us for the blob file for the name jar we have downloaded it but don t have the file even though we did have it when we checked e e return true final partially received bulk prb long length try length raf size prb new partially received bulk update manager node getusm length node packet size raf true catch io exception e logger error this peer source asked us for the blob file for the name jar we have downloaded it but we can t determine the file size e e return true final bulk transmitter bt try bt new bulk transmitter prb source uid false update manager ctr catch disconnected exception e logger error this peer source asked us for the blob file for the name jar then disconnected e e return true final runnable r new runnable public void run if bt send logger error this failed to send name jar blob to source user to string bt get cancel reason else logger normal this sent name jar blob to source user to string message msg is ext dmt createuom sending extra uid length update manager exturi to string version dmt createuom sending main uid length update manager updateuri to string version try source send async msg new async message callback public void acknowledged if logminor logger minor this sending data send the data update manager node executor execute r name jar send for uid to source user to string public void disconnected argh logger error this peer source asked us for the blob file for the name jar then disconnected when we tried to send the uom sending main public void fatal error argh logger error this peer source asked us for the blob file for the name jar then got a fatal error when we tried to send the uom sending main public void sent if logminor logger minor this message sent data soon override public string to string return super to string uid source get peer update manager ctr catch not connected exception e logger error this peer source asked us for the blob file for the name jar then disconnected when we tried to send the uom sending ext e e return true return true handlerequestjar peernode isext isext updatemanager newextjarversion updatemanager newmainjarversion isext updatemanager getextblob updatemanager getmainblob isext getlong randomaccessfilewrapper randomaccessfilewrapper filenotfoundexception partiallyreceivedbulk partiallyreceivedbulk updatemanager packet_size ioexception bulktransmitter bulktransmitter updatemanager disconnectedexception usertostring getcancelreason usertostring isext createuomsendingextra updatemanager tostring createuomsendingmain updatemanager tostring sendasync asyncmessagecallback updatemanager usertostring uomsendingmain fatalerror uomsendingmain tostring tostring getpeer updatemanager notconnectedexception uomsendingext public void run if bt send logger error this failed to send name jar blob to source user to string bt get cancel reason else logger normal this sent name jar blob to source user to string usertostring getcancelreason usertostring public void acknowledged if logminor logger minor this sending data send the data update manager node executor execute r name jar send for uid to source user to string updatemanager usertostring public void disconnected argh logger error this peer source asked us for the blob file for the name jar then disconnected when we tried to send the uom sending main uomsendingmain public void fatal error argh logger error this peer source asked us for the blob file for the name jar then got a fatal error when we tried to send the uom sending main fatalerror uomsendingmain public void sent if logminor logger minor this message sent data soon override public string to string return super to string uid source get peer tostring tostring getpeer public boolean handle sending main message m final peer node source final long uid m get long dmt uid final long length m get long dmt file length string key m get string dmt main jar key final int version m get int dmt main jar version final freeneturi jaruri try jaruri new freeneturi key set suggested edition version catch malformedurl exception e logger error this failed receiving main jar version because uri not parsable e for key e system err println failed receiving main jar version because uri not parsable e for key e print stack trace cancel send source uid synchronized this this nodes asked send main jar remove source return true if jaruri equals update manager updateuri set suggested edition version system err println node sending us a main jar update version from the wrong uri n node source user to string n our uri update manager updateuri n their uri jaruri cancel send source uid synchronized this this nodes asked send main jar remove source return true if update manager is blown if logminor logger minor this key blown so not receiving main jar from source uid cancel send source uid synchronized this this nodes asked send main jar remove source return true if length node update manager max main jar length system err println node source user to string offered us a main jar version size util format size length long this is unacceptably long so we have refused the transfer logger error this node source user to string offered us a main jar version size util format size length long this is unacceptably long so we have refused the transfer if the transfer fails we don t try again cancel send source uid synchronized this this nodes asked send main jar remove source return true okay we can receive it final file temp try temp file create temp file main fblob tmp update manager node client core get persistent temp dir temp delete on exit catch io exception e system err println cannot save new main jar to disk and therefore cannot fetch it from our peer e e print stack trace cancel send source uid synchronized this this nodes asked send main jar remove source return true random access file wrapper raf try raf new random access file wrapper temp rw catch file not found exception e logger error this peer source sending us a main jar binary blob but we lost the temp file temp e e synchronized this this nodes asked send main jar remove source return true partially received bulk prb new partially received bulk update manager node getusm length node packet size raf false final bulk receiver br new bulk receiver prb source uid update manager ctr update manager node executor execute new runnable public void run try synchronized update over mandatory manager class nodes asked send main jar remove source nodes sending main jar add source if br receive success process main jar blob temp source version jaruri else logger error this failed to transfer main jar version from source system err println failed to transfer main jar version from source finally synchronized update over mandatory manager class nodes sending main jar remove source main jar version receive for uid from source user to string return true handlesendingmain peernode getlong getlong file_length getstring main_jar_key getint main_jar_version setsuggestededition malformedurlexception printstacktrace cancelsend nodesaskedsendmainjar updatemanager setsuggestededition usertostring updatemanager cancelsend nodesaskedsendmainjar updatemanager isblown cancelsend nodesaskedsendmainjar nodeupdatemanager max_main_jar_length usertostring sizeutil formatsize usertostring sizeutil formatsize cancelsend nodesaskedsendmainjar createtempfile updatemanager clientcore getpersistenttempdir deleteonexit ioexception printstacktrace cancelsend nodesaskedsendmainjar randomaccessfilewrapper randomaccessfilewrapper filenotfoundexception nodesaskedsendmainjar partiallyreceivedbulk partiallyreceivedbulk updatemanager packet_size bulkreceiver bulkreceiver updatemanager updatemanager updateovermandatorymanager nodesaskedsendmainjar nodessendingmainjar processmainjarblob updateovermandatorymanager nodessendingmainjar usertostring public void run try synchronized update over mandatory manager class nodes asked send main jar remove source nodes sending main jar add source if br receive success process main jar blob temp source version jaruri else logger error this failed to transfer main jar version from source system err println failed to transfer main jar version from source finally synchronized update over mandatory manager class nodes sending main jar remove source updateovermandatorymanager nodesaskedsendmainjar nodessendingmainjar processmainjarblob updateovermandatorymanager nodessendingmainjar public boolean handle sending ext message m final peer node source final long uid m get long dmt uid final long length m get long dmt file length string key m get string dmt extra jar key final int version m get int dmt extra jar version final freeneturi jaruri try jaruri new freeneturi key set suggested edition version catch malformedurl exception e logger error this failed receiving ext jar version because uri not parsable e for key e system err println failed receiving ext jar version because uri not parsable e for key e print stack trace cancel send source uid synchronized this this nodes asked send ext jar remove source return true if jaruri equals update manager exturi set suggested edition version system err println node sending us a ext jar update version from the wrong uri n node source user to string n our uri update manager exturi n their uri jaruri cancel send source uid synchronized this this nodes asked send ext jar remove source return true if update manager is blown if logminor logger minor this key blown so not receiving main jar from source uid cancel send source uid synchronized this this nodes asked send ext jar remove source return true if length node update manager max main jar length system err println node source user to string offered us a ext jar version size util format size length long this is unacceptably long so we have refused the transfer logger error this node source user to string offered us a ext jar version size util format size length long this is unacceptably long so we have refused the transfer if the transfer fails we don t try again cancel send source uid synchronized this this nodes asked send ext jar remove source return true okay we can receive it final file temp try temp file create temp file ext fblob tmp update manager node client core get persistent temp dir temp delete on exit catch io exception e system err println cannot save new ext jar to disk and therefore cannot fetch it from our peer e e print stack trace cancel send source uid synchronized this this nodes asked send ext jar remove source return true random access file wrapper raf try raf new random access file wrapper temp rw catch file not found exception e logger error this peer source sending us a ext jar binary blob but we lost the temp file temp e e synchronized this this nodes asked send ext jar remove source return true partially received bulk prb new partially received bulk update manager node getusm length node packet size raf false final bulk receiver br new bulk receiver prb source uid update manager ctr update manager node executor execute new runnable public void run try synchronized update over mandatory manager class nodes asked send ext jar remove source nodes sending ext jar add source if br receive success process ext jar blob temp source version jaruri else logger error this failed to transfer ext jar version from source system err println failed to transfer ext jar version from source finally synchronized update over mandatory manager class nodes sending ext jar remove source ext jar version receive for uid from source user to string return true handlesendingext peernode getlong getlong file_length getstring extra_jar_key getint extra_jar_version setsuggestededition malformedurlexception printstacktrace cancelsend nodesaskedsendextjar updatemanager setsuggestededition usertostring updatemanager cancelsend nodesaskedsendextjar updatemanager isblown cancelsend nodesaskedsendextjar nodeupdatemanager max_main_jar_length usertostring sizeutil formatsize usertostring sizeutil formatsize cancelsend nodesaskedsendextjar createtempfile updatemanager clientcore getpersistenttempdir deleteonexit ioexception printstacktrace cancelsend nodesaskedsendextjar randomaccessfilewrapper randomaccessfilewrapper filenotfoundexception nodesaskedsendextjar partiallyreceivedbulk partiallyreceivedbulk updatemanager packet_size bulkreceiver bulkreceiver updatemanager updatemanager updateovermandatorymanager nodesaskedsendextjar nodessendingextjar processextjarblob updateovermandatorymanager nodessendingextjar usertostring public void run try synchronized update over mandatory manager class nodes asked send ext jar remove source nodes sending ext jar add source if br receive success process ext jar blob temp source version jaruri else logger error this failed to transfer ext jar version from source system err println failed to transfer ext jar version from source finally synchronized update over mandatory manager class nodes sending ext jar remove source updateovermandatorymanager nodesaskedsendextjar nodessendingextjar processextjarblob updateovermandatorymanager nodessendingextjar protected void process main jar blob final file temp final peer node source final int version freeneturi uri simple block set blocks new simple block set data input stream dis null try dis new data input stream new buffered input stream new file input stream temp binary blob read binary blob dis blocks true catch file not found exception e logger error this somebody deleted temp we lost the main jar version from source user to string system err println somebody deleted temp we lost the main jar version from source user to string return catch io exception e logger error this could not read main jar version from temp file temp from node source user to string system err println could not read main jar version from temp file temp from node source user to string fixme will be kept until exit for debugging purposes return catch binary blob format exception e logger error this peer source user to string sent us an invalid main jar version e e system err println peer source user to string sent us an invalid main jar version e e print stack trace fixme will be kept until exit for debugging purposes return finally if dis null try dis close catch io exception e ignore fetch the jar from the datastore plus the binary blob fetch context seed context update manager node client core make client short 0 true get fetch context fetch context temp context new fetch context seed context fetch context identical mask true blocks temp context local request only true file f file bucket b null try f file create temp file main fblob tmp update manager node client core get persistent temp dir f delete on exit b new file bucket f false false true true true catch io exception e logger error this cannot share main jar from source user to string with our peers because cannot write the cleaned version to disk e e system err println cannot share main jar from source user to string with our peers because cannot write the cleaned version to disk e e print stack trace b null f null final file bucket cleaned blob b final file cleaned blob file f client callback my callback new client callback public void on failure fetch exception e client getter state object container container if e mode fetch exception cancelled eh logger error this cancelled fetch from store blob of main jar version from source user to string system err println cancelled fetch from store blob of main jar version from source user to string to temp please report to developers probably best to keep files around for now else if e is fatal bogus as inserted ignore temp delete logger error this failed to fetch main jar version from source user to string fatal error update was probably inserted badly e e system err println failed to fetch main jar version from source user to string fatal error update was probably inserted badly e else logger error this failed to fetch main jar version from blob from source user to string system err println failed to fetch main jar version from blob from source user to string public void on failure insert exception e base client putter state object container container ignore not possible public void on fetchable base client putter state object container container irrelevant public void on generateduri freeneturi uri base client putter state object container container ignore not possible public void on major progress object container container ignore public void on success fetch result result client getter state object container container system err println got main jar version version from source user to string if result size 0 system err println ignoring because 0 bytes long return node updater main updater update manager main updater if main updater null system err println not updating because updater is disabled return main updater on success result state cleaned blob file version temp delete insert blob main updater get blob file version main jar public void on success base client putter state object container container ignore not possible client getter cg new client getter my callback uri temp context short 0 this null cleaned blob try update manager node client core client context start cg catch fetch exception e1 my callback on failure e1 cg null processmainjarblob peernode simpleblockset simpleblockset datainputstream datainputstream bufferedinputstream fileinputstream binaryblob readbinaryblob filenotfoundexception usertostring usertostring ioexception usertostring usertostring binaryblobformatexception usertostring usertostring printstacktrace ioexception fetchcontext seedcontext updatemanager clientcore makeclient getfetchcontext fetchcontext tempcontext fetchcontext seedcontext fetchcontext identical_mask tempcontext localrequestonly filebucket createtempfile updatemanager clientcore getpersistenttempdir deleteonexit filebucket ioexception usertostring usertostring printstacktrace filebucket cleanedblob cleanedblobfile clientcallback mycallback clientcallback onfailure fetchexception clientgetter objectcontainer fetchexception usertostring usertostring isfatal usertostring usertostring usertostring usertostring onfailure insertexception baseclientputter objectcontainer onfetchable baseclientputter objectcontainer ongenerateduri baseclientputter objectcontainer onmajorprogress objectcontainer onsuccess fetchresult clientgetter objectcontainer usertostring nodeupdater mainupdater updatemanager mainupdater mainupdater mainupdater onsuccess cleanedblobfile insertblob mainupdater getblobfile onsuccess baseclientputter objectcontainer clientgetter clientgetter mycallback tempcontext cleanedblob updatemanager clientcore clientcontext fetchexception mycallback onfailure public void on failure fetch exception e client getter state object container container if e mode fetch exception cancelled eh logger error this cancelled fetch from store blob of main jar version from source user to string system err println cancelled fetch from store blob of main jar version from source user to string to temp please report to developers probably best to keep files around for now else if e is fatal bogus as inserted ignore temp delete logger error this failed to fetch main jar version from source user to string fatal error update was probably inserted badly e e system err println failed to fetch main jar version from source user to string fatal error update was probably inserted badly e else logger error this failed to fetch main jar version from blob from source user to string system err println failed to fetch main jar version from blob from source user to string onfailure fetchexception clientgetter objectcontainer fetchexception usertostring usertostring isfatal usertostring usertostring usertostring usertostring public void on failure insert exception e base client putter state object container container ignore not possible onfailure insertexception baseclientputter objectcontainer public void on fetchable base client putter state object container container irrelevant onfetchable baseclientputter objectcontainer public void on generateduri freeneturi uri base client putter state object container container ignore not possible ongenerateduri baseclientputter objectcontainer public void on major progress object container container ignore onmajorprogress objectcontainer public void on success fetch result result client getter state object container container system err println got main jar version version from source user to string if result size 0 system err println ignoring because 0 bytes long return node updater main updater update manager main updater if main updater null system err println not updating because updater is disabled return main updater on success result state cleaned blob file version temp delete insert blob main updater get blob file version main jar onsuccess fetchresult clientgetter objectcontainer usertostring nodeupdater mainupdater updatemanager mainupdater mainupdater mainupdater onsuccess cleanedblobfile insertblob mainupdater getblobfile public void on success base client putter state object container container ignore not possible onsuccess baseclientputter objectcontainer protected void process ext jar blob final file temp final peer node source final int version freeneturi uri simple block set blocks new simple block set data input stream dis null try dis new data input stream new buffered input stream new file input stream temp binary blob read binary blob dis blocks true catch file not found exception e logger error this somebody deleted temp we lost the ext jar version from source user to string system err println somebody deleted temp we lost the ext jar version from source user to string return catch io exception e logger error this could not read ext jar version from temp file temp from node source user to string system err println could not read ext jar version from temp file temp from node source user to string fixme will be kept until exit for debugging purposes return catch binary blob format exception e logger error this peer source user to string sent us an invalid ext jar version e e system err println peer source user to string sent us an invalid ext jar version e e print stack trace fixme will be kept until exit for debugging purposes return finally if dis null try dis close catch io exception e ignore fetch the jar from the datastore plus the binary blob fetch context seed context update manager node client core make client short 0 true get fetch context fetch context temp context new fetch context seed context fetch context identical mask true blocks temp context local request only true file f file bucket b null try f file create temp file ext fblob tmp update manager node client core get persistent temp dir f delete on exit b new file bucket f false false true true true catch io exception e logger error this cannot share ext jar from source user to string with our peers because cannot write the cleaned version to disk e e system err println cannot share ext jar from source user to string with our peers because cannot write the cleaned version to disk e e print stack trace b null f null final file bucket cleaned blob b final file cleaned blob file f client callback my callback new client callback public void on failure fetch exception e client getter state object container container if e mode fetch exception cancelled eh logger error this cancelled fetch from store blob of ext jar version from source user to string system err println cancelled fetch from store blob of ext jar version from source user to string to temp please report to developers probably best to keep files around for now else if e is fatal bogus as inserted ignore temp delete logger error this failed to fetch ext jar version from source user to string fatal error update was probably inserted badly e e system err println failed to fetch ext jar version from source user to string fatal error update was probably inserted badly e else logger error this failed to fetch ext jar version from blob from source user to string system err println failed to fetch ext jar version from blob from source user to string public void on failure insert exception e base client putter state object container container ignore not possible public void on fetchable base client putter state object container container irrelevant public void on generateduri freeneturi uri base client putter state object container container ignore not possible public void on major progress object container container ignore public void on success fetch result result client getter state object container container system err println got ext jar version version from source user to string if result size 0 system err println ignoring because 0 bytes long return node updater ext updater update manager ext updater if ext updater null system err println not updating because ext updater is disabled return ext updater on success result state cleaned blob file version temp delete insert blob ext updater get blob file version ext jar public void on success base client putter state object container container ignore not possible client getter cg new client getter my callback uri temp context short 0 this null cleaned blob try update manager node client core client context start cg catch fetch exception e1 my callback on failure e1 cg null processextjarblob peernode simpleblockset simpleblockset datainputstream datainputstream bufferedinputstream fileinputstream binaryblob readbinaryblob filenotfoundexception usertostring usertostring ioexception usertostring usertostring binaryblobformatexception usertostring usertostring printstacktrace ioexception fetchcontext seedcontext updatemanager clientcore makeclient getfetchcontext fetchcontext tempcontext fetchcontext seedcontext fetchcontext identical_mask tempcontext localrequestonly filebucket createtempfile updatemanager clientcore getpersistenttempdir deleteonexit filebucket ioexception usertostring usertostring printstacktrace filebucket cleanedblob cleanedblobfile clientcallback mycallback clientcallback onfailure fetchexception clientgetter objectcontainer fetchexception usertostring usertostring isfatal usertostring usertostring usertostring usertostring onfailure insertexception baseclientputter objectcontainer onfetchable baseclientputter objectcontainer ongenerateduri baseclientputter objectcontainer onmajorprogress objectcontainer onsuccess fetchresult clientgetter objectcontainer usertostring nodeupdater extupdater updatemanager extupdater extupdater extupdater onsuccess cleanedblobfile insertblob extupdater getblobfile onsuccess baseclientputter objectcontainer clientgetter clientgetter mycallback tempcontext cleanedblob updatemanager clientcore clientcontext fetchexception mycallback onfailure public void on failure fetch exception e client getter state object container container if e mode fetch exception cancelled eh logger error this cancelled fetch from store blob of ext jar version from source user to string system err println cancelled fetch from store blob of ext jar version from source user to string to temp please report to developers probably best to keep files around for now else if e is fatal bogus as inserted ignore temp delete logger error this failed to fetch ext jar version from source user to string fatal error update was probably inserted badly e e system err println failed to fetch ext jar version from source user to string fatal error update was probably inserted badly e else logger error this failed to fetch ext jar version from blob from source user to string system err println failed to fetch ext jar version from blob from source user to string onfailure fetchexception clientgetter objectcontainer fetchexception usertostring usertostring isfatal usertostring usertostring usertostring usertostring public void on failure insert exception e base client putter state object container container ignore not possible onfailure insertexception baseclientputter objectcontainer public void on fetchable base client putter state object container container irrelevant onfetchable baseclientputter objectcontainer public void on generateduri freeneturi uri base client putter state object container container ignore not possible ongenerateduri baseclientputter objectcontainer public void on major progress object container container ignore onmajorprogress objectcontainer public void on success fetch result result client getter state object container container system err println got ext jar version version from source user to string if result size 0 system err println ignoring because 0 bytes long return node updater ext updater update manager ext updater if ext updater null system err println not updating because ext updater is disabled return ext updater on success result state cleaned blob file version temp delete insert blob ext updater get blob file version ext jar onsuccess fetchresult clientgetter objectcontainer usertostring nodeupdater extupdater updatemanager extupdater extupdater extupdater onsuccess cleanedblobfile insertblob extupdater getblobfile public void on success base client putter state object container container ignore not possible onsuccess baseclientputter objectcontainer protected boolean remove old temp files file old temp files peer dir update manager node client core get persistent temp dir if old temp files peer dir exists return false if old temp files peer dir is directory logger error this persistent temporary files location is not a directory old temp files peer dir get path return false boolean got error false file old temp files old temp files peer dir list files new file filter private final int last good main build number version last good build private final int recommended ext build number node starter recommended ext build number public boolean accept file file string file name file get name if file name starts with revocation file name ends with fblob tmp return true string build number str int build number matcher ext build number matcher ext build number pattern matcher file name matcher main build number matcher main build number pattern matcher file name matcher ext temp build number matcher ext temp build number pattern matcher file name matcher main temp build number matcher main temp build number pattern matcher file name matcher revocation temp build number matcher revocation temp build number pattern matcher file name if main build number matcher matches try build number str main build number matcher group 1 build number integer parse int build number str if build number last good main build number return true catch number format exception e logger error this wierd file in persistent temp file name return false else if ext build number matcher matches try build number str ext build number matcher group 1 build number integer parse int build number str if build number recommended ext build number return true catch number format exception e logger error this wierd file in persistent temp file name return false else if main temp build number matcher matches ext temp build number matcher matches revocation temp build number matcher matches temporary file can be deleted return true return false for file file to delete old temp files string file to delete name file to delete get name if file to delete delete if file to delete exists logger error this cannot delete temporary persistent file file to delete name even though it exists must be too persistent else logger normal this temporary persistent file does not exist when deleting file to delete name got error true return got error removeoldtempfiles oldtempfilespeerdir updatemanager clientcore getpersistenttempdir oldtempfilespeerdir oldtempfilespeerdir isdirectory oldtempfilespeerdir getpath goterror oldtempfiles oldtempfilespeerdir listfiles filefilter lastgoodmainbuildnumber lastgoodbuild recommendedextbuildnumber nodestarter recommended_ext_build_number filename getname filename startswith filename endswith buildnumberstr buildnumber extbuildnumbermatcher extbuildnumberpattern filename mainbuildnumbermatcher mainbuildnumberpattern filename exttempbuildnumbermatcher exttempbuildnumberpattern filename maintempbuildnumbermatcher maintempbuildnumberpattern filename revocationtempbuildnumbermatcher revocationtempbuildnumberpattern filename mainbuildnumbermatcher buildnumberstr mainbuildnumbermatcher buildnumber parseint buildnumberstr buildnumber lastgoodmainbuildnumber numberformatexception filename extbuildnumbermatcher buildnumberstr extbuildnumbermatcher buildnumber parseint buildnumberstr buildnumber recommendedextbuildnumber numberformatexception filename maintempbuildnumbermatcher exttempbuildnumbermatcher revocationtempbuildnumbermatcher filetodelete oldtempfiles filetodeletename filetodelete getname filetodelete filetodelete filetodeletename filetodeletename goterror goterror public boolean accept file file string file name file get name if file name starts with revocation file name ends with fblob tmp return true string build number str int build number matcher ext build number matcher ext build number pattern matcher file name matcher main build number matcher main build number pattern matcher file name matcher ext temp build number matcher ext temp build number pattern matcher file name matcher main temp build number matcher main temp build number pattern matcher file name matcher revocation temp build number matcher revocation temp build number pattern matcher file name if main build number matcher matches try build number str main build number matcher group 1 build number integer parse int build number str if build number last good main build number return true catch number format exception e logger error this wierd file in persistent temp file name return false else if ext build number matcher matches try build number str ext build number matcher group 1 build number integer parse int build number str if build number recommended ext build number return true catch number format exception e logger error this wierd file in persistent temp file name return false else if main temp build number matcher matches ext temp build number matcher matches revocation temp build number matcher matches temporary file can be deleted return true return false filename getname filename startswith filename endswith buildnumberstr buildnumber extbuildnumbermatcher extbuildnumberpattern filename mainbuildnumbermatcher mainbuildnumberpattern filename exttempbuildnumbermatcher exttempbuildnumberpattern filename maintempbuildnumbermatcher maintempbuildnumberpattern filename revocationtempbuildnumbermatcher revocationtempbuildnumberpattern filename mainbuildnumbermatcher buildnumberstr mainbuildnumbermatcher buildnumber parseint buildnumberstr buildnumber lastgoodmainbuildnumber numberformatexception filename extbuildnumbermatcher buildnumberstr extbuildnumbermatcher buildnumber parseint buildnumberstr buildnumber recommendedextbuildnumber numberformatexception filename maintempbuildnumbermatcher exttempbuildnumbermatcher revocationtempbuildnumbermatcher public boolean persistent return false public void remove from object container container throw new unsupported operation exception removefrom objectcontainer unsupportedoperationexception public static void main string args throws exception system out println routing test using real nodes system out println string dir real node request insert test file wd new file dir if file util remove all wd system err println mass delete failed test may not be accurate system exit exit cannot delete old data wd mkdir note global test init returns in ignored random source node starter global test init dir false logger error true dummy random source random new dummy random source diffie hellman init random node nodes new node number of nodes logger normal real node routing test class creating nodes executor executor new pooled executor for int i 0 i number of nodes i system err println creating node i nodes i node starter create test node 5001 i 0 dir false true true max htl 0 no dropped packets random executor 500 number of nodes 65536 true enable swapping false false false enable swap queueing true 0 enable foaf false null logger normal real node routing test class created node i logger normal real node routing test class created number of nodes nodes now link them up make kleinberg network nodes start with ideal locations degree force neighbour connections logger normal real node routing test class added random links for int i 0 i number of nodes i system err println starting node i nodes i start false wait for all connected nodes wait for ping average 0 98 nodes random max pings 5000 realnoderequestinserttest fileutil removeall exit_cannot_delete_old_data globaltestinit nodestarter globaltestinit dummyrandomsource dummyrandomsource diffiehellman number_of_nodes realnoderoutingtest pooledexecutor number_of_nodes nodestarter createtestnode max_htl number_of_nodes enable_swapping enable_swap_queueing enable_foaf realnoderoutingtest realnoderoutingtest number_of_nodes makekleinbergnetwork start_with_ideal_locations force_neighbour_connections realnoderoutingtest number_of_nodes waitforallconnected waitforpingaverage max_pings static void wait for ping average double accuracy node nodes random source random int max tests int sleep time throws interrupted exception int total hops taken 0 int cycle number 0 int last swaps 0 int last no swaps 0 int failures 0 int successes 0 running average avg new simple running average 100 0 0 running average avg2 new bootstrapping decaying running average 0 0 0 0 1 0 100 null int pings 0 for int total 0 total max tests total cycle number try thread sleep sleep time catch interrupted exception e ignore for int i 0 i nodes length i system err println cycle cycle number node i nodes i get location int new swaps location manager swaps int total started location manager started swaps int no swaps location manager no swaps system err println swaps new swaps last swaps system err println n total swaps started 2 total started 2 succeeded new swaps last minute failures no swaps ratio double no swaps double new swaps early failures total started 2 no swaps new swaps system err println this cycle ratio double no swaps last no swaps double new swaps last swaps last no swaps no swaps system err println swaps rejected already locked location manager swaps rejected already locked system err println swaps rejected nowhere to go location manager swaps rejected nowhere to go system err println swaps rejected rate limit location manager swaps rejected rate limit system err println swaps rejected recognized id location manager swaps rejected recognizedid system err println swaps failed location manager no swaps system err println swaps succeeded location manager swaps double total swap interval 0 0 double total swap time 0 0 for int i 0 i nodes length i total swap interval nodes i lm get send swap interval total swap time nodes i lm get average swap time system err println average swap time total swap time nodes length system err println average swap sender interval total swap interval nodes length wait for all connected nodes last swaps new swaps do some routed test pings for int i 0 i 10 i try thread sleep sleep time catch interrupted exception e1 try node random node nodes random next int nodes length node random node2 random node while random node2 random node random node2 nodes random next int nodes length double loc2 random node2 get location logger normal real node routing test class pinging random node2 get darknet port number loc2 from random node get darknet port number random node get location int hops taken random node routed ping loc2 random node2 get darknet identity pings if hops taken 0 failures avg report 0 0 avg2 report 0 0 double ratio double successes double failures successes system err println routed ping pings failed from random node get darknet port number to random node2 get darknet port number long ratio short avg current value vague avg2 current value else total hops taken hops taken successes avg report 1 0 avg2 report 1 0 double ratio double successes double failures successes system err println routed ping pings success hops taken random node get darknet port number to random node2 get darknet port number long ratio short avg current value vague avg2 current value catch throwable t logger error real node routing test class caught t t if pings 10 avg current value accuracy double successes double failures successes accuracy system err println system err println reached accuracy 100 accuracy system err println system err println network size nodes length system err println maximum htl max htl system err println average path length for successful requests total hops taken successes system err println total started swaps location manager started swaps system err println total rejected swaps already locked location manager swaps rejected already locked system err println total swaps rejected nowhere to go location manager swaps rejected nowhere to go system err println total swaps rejected rate limit location manager swaps rejected rate limit system err println total swaps rejected recognized id location manager swaps rejected recognizedid system err println total swaps failed location manager no swaps system err println total swaps succeeded location manager swaps return system exit exit ping target not reached waitforpingaverage randomsource maxtests sleeptime interruptedexception totalhopstaken cyclenumber lastswaps lastnoswaps runningaverage simplerunningaverage runningaverage bootstrappingdecayingrunningaverage maxtests cyclenumber sleeptime interruptedexception cyclenumber getlocation newswaps locationmanager totalstarted locationmanager startedswaps noswaps locationmanager noswaps newswaps lastswaps ntotal totalstarted newswaps noswaps noswaps newswaps totalstarted noswaps newswaps noswaps lastnoswaps newswaps lastswaps lastnoswaps noswaps locationmanager swapsrejectedalreadylocked locationmanager swapsrejectednowheretogo locationmanager swapsrejectedratelimit locationmanager swapsrejectedrecognizedid locationmanager noswaps locationmanager totalswapinterval totalswaptime totalswapinterval getsendswapinterval totalswaptime getaverageswaptime totalswaptime totalswapinterval waitforallconnected lastswaps newswaps sleeptime interruptedexception randomnode nextint randomnode2 randomnode randomnode2 randomnode randomnode2 nextint randomnode2 getlocation realnoderoutingtest randomnode2 getdarknetportnumber randomnode getdarknetportnumber randomnode getlocation hopstaken randomnode routedping randomnode2 getdarknetidentity hopstaken randomnode getdarknetportnumber randomnode2 getdarknetportnumber currentvalue currentvalue totalhopstaken hopstaken hopstaken randomnode getdarknetportnumber randomnode2 getdarknetportnumber currentvalue currentvalue realnoderoutingtest currentvalue max_htl totalhopstaken locationmanager startedswaps locationmanager swapsrejectedalreadylocked locationmanager swapsrejectednowheretogo locationmanager swapsrejectedratelimit locationmanager swapsrejectedrecognizedid locationmanager noswaps locationmanager exit_ping_target_not_reached logger register log threshold callback new log threshold callback override public void should update logminor logger should log logger minor this logdebug logger should log logger debug this registerlogthresholdcallback logthresholdcallback shouldupdate shouldlog shouldlog create from serialized form on a data input stream public freenet inet address data input dis throws io exception int first byte dis read unsigned byte byte ba if first byte 255 if logminor logger minor this new format i pv6 address new format i pv6 address ba new byte 16 dis read fully ba else if first byte 0 if logminor logger minor this new format i pv4 address new format i pv4 address ba new byte 4 dis read fully ba else throw new io exception unknown type byte old form corrupt stream too short long prev field first byte address inet address get by address ba string name null string s dis readutf if s length 0 name s hostname name datainputstream freenetinetaddress datainput ioexception firstbyte readunsignedbyte firstbyte ipv6 ipv6 readfully firstbyte ipv4 ipv4 readfully ioexception firstbyte _address inetaddress getbyaddress create from serialized form on a data input stream public freenet inet address data input dis boolean check hostname orip syntax throws hostname syntax exception io exception int first byte dis read unsigned byte byte ba if first byte 255 if logminor logger minor this new format i pv6 address new format i pv6 address ba new byte 16 dis read fully ba else if first byte 0 if logminor logger minor this new format i pv4 address new format i pv4 address ba new byte 4 dis read fully ba else old format i pv4 address ba new byte 4 ba 0 byte first byte dis read fully ba 1 3 address inet address get by address ba string name null string s dis readutf if s length 0 name s hostname name if check hostname orip syntax null hostname if hostname util is valid hostname hostname true throw new hostname syntax exception datainputstream freenetinetaddress datainput checkhostnameoripsyntax hostnamesyntaxexception ioexception firstbyte readunsignedbyte firstbyte ipv6 ipv6 readfully firstbyte ipv4 ipv4 readfully ipv4 firstbyte readfully _address inetaddress getbyaddress checkhostnameoripsyntax hostnameutil isvalidhostname hostnamesyntaxexception create from an inet address the ip address is primary i e fixed the hostname either doesn t exist or is looked up public freenet inet address inet address address address address hostname null inetaddress freenetinetaddress inetaddress _address public freenet inet address string host boolean allow unknown throws unknown host exception inet address addr null if host null if host starts with host host substring 1 host host trim if we were created with an explicit ip address use it as such debugging log messages because address identifier doesn t appear to handle all i pv6 literals correctly such as fe80 204 1234 dead beef address identifier address type address type address identifier get address type host if logdebug logger debug this address type of host appears to be address type if address type address identifier address type other is an ip address addr inet address get by name host don t catch unknown host exception here if it happens there s a bug in address identifier if logdebug logger debug this host is host and addr get host address is addr get host address if addr null host null else addr null if addr null if logdebug logger debug this host does not look like an ip address this address addr this hostname host we re created with a hostname so delay the lookup of the address until it s needed to work better with dynamic dns hostnames freenetinetaddress allowunknown unknownhostexception inetaddress startswith addressidentifier ipv6 addressidentifier addresstype addresstype addressidentifier getaddresstype addresstype addresstype addressidentifier addresstype inetaddress getbyname unknownhostexception addressidentifier gethostaddress gethostaddress _address public freenet inet address string host boolean allow unknown boolean check hostname orip syntax throws hostname syntax exception unknown host exception inet address addr null if host null if host starts with host host substring 1 host host trim if we were created with an explicit ip address use it as such debugging log messages because address identifier doesn t appear to handle all i pv6 literals correctly such as fe80 204 1234 dead beef address identifier address type address type address identifier get address type host if logdebug logger debug this address type of host appears to be address type if address type address identifier address type other try addr inet address get by name host catch unknown host exception e if allow unknown throw e addr null if logdebug logger debug this host is host and addr get host address is addr null addr get host address if addr null addr get host address equals host if logdebug logger debug this host looks like an ip address host null else addr null if addr null if logdebug logger debug this host does not look like an ip address this address addr this hostname host if check hostname orip syntax null this hostname if hostname util is valid hostname this hostname true throw new hostname syntax exception we re created with a hostname so delay the lookup of the address until it s needed to work better with dynamic dns hostnames freenetinetaddress allowunknown checkhostnameoripsyntax hostnamesyntaxexception unknownhostexception inetaddress startswith addressidentifier ipv6 addressidentifier addresstype addresstype addressidentifier getaddresstype addresstype addresstype addressidentifier addresstype inetaddress getbyname unknownhostexception allowunknown gethostaddress gethostaddress gethostaddress _address checkhostnameoripsyntax hostnameutil isvalidhostname hostnamesyntaxexception override public boolean equals object o if o instanceof freenet inet address return false freenet inet address addr freenet inet address o if hostname null if addr hostname null return false if hostname equals ignore case addr hostname return false now that we know we have the same hostname we can propagate the ip if address null addr address null addr address address if addr address null address null address addr address except if we actually do have two different looked up i ps if addr address null address null addr address equals address return false equal return true if addr hostname null return false no hostname go by address if address equals addr address return false return true freenetinetaddress freenetinetaddress freenetinetaddress equalsignorecase _address _address _address _address _address _address _address _address ips _address _address _address _address _address _address public boolean strict equals freenet inet address addr if hostname null if addr hostname null return false if hostname equals ignore case addr hostname return false now that we know we have the same hostname we can propagate the ip if address null addr address null addr address address if addr address null address null address addr address except if we actually do have two different looked up i ps if addr address null address null addr address equals address return false equal return true no hostname go by address if get host name address equals ignore case get host name addr address logger minor this addresses do not match mine get host name address his get host name addr address return false return true strictequals freenetinetaddress equalsignorecase _address _address _address _address _address _address _address _address ips _address _address _address _address gethostname _address equalsignorecase gethostname _address gethostname _address gethostname _address get the ip address look it up if necessary but return the last value if it has ever been looked up before will not trigger a new lookup if it has been looked up before public inet address get address return get address true inetaddress getaddress getaddress get the ip address look it up only if allowed to but return the last value if it has ever been looked up before will not trigger a new lookup if it has been looked up before public inet address get address boolean dodns request if address null return address else if dodns request return null inet address addr get handshake address if addr null this address addr return addr inetaddress getaddress dodnsrequest _address _address dodnsrequest inetaddress gethandshakeaddress _address get the ip address looking up the hostname if the hostname is primary even if it has been looked up before typically called on a reconnect attempt when the dyndns address may have changed public inet address get handshake address since we re handshaking hostname to ip may have changed if address null hostname null if logminor logger minor this hostname is null returning address return address else if logminor logger minor this looking up hostname in dns new exception debug peers are constructed from an address once a handshake has been completed so this lookup will only be performed during a handshake this method should normally only be called from peer node get handshakei ps and once each connection from this get address otherwise it doesn t mean we perform a dns lookup with every packet we send try inet address addr inet address get by name hostname if logminor logger minor this look up got addr if addr null cache the answer since get handshake address doesn t use the cached value thus get handshakei ps should always get the latest value from dns minus java s caching this address inet address get by address addr get address if logminor logger minor this setting address to address return addr catch unknown host exception e if logminor logger minor this dns said hostname hostname is an unknown host returning null return null inetaddress gethandshakeaddress _address _address _address peernode gethandshakeips getaddress inetaddress inetaddress getbyname gethandshakeaddress gethandshakeips _address inetaddress getbyaddress getaddress _address unknownhostexception override public int hash code if hostname null return hostname hash code was set at creation so it can safely be used here else return address hash code can be null but if so hostname will be non null hashcode hashcode _address hashcode override public string to string if hostname null return hostname else return address get host address tostring _address gethostaddress public string to string pref numeric if address null return address get host address else return hostname tostringprefnumeric _address _address gethostaddress public void write to data output stream data output stream dos throws io exception inet address addr this get address if addr null throw new unknown host exception byte data addr get address if data length 4 dos write 0 else dos write 255 dos write data if hostname null dos writeutf hostname else dos writeutf writetodataoutputstream dataoutputstream ioexception inetaddress getaddress unknownhostexception getaddress return the hostname or the ip address of the given inet address does not attempt to do a reverse lookup if the hostname is known return it otherwise return the textual ip address public static string get host name inet address primaryip address if primaryip address null return null string s primaryip address to string string addr s substring 0 s index of trim if addr length 0 return primaryip address get host address else return addr inetaddress gethostname inetaddress primaryipaddress primaryipaddress primaryipaddress tostring indexof primaryipaddress gethostaddress public boolean is real internet address boolean lookup boolean default val boolean allow local addresses if address null return ip util is valid address address allow local addresses else if lookup inet address a get address if a null return ip util is valid address a allow local addresses return default val isrealinternetaddress defaultval allowlocaladdresses _address iputil isvalidaddress _address allowlocaladdresses inetaddress getaddress iputil isvalidaddress allowlocaladdresses defaultval get a new code freenet inet address code with host name removed return a new code freenet inet address code with host name removed or code null if no known ip address is associated with this object you may want to do a code get address true code before calling this public freenet inet address drop hostname if address null logger error this can t drop hostname if no address return null if hostname null return new freenet inet address address else return this freenetinetaddress freenetinetaddress getaddress freenetinetaddress drophostname _address drophostname freenetinetaddress _address public boolean has hostname noip return hostname null hostname length 0 address null hashostnamenoip _address construct an opacity filter with 50 opacity public opacity filter this 0x88 opacityfilter opacityfilter construct an opacity filter with the given opacity alpha param opacity the opacity alpha in the range 0 255 public opacity filter int opacity set opacity opacity opacityfilter opacityfilter setopacity set the opacity param opacity the opacity alpha in the range 0 255 see get opacity public void set opacity int opacity this opacity opacity opacity24 opacity 24 getopacity setopacity get the opacity setting return the opacity see set opacity public int get opacity return opacity setopacity getopacity override public int filterrgb int x int y int rgb if rgb 0xff000000 0 return rgb 0xffffff opacity24 return rgb override public string to string return colors transparency tostring public ssdp notify socket string bind addr string addr ssdp address usei pv6 address false if host interface isi pv6 address bind addr true addr ssdp geti pv6 address usei pv6 address true open addr ssdp port bind addr set control point null ssdpnotifysocket bindaddr useipv6address hostinterface isipv6address bindaddr getipv6address useipv6address bindaddr setcontrolpoint private control point control point null public void set control point control point ctrlp this control point ctrlp controlpoint controlpoint setcontrolpoint controlpoint controlpoint public control point get control point return control point controlpoint getcontrolpoint controlpoint public boolean post ssdp notify request req string ssdp addr ssdp address if usei pv6 address true ssdp addr ssdp geti pv6 address req set host ssdp addr ssdp port return post http request req ssdpnotifyrequest ssdpaddr useipv6address ssdpaddr getipv6address sethost ssdpaddr httprequest public void run thread this thread thread current thread control point ctrl point get control point while device notify thread this thread thread yield ssdp packet packet receive thanks for mikael hakman 04 20 05 if packet null continue thanks for inma 02 20 04 inet address maddr get multicast inet address inet address pmaddr packet get host inet address if maddr equals pmaddr false debug warning invalidate multicast recieved maddr pmaddr continue if ctrl point null ctrl point notify received packet thisthread currentthread controlpoint ctrlpoint getcontrolpoint devicenotifythread thisthread ssdppacket inetaddress getmulticastinetaddress inetaddress gethostinetaddress ctrlpoint ctrlpoint notifyreceived public void start device notify thread new thread this u pnp ssdp notify socket device notify thread set daemon true device notify thread start devicenotifythread upnp ssdpnotifysocket devicenotifythread setdaemon devicenotifythread public void stop thanks for mikael hakman 04 20 05 close device notify thread null devicenotifythread private final boolean global public persistent request removed message string identifier boolean global this ident identifier this global global persistentrequestremovedmessage override public simple field set get field set simple field set fs new simple field set true fs put single identifier ident if global fs put single global true return fs simplefieldset getfieldset simplefieldset simplefieldset putsingle putsingle override public string get name return persistent request removed getname persistentrequestremoved override public void run fcp connection handler handler node node throws message invalid exception throw new message invalid exception protocol error message invalid message persistent request removed goes from server to client not the other way around ident global fcpconnectionhandler messageinvalidexception messageinvalidexception protocolerrormessage invalid_message persistentrequestremoved override public void remove from object container container container delete this removefrom objectcontainer public error page web interface my web interface ft own identity viewer http request request string error title string error message super my web interface viewer request m error title error title m error message error message errorpage webinterface mywebinterface ftownidentity httprequest errortitle errormessage mywebinterface merrortitle errortitle merrormessage errormessage public final void make html node error box add alert box m error title error box add child m error message htmlnode errorbox addalertbox merrortitle errorbox addchild merrormessage private boolean m needs new wot public wot is missing page web interface my web interface http request request boolean wot is outdated super my web interface null request m needs new wot wot is outdated mneedsnewwot wotismissingpage webinterface mywebinterface httprequest wotisoutdated mywebinterface mneedsnewwot wotisoutdated public void make if m needs new wot html node box add alert box your web of trust plugin is outdated box add child this freetalk version is incompatible with the wot plugin version which you have installed please upgrade the wot plugin at box add child a href plugins add child your freenet node s plugin page box add child fixme add by going to the plugins page and pressing reload after we have wot in the official plugins list else html node box add alert box web of trust plugin is missing box add child freetalk needs the wot plugin to be loaded in your freenet node please go to box add child a href plugins add child your freenet node s plugin page box add child and load the wot plugin mneedsnewwot htmlnode addalertbox addchild addchild addchild addchild htmlnode addalertbox addchild addchild addchild addchild public static void fill byte array from ints int ints byte bytes int ic 0 for int i 0 i ints length i bytes ic byte ints i 24 bytes ic byte ints i 16 bytes ic byte ints i 8 bytes ic byte ints i fillbytearrayfromints public static void fill byte array from longs long ints byte bytes int ic 0 for int i 0 i ints length i bytes ic byte ints i 56 bytes ic byte ints i 48 bytes ic byte ints i 40 bytes ic byte ints i 32 bytes ic byte ints i 24 bytes ic byte ints i 16 bytes ic byte ints i 8 bytes ic byte ints i fillbytearrayfromlongs public static void fill int array from bytes byte bytes int ints int ic 0 for int i 0 i ints length 2 i 4 ints ic bytes i bytes i 1 8 bytes i 2 16 bytes i 3 24 fillintarrayfrombytes public static void fill long array from bytes byte bytes long longs int ic 0 for int i 0 i longs length 3 i 8 longs ic bytes i long bytes i 1 8 long bytes i 2 16 long bytes i 3 24 long bytes i 4 32 long bytes i 5 40 long bytes i 6 48 long bytes i 7 56 filllongarrayfrombytes public static byte mp ibytes big integer num int len num bit length byte bytes new byte 2 len 8 3 system arraycopy num to byte array 0 bytes 2 bytes length 2 bytes 0 byte len 8 bytes 1 byte len return bytes mpibytes biginteger bitlength tobytearray public static void writempi big integer num output stream out throws io exception out write mp ibytes num biginteger outputstream ioexception mpibytes public static big integer readmpi input stream in throws io exception int b1 in read int b2 in read if b1 1 b2 1 throw new eof exception byte data new byte b1 8 b2 8 3 read fully in data 0 data length new data input stream in read fully data 0 data length redflag this can t possibly be negative right return new native big integer 1 data biginteger inputstream ioexception eofexception readfully datainputstream readfully nativebiginteger creates a large random number big integer up to b bits b bits this differs from the big integer constructor in that it generates all numbers from the range 2 lower to 2 n rather than 2 n 1 to 2 n public static big integer generate large random int lower bound int upper bound random r if lower bound upper bound return new native big integer lower bound r int bl do bl r next int 0x7fffffff upper bound while bl lower bound return new native big integer bl r biginteger biginteger biginteger generatelargerandom lowerbound upperbound lowerbound upperbound nativebiginteger lowerbound nextint upperbound lowerbound nativebiginteger public static byte hash bytes message digest d byte b return hash bytes d b 0 b length hashbytes messagedigest hashbytes public static byte hash bytes message digest d byte b int offset int length d update b offset length return d digest hashbytes messagedigest hashes a string in a consistent manner public static byte hash string digest d string s try byte sbytes s get bytes utf 8 d update sbytes 0 sbytes length return d digest catch exception e e print stack trace return null hashstring getbytes printstacktrace public static byte xor byte b1 byte b2 int maxl math max b1 length b2 length byte rv new byte maxl int minl math min b1 length b2 length for int i 0 i minl i rv i byte b1 i b2 i return rv if you have two method if you have two equally sized arrays public static boolean byte array equal byte a byte b int offset int length int lim offset length if a length lim b length lim return false for int i offset i lim i if a i b i return false return true bytearrayequal public static void make key byte entropy byte key int offset int len synchronized ctx ctx digest reinitialize int ic 0 while len 0 ic for int i 0 i ic i ctx update byte 0 ctx update entropy 0 entropy length int bc if len 20 ctx digest true key offset bc 20 else byte hash ctx digest bc math min len hash length system arraycopy hash 0 key offset bc offset bc len bc arrays fill entropy byte 0 makekey public static block cipher get cipher by name string name throws unsupported cipher exception try return block cipher loader get instance freenet crypt ciphers name catch exception e throw new unsupported cipher exception e e print stack trace return null blockcipher getcipherbyname unsupportedcipherexception blockcipher getinstance unsupportedcipherexception printstacktrace public static block cipher get cipher by name string name int key size throws unsupported cipher exception try return block cipher loader get instance freenet crypt ciphers name new class integer class new object integer value of key size catch exception e throw new unsupported cipher exception e e print stack trace return null blockcipher getcipherbyname keysize unsupportedcipherexception blockcipher getinstance valueof keysize unsupportedcipherexception printstacktrace public static digest get digest by name string name throws unsupported digest exception try return digest loader get instance freenet crypt name catch exception e throw new unsupported digest exception e e print stack trace return null getdigestbyname unsupporteddigestexception getinstance unsupporteddigestexception printstacktrace public static void main string args throws exception if args length 0 args 0 equals write writempi new big integer 9 system out writempi new big integer 1234567890123456789 system out writempi new big integer 100200300400500600700800900 system out else if args 0 equals read system out println 9 system out println readmpi system in system out println 1234567890123456789 system out println readmpi system in system out println 100200300400500600700800900 system out println readmpi system in else if args 0 equals write mpi writempi new big integer args 1 system out else if args 0 equals read mpi system err println readmpi system in else if args 0 equals keygen byte entropy readmpi system in to byte array byte key new byte args length 1 integer parse int args 1 16 make key entropy key 0 key length system err println hex util bytes to hex key 0 key length else if args 0 equals shatest synchronized ctx ctx digest ctx update byte a ctx update byte b ctx update byte c system err println hex util bytes to hex ctx digest biginteger biginteger biginteger biginteger tobytearray parseint makekey hexutil bytestohex hexutil bytestohex return log2 of n rounded up to the nearest integer public static int log2 long n int log2 0 while log2 63 1l log2 n log2 return log2 public static void read fully input stream in byte b throws io exception read fully in b 0 b length readfully inputstream ioexception readfully public static void read fully input stream in byte b int off int length throws io exception int total 0 while total length int got in read b off total length total if got 1 throw new eof exception total got readfully inputstream ioexception eofexception public class assert check specified condition and raise code assertion failed code exception if it is not true param cond result of checked condition public static final void that boolean cond if cond throw new assertion failed assertionfailed assertionfailed check specified condition and raise code assertion failed code exception if it is not true param description string describing checked condition param cond result of checked condition public static final void that string description boolean cond if cond throw new assertion failed description assertionfailed assertionfailed throw assertion failed exception public static final void failed throw new assertion failed assertionfailed throw assertion failed exception with given description public static final void failed string description throw new assertion failed description assertionfailed private function2d basis public fbm filter set basis type noise fbmfilter setbasistype set the amount of effect param amount the amount min value 0 max value 1 see get amount public void set amount float amount this amount amount getamount setamount get the amount of texture return the amount see set amount public float get amount return amount setamount getamount public void set operation int operation this operation operation setoperation public int get operation return operation getoperation specifies the scale of the texture param scale the scale of the texture min value 1 max value 300 see get scale public void set scale float scale this scale scale getscale setscale returns the scale of the texture return the scale of the texture see set scale public float get scale return scale setscale getscale specifies the stretch factor of the texture param stretch the stretch factor of the texture min value 1 max value 50 see get stretch public void set stretch float stretch this stretch stretch getstretch setstretch returns the stretch factor of the texture return the stretch factor of the texture see set stretch public float get stretch return stretch setstretch getstretch specifies the angle of the texture param angle the angle of the texture angle see get angle public void set angle float angle this angle angle float cos float math cos this angle float sin float math sin this angle m00 cos m01 sin m10 sin m11 cos getangle setangle returns the angle of the texture return the angle of the texture see set angle public float get angle return angle setangle getangle public void set octaves float octaves this octaves octaves setoctaves public float get octaves return octaves getoctaves public void seth float h this h h public float geth return h public void set lacunarity float lacunarity this lacunarity lacunarity setlacunarity public float get lacunarity return lacunarity getlacunarity public void set gain float gain this gain gain setgain public float get gain return gain getgain public void set bias float bias this bias bias setbias public float get bias return bias getbias set the colormap to be used for the filter param colormap the colormap see get colormap public void set colormap colormap colormap this colormap colormap getcolormap setcolormap get the colormap to be used for the filter return the colormap see set colormap public colormap get colormap return colormap setcolormap getcolormap public void set basis type int basis type this basis type basis type switch basis type default case noise basis new noise break case ridged basis new ridgedfbm break case vlnoise basis new vl noise break case scnoise basis new sc noise break case cellular basis new cellular function2d break setbasistype basistype basistype basistype basistype vlnoise scnoise cellularfunction2d public int get basis type return basis type getbasistype basistype public void set basis function2d basis this basis basis setbasis public function2d get basis return basis getbasis protected fbm makefbm float h float lacunarity float octaves fbm fbm new fbm h lacunarity octaves basis float minmax noise find range fbm null min minmax 0 max minmax 1 return fbm findrange override public buffered image filter buffered image src buffered image dst f bm makefbm h lacunarity octaves return super filter src dst bufferedimage bufferedimage bufferedimage fbm override public int filterrgb int x int y int rgb float nx m00 x m01 y float ny m10 x m11 y nx scale ny scale stretch float f f bm evaluate nx ny normalize to 0 1 f f min max min f image math gain f gain f image math bias f bias f amount int a rgb 0xff000000 int v if colormap null v colormap get color f else v pixel utils clamp int f 255 int r v 16 int g v 8 int b v v a r g b if operation pixel utils replace v pixel utils combine pixels rgb v operation return v fbm imagemath imagemath getcolor pixelutils pixelutils pixelutils combinepixels override public string to string return texture fractal brownian motion tostring override public void should update logminor logger should log logger minor this logdebug logger should log logger debug this shouldupdate shouldlog shouldlog callbacks are told when the usk fetcher finishes and unless background poll is enabled they are only sent on found edition once on completion fixme don t allow callbacks if background poll is enabled param cb return public synchronized boolean add callback usk fetcher callback cb if completed return false callbacks add cb return true uskfetcher onfoundedition backgroundpoll addcallback uskfetchercallback boolean cancelled public usk attempt long i this number i this succeeded false this dnf false this checker new usk checker this origusk getssk i ctx maxusk retries ctx parent uskattempt uskchecker maxuskretries public void ondnf client context context checker null dnf true usk fetcher this ondnf this context clientcontext uskfetcher public void on success clientssk block block client context context checker null succeeded true usk fetcher this on success this false block context onsuccess clientsskblock clientcontext uskfetcher onsuccess public void on fatal author error client context context checker null counts as success except it doesn t update usk fetcher this on success this true null context onfatalauthorerror clientcontext uskfetcher onsuccess public void on network error client context context checker null not a dnf usk fetcher this on fail this context onnetworkerror clientcontext uskfetcher onfail public void on cancelled client context context checker null usk fetcher this on cancelled this context oncancelled clientcontext uskfetcher oncancelled public void cancel object container container client context context assert container null cancelled true if checker null checker cancel container context on cancelled context objectcontainer clientcontext oncancelled public void schedule object container container client context context assert container null if checker null if logminor logger minor this checker null in schedule for this new exception debug else assert checker persistent checker schedule container context objectcontainer clientcontext override public string to string return usk attempt for number for origusk geturi for usk fetcher this tostring uskattempt uskfetcher public short get priority if background poll if min failures orig min failures min failures max min failures either just started or just advanced either way boost the priority return progress poll priority else return normal poll priority else return parent get priority class getpriority backgroundpoll minfailures origminfailures minfailures maxminfailures progresspollpriority normalpollpriority getpriorityclass private short progress poll priority default progress poll priority usk fetcher usk origusk usk manager manager fetch context ctx client requester requester int min failures boolean poll forever boolean keep last data this origusk manager ctx requester min failures poll forever default max min failures keep last data progresspollpriority default_progress_poll_priority uskfetcher uskmanager fetchcontext clientrequester minfailures pollforever keeplastdata minfailures pollforever default_max_min_failures keeplastdata fixme use this usk fetcher usk origusk usk manager manager fetch context ctx client requester requester int min failures boolean poll forever long max probe editions boolean keep last data this parent requester this max min failures max probe editions this origusk origusk this usk manager manager this min failures this orig min failures min failures running attempts new vector usk attempt callbacks new linked list usk fetcher callback subscribers new hash set usk callback last fetched edition 1 last added edition 1 this ctx ctx this background poll poll forever this keep last data keep last data keys watching new array list clientssk attempts to start new array list usk attempt uskfetcher uskmanager fetchcontext clientrequester minfailures pollforever maxprobeeditions keeplastdata maxminfailures maxprobeeditions uskmanager minfailures origminfailures minfailures runningattempts uskattempt linkedlist uskfetchercallback hashset uskcallback lastfetchededition lastaddededition backgroundpoll pollforever keeplastdata keeplastdata keyswatching arraylist attemptstostart arraylist uskattempt void ondnf usk attempt att client context context if logminor logger minor this dnf att boolean finished false long cur latest usk manager lookup latest slot origusk synchronized this if completed cancelled return last fetched edition math max last fetched edition att number running attempts remove att if running attempts is empty if logminor logger minor this latest cur latest last fetched last fetched edition cur latest min failures cur latest min failures if started finished true else if logminor logger minor this remaining running attempts size if finished finish success context uskattempt clientcontext curlatest uskmanager lookuplatestslot lastfetchededition lastfetchededition runningattempts runningattempts isempty curlatest lastfetchededition curlatest min_failures curlatest minfailures runningattempts finishsuccess private void finish success client context context if background poll long val at end usk manager lookup latest slot origusk long end long now system current time millis synchronized this started false don t finish before have rescheduled find out when we should check next end in an increasing delay unless we make progress int new sleep time sleep time 2 if new sleep time max sleep time new sleep time max sleep time sleep time new sleep time end now context random next int sleep time if val at end value at schedule val at end origusk suggested edition we have advanced keep trying as if we just started only if we actually do advance not if we just confirm our suspicion value at schedule always starts at 0 min failures orig min failures sleep time orig sleep time end now if logminor logger minor this we have advanced at start value at schedule at end val at end else we have not found any new version increase exponentially but relatively slowly long new min failures math max int min failures 1 25 min failures 1 if new min failures max min failures new min failures max min failures min failures new min failures schedule end now null context else usk manager unsubscribe origusk this usk manager on finished this context get ssk fetch scheduler sched transient remove pending keys key listener this long ed usk manager lookup latest slot origusk usk fetcher callback cb synchronized this completed true cb callbacks to array new usk fetcher callback callbacks size byte data if last request data null data null else try data bucket tools to byte array last request data catch io exception e logger error this unable to turn last request data into byte caught i o exception e e data null for int i 0 i cb length i try cb i on found edition ed origusk copy ed null context last was metadata last compression codec data false false catch exception e logger error this an exception occured while dealing with a callback cb i to string n e get message e finishsuccess clientcontext backgroundpoll valatend uskmanager lookuplatestslot currenttimemillis newsleeptime sleeptime newsleeptime maxsleeptime newsleeptime maxsleeptime sleeptime newsleeptime nextint sleeptime valatend valueatschedule valatend suggestededition valueatschedule minfailures origminfailures sleeptime origsleeptime valueatschedule valatend newminfailures minfailures minfailures newminfailures maxminfailures newminfailures maxminfailures minfailures newminfailures uskmanager uskmanager onfinished getsskfetchscheduler schedtransient removependingkeys keylistener uskmanager lookuplatestslot uskfetchercallback toarray uskfetchercallback lastrequestdata buckettools tobytearray lastrequestdata ioexception lastrequestdata onfoundedition lastwasmetadata lastcompressioncodec tostring getmessage void on success usk attempt att boolean dont update clientssk block block final client context context final long last ed usk manager lookup latest slot origusk long cur latest boolean decode false vector usk attempt kill attempts synchronized this running attempts remove att cur latest att number if completed cancelled return decode cur latest last ed dont update block null cur latest math max last ed cur latest if logminor logger minor this latest cur latest long add to cur latest min failures long add from math max last added edition 1 cur latest 1 if logminor logger minor this adding from add from to add to for origusk if add to add from for long i add from i add to i if logminor logger minor this adding checker for edition i for origusk attempts to start add add i kill attempts cancel before cur latest context fill keys watching cur latest 1 context finish cancel before kill attempts context bucket data null if decode try data block decode context get bucket factory parent persistent 1025 it s an ssk true catch key decode exception e data null catch io exception e data null logger error this an ioe occured while decoding e get message e synchronized this if decode last compression codec block get compression codec last was metadata block is metadata if keep last data if last request data null last request data free last request data data else data free if dont update usk manager update slot origusk cur latest context onsuccess uskattempt dontupdate clientsskblock clientcontext lasted uskmanager lookuplatestslot curlatest uskattempt killattempts runningattempts curlatest curlatest lasted dontupdate curlatest lasted curlatest curlatest addto curlatest minfailures addfrom lastaddededition curlatest addfrom addto addto addfrom addfrom addto attemptstostart killattempts cancelbefore curlatest fillkeyswatching curlatest finishcancelbefore killattempts getbucketfactory keydecodeexception ioexception getmessage lastcompressioncodec getcompressioncodec lastwasmetadata ismetadata keeplastdata lastrequestdata lastrequestdata lastrequestdata dontupdate uskmanager updateslot curlatest void on cancelled usk attempt att client context context synchronized this running attempts remove att if running attempts is empty return if cancelled finish cancelled context oncancelled uskattempt clientcontext runningattempts runningattempts isempty finishcancelled private void finish cancelled client context context usk fetcher callback cb synchronized this completed true cb callbacks to array new usk fetcher callback callbacks size for int i 0 i cb length i cb i on cancelled null context finishcancelled clientcontext uskfetchercallback toarray uskfetchercallback oncancelled public void on fail usk attempt attempt client context context fixme what else can we do certainly we don t want to continue fetching indefinitely e g rn fs don t indicate we should try a later slot none of them really do ondnf attempt context onfail uskattempt clientcontext rnfs private vector usk attempt cancel before long cur latest client context context vector usk attempt v null int count 0 synchronized this for iterator usk attempt i running attempts iterator i has next usk attempt att i next if att number cur latest if v null v new vector usk attempt running attempts size count v add att i remove count return v uskattempt cancelbefore curlatest clientcontext uskattempt uskattempt runningattempts hasnext uskattempt curlatest uskattempt runningattempts private void finish cancel before vector usk attempt v client context context if v null for int i 0 i v size i usk attempt att v get i att cancel null context finishcancelbefore uskattempt clientcontext uskattempt add a usk attempt for another edition number caller is responsible for calling schedule private synchronized usk attempt add long i if cancelled return null if logminor logger minor this adding usk attempt for i for origusk geturi if running attempts is empty usk attempt last running attempts last element if last number i if logminor logger minor this returning because last number i for origusk geturi return null usk attempt a new usk attempt i running attempts add a last added edition i if logminor logger minor this added a for origusk return a uskattempt uskattempt uskattempt runningattempts isempty uskattempt runningattempts lastelement uskattempt uskattempt runningattempts lastaddededition public freeneturi geturi return origusk geturi public boolean is finished synchronized this return completed cancelled isfinished public usk get originalusk return origusk getoriginalusk public void schedule long delay object container container final client context context assert container null if delay 0 schedule container context else context ticker queue timed job new runnable public void run usk fetcher this schedule null context delay objectcontainer clientcontext queuetimedjob uskfetcher public void schedule object container container client context context context get ssk fetch scheduler sched transient add pending keys this update priorities usk manager subscribe origusk this false parent get client usk attempt attempts long looked up usk manager lookup latest slot origusk synchronized this value at schedule math max looked up value at schedule if cancelled return long start point math max origusk suggested edition value at schedule for long i start point i start point min failures i attempts to start add add i started true fill keys watching value at schedule context objectcontainer clientcontext getsskfetchscheduler schedtransient addpendingkeys updatepriorities uskmanager getclient uskattempt lookedup uskmanager lookuplatestslot valueatschedule lookedup valueatschedule startpoint suggestededition valueatschedule startpoint startpoint minfailures attemptstostart fillkeyswatching valueatschedule public void cancel object container container client context context usk manager unsubscribe origusk this context get ssk fetch scheduler sched transient remove pending keys key listener this assert container null usk attempt attempts usk manager on finished this synchronized this cancelled true attempts running attempts to array new usk attempt running attempts size for int i 0 i attempts length i attempts i cancel container context objectcontainer clientcontext uskmanager getsskfetchscheduler schedtransient removependingkeys keylistener uskattempt uskmanager onfinished runningattempts toarray uskattempt runningattempts add a subscriber subscribers are not directly sent on found edition s by the usk fetcher we just use them to determine the priority of our requests and whether we should continue to request param cb public void add subscriber usk callback cb synchronized this subscribers add cb update priorities onfoundedition uskfetcher addsubscriber uskcallback updatepriorities private void update priorities fixme should this be synchronized imho it doesn t matter that much if we get the priority wrong for a few requests also we avoid any possible deadlock this way if the callbacks take locks short normal prio request starter minimum priority class short progress prio request starter minimum priority class usk callback local callbacks synchronized this local callbacks subscribers to array new usk callback subscribers size if local callbacks length 0 normal poll priority default normal poll priority progress poll priority default progress poll priority return for int i 0 i local callbacks length i usk callback cb local callbacks i short prio cb get polling priority normal if logdebug logger debug this normal priority for cb prio if prio normal prio normal prio prio if logdebug logger debug this progress priority for cb prio prio cb get polling priority progress if prio progress prio progress prio prio if logminor logger minor this updating priorities normal normal prio progress progress prio for this for origusk synchronized this normal poll priority normal prio progress poll priority progress prio updatepriorities normalprio requeststarter minimum_priority_class progressprio requeststarter minimum_priority_class uskcallback localcallbacks localcallbacks toarray uskcallback localcallbacks normalpollpriority default_normal_poll_priority progresspollpriority default_progress_poll_priority localcallbacks uskcallback localcallbacks getpollingprioritynormal normalprio normalprio getpollingpriorityprogress progressprio progressprio normalprio progressprio normalpollpriority normalprio progresspollpriority progressprio public synchronized boolean has subscribers return subscribers is empty hassubscribers isempty public synchronized boolean has callbacks return callbacks is empty hascallbacks isempty public void remove subscriber usk callback cb client context context synchronized this subscribers remove cb update priorities removesubscriber uskcallback clientcontext updatepriorities public void remove callback usk callback cb synchronized this subscribers remove cb removecallback uskcallback public synchronized boolean has last data return this last request data null haslastdata lastrequestdata public synchronized boolean last content was metadata return this last was metadata lastcontentwasmetadata lastwasmetadata public synchronized short last compression codec return this last compression codec lastcompressioncodec lastcompressioncodec public synchronized bucket get last data return this last request data getlastdata lastrequestdata public synchronized void free last data if last request data null return last request data free usk fetcher s cannot be persistent so no need to remove from last request data null freelastdata lastrequestdata lastrequestdata uskfetcher removefrom lastrequestdata public synchronized void kill on lose subscribers this kill on lose subscribers true killonlosesubscribers killonlosesubscribers public long get token return 1 gettoken public void remove from object container container client context context throw new unsupported operation exception removefrom objectcontainer clientcontext unsupportedoperationexception public boolean object can new object container container logger error this not storing usk fetcher in database new exception error return false objectcannew objectcontainer uskfetcher public short get polling priority normal throw new unsupported operation exception getpollingprioritynormal unsupportedoperationexception public short get polling priority progress throw new unsupported operation exception getpollingpriorityprogress unsupportedoperationexception public void on found edition long ed usk key object container container final client context context boolean metadata short codec byte data boolean new known good boolean new slot too if new known good new slot too return only interested in slots because this is frequently run off thread it is actually possible that the looked up edition is not the same as the edition we are being notified of final long last ed usk manager lookup latest slot origusk boolean decode false vector usk attempt kill attempts synchronized this if completed cancelled return decode last ed ed data null ed math max last ed ed if logminor logger minor this latest ed long add to ed min failures long add from math max last added edition 1 ed 1 if logminor logger minor this adding from add from to add to for origusk if add to add from for long i add from i add to i if logminor logger minor this adding checker for edition i for origusk attempts to start add add i kill attempts cancel before ed context fill keys watching ed 1 context finish cancel before kill attempts context synchronized this if decode last compression codec codec last was metadata metadata if keep last data fixme inefficient to convert from bucket to byte to bucket if last request data null last request data free try last request data bucket tools make immutable bucket context temp bucket factory data catch io exception e logger error this caught e e onfoundedition objectcontainer clientcontext newknowngood newslottoo newknowngood newslottoo lasted uskmanager lookuplatestslot uskattempt killattempts lasted lasted addto minfailures addfrom lastaddededition addfrom addto addto addfrom addfrom addto attemptstostart killattempts cancelbefore fillkeyswatching finishcancelbefore killattempts lastcompressioncodec lastwasmetadata keeplastdata lastrequestdata lastrequestdata lastrequestdata buckettools makeimmutablebucket tempbucketfactory ioexception private synchronized void fill keys watching long ed client context context if logminor logger minor this fill keys watching from ed for this origusk new exception debug if first key watching 1 first key watching ed for int i 0 i watch keys i keys watching add origusk getssk ed i else long first first key watching long last first key watching keys watching size 1 if last ed keys watching clear for int i 0 i watch keys i keys watching add origusk getssk ed i else int drop int ed first clientssk keep new clientssk keys watching size drop for int i drop i keys watching size i keep i drop keys watching get i keys watching clear for clientssk ssk keep keys watching add ssk for long l last 1 l ed watch keys l keys watching add origusk getssk l first key watching ed if running store checker return long first check math max first key watching checked datastore up to 1 final long last check first key watching keys watching size 1 if logminor logger minor this first check first check last check last check if last check first check return int check count int last check first check 1 int offset int first check first key watching final key check store new key check count for int i 0 i check store length i check store i keys watching get i offset get node key assert offset check store length keys watching size assert keys watching get keys watching size 1 geturi usk forssk get suggested edition last check if logminor logger minor this checking from first check to last check for this origusk sendable get store checker new sendable get parent boolean done false override public boolean dont cache object container container return false override public fetch context get context return ctx override public long get cooldown wakeup object token object container container return 1 override public long get cooldown wakeup by key key key object container container return 1 override public client key get key object token object container container return null override public boolean ignore store return false override public key list keys object container container return check store override public void on failure low level get exception e object token object container container client context context ignore override public void requeue after cooldown key key long time object container container client context context ignore override public void reset cooldown times object container container ignore override public boolean has valid keys keys fetching locally fetching object container container client context context return true override public void pre register object container container client context context boolean to network unregister container context usk attempt attempts synchronized usk fetcher this if cancelled return running store checker false fixme should we only start the usk attempt s if the datastore check hasn t made progress attempts attempts to start to array new usk attempt attempts to start size attempts to start clear done true checked datastore up to last check if logminor logger minor this checked datastore finishing registration for attempts length checkers for usk fetcher this for origusk if attempts length 0 parent to network container context for int i 0 i attempts length i long last ed usk manager lookup latest slot origusk fixme not sure this condition works test it if keep last data last request data null last ed origusk suggested edition last ed if we want the data then get it for the known edition so we always get the data so usk inserter can compare it and return the old edition if it is identical if attempts i null continue if attempts i number last ed attempts i schedule container context else synchronized this running attempts remove attempts i long last ed usk manager lookup latest slot origusk do not check beyond watch keys after the current slot fill keys watching last ed context override public sendable request item choose key keys fetching locally keys object container container client context context return null override public long count all keys object container container client context context return keys watching size override public long count sendable keys object container container client context context return 0 override public request client get client object container container return usk fetcher this usk manager override public client requester get client request return parent override public short get priority class object container container return progress poll priority fixme override public int get retry count return 0 override public boolean is cancelled object container container return done override public boolean isssk return true override public list persistent chosen block make blocks persistent chosen request request request scheduler sched object container container client context context return null public boolean is empty object container container return done running store checker true try context get ssk fetch scheduler register null new sendable get store checker false false null null false catch key listener construction exception e1 impossible running store checker false catch throwable t running store checker false logger error this unable to start t t fillkeyswatching clientcontext fillkeyswatching firstkeywatching firstkeywatching watch_keys keyswatching firstkeywatching firstkeywatching keyswatching keyswatching watch_keys keyswatching keyswatching keyswatching keyswatching keyswatching keyswatching watch_keys keyswatching firstkeywatching runningstorechecker firstcheck firstkeywatching checkeddatastoreupto lastcheck firstkeywatching keyswatching firstcheck firstcheck lastcheck lastcheck lastcheck firstcheck checkcount lastcheck firstcheck firstcheck firstkeywatching checkstore checkcount checkstore checkstore keyswatching getnodekey checkstore keyswatching keyswatching keyswatching uskforssk getsuggestededition lastcheck firstcheck lastcheck sendableget storechecker sendableget dontcache objectcontainer fetchcontext getcontext getcooldownwakeup objectcontainer getcooldownwakeupbykey objectcontainer clientkey getkey objectcontainer ignorestore listkeys objectcontainer checkstore onfailure lowlevelgetexception objectcontainer clientcontext requeueaftercooldown objectcontainer clientcontext resetcooldowntimes objectcontainer hasvalidkeys keysfetchinglocally objectcontainer clientcontext preregister objectcontainer clientcontext tonetwork uskattempt uskfetcher runningstorechecker uskattempt attemptstostart toarray uskattempt attemptstostart attemptstostart checkeddatastoreupto lastcheck uskfetcher tonetwork lasted uskmanager lookuplatestslot keeplastdata lastrequestdata lasted suggestededition lasted uskinserter lasted runningattempts lasted uskmanager lookuplatestslot watch_keys fillkeyswatching lasted sendablerequestitem choosekey keysfetchinglocally objectcontainer clientcontext countallkeys objectcontainer clientcontext keyswatching countsendablekeys objectcontainer clientcontext requestclient getclient objectcontainer uskfetcher uskmanager clientrequester getclientrequest getpriorityclass objectcontainer progresspollpriority getretrycount iscancelled objectcontainer persistentchosenblock makeblocks persistentchosenrequest requestscheduler objectcontainer clientcontext isempty objectcontainer runningstorechecker getsskfetchscheduler sendableget storechecker keylistenerconstructionexception runningstorechecker runningstorechecker boolean done false override public boolean dont cache object container container return false dontcache objectcontainer override public fetch context get context return ctx fetchcontext getcontext override public long get cooldown wakeup object token object container container return 1 getcooldownwakeup objectcontainer override public long get cooldown wakeup by key key key object container container return 1 getcooldownwakeupbykey objectcontainer override public client key get key object token object container container return null clientkey getkey objectcontainer override public boolean ignore store return false ignorestore override public key list keys object container container return check store listkeys objectcontainer checkstore override public void on failure low level get exception e object token object container container client context context ignore onfailure lowlevelgetexception objectcontainer clientcontext override public void requeue after cooldown key key long time object container container client context context ignore requeueaftercooldown objectcontainer clientcontext override public void reset cooldown times object container container ignore resetcooldowntimes objectcontainer override public boolean has valid keys keys fetching locally fetching object container container client context context return true hasvalidkeys keysfetchinglocally objectcontainer clientcontext override public void pre register object container container client context context boolean to network unregister container context usk attempt attempts synchronized usk fetcher this if cancelled return running store checker false fixme should we only start the usk attempt s if the datastore check hasn t made progress attempts attempts to start to array new usk attempt attempts to start size attempts to start clear done true checked datastore up to last check if logminor logger minor this checked datastore finishing registration for attempts length checkers for usk fetcher this for origusk if attempts length 0 parent to network container context for int i 0 i attempts length i long last ed usk manager lookup latest slot origusk fixme not sure this condition works test it if keep last data last request data null last ed origusk suggested edition last ed if we want the data then get it for the known edition so we always get the data so usk inserter can compare it and return the old edition if it is identical if attempts i null continue if attempts i number last ed attempts i schedule container context else synchronized this running attempts remove attempts i long last ed usk manager lookup latest slot origusk do not check beyond watch keys after the current slot fill keys watching last ed context preregister objectcontainer clientcontext tonetwork uskattempt uskfetcher runningstorechecker uskattempt attemptstostart toarray uskattempt attemptstostart attemptstostart checkeddatastoreupto lastcheck uskfetcher tonetwork lasted uskmanager lookuplatestslot keeplastdata lastrequestdata lasted suggestededition lasted uskinserter lasted runningattempts lasted uskmanager lookuplatestslot watch_keys fillkeyswatching lasted override public sendable request item choose key keys fetching locally keys object container container client context context return null sendablerequestitem choosekey keysfetchinglocally objectcontainer clientcontext override public long count all keys object container container client context context return keys watching size countallkeys objectcontainer clientcontext keyswatching override public long count sendable keys object container container client context context return 0 countsendablekeys objectcontainer clientcontext override public request client get client object container container return usk fetcher this usk manager requestclient getclient objectcontainer uskfetcher uskmanager override public client requester get client request return parent clientrequester getclientrequest override public short get priority class object container container return progress poll priority fixme getpriorityclass objectcontainer progresspollpriority override public int get retry count return 0 getretrycount override public boolean is cancelled object container container return done iscancelled objectcontainer override public boolean isssk return true override public list persistent chosen block make blocks persistent chosen request request request scheduler sched object container container client context context return null persistentchosenblock makeblocks persistentchosenrequest requestscheduler objectcontainer clientcontext public boolean is empty object container container return done isempty objectcontainer public synchronized boolean is cancelled object container container return completed cancelled iscancelled objectcontainer public key listener make key listener object container container client context context throws key listener construction exception return this keylistener makekeylistener objectcontainer clientcontext keylistenerconstructionexception public void on failed key listener construction exception e object container container client context context logger error this failed to construct key listener on usk fetcher e e onfailed keylistenerconstructionexception objectcontainer clientcontext keylistener uskfetcher public synchronized long count keys return keys watching size countkeys keyswatching public synchronized short definitely want key key key byte salted key object container container client context context for clientssk ssk keys watching if ssk get node key equals key return progress poll priority return 1 definitelywantkey saltedkey objectcontainer clientcontext keyswatching getnodekey progresspollpriority public boolean dont cache return ctx cache local requests dontcache cachelocalrequests public has key listener get has key listener return this haskeylistener gethaskeylistener public short get priority class object container container return progress poll priority getpriorityclass objectcontainer progresspollpriority public sendable get get requests for key key key byte salted key object container container client context context return new sendable get 0 sendableget getrequestsforkey saltedkey objectcontainer clientcontext sendableget public boolean handle block key key byte salted key key block found object container container client context context if found instanceof ssk block return false clientssk real key null long edition 1 synchronized this for int i 0 i keys watching size i clientssk ssk keys watching get i if ssk get node key equals key real key ssk edition first key watching i break if real key null return false fixme remove assert edition real key geturi usk forssk get suggested edition on found edition edition origusk container context false short 1 null false false return true handleblock saltedkey keyblock objectcontainer clientcontext sskblock realkey keyswatching keyswatching getnodekey realkey firstkeywatching realkey realkey uskforssk getsuggestededition onfoundedition public synchronized boolean is empty return cancelled completed isempty public boolean isssk return true public void on remove ignore onremove public boolean persistent return false public synchronized boolean probably want key key key byte salted key for clientssk ssk keys watching if ssk get node key equals key return true return false probablywantkey saltedkey keyswatching getnodekey public class xml exporter public xml exporter storage impl storage writer writer this storage storage this writer writer xmlexporter xmlexporter storageimpl public void export database int root oid throws io exception if storage encoding null writer write xml version 1 0 encoding storage encoding n else writer write xml version 1 0 encoding utf 8 n writer write database root root oid n exported bitmap new int storage curr index size 31 32 marked bitmap new int storage curr index size 31 32 marked bitmap root oid 5 1 root oid 31 int n exported objects do n exported objects 0 for int i 0 i marked bitmap length i int mask marked bitmap i if mask 0 for int j 0 bit 1 j 32 j bit 1 if mask bit 0 int oid i 5 j exported bitmap i bit marked bitmap i bit try byte obj storage get oid int type oid object header get type obj 0 class descriptor desc storage find class descriptor type oid if desc cls btree class export index oid obj plugins xml spider org garret perst impl btree else if desc cls bit index impl class export index oid obj plugins xml spider org garret perst impl bit index impl else if desc cls persistent set class export set oid obj else if desc cls btree field index class export field index oid obj plugins xml spider org garret perst impl btree field index else if desc cls btree case insensitive field index class export field index oid obj plugins xml spider org garret perst impl btree case insensitive field index else if desc cls btree multi field index class export multi field index oid obj plugins xml spider org garret perst impl btree multi field index else if desc cls btree case insensitive multi field index class export multi field index oid obj plugins xml spider org garret perst impl btree case insensitive multi field index else if desc cls btree compound index class export compound index oid obj else string class name export identifier desc name writer write class name id oid n export object desc obj object header sizeof 2 writer write class name n n exported objects 1 catch storage error x if storage listener null storage listener object not exported oid x else system err println xml export failed for object oid x while n exported objects 0 writer write database n writer flush writer should be closed by calling code exportdatabase rootoid ioexception rootoid exportedbitmap currindexsize markedbitmap currindexsize markedbitmap rootoid rootoid nexportedobjects nexportedobjects markedbitmap markedbitmap exportedbitmap markedbitmap typeoid objectheader gettype classdescriptor findclassdescriptor typeoid exportindex xmlspider bitindeximpl exportindex xmlspider bitindeximpl persistentset exportset btreefieldindex exportfieldindex xmlspider btreefieldindex btreecaseinsensitivefieldindex exportfieldindex xmlspider btreecaseinsensitivefieldindex btreemultifieldindex exportmultifieldindex xmlspider btreemultifieldindex btreecaseinsensitivemultifieldindex exportmultifieldindex xmlspider btreecaseinsensitivemultifieldindex btreecompoundindex exportcompoundindex classname exportidentifier classname exportobject objectheader classname nexportedobjects storageerror objectnotexported nexportedobjects final string export identifier string name return name replace exportidentifier final void export set int oid byte data throws io exception btree btree new btree data object header sizeof storage assign oid btree oid writer write plugins xml spider org garret perst impl persistent set id oid n btree export this writer write plugins xml spider org garret perst impl persistent set n exportset ioexception objectheader assignoid xmlspider persistentset xmlspider persistentset final void export index int oid byte data string name throws io exception btree btree new btree data object header sizeof storage assign oid btree oid writer write name id oid unique btree unique 1 0 type class descriptor signature btree type n btree export this writer write name n exportindex ioexception objectheader assignoid classdescriptor final void export field index int oid byte data string name throws io exception btree btree new btree data object header sizeof storage assign oid btree oid writer write name id oid unique btree unique 1 0 int offs btree sizeof writer write autoinc bytes unpack8 data offs offs 8 writer write class offs export string data offs writer write field offs export string data offs writer write n btree export this writer write name n exportfieldindex ioexception objectheader assignoid exportstring exportstring final void export multi field index int oid byte data string name throws io exception btree btree new btree data object header sizeof storage assign oid btree oid writer write name id oid unique btree unique 1 0 class int offs export string data btree sizeof int n fields bytes unpack4 data offs offs 4 for int i 0 i n fields i writer write field i offs export string data offs writer write n int n types bytes unpack4 data offs offs 4 compound key types new int n types for int i 0 i n types i compound key types i bytes unpack4 data offs offs 4 btree export this compound key types null writer write name n exportmultifieldindex ioexception objectheader assignoid exportstring nfields nfields exportstring ntypes compoundkeytypes ntypes ntypes compoundkeytypes compoundkeytypes final void export compound index int oid byte data throws io exception btree btree new btree data object header sizeof storage assign oid btree oid writer write plugins xml spider org garret perst impl btree compound index id oid unique btree unique 1 0 int offs btree sizeof int n types bytes unpack4 data offs offs 4 compound key types new int n types for int i 0 i n types i int type bytes unpack4 data offs writer write type i class descriptor signature type compound key types i type offs 4 writer write n btree export this compound key types null writer write plugins xml spider org garret perst impl btree compound index n exportcompoundindex ioexception objectheader assignoid xmlspider btreecompoundindex ntypes compoundkeytypes ntypes ntypes classdescriptor compoundkeytypes compoundkeytypes xmlspider btreecompoundindex final int export key byte body int offs int size int type throws io exception switch type case class descriptor tp boolean writer write body offs 0 1 0 break case class descriptor tp byte writer write integer to string body offs break case class descriptor tp char writer write integer to string char bytes unpack2 body offs offs 2 break case class descriptor tp short writer write integer to string bytes unpack2 body offs offs 2 break case class descriptor tp int case class descriptor tp object case class descriptor tp enum writer write integer to string bytes unpack4 body offs offs 4 break case class descriptor tp long writer write long to string bytes unpack8 body offs offs 8 break case class descriptor tp float writer write float to string float int bits to float bytes unpack4 body offs offs 4 break case class descriptor tp double writer write double to string double long bits to double bytes unpack8 body offs offs 8 break case class descriptor tp string for int i 0 i size i export char char bytes unpack2 body offs offs 2 break case class descriptor tp array of byte for int i 0 i size i byte b body offs writer write hex digit b 4 0xf writer write hex digit b 0xf break case class descriptor tp date long msec bytes unpack8 body offs offs 8 if msec 0 writer write xml importer http formatter format new date msec else writer write null break default assert that false return offs exportkey ioexception classdescriptor tpboolean classdescriptor tpbyte tostring classdescriptor tpchar tostring classdescriptor tpshort tostring classdescriptor tpint classdescriptor tpobject classdescriptor tpenum tostring classdescriptor tplong tostring classdescriptor tpfloat tostring intbitstofloat classdescriptor tpdouble tostring longbitstodouble classdescriptor tpstring exportchar classdescriptor tparrayofbyte hexdigit hexdigit classdescriptor tpdate xmlimporter httpformatter final void export compound key byte body int offs int size int type throws io exception assert that type class descriptor tp array of byte int end offs size for int i 0 i compound key types length i type compound key types i if type class descriptor tp array of byte type class descriptor tp string size bytes unpack4 body offs offs 4 writer write key i offs export key body offs size type writer write assert that offs end exportcompoundkey ioexception classdescriptor tparrayofbyte compoundkeytypes compoundkeytypes classdescriptor tparrayofbyte classdescriptor tpstring exportkey final void export assoc int oid byte body int offs int size int type throws io exception writer write ref id oid if exported bitmap oid 5 1 oid 31 0 marked bitmap oid 5 1 oid 31 if compound key types null export compound key body offs size type else writer write key export key body offs size type writer write writer write n exportassoc ioexception exportedbitmap markedbitmap compoundkeytypes exportcompoundkey exportkey final void indentation int indent throws io exception while indent 0 writer write ioexception final void export char char ch throws io exception switch ch case writer write lt break case writer write gt break case writer write amp break case writer write quot break default writer write ch exportchar ioexception final int export string byte body int offs throws io exception int len bytes unpack4 body offs offs 4 if len 0 writer write while len 0 export char char bytes unpack2 body offs offs 2 writer write else if len 1 writer write string s if storage encoding null s new string body offs len 2 storage encoding else s new string body offs len 2 offs len 2 for int i 0 n s length i n i export char s char at i writer write else writer write null return offs exportstring ioexception exportchar exportchar charat final int export binary byte body int offs throws io exception int len bytes unpack4 body offs offs 4 if len 0 if len 2 class descriptor tp object export ref bytes unpack4 body offs offs 4 else if len 1 writer write writer write hex digit 2 len len class descriptor sizeof 2 len while len 0 byte b body offs writer write hex digit b 4 0xf writer write hex digit b 0xf writer write else writer write null else writer write while len 0 byte b body offs writer write hex digit b 4 0xf writer write hex digit b 0xf writer write return offs exportbinary ioexception classdescriptor tpobject exportref hexdigit classdescriptor hexdigit hexdigit hexdigit hexdigit final void export ref int oid throws io exception writer write ref id oid if oid 0 exported bitmap oid 5 1 oid 31 0 marked bitmap oid 5 1 oid 31 exportref ioexception exportedbitmap markedbitmap final int export object class descriptor desc byte body int offs int indent throws io exception class descriptor field descriptor all desc all fields for int i 0 n all length i n i class descriptor field descriptor fd all i indentation indent string field name export identifier fd field name writer write field name switch fd type case class descriptor tp boolean writer write body offs 0 1 0 break case class descriptor tp byte writer write integer to string body offs break case class descriptor tp char writer write integer to string char bytes unpack2 body offs offs 2 break case class descriptor tp short writer write integer to string bytes unpack2 body offs offs 2 break case class descriptor tp int writer write integer to string bytes unpack4 body offs offs 4 break case class descriptor tp long writer write long to string bytes unpack8 body offs offs 8 break case class descriptor tp float writer write float to string float int bits to float bytes unpack4 body offs offs 4 break case class descriptor tp double writer write double to string double long bits to double bytes unpack8 body offs offs 8 break case class descriptor tp enum int ordinal bytes unpack4 body offs if ordinal 0 writer write null else writer write enum fd field get type get enum constants ordinal name offs 4 break case class descriptor tp string offs export string body offs break case class descriptor tp date long msec bytes unpack8 body offs offs 8 if msec 0 writer write xml importer http formatter format new date msec else writer write null break case class descriptor tp object export ref bytes unpack4 body offs offs 4 break case class descriptor tp value writer write n offs export object fd value desc body offs indent 1 indentation indent break case class descriptor tp raw case class descriptor tp array of byte offs export binary body offs break case class descriptor tp custom byte array input stream in new byte array input stream body offs body length offs custom serializable obj storage serializer unpack in string str obj to string writer write for int j 0 len str length j len j export char str char at j writer write offs body length in available break case class descriptor tp array of boolean int len bytes unpack4 body offs offs 4 if len 0 writer write null else writer write n while len 0 indentation indent 1 writer write element body offs 0 1 0 element n indentation indent break case class descriptor tp array of char int len bytes unpack4 body offs offs 4 if len 0 writer write null else writer write n while len 0 indentation indent 1 writer write element bytes unpack2 body offs 0xffff element n offs 2 indentation indent break case class descriptor tp array of short int len bytes unpack4 body offs offs 4 if len 0 writer write null else writer write n while len 0 indentation indent 1 writer write element bytes unpack2 body offs element n offs 2 indentation indent break case class descriptor tp array of enum int len bytes unpack4 body offs offs 4 if len 0 writer write null else writer write n enum enum constants enum fd field get type get enum constants while len 0 indentation indent 1 int ordinal bytes unpack4 body offs if ordinal 0 writer write null else writer write element enum constants ordinal name element n offs 4 indentation indent break case class descriptor tp array of int int len bytes unpack4 body offs offs 4 if len 0 writer write null else writer write n while len 0 indentation indent 1 writer write element bytes unpack4 body offs element n offs 4 indentation indent break case class descriptor tp array of long int len bytes unpack4 body offs offs 4 if len 0 writer write null else writer write n while len 0 indentation indent 1 writer write element bytes unpack8 body offs element n offs 8 indentation indent break case class descriptor tp array of float int len bytes unpack4 body offs offs 4 if len 0 writer write null else writer write n while len 0 indentation indent 1 writer write element float int bits to float bytes unpack4 body offs element n offs 4 indentation indent break case class descriptor tp array of double int len bytes unpack4 body offs offs 4 if len 0 writer write null else writer write n while len 0 indentation indent 1 writer write element double long bits to double bytes unpack8 body offs element n offs 8 exportobject classdescriptor ioexception classdescriptor fielddescriptor allfields classdescriptor fielddescriptor fieldname exportidentifier fieldname fieldname classdescriptor tpboolean classdescriptor tpbyte tostring classdescriptor tpchar tostring classdescriptor tpshort tostring classdescriptor tpint tostring classdescriptor tplong tostring classdescriptor tpfloat tostring intbitstofloat classdescriptor tpdouble tostring longbitstodouble classdescriptor tpenum gettype getenumconstants classdescriptor tpstring exportstring classdescriptor tpdate xmlimporter httpformatter classdescriptor tpobject exportref classdescriptor tpvalue exportobject valuedesc classdescriptor tpraw classdescriptor tparrayofbyte exportbinary classdescriptor tpcustom bytearrayinputstream bytearrayinputstream customserializable tostring exportchar charat classdescriptor tparrayofboolean classdescriptor tparrayofchar classdescriptor tparrayofshort classdescriptor tparrayofenum enumconstants gettype getenumconstants enumconstants classdescriptor tparrayofint classdescriptor tparrayoflong classdescriptor tparrayoffloat intbitstofloat classdescriptor tparrayofdouble longbitstodouble public service state table servicestatetable public state variable get state variable int n return state variable get n statevariable getstatevariable statevariable private static final long serial versionuid 1l public resume exception string msg super msg serialversionuid resumeexception public resume exception string msg cannot create from field set exception e super msg e e resumeexception cannotcreatefromfieldsetexception public final class dodge composite extends rgb composite public dodge composite float alpha super alpha dodgecomposite rgbcomposite dodgecomposite public composite context create context color model src color model color model dst color model rendering hints hints return new context extra alpha src color model dst color model compositecontext createcontext colormodel srccolormodel colormodel dstcolormodel renderinghints extraalpha srccolormodel dstcolormodel static class context extends rgb composite context public context float alpha color model src color model color model dst color model super alpha src color model dst color model rgbcompositecontext colormodel srccolormodel colormodel dstcolormodel srccolormodel dstcolormodel override public void composergb int src int dst float alpha int w src length for int i 0 i w i 4 int sr src i int dir dst i int sg src i 1 int dig dst i 1 int sb src i 2 int dib dst i 2 int sa src i 3 int dia dst i 3 int dor dog dob dor clamp sr 8 256 dir dog clamp sg 8 256 dig dob clamp sb 8 256 dib float a alpha sa 255f float ac 1 a dst i int a dor ac dir dst i 1 int a dog ac dig dst i 2 int a dob ac dib dst i 3 int sa alpha dia ac smallest y coordinate of the rectangle public final int get top return top gettop smallest x coordinate of the rectangle public final int get left return left getleft greatest y coordinate of the rectangle public final int get bottom return bottom getbottom greatest x coordinate of the rectangle public final int get right return right getright rectangle area public final long area return long bottom top right left area of covered rectangle for two sepcified rectangles public static long join area rectangle a rectangle b int left a left b left a left b left int right a right b right a right b right int top a top b top a top b top int bottom a bottom b bottom a bottom b bottom return long bottom top right left joinarea clone rectangle public object clone try rectangle r rectangle super clone r top this top r left this left r bottom this bottom r right this right return r catch clone not supported exception e this shouldn t happen since we are cloneable throw new internal error clonenotsupportedexception internalerror create copy of the rectangle public rectangle rectangle r this top r top this left r left this bottom r bottom this right r right construct rectangle with specified coordinates public rectangle int top int left int bottom int right assert that top bottom left right this top top this left left this bottom bottom this right right default constructor for perst public rectangle join two rectangles this rectangle is updates to contain cover of this and specified rectangle param r rectangle to be joined with this rectangle public final void join rectangle r if left r left left r left if right r right right r right if top r top top r top if bottom r bottom bottom r bottom non destructive join of two rectangles param a first joined rectangle param b second joined rectangle return rectangle containing cover of these two rectangles public static rectangle join rectangle a rectangle b rectangle r new rectangle a r join b return r checks if this rectangle intersects with specified rectangle public final boolean intersects rectangle r return left r right top r bottom right r left bottom r top checks if this rectangle contains the specified rectangle public final boolean contains rectangle r return left r left top r top right r right bottom r bottom check if two rectangles are equal public boolean equals object o if o instanceof rectangle rectangle r rectangle o return left r left top r top right r right bottom r bottom return false hash code consists of all rectangle coordinates public int hash code return top bottom 1 left 2 right 3 hashcode public string to string return top top left left bottom bottom right right tostring private ssdp search response socket list ssdp search response socket list private ssdp notify socket list getssdp notify socket list return ssdp notify socket list ssdpsearchresponsesocketlist ssdpsearchresponsesocketlist ssdpnotifysocketlist getssdpnotifysocketlist ssdpnotifysocketlist private ssdp search response socket list getssdp search response socket list return ssdp search response socket list ssdpsearchresponsesocketlist getssdpsearchresponsesocketlist ssdpsearchresponsesocketlist public control point int ssdp port int http port ssdp notify socket list new ssdp notify socket list ssdp search response socket list new ssdp search response socket list setssdp port ssdp port sethttp port http port set device disposer null set expired device monitoring interval default expired device monitoring interval set renew subscriber null setnmpr mode false set renew subscriber null controlpoint ssdpport httpport ssdpnotifysocketlist ssdpnotifysocketlist ssdpsearchresponsesocketlist ssdpsearchresponsesocketlist setssdpport ssdpport sethttpport httpport setdevicedisposer setexpireddevicemonitoringinterval default_expired_device_monitoring_interval setrenewsubscriber setnmprmode setrenewsubscriber public control point this default ssdp port default eventsub port controlpoint default_ssdp_port default_eventsub_port public void finalize stop private mutex mutex new mutex public void lock mutex lock public void unlock mutex unlock private int ssdp port 0 public int getssdp port return ssdp port ssdpport getssdpport ssdpport public void setssdp port int port ssdp port port setssdpport ssdpport private int http port 0 public int gethttp port return http port httpport gethttpport httpport public void sethttp port int port http port port sethttpport httpport private boolean nmpr mode public void setnmpr mode boolean flag nmpr mode flag nmprmode setnmprmode nmprmode public boolean isnmpr mode return nmpr mode isnmprmode nmprmode private node list dev node list new node list private void add device node root node dev node list add root node nodelist devnodelist nodelist adddevice rootnode devnodelist rootnode private synchronized void add device ssdp packet ssdp packet if ssdp packet is root device false return string usn ssdp packet getusn string udn usn getudn usn device dev get device udn if dev null dev setssdp packet ssdp packet return string location ssdp packet get location try url location url new url location parser parser u pnp getxml parser node root node parser parse location url device root dev get device root node if root dev null return root dev setssdp packet ssdp packet add device root node thanks for oliver newell 2004 10 16 after node is added invoke the add device listener to notify high level control point application that a new device has been added the control point application must implement the device change listener interface to receive the notifications perform add device listener root dev catch malformedurl exception me debug warning ssdp packet to string debug warning me catch parser exception pe debug warning ssdp packet to string debug warning pe adddevice ssdppacket ssdppacket ssdppacket isrootdevice ssdppacket getdevice setssdppacket ssdppacket ssdppacket getlocation locationurl upnp getxmlparser rootnode locationurl rootdev getdevice rootnode rootdev rootdev setssdppacket ssdppacket adddevice rootnode adddevicelistener devicechangelistener performadddevicelistener rootdev malformedurlexception ssdppacket tostring parserexception ssdppacket tostring private device get device node root node if root node null return null node dev node root node get node device elem name if dev node null return null return new device root node dev node getdevice rootnode rootnode devnode rootnode getnode elem_name devnode rootnode devnode public device list get device list device list dev list new device list int n roots dev node list size for int n 0 n n roots n node root node dev node list get node n device dev get device root node if dev null continue dev list add dev return dev list devicelist getdevicelist devicelist devlist devicelist nroots devnodelist nroots rootnode devnodelist getnode getdevice rootnode devlist devlist public device get device string name int n roots dev node list size for int n 0 n n roots n node root node dev node list get node n device dev get device root node if dev null continue if dev is device name true return dev device cdev dev get device name if cdev null return cdev return null getdevice nroots devnodelist nroots rootnode devnodelist getnode getdevice rootnode isdevice getdevice public boolean has device string name return get device name null true false hasdevice getdevice private void remove device node root node thanks for oliver newell 2004 10 16 invoke device removal listener prior to actual removal so device node remains valid for the duration of the listener application may want to access the node device dev get device root node if dev null dev is root device perform remove device listener dev dev node list remove root node removedevice rootnode getdevice rootnode isrootdevice performremovedevicelistener devnodelist rootnode private void remove device device dev if dev null return remove device dev get root node removedevice removedevice getrootnode private void remove device string name device dev get device name remove device dev removedevice getdevice removedevice private void remove device ssdp packet packet if packet is bye bye false return string usn packet getusn string udn usn getudn usn remove device udn removedevice ssdppacket isbyebye removedevice public void remove expired devices device list dev list get device list int dev cnt dev list size device dev new device dev cnt for int n 0 n dev cnt n dev n dev list get device n for int n 0 n dev cnt n if dev n is expired true debug message expired device dev n get friendly name remove device dev n removeexpireddevices devicelist devlist getdevicelist devcnt devlist devcnt devcnt devlist getdevice devcnt isexpired getfriendlyname removedevice public void set expired device monitoring interval long interval expired device monitoring interval interval setexpireddevicemonitoringinterval expireddevicemonitoringinterval public long get expired device monitoring interval return expired device monitoring interval getexpireddevicemonitoringinterval expireddevicemonitoringinterval public void set device disposer disposer disposer device disposer disposer setdevicedisposer devicedisposer public disposer get device disposer return device disposer getdevicedisposer devicedisposer private listener list device notify listener list new listener list public void add notify listener notify listener listener device notify listener list add listener listenerlist devicenotifylistenerlist listenerlist addnotifylistener notifylistener devicenotifylistenerlist public void remove notify listener notify listener listener device notify listener list remove listener removenotifylistener notifylistener devicenotifylistenerlist public void perform notify listener ssdp packet ssdp packet int listener size device notify listener list size for int n 0 n listener size n notify listener listener notify listener device notify listener list get n listener device notify received ssdp packet performnotifylistener ssdppacket ssdppacket listenersize devicenotifylistenerlist listenersize notifylistener notifylistener devicenotifylistenerlist devicenotifyreceived ssdppacket private listener list device search response listener list new listener list public void add search response listener search response listener listener device search response listener list add listener listenerlist devicesearchresponselistenerlist listenerlist addsearchresponselistener searchresponselistener devicesearchresponselistenerlist public void remove search response listener search response listener listener device search response listener list remove listener removesearchresponselistener searchresponselistener devicesearchresponselistenerlist public void perform search response listener ssdp packet ssdp packet int listener size device search response listener list size for int n 0 n listener size n search response listener listener search response listener device search response listener list get n listener device search response received ssdp packet performsearchresponselistener ssdppacket ssdppacket listenersize devicesearchresponselistenerlist listenersize searchresponselistener searchresponselistener devicesearchresponselistenerlist devicesearchresponsereceived ssdppacket listener list device change listener list new listener list public void add device change listener device change listener listener device change listener list add listener listenerlist devicechangelistenerlist listenerlist adddevicechangelistener devicechangelistener devicechangelistenerlist public void remove device change listener device change listener listener device change listener list remove listener removedevicechangelistener devicechangelistener devicechangelistenerlist public void perform add device listener device dev int listener size device change listener list size for int n 0 n listener size n device change listener listener device change listener device change listener list get n listener device added dev performadddevicelistener listenersize devicechangelistenerlist listenersize devicechangelistener devicechangelistener devicechangelistenerlist deviceadded public void perform remove device listener device dev int listener size device change listener list size for int n 0 n listener size n device change listener listener device change listener device change listener list get n listener device removed dev performremovedevicelistener listenersize devicechangelistenerlist listenersize devicechangelistener devicechangelistener devicechangelistenerlist deviceremoved public void notify received ssdp packet packet if packet is root device true if packet is alive true add device packet if packet is bye bye true remove device packet perform notify listener packet notifyreceived ssdppacket isrootdevice isalive adddevice isbyebye removedevice performnotifylistener public void search response received ssdp packet packet if packet is root device true add device packet perform search response listener packet searchresponsereceived ssdppacket isrootdevice adddevice performsearchresponselistener private int search mx ssdp default msearch mx public int get search mx return search mx searchmx default_msearch_mx getsearchmx searchmx public void set search mx int mx search mx mx setsearchmx searchmx public void search string target int mx ssdp search request ms req new ssdp search request target mx ssdp search response socket list ssdp search response socket list getssdp search response socket list ssdp search response socket list post ms req ssdpsearchrequest msreq ssdpsearchrequest ssdpsearchresponsesocketlist ssdpsearchresponsesocketlist getssdpsearchresponsesocketlist ssdpsearchresponsesocketlist msreq public void search string target search target ssdp default msearch mx default_msearch_mx public void search search st root device ssdp default msearch mx root_device default_msearch_mx private http server list http server list new http server list private http server list gethttp server list return http server list httpserverlist httpserverlist httpserverlist httpserverlist gethttpserverlist httpserverlist public void http request recieved http request http req if debug is on true http req print thanks for giordano sassaroli sassarol cefriel it 09 08 03 if http req is notify request true notify request notify req new notify request http req string uuid notify req getsid long seq notify req getseq property list props notify req get property list int prop cnt props size for int n 0 n prop cnt n property prop props get property n string var name prop get name string var value prop get value perform event listener uuid seq var name var value http req returnok return http req return bad request httprequestrecieved httprequest httpreq ison httpreq httpreq isnotifyrequest notifyrequest notifyreq notifyrequest httpreq notifyreq notifyreq propertylist notifyreq getpropertylist propcnt propcnt getproperty varname getname varvalue getvalue performeventlistener varname varvalue httpreq httpreq returnbadrequest private listener list event listener list new listener list public void add event listener event listener listener event listener list add listener listenerlist eventlistenerlist listenerlist addeventlistener eventlistener eventlistenerlist public void remove event listener event listener listener event listener list remove listener removeeventlistener eventlistener eventlistenerlist public void perform event listener string uuid long seq string name string value int listener size event listener list size for int n 0 n listener size n event listener listener event listener event listener list get n listener event notify received uuid seq name value performeventlistener listenersize eventlistenerlist listenersize eventlistener eventlistener eventlistenerlist eventnotifyreceived private string event suburi default eventsub uri public string get event suburi return event suburi eventsuburi default_eventsub_uri geteventsuburi eventsuburi public void set event suburi string url event suburi url seteventsuburi eventsuburi private string get event sub callbackurl string host return host interface get hosturl host gethttp port get event suburi geteventsubcallbackurl hostinterface gethosturl gethttpport geteventsuburi public boolean subscribe service service long timeout if service is subscribed true string sid service getsid return subscribe service sid timeout device root dev service get root device if root dev null return false string if address root dev get interface address subscription request sub req new subscription request sub req set subscribe request service get event sub callbackurl if address timeout subscription response sub res sub req post if sub res is successful true service setsid sub res getsid service set timeout sub res get timeout return true service clearsid return false issubscribed rootdev getrootdevice rootdev ifaddress rootdev getinterfaceaddress subscriptionrequest subreq subscriptionrequest subreq setsubscriberequest geteventsubcallbackurl ifaddress subscriptionresponse subres subreq subres issuccessful subres settimeout subres gettimeout public boolean subscribe service service return subscribe service subscription infinite value infinite_value public boolean subscribe service service string uuid long timeout subscription request sub req new subscription request sub req set renew request service uuid timeout if debug is on true sub req print subscription response sub res sub req post if debug is on true sub res print if sub res is successful true service setsid sub res getsid service set timeout sub res get timeout return true service clearsid return false subscriptionrequest subreq subscriptionrequest subreq setrenewrequest ison subreq subscriptionresponse subres subreq ison subres subres issuccessful subres settimeout subres gettimeout public boolean subscribe service service string uuid return subscribe service uuid subscription infinite value infinite_value public boolean is subscribed service service if service null return false return service is subscribed issubscribed issubscribed public boolean unsubscribe service service subscription request sub req new subscription request sub req set unsubscribe request service subscription response sub res sub req post if sub res is successful true service clearsid return true return false subscriptionrequest subreq subscriptionrequest subreq setunsubscriberequest subscriptionresponse subres subreq subres issuccessful public void unsubscribe device device service list service list device get service list int service cnt service list size for int n 0 n service cnt n service service service list get service n if service hassid true unsubscribe service device list child dev list device get device list int child dev cnt child dev list size for int n 0 n child dev cnt n device cdev child dev list get device n unsubscribe cdev servicelist servicelist getservicelist servicecnt servicelist servicecnt servicelist getservice devicelist childdevlist getdevicelist childdevcnt childdevlist childdevcnt childdevlist getdevice public void unsubscribe device list dev list get device list int dev cnt dev list size for int n 0 n dev cnt n device dev dev list get device n unsubscribe dev devicelist devlist getdevicelist devcnt devlist devcnt devlist getdevice public service get subscriber service string uuid device list dev list get device list int dev cnt dev list size for int n 0 n dev cnt n device dev dev list get device n service service dev get subscriber service uuid if service null return service return null getsubscriberservice devicelist devlist getdevicelist devcnt devlist devcnt devlist getdevice getsubscriberservice public void renew subscriber service device dev long timeout service list service list dev get service list int service cnt service list size for int n 0 n service cnt n service service service list get service n if service is subscribed false continue string sid service getsid boolean is renewed subscribe service sid timeout if is renewed false subscribe service timeout device list cdev list dev get device list int cdev cnt cdev list size for int n 0 n cdev cnt n device cdev cdev list get device n renew subscriber service cdev timeout renewsubscriberservice servicelist servicelist getservicelist servicecnt servicelist servicecnt servicelist getservice issubscribed isrenewed isrenewed devicelist cdevlist getdevicelist cdevcnt cdevlist cdevcnt cdevlist getdevice renewsubscriberservice public void renew subscriber service long timeout device list dev list get device list int dev cnt dev list size for int n 0 n dev cnt n device dev dev list get device n renew subscriber service dev timeout renewsubscriberservice devicelist devlist getdevicelist devcnt devlist devcnt devlist getdevice renewsubscriberservice public void renew subscriber service renew subscriber service subscription infinite value renewsubscriberservice renewsubscriberservice infinite_value private renew subscriber renew subscriber public void set renew subscriber renew subscriber sub renew subscriber sub renewsubscriber renewsubscriber setrenewsubscriber renewsubscriber renewsubscriber public renew subscriber get renew subscriber return renew subscriber renewsubscriber getrenewsubscriber renewsubscriber public boolean start string target int mx stop http server int retry cnt 0 int bind port gethttp port http server list http server list gethttp server list while http server list open bind port false retry cnt if u pnp server retry count retry cnt return false sethttp port bind port 1 bind port gethttp port http server list add request listener this http server list start notify socket ssdp notify socket list ssdp notify socket list getssdp notify socket list if ssdp notify socket list open false return false ssdp notify socket list set control point this ssdp notify socket list start seach response socket int ssdp port getssdp port retry cnt 0 ssdp search response socket list ssdp search response socket list getssdp search response socket list while ssdp search response socket list open ssdp port false retry cnt if u pnp server retry count retry cnt return false setssdp port ssdp port 1 ssdp port getssdp port ssdp search response socket list set control point this ssdp search response socket list start search root devices search target mx disposer disposer disposer new disposer this set device disposer disposer disposer start subscriber if isnmpr mode true renew subscriber renew sub new renew subscriber this set renew subscriber renew sub renew sub start return true retrycnt bindport gethttpport httpserverlist httpserverlist gethttpserverlist httpserverlist bindport retrycnt upnp server_retry_count retrycnt sethttpport bindport bindport gethttpport httpserverlist addrequestlistener httpserverlist ssdpnotifysocketlist ssdpnotifysocketlist getssdpnotifysocketlist ssdpnotifysocketlist ssdpnotifysocketlist setcontrolpoint ssdpnotifysocketlist seachresponse ssdpport getssdpport retrycnt ssdpsearchresponsesocketlist ssdpsearchresponsesocketlist getssdpsearchresponsesocketlist ssdpsearchresponsesocketlist ssdpport retrycnt upnp server_retry_count retrycnt setssdpport ssdpport ssdpport getssdpport ssdpsearchresponsesocketlist setcontrolpoint ssdpsearchresponsesocketlist setdevicedisposer isnmprmode renewsubscriber renewsub renewsubscriber setrenewsubscriber renewsub renewsub public boolean start string target return start target ssdp default msearch mx default_msearch_mx public boolean start return start st root device ssdp default msearch mx root_device default_msearch_mx public boolean stop unsubscribe ssdp notify socket list ssdp notify socket list getssdp notify socket list ssdp notify socket list stop ssdp notify socket list close ssdp notify socket list clear ssdp search response socket list ssdp search response socket list getssdp search response socket list ssdp search response socket list stop ssdp search response socket list close ssdp search response socket list clear http server list http server list gethttp server list http server list stop http server list close http server list clear disposer disposer disposer get device disposer if disposer null disposer stop set device disposer null subscriber renew subscriber renew sub get renew subscriber if renew sub null renew sub stop set renew subscriber null return true ssdpnotifysocketlist ssdpnotifysocketlist getssdpnotifysocketlist ssdpnotifysocketlist ssdpnotifysocketlist ssdpnotifysocketlist ssdpsearchresponsesocketlist ssdpsearchresponsesocketlist getssdpsearchresponsesocketlist ssdpsearchresponsesocketlist ssdpsearchresponsesocketlist ssdpsearchresponsesocketlist httpserverlist httpserverlist gethttpserverlist httpserverlist httpserverlist httpserverlist getdevicedisposer setdevicedisposer renewsubscriber renewsub getrenewsubscriber renewsub renewsub setrenewsubscriber public void print device list dev list get device list int dev cnt dev list size debug message device num dev cnt for int n 0 n dev cnt n device dev dev list get device n debug message n dev get friendly name dev get lease time dev get elapsed time devicelist devlist getdevicelist devcnt devlist devcnt devcnt devlist getdevice getfriendlyname getleasetime getelapsedtime private string code description switch code case client hello must be first message return client hello must be first message case no late client hellos return no late client hello s accepted case message parse error return unknown message parsing error case freenet uri parse error return error parsing freenet uri case missing field return missing field case error parsing number return error parsing a numeric field case invalid message return don t know what to do with message case invalid field return invalid field value case file not found return file not found not a file or not readable case disk target exists return disk target exists refusing to overwrite for security reasons case filename and temp filename must be in same dir return filename and temp filename must be in same directory so can rename case could not create file return could not create file case could not write file return could not write file case could not rename file return could not rename file case no such identifier return no such identifier case not supported return not supported case internal error return internal error case shutting down return shutting down case no such node identifier unused return no such node identifier case url parse error return error parsing url case ref parse error return reference could not be parsed case file parse error return file could not be read case not a file error return filepath is not a file case access denied return access denied case direct disk access denied return direct disk access operation denied did you send a file hash field did you use testdda case could not read file return could not read file case ref signature invalid return reference signature failed to verify case cannot peer with self return node cannot peer with itself case duplicate peer ref return node already has a peer with that ref case opennet disabled return opennet is currently disabled in the node s configuration case darknet only return operation only available on a darknet peer case no such plugin return no such plugin default logger error this unknown error code code new exception debug return unknown codedescription client_hello_must_be_first_message clienthello no_late_client_hellos clienthello message_parse_error freenet_uri_parse_error missing_field error_parsing_number invalid_message invalid_field file_not_found disk_target_exists filename_and_temp_filename_must_be_in_same_dir could_not_create_file could_not_write_file could_not_rename_file no_such_identifier not_supported internal_error shutting_down no_such_node_identifier nodeidentifier url_parse_error ref_parse_error file_parse_error not_a_file_error access_denied direct_disk_access_denied filehash could_not_read_file ref_signature_invalid cannot_peer_with_self duplicate_peer_ref opennet_disabled darknet_only no_such_plugin public protocol error message int code boolean fatal string extra string ident boolean global this code code this extra extra this fatal fatal this ident ident this global global protocolerrormessage public protocol error message simple field set fs ident fs get identifier code integer parse int fs get code extra fs get extra description fatal fields string to bool fs get fatal false global fields string to bool fs get global false protocolerrormessage simplefieldset parseint extradescription stringtobool stringtobool override public simple field set get field set simple field set sfs new simple field set true if ident null sfs put single identifier ident sfs put code code sfs put single code description code description if extra null sfs put single extra description extra sfs put fatal fatal if global sfs put single global true return sfs simplefieldset getfieldset simplefieldset simplefieldset putsingle putsingle codedescription codedescription putsingle extradescription putsingle override public void run fcp connection handler handler node node logger error this client reported protocol error fcpconnectionhandler override public string get name return protocol error getname protocolerror override public void remove from object container container container delete this removefrom objectcontainer private float icentrex icentrey public flare filter set radius 50 0f flarefilter setradius public void set color int color this color color setcolor public int get color return color getcolor public void set ring width float ring width this ring width ring width setringwidth ringwidth ringwidth ringwidth public float get ring width return ring width getringwidth ringwidth public void set base amount float base amount this base amount base amount setbaseamount baseamount baseamount baseamount public float get base amount return base amount getbaseamount baseamount public void set ring amount float ring amount this ring amount ring amount setringamount ringamount ringamount ringamount public float get ring amount return ring amount getringamount ringamount public void set ray amount float ray amount this ray amount ray amount setrayamount rayamount rayamount rayamount public float get ray amount return ray amount getrayamount rayamount public void set centre point2d centre this centrex float centre getx this centrey float centre gety setcentre public point2d get centre return new point2d float centrex centrey getcentre set the radius of the effect param radius the radius min value 0 see get radius public void set radius float radius this radius radius sigma radius 3 getradius setradius get the radius of the effect return the radius see set radius public float get radius return radius setradius getradius override public void set dimensions int width int height this width width this height height icentrex centrex width icentrey centrey height super set dimensions width height setdimensions setdimensions override public int filterrgb int x int y int rgb float dx x icentrex float dy y icentrey float distance float math sqrt dx dx dy dy float a float math exp distance distance gauss mix float math exp distance linear 1 mix float ring a base amount if distance radius ring width a image math lerp distance radius ring width falloff a 0 if distance radius ring width distance radius ring width ring 0 else ring math abs distance radius ring width ring 1 ring ring 3 2 ring ring ring amount a ring float angle float math atan2 dx dy image math pi angle image math mod angle image math pi 17 1 0f noise noise1 angle 10 1 0f 0 5f 2 angle math abs angle angle float math pow angle 5 0 float b ray amount angle 1 distance 0 1f a b a image math clamp a 0 1 return image math mix colors a rgb color baseamount ringwidth imagemath ringwidth ringwidth ringwidth ringwidth ringamount imagemath imagemath imagemath rayamount imagemath imagemath mixcolors override public string to string return stylize flare tostring transient field fld rnd btree field index rndbtreefieldindex private final void locate field fld class descriptor locate field cls field name if fld null throw new storage error storage error indexed field not found class name field name locatefield classdescriptor locatefield fieldname storageerror storageerror indexed_field_not_found classname fieldname public class get indexed class return cls getindexedclass public field get key fields return new field fld getkeyfields public void on load cls class descriptor load class get storage class name locate field onload classdescriptor loadclass getstorage classname locatefield rnd btree field index class cls string field name boolean unique this cls cls this unique unique this field name field name this class name class descriptor get class name cls locate field type check type fld get type rndbtreefieldindex fieldname fieldname fieldname classname classdescriptor getclassname locatefield checktype gettype private key extract key i persistent obj try field f fld key key null switch type case class descriptor tp boolean key new key f get boolean obj break case class descriptor tp byte key new key f get byte obj break case class descriptor tp short key new key f get short obj break case class descriptor tp char key new key f get char obj break case class descriptor tp int key new key f get int obj break case class descriptor tp object i persistent ptr i persistent f get obj if ptr null ptr is persistent get storage make persistent ptr key new key ptr break case class descriptor tp long key new key f get long obj break case class descriptor tp date key new key date f get obj break case class descriptor tp float key new key f get float obj break case class descriptor tp double key new key f get double obj break case class descriptor tp enum key new key enum f get obj break case class descriptor tp string key new key string f get obj break case class descriptor tp raw key new key comparable f get obj break default assert failed invalid type return key catch exception x throw new storage error storage error access violation x extractkey ipersistent classdescriptor tpboolean getboolean classdescriptor tpbyte getbyte classdescriptor tpshort getshort classdescriptor tpchar getchar classdescriptor tpint getint classdescriptor tpobject ipersistent ipersistent ispersistent getstorage makepersistent classdescriptor tplong getlong classdescriptor tpdate classdescriptor tpfloat getfloat classdescriptor tpdouble getdouble classdescriptor tpenum classdescriptor tpstring classdescriptor tpraw storageerror storageerror access_violation public boolean put t obj return super insert extract key obj obj false null extractkey public t set t obj return super set extract key obj obj extractkey public void remove t obj super remove extract key obj obj extractkey public boolean contains object t obj key key extract key obj if unique return super get key null else i persistent mbrs get key key for int i 0 i mbrs length i if mbrs i obj return true return false containsobject extractkey ipersistent public boolean contains t obj key key extract key obj if unique return super get key null else i persistent mbrs get key key for int i 0 i mbrs length i if mbrs i equals obj return true return false extractkey ipersistent public synchronized void append t obj key key try switch type case class descriptor tp int key new key int autoinc count fld set int obj int autoinc count break case class descriptor tp long key new key autoinc count fld set long obj autoinc count break default throw new storage error storage error unsupported index type fld get type catch exception x throw new storage error storage error access violation x autoinc count 1 obj modify super insert key obj false classdescriptor tpint autoinccount setint autoinccount classdescriptor tplong autoinccount setlong autoinccount storageerror storageerror unsupported_index_type gettype storageerror storageerror access_violation autoinccount public t get prefix string prefix array list t list get list new key prefix true new key prefix character max value false return t list to array t array new instance cls list size getprefix arraylist getlist max_value toarray newinstance public t prefix search string key array list t list prefix search list key return t list to array t array new instance cls list size prefixsearch arraylist prefixsearchlist toarray newinstance public t get key from key till array list t list new array list if root null root find check key from check key till height list return t list to array t array new instance cls list size arraylist arraylist checkkey checkkey toarray newinstance public t to persistent array t arr t array new instance cls n elems if root null root traverse forward height arr 0 return arr topersistentarray newinstance nelems traverseforward public iterable iterator t query by example t obj key key extract key obj return iterator key key ascent order iterableiterator querybyexample extractkey ascent_order public iterable iterator t select string predicate query t query new query impl t get storage return query select cls iterator predicate iterableiterator queryimpl getstorage public boolean is case insensitive return false iscaseinsensitive class rnd btree case insensitive field index t extends i persistent extends rnd btree field index t rnd btree case insensitive field index rndbtreecaseinsensitivefieldindex ipersistent rndbtreefieldindex rndbtreecaseinsensitivefieldindex rnd btree case insensitive field index rnd btree case insensitive field index class cls string field name boolean unique super cls field name unique rndbtreecaseinsensitivefieldindex rndbtreecaseinsensitivefieldindex fieldname fieldname key check key key key if key null key oval instanceof string key new key string key oval to lower case key inclusion 0 return super check key key checkkey tolowercase checkkey public boolean is case insensitive return true iscaseinsensitive final string identifier public plugin reply sender string pluginname2 string identifier2 pluginname pluginname2 identifier identifier2 pluginreplysender public void send simple field set params throws plugin not found exception send params bucket null simplefieldset pluginnotfoundexception public void send simple field set params byte data throws plugin not found exception send params new array bucket data simplefieldset pluginnotfoundexception arraybucket public abstract void send simple field set params bucket bucket throws plugin not found exception simplefieldset pluginnotfoundexception private float width45 3 0f public emboss filter embossfilter public void set azimuth float azimuth this azimuth azimuth setazimuth public float get azimuth return azimuth getazimuth public void set elevation float elevation this elevation elevation setelevation public float get elevation return elevation getelevation public void set bump height float bump height this width45 3 bump height setbumpheight bumpheight bumpheight public float get bump height return width45 3 getbumpheight public void set emboss boolean emboss this emboss emboss setemboss public boolean get emboss return emboss getemboss override protected int filter pixels int width int height int in pixels rectangle transformed space int index 0 int out pixels new int width height int bump pixels int bump map width bump map height bump map width width bump map height height bump pixels new int bump map width bump map height for int i 0 i in pixels length i bump pixels i pixel utils brightness in pixels i int nx ny nz lx ly lz nz2 nz lz ndotl int shade background lx int math cos azimuth math cos elevation pixel scale ly int math sin azimuth math cos elevation pixel scale lz int math sin elevation pixel scale nz int 6 255 width45 nz2 nz nz nz lz nz lz background lz int bump index 0 for int y 0 y height y bump index bump map width int s1 bump index int s2 s1 bump map width int s3 s2 bump map width for int x 0 x width x s1 s2 s3 if y 0 y height 2 x 0 x width 2 nx bump pixels s1 1 bump pixels s2 1 bump pixels s3 1 bump pixels s1 1 bump pixels s2 1 bump pixels s3 1 ny bump pixels s3 1 bump pixels s3 bump pixels s3 1 bump pixels s1 1 bump pixels s1 bump pixels s1 1 if nx 0 ny 0 shade background else if ndotl nx lx ny ly nz lz 0 shade 0 else shade int ndotl math sqrt nx nx ny ny nz2 else shade background if emboss int rgb in pixels index int a rgb 0xff000000 int r rgb 16 0xff int g rgb 8 0xff int b rgb 0xff r r shade 8 g g shade 8 b b shade 8 out pixels index a r 16 g 8 b else out pixels index 0xff000000 shade 16 shade 8 shade return out pixels filterpixels inpixels transformedspace outpixels bumppixels bumpmapwidth bumpmapheight bumpmapwidth bumpmapheight bumppixels bumpmapwidth bumpmapheight inpixels bumppixels pixelutils inpixels nzlz pixelscale pixelscale pixelscale nzlz bumpindex bumpindex bumpmapwidth bumpindex bumpmapwidth bumpmapwidth bumppixels bumppixels bumppixels bumppixels bumppixels bumppixels bumppixels bumppixels bumppixels bumppixels bumppixels bumppixels nzlz inpixels outpixels outpixels outpixels override public string to string return stylize emboss tostring public final class wot own message list extends own message list public wot own message list ft own identity new author int new index super new author new index todo auto generated constructor stub wotownmessagelist ownmessagelist wotownmessagelist ftownidentity newauthor newindex newauthor newindex override protected freeneturi generateuri freeneturi baseuri int index return wot message list assembleuri baseuri index wotmessagelist public synchronized void increment insert index synchronized wot own message list class int free index wot message manager m message manager get free own message list index wot own identity m author m index math max m index 1 free index mid calculateid store incrementinsertindex wotownmessagelist freeindex wotmessagemanager mmessagemanager getfreeownmessagelistindex wotownidentity mauthor mindex mindex freeindex public wot own identity get author return wot own identity m author wotownidentity getauthor wotownidentity mauthor returns true if the xml of this message list fits into a single ssk block protected boolean fits into container fixme implement return true fitsintocontainer public pproxy toadlet high level simple client client node node node client core core super client this node node this core core pproxytoadlet highlevelsimpleclient nodeclientcore override public string supported methods return get post supportedmethods override public void handle post uri uri http request request toadlet context ctx throws toadlet context closed exception io exception multi value table string string headers new multi value table string string string pass request get part as string form password 32 if pass null pass equals core form password headers put location plugins ctx send reply headers 302 found headers null 0 return if ctx is allowed full access super send error page ctx 403 l10n unauthorized title l10n unauthorized return string path request get path remove leading and plugins from path if path starts with path path substring 1 if path starts with plugins path path substring plugins length if logger should log logger minor this logger minor this pproxy received post on path plugin manager pm node plugin manager if path length 0 try string plugin null split path into plugin class name and daa path for plugin int to path index of if to 1 plugin path else plugin path substring 0 to writehtml reply ctx 200 ok pm handlehttp post plugin request catch redirect pluginhttp exception e write temporary redirect ctx e message e new location catch not found pluginhttp exception e send error page ctx not found pluginhttp exception code e message e location catch access denied pluginhttp exception e send error page ctx access denied pluginhttp exception code e message e location catch download pluginhttp exception e fixme maybe it ought to be defined like send error page in toadlets multi value table string string head new multi value table string string head put content disposition attachment filename e filename ctx send reply headers download pluginhttp exception code found head e mime type e data length ctx write data e data catch pluginhttp exception e send error page ctx pluginhttp exception code e message e location catch throwable t write internal error t ctx else page maker page maker ctx get page maker if request is part set submit official string plugin name null plugin name request get part as string plugin name 40 pm start plugin official plugin name true headers put location ctx send reply headers 302 found headers null 0 return if request is part set submit other string plugin name null plugin name request get part as string plugin url 200 boolean fileonly on equals ignore case request get part as string fileonly 20 if fileonly pm start plugin file plugin name true else pm start pluginurl plugin name true headers put location ctx send reply headers 302 found headers null 0 return if request is part set submit freenet string plugin name null plugin name request get part as string plugin uri 300 pm start plugin freenet plugin name true headers put location ctx send reply headers 302 found headers null 0 return if request is part set dismiss user alert int user alert hash code request get int part disable 1 core alerts dismiss alert user alert hash code headers put location ctx send reply headers 302 found headers null 0 return if request is part set cancel headers put location plugins ctx send reply headers 302 found headers null 0 return if request get part as string unloadconfirm max plugin name length length 0 string plugin thread name request get part as string unloadconfirm max plugin name length string plugin specification get plugin specification pm plugin thread name pm kill plugin plugin thread name max threaded unload wait time if request is part set purge pm remove cached copy plugin specification html node page node page maker get page node l10n plugins ctx html node content node page maker get content node page node html node infobox content node add child div class infobox infobox success infobox add child div class infobox header l10n plugin unloaded html node infobox content infobox add child div class infobox content infobox content add child l10n plugin unloaded with name name plugin thread name infobox content add child br infobox content add child a href plugins l10n return to plugin page writehtml reply ctx 200 ok page node generate return if request get part as string unload max plugin name length length 0 html node page node page maker get page node l10n plugins ctx html node content node page maker get content node page node html node infobox content node add child div class infobox infobox query infobox add child div class infobox header l10n unload plugin title html node infobox content infobox add child div class infobox content infobox content add child l10n unload plugin with name name request get part as string unload max plugin name length html node unload form ctx add form child infobox content plugins unload plugin confirm form unload form add child input new string type name value new string hidden unloadconfirm request get part as string unload max plugin name length html node temp node unload form add child p temp node add child input new string type name new string checkbox purge temp node add child l10n unload purge temp node unload form add child p temp node add child input new string type name value new string submit confirm l10n unload temp node add child temp node add child input new string type name value new string submit cancel l10n get string toadlet cancel writehtml reply ctx 200 ok page node generate return else if request get part as string reload max plugin name length length 0 html node page node page maker get page node l10n plugins ctx html node content node page maker get content node page node html node reload box content node add child page maker get infobox infobox infobox query l10n reload plugin title html node reload content page maker get content node reload box reload content add child p l10n reload explanation reload content add child p l10n reload warning html node reload form ctx add form child reload content plugins reload plugin confirm form reload form add child input new string type name value new string hidden reloadconfirm request get part as string reload max plugin name length html node temp node reload form add child p temp node add child input new string type name new string checkbox purge temp node add child l10n reload purge warning temp node reload form add child p temp node add child input new string type name value new string submit confirm l10n reload temp node add child temp node add child input new string type name value new string submit cancel l10n get string toadlet cancel writehtml reply ctx 200 ok page node generate return else if request get part as string reloadconfirm max plugin name length length 0 boolean purge request is part set purge string plugin thread name request get part as string reloadconfirm max plugin name length string fn get plugin specification pm plugin thread name if fn null send error page ctx 404 l10n plugin not found reload title l10n get string plugin toadlet plugin not found reload else pm kill plugin plugin thread name max threaded unload wait time if purge pm remove cached copy fn fixme pm start plugin auto fn true headers put location ctx send reply headers 302 found headers null 0 return else ignore headers put location ctx send reply headers 302 found headers null 0 handlepost httprequest toadletcontext toadletcontextclosedexception ioexception multivaluetable multivaluetable getpartasstring formpassword formpassword sendreplyheaders isallowedfullaccess senderrorpage unauthorizedtitle getpath startswith startswith shouldlog pluginmanager pluginmanager indexof writehtmlreply handlehttppost redirectpluginhttpexception writetemporaryredirect newlocation notfoundpluginhttpexception senderrorpage notfoundpluginhttpexception accessdeniedpluginhttpexception senderrorpage accessdeniedpluginhttpexception downloadpluginhttpexception senderrorpage multivaluetable multivaluetable sendreplyheaders downloadpluginhttpexception mimetype writedata pluginhttpexception senderrorpage pluginhttpexception writeinternalerror pagemaker pagemaker getpagemaker ispartset pluginname pluginname getpartasstring startpluginofficial pluginname sendreplyheaders ispartset pluginname pluginname getpartasstring equalsignorecase getpartasstring startpluginfile pluginname startpluginurl pluginname sendreplyheaders ispartset pluginname pluginname getpartasstring startpluginfreenet pluginname sendreplyheaders ispartset useralerthashcode getintpart dismissalert useralerthashcode sendreplyheaders ispartset sendreplyheaders getpartasstring max_plugin_name_length pluginthreadname getpartasstring max_plugin_name_length pluginspecification getpluginspecification pluginthreadname killplugin pluginthreadname max_threaded_unload_wait_time ispartset removecachedcopy pluginspecification htmlnode pagenode pagemaker getpagenode htmlnode contentnode pagemaker getcontentnode pagenode htmlnode contentnode addchild addchild pluginunloaded htmlnode infoboxcontent addchild infoboxcontent addchild pluginunloadedwithname pluginthreadname infoboxcontent addchild infoboxcontent addchild returntopluginpage writehtmlreply pagenode getpartasstring max_plugin_name_length htmlnode pagenode pagemaker getpagenode htmlnode contentnode pagemaker getcontentnode pagenode htmlnode contentnode addchild addchild unloadplugintitle htmlnode infoboxcontent addchild infoboxcontent addchild unloadpluginwithname getpartasstring max_plugin_name_length htmlnode unloadform addformchild infoboxcontent unloadpluginconfirmform unloadform addchild getpartasstring max_plugin_name_length htmlnode tempnode unloadform addchild tempnode addchild tempnode addchild unloadpurge tempnode unloadform addchild tempnode addchild tempnode addchild tempnode addchild getstring writehtmlreply pagenode getpartasstring max_plugin_name_length htmlnode pagenode pagemaker getpagenode htmlnode contentnode pagemaker getcontentnode pagenode htmlnode reloadbox contentnode addchild pagemaker getinfobox reloadplugintitle htmlnode reloadcontent pagemaker getcontentnode reloadbox reloadcontent addchild reloadexplanation reloadcontent addchild reloadwarning htmlnode reloadform addformchild reloadcontent reloadpluginconfirmform reloadform addchild getpartasstring max_plugin_name_length htmlnode tempnode reloadform addchild tempnode addchild tempnode addchild reloadpurgewarning tempnode reloadform addchild tempnode addchild tempnode addchild tempnode addchild getstring writehtmlreply pagenode getpartasstring max_plugin_name_length ispartset pluginthreadname getpartasstring max_plugin_name_length getpluginspecification pluginthreadname senderrorpage pluginnotfoundreloadtitle getstring plugintoadlet pluginnotfoundreload killplugin pluginthreadname max_threaded_unload_wait_time removecachedcopy startpluginauto sendreplyheaders sendreplyheaders searches all plugins for the plugin with the given thread name and returns the plugin specification used to load the plugin param plugin manager the plugin manager param plugin thread name the thread name of the plugin return the plugin specification of the plugin or code null code if no plugin was found private string get plugin specification plugin manager plugin manager string plugin thread name iterator plugin info wrapper it plugin manager get plugins iterator while it has next plugin info wrapper pi it next if pi get thread name equals plugin thread name return pi get filename return null pluginmanager pluginthreadname getpluginspecification pluginmanager pluginmanager pluginthreadname plugininfowrapper pluginmanager getplugins hasnext plugininfowrapper getthreadname pluginthreadname getfilename private string l10n string key string pattern string value return l10n get string pproxy toadlet key new string pattern new string value getstring pproxytoadlet private string l10n string key return l10n get string pproxy toadlet key getstring pproxytoadlet override public void handle get uri uri http request request toadlet context ctx throws toadlet context closed exception io exception string basepath plugins string path request get path remove leading and plugins from path if path starts with path path substring 1 if path starts with plugins path path substring plugins length plugin manager pm node plugin manager if logger should log logger minor this logger minor this pproxy fetching path try if path equals if ctx is allowed full access super send error page ctx 403 unauthorized l10n get string toadlet unauthorized return iterator plugin progress loading plugins pm get starting plugins iterator html node page node ctx get page maker get page node l10n plugins with node name name core get my name ctx if loading plugins has next okay add a refresh html node head node ctx get page maker get head node page node head node add child meta new string http equiv content new string refresh 10 url html node content node ctx get page maker get content node page node content node add child core alerts create summary user alert user alerts core alerts get alerts for int index 0 count user alerts length index count index user alert user alert user alerts index if user alert is valid user alert get user identifier plugin manager class content node add child core alerts render alert user alert find which plugins have already been loaded list string available plugins pm find available plugins iterator plugin info wrapper loaded plugins pm get plugins iterator while loaded plugins has next plugin info wrapper plugin info wrapper loaded plugins next string plugin name plugin info wrapper get plugin class name string short plugin name plugin name substring plugin name last index of 1 available plugins remove short plugin name while loading plugins has next plugin progress plugin progress loading plugins next string plugin name plugin progress get name available plugins remove plugin name show starting plugins pm content node show plugin list ctx pm content node show official plugin loader ctx content node available plugins show unofficial plugin loader ctx content node show freenet plugin loader ctx content node writehtml reply ctx 200 ok page node generate else split path into plugin class name and data path for plugin int to path index of string plugin if to 1 plugin path else plugin path substring 0 to plugin may need to know where it was accessed from so it can e g produce relative ur ls write reply ctx 200 text html ok mk page plugin pm handlehttp get plugin data writehtml reply ctx 200 ok pm handlehttp get plugin request fetch result result fetch key write reply ctx 200 result get mime type ok result as bucket catch redirect pluginhttp exception e write temporary redirect ctx e message e new location catch not found pluginhttp exception e send error page ctx not found pluginhttp exception code e message e location catch access denied pluginhttp exception e send error page ctx access denied pluginhttp exception code e message e location catch download pluginhttp exception e fixme maybe it ought to be defined like send error page in toadlets multi value table string string head new multi value table string string head put content disposition attachment filename e filename ctx send reply headers download pluginhttp exception code found head e mime type e data length ctx write data e data catch pluginhttp exception e send error page ctx pluginhttp exception code e message e location catch throwable t ctx force disconnect write internal error t ctx handleget httprequest toadletcontext toadletcontextclosedexception ioexception getpath startswith startswith pluginmanager pluginmanager shouldlog isallowedfullaccess senderrorpage getstring pluginprogress loadingplugins getstartingplugins htmlnode pagenode getpagemaker getpagenode pluginswithnodename getmyname loadingplugins hasnext htmlnode headnode getpagemaker getheadnode pagenode headnode addchild htmlnode contentnode getpagemaker getcontentnode pagenode contentnode addchild createsummary useralert useralerts getalerts useralerts useralert useralert useralerts useralert isvalid useralert getuseridentifier pluginmanager contentnode addchild renderalert useralert availableplugins findavailableplugins plugininfowrapper loadedplugins getplugins loadedplugins hasnext plugininfowrapper plugininfowrapper loadedplugins pluginname plugininfowrapper getpluginclassname shortpluginname pluginname pluginname lastindexof availableplugins shortpluginname loadingplugins hasnext pluginprogress pluginprogress loadingplugins pluginname pluginprogress getname availableplugins pluginname showstartingplugins contentnode showpluginlist contentnode showofficialpluginloader contentnode availableplugins showunofficialpluginloader contentnode showfreenetpluginloader contentnode writehtmlreply pagenode indexof urls writereply mkpage handlehttpget writehtmlreply handlehttpget fetchresult writereply getmimetype asbucket redirectpluginhttpexception writetemporaryredirect newlocation notfoundpluginhttpexception senderrorpage notfoundpluginhttpexception accessdeniedpluginhttpexception senderrorpage accessdeniedpluginhttpexception downloadpluginhttpexception senderrorpage multivaluetable multivaluetable sendreplyheaders downloadpluginhttpexception mimetype writedata pluginhttpexception senderrorpage pluginhttpexception forcedisconnect writeinternalerror shows a list of all currently loading plugins param plugin manager the plugin manager param content node the node to add content to private void show starting plugins plugin manager plugin manager html node content node set plugin progress starting plugins plugin manager get starting plugins if starting plugins is empty html node starting plugins box content node add child div class infobox infobox normal starting plugins box add child div class infobox header l10n starting plugins title html node starting plugins content starting plugins box add child div class infobox content html node starting plugins table starting plugins content add child table html node starting plugins header starting plugins table add child tr starting plugins header add child th l10n starting plugin name starting plugins header add child th l10n starting plugin status starting plugins header add child th l10n starting plugin time iterator plugin progress starting plugins iterator starting plugins iterator while starting plugins iterator has next plugin progress plugin progress starting plugins iterator next html node starting plugins row starting plugins table add child tr starting plugins row add child td plugin progress get name starting plugins row add child td l10n starting plugin status plugin progress get progress to string starting plugins row add child td aligh right time util format time plugin progress get time pluginmanager contentnode showstartingplugins pluginmanager pluginmanager htmlnode contentnode pluginprogress startingplugins pluginmanager getstartingplugins startingplugins isempty htmlnode startingpluginsbox contentnode addchild startingpluginsbox addchild startingpluginstitle htmlnode startingpluginscontent startingpluginsbox addchild htmlnode startingpluginstable startingpluginscontent addchild htmlnode startingpluginsheader startingpluginstable addchild startingpluginsheader addchild startingpluginname startingpluginsheader addchild startingpluginstatus startingpluginsheader addchild startingplugintime pluginprogress startingpluginsiterator startingplugins startingpluginsiterator hasnext pluginprogress pluginprogress startingpluginsiterator htmlnode startingpluginsrow startingpluginstable addchild startingpluginsrow addchild pluginprogress getname startingpluginsrow addchild startingpluginstatus pluginprogress getprogress tostring startingpluginsrow addchild timeutil formattime pluginprogress gettime private void show plugin list toadlet context ctx plugin manager pm html node content node throws toadlet context closed exception io exception html node infobox content node add child div class infobox infobox normal infobox add child div class infobox header l10n get string plugin toadlet plugin list title html node infobox content infobox add child div class infobox content if pm get plugins is empty infobox content add child div l10n no plugins else html node plugin table infobox content add child table class plugins html node header row plugin table add child tr header row add child th l10n class name title header row add child th l10n version title header row add child th l10n internalid title header row add child th l10n started at title header row add child th header row add child th header row add child th iterator plugin info wrapper it pm get plugins iterator while it has next plugin info wrapper pi it next html node plugin row plugin table add child tr plugin row add child td pi get plugin class name long ver pi get plugin long version if ver 1 plugin row add child td pi get plugin version ver else plugin row add child td pi get plugin version plugin row add child td pi get thread name plugin row add child td new date pi get started to string if pi is stopping plugin row add child td l10n plugin stopping add two empty cells plugin row add child td plugin row add child td else if pi is pproxy plugin html node visit form plugin row add child td add child form new string method action target new string get pi get plugin class name blank visit form add child input new string type name value new string hidden form password core form password visit form add child input new string type value new string submit l10n get string plugin toadlet visit html node unload form ctx add form child plugin row add child td unload plugin form unload form add child input new string type name value new string hidden unload pi get thread name unload form add child input new string type value new string submit l10n unload html node reload form ctx add form child plugin row add child td reload plugin form reload form add child input new string type name value new string hidden reload pi get thread name reload form add child input new string type value new string submit l10n reload showpluginlist toadletcontext pluginmanager htmlnode contentnode toadletcontextclosedexception ioexception htmlnode contentnode addchild addchild getstring plugintoadlet pluginlisttitle htmlnode infoboxcontent addchild getplugins isempty infoboxcontent addchild noplugins htmlnode plugintable infoboxcontent addchild htmlnode headerrow plugintable addchild headerrow addchild classnametitle headerrow addchild versiontitle headerrow addchild internalidtitle headerrow addchild startedattitle headerrow addchild headerrow addchild headerrow addchild plugininfowrapper getplugins hasnext plugininfowrapper htmlnode pluginrow plugintable addchild pluginrow addchild getpluginclassname getpluginlongversion pluginrow addchild getpluginversion pluginrow addchild getpluginversion pluginrow addchild getthreadname pluginrow addchild getstarted tostring isstopping pluginrow addchild pluginstopping pluginrow addchild pluginrow addchild ispproxyplugin htmlnode visitform pluginrow addchild addchild getpluginclassname _blank visitform addchild formpassword formpassword visitform addchild getstring plugintoadlet htmlnode unloadform addformchild pluginrow addchild unloadpluginform unloadform addchild getthreadname unloadform addchild htmlnode reloadform addformchild pluginrow addchild reloadpluginform reloadform addchild getthreadname reloadform addchild private void show official plugin loader toadlet context toadlet context html node content node list string available plugins box for official plugins html node add official plugin box content node add child div class infobox infobox normal add official plugin box add child div class infobox header l10n load official plugin html node add official plugin content add official plugin box add child div class infobox content html node add official form toadlet context add form child add official plugin content add official plugin form add official form add child div l10n load official plugin text fixme css ize this add official form add child p add child b add child font new string color new string red l10n load official plugin warning add official form add child l10n load official plugin label html node select node add official form add child select name plugin name iterator string available plugin iterator available plugins iterator while available plugin iterator has next string plugin name available plugin iterator next select node add child option value plugin name plugin name add official form add child add official form add child input new string type name value new string submit submit official l10n load showofficialpluginloader toadletcontext toadletcontext htmlnode contentnode availableplugins htmlnode addofficialpluginbox contentnode addchild addofficialpluginbox addchild loadofficialplugin htmlnode addofficialplugincontent addofficialpluginbox addchild htmlnode addofficialform toadletcontext addformchild addofficialplugincontent addofficialpluginform addofficialform addchild loadofficialplugintext addofficialform addchild addchild addchild loadofficialpluginwarning addofficialform addchild loadofficialpluginlabel htmlnode selectnode addofficialform addchild availablepluginiterator availableplugins availablepluginiterator hasnext pluginname availablepluginiterator selectnode addchild pluginname pluginname addofficialform addchild addofficialform addchild private void show unofficial plugin loader toadlet context toadlet context html node content node box for unofficial plugins html node add other plugin box content node add child div class infobox infobox normal add other plugin box add child div class infobox header l10n load other plugin html node add other plugin content add other plugin box add child div class infobox content html node add other form toadlet context add form child add other plugin content add other plugin form add other form add child div l10n load other plugin text add other form add child l10n load otherurl label add other form add child input new string type name size new string text plugin url 80 add other form add child add other form add child input new string type name value new string submit submit other l10n load add other form add child br add other form add child input new string type name checked new string checkbox fileonly checked add other form add child l10n fileonly showunofficialpluginloader toadletcontext toadletcontext htmlnode contentnode htmlnode addotherpluginbox contentnode addchild addotherpluginbox addchild loadotherplugin htmlnode addotherplugincontent addotherpluginbox addchild htmlnode addotherform toadletcontext addformchild addotherplugincontent addotherpluginform addotherform addchild loadotherplugintext addotherform addchild loadotherurllabel addotherform addchild addotherform addchild addotherform addchild addotherform addchild addotherform addchild addotherform addchild private void show freenet plugin loader toadlet context toadlet context html node content node box for freenet plugins html node add freenet plugin box content node add child div class infobox infobox normal add freenet plugin box add child div class infobox header l10n load freenet plugin html node add freenet plugin content add freenet plugin box add child div class infobox content html node add freenet form toadlet context add form child add freenet plugin content add freenet plugin form add freenet form add child div l10n load freenet plugin text add freenet form add child l10n load freeneturl label add freenet form add child input new string type name size new string text plugin uri 80 add freenet form add child add freenet form add child input new string type name value new string submit submit freenet l10n load showfreenetpluginloader toadletcontext toadletcontext htmlnode contentnode htmlnode addfreenetpluginbox contentnode addchild addfreenetpluginbox addchild loadfreenetplugin htmlnode addfreenetplugincontent addfreenetpluginbox addchild htmlnode addfreenetform toadletcontext addformchild addfreenetplugincontent addfreenetpluginform addfreenetform addchild loadfreenetplugintext addfreenetform addchild loadfreeneturllabel addfreenetform addchild addfreenetform addchild addfreenetform addchild private language string short code string full name string iso code this short code short code this full name full name this iso code iso code this l10n filename freenet l10n freenet l10n short code properties this l10n override filename freenet l10n short code override properties shortcode fullname isocode shortcode shortcode fullname fullname isocode isocode l10nfilename shortcode l10noverridefilename shortcode language language l this l short code l full name l iso code shortcode fullname isocode public static language map to language string whatever for language current language language values if current language short code equals ignore case whatever current language full name equals ignore case whatever current language iso code equals ignore case whatever current language to string equals ignore case whatever return current language return null maptolanguage currentlanguage currentlanguage shortcode equalsignorecase currentlanguage fullname equalsignorecase currentlanguage isocode equalsignorecase currentlanguage tostring equalsignorecase currentlanguage public static string values with full names language all values values string result new string all values length for int i 0 i all values length i result i all values i full name return result valueswithfullnames allvalues allvalues allvalues allvalues fullname public static language get default return english getdefault l10n language selected selected language selected try file tmp file new file selected l10n override filename if tmp file exists tmp file can read tmp file length 0 logger normal this override file detected let s try to load it translation override simple field set read from tmp file false false else try to restore a backup file backup new file tmp file get parent file tmp file get name bak if backup exists backup length 0 logger normal this override backup file detected let s try to load it translation override simple field set read from backup false false translation override null catch io exception e translation override null logger error this io error while accessing the file e get message e current translation load translation selected language if current translation null logger error this the translation file for selected language is invalid the node will load an empty template current translation null translation override new simple field set false selectedlanguage tmpfile l10noverridefilename tmpfile tmpfile canread tmpfile translationoverride simplefieldset readfrom tmpfile tmpfile getparentfile tmpfile getname translationoverride simplefieldset readfrom translationoverride ioexception translationoverride ioerror getmessage currenttranslation loadtranslation selectedlanguage currenttranslation selectedlanguage currenttranslation translationoverride simplefieldset set the default language used by the framework param selected language 2 letter code throws missing resource exception public static void set language string selected language throws missing resource exception synchronized sync logger normal class name changing the current language to selected language l10n old class current class language lang language map to language selected language if lang null current class old class null old class new l10n language get default logger error class name the requested translation is not available selected language throw new missing resource exception the requested translation selected language hasn t been found class name selected language else current class new l10n lang selectedlanguage missingresourceexception setlanguage selectedlanguage missingresourceexception class_name selectedlanguage oldclass currentclass maptolanguage selectedlanguage currentclass oldclass oldclass getdefault class_name selectedlanguage missingresourceexception selectedlanguage class_name selectedlanguage currentclass public static void set override string key string value key key trim value value trim synchronized sync is the override already declared if not create it if translation override null translation override new simple field set false if there is no need to keep it in the override remove it unless the original default is the same as the translation if equals value value equals current translation get key translation override remove value key else value value replace all r n t set the value of the override translation override put overwrite key value logger normal class name got a new translation key set the override save the file to disk savetranslationfile setoverride translationoverride translationoverride simplefieldset currenttranslation translationoverride removevalue replaceall translationoverride putoverwrite class_name _savetranslationfile private static void savetranslationfile file output stream fos null file final file new file get selected language l10n override filename try we don t set delete on exit on it if the save operation fails we want a backup fixme redflag not symlink race proof file temp file new file final file get parent file final file get name bak logger minor class name the temporary filename is temp file fos new file output stream temp file l10n translation override write to fos file util rename to temp file final file logger normal class name override file saved successfully catch io exception e logger error class name error while saving the translation override e get message e finally closer close fos _savetranslationfile fileoutputstream finalfile getselectedlanguage l10noverridefilename deleteonexit tempfile finalfile getparentfile finalfile getname class_name tempfile fileoutputstream tempfile translationoverride writeto fileutil renameto tempfile finalfile class_name ioexception class_name getmessage return a new copy of the current translation file return simple field set or null public static simple field set get current language translation synchronized sync return current translation null null new simple field set current translation simplefieldset simplefieldset getcurrentlanguagetranslation currenttranslation simplefieldset currenttranslation return a copy of the current translation override if it exists or null return simple field set or null public static simple field set get override for current language translation synchronized sync return translation override null null new simple field set translation override simplefieldset simplefieldset getoverrideforcurrentlanguagetranslation translationoverride simplefieldset translationoverride return a copy of the default translation file english one return simple field set public static simple field set get default language translation synchronized sync if fallback translation null fallback translation load translation language get default return new simple field set fallback translation simplefieldset simplefieldset getdefaultlanguagetranslation fallbacktranslation fallbacktranslation loadtranslation getdefault simplefieldset fallbacktranslation the real meat same thing as get string key false ensure it will always return a string value param key return the translated string or the default value from the default language or the key if nothing is found public static string get string string key return get string key false getstring getstring getstring you probably don t want to use that one directly see get string string public static string get string string key boolean return null if not found string result null synchronized sync if translation override null result translation override get key if result null return result synchronized sync if current translation null result current translation get key if result null return result else logger normal class name the translation for key hasn t been found get selected language please tell the maintainer return return null if not found null get default string key getstring getstring returnnullifnotfound translationoverride translationoverride currenttranslation currenttranslation class_name getselectedlanguage returnnullifnotfound getdefaultstring almost the same as get string string but it returns a html node and gives the user the ability to contribute to the translation though the translation toadlet param key return html node public static html node gethtml node string key string value get string key true if value null return new html node value html node translation field new html node span class translate it translation field add child get default string key translation field add child a href translation toadlet toadlet url translate key add child small translate it in your native language return translation field getstring htmlnode htmlnode htmlnode gethtmlnode getstring htmlnode htmlnode translationfield htmlnode translate_it translationfield addchild getdefaultstring translationfield addchild translationtoadlet toadlet_url addchild translationfield return the english translation of the key or the key itself if it doesn t exist param key return string public static string get default string string key string result null we instanciate it only if necessary synchronized sync if fallback translation null fallback translation load translation language get default result fallback translation get key if result null return result logger error class name the default translation for key hasn t been found system err println the default translation for key hasn t been found new exception print stack trace return key getdefaultstring fallbacktranslation fallbacktranslation loadtranslation getdefault fallbacktranslation class_name printstacktrace allows things like l10n get string testing test new string test1 test2 a b param key param patterns a list of patterns wich are matchable from the translation param values the values corresponding to the list return the translated string or the default value from the default language or the key if nothing is found public static string get string string key string patterns string values assert patterns length values length string result get string key for int i 0 i patterns length i result result replace all patterns i quote replacement values i return result getstring getstring getstring replaceall quotereplacement private static string quote replacement string s if s index of 1 s index of 1 return s string builder sb new string builder for int i 0 i s length i char c s char at i if c sb append sb append else if c sb append sb append else sb append c return sb to string quotereplacement indexof indexof stringbuilder stringbuilder charat tostring return the iso code of the language used by the framework return string public static language get selected language synchronized sync if current class null current class selected language null return language get default else return current class selected language getselectedlanguage currentclass currentclass selectedlanguage getdefault currentclass selectedlanguage load a translation file depending on the given name and using the prefix param lang the chosen language return the properties object or null if not found public static simple field set load translation language lang simple field set result null input stream in null try class loader loader class loader get system class loader returns null on lookup failures in loader get resource as stream lang l10n filename if in null result simple field set read from in false false catch exception e logger error class name error while loading the l10n file from lang l10n filename e get message e result null finally closer close in return result simplefieldset loadtranslation simplefieldset inputstream classloader classloader getsystemclassloader getresourceasstream l10nfilename simplefieldset readfrom class_name l10nfilename getmessage public static boolean is overridden string key synchronized sync if translation override null return false return translation override get key null isoverridden translationoverride translationoverride add a localised string with some raw html substitutions useful when some part of a sentence needs to be bold e g param key the l10n key param patterns the strings to search for param values the strings to substitute in public static void addl10n substitution html node node string key string patterns string values string result html encoder encode get string key assert patterns length values length for int i 0 i patterns length i result result replace all patterns i quote replacement values i node add child result addl10nsubstitution htmlnode htmlencoder getstring replaceall quotereplacement addchild public static string get string string key string pattern string value return get string key new string pattern new string value fixme code efficiently getstring getstring private static final long serial versionuid 1 public invalid parameter exception string message super message serialversionuid invalidparameterexception public abstract class sendable insert extends sendable request public sendable insert boolean persistent super persistent sendableinsert sendablerequest sendableinsert called when we successfully insert the data public abstract void on success object key num object container container client context context onsuccess keynum objectcontainer clientcontext public abstract void on success object key num object container container client context context called when we don t public abstract void on failure low level put exception e object key num object container container client context context onsuccess keynum objectcontainer clientcontext onfailure lowlevelputexception keynum objectcontainer clientcontext public abstract void on failure low level put exception e object key num object container container client context context override public void internal error throwable t request scheduler sched object container container client context context boolean persistent sched call failure this new low level put exception low level put exception internal error t get message t native thread max priority persistent onfailure lowlevelputexception keynum objectcontainer clientcontext internalerror requestscheduler objectcontainer clientcontext callfailure lowlevelputexception lowlevelputexception internal_error getmessage nativethread max_priority override public final boolean is insert return true isinsert override public client request scheduler get scheduler client context context if isssk return context get ssk insert scheduler else return context get chk insert scheduler clientrequestscheduler getscheduler clientcontext getsskinsertscheduler getchkinsertscheduler public abstract boolean cache inserts object container container cacheinserts objectcontainer public static final message create packet transmit long uid int packet no bit array sent buffer data message msg new message packet transmit msg set uid uid msg set packet no packet no msg set sent sent msg set data data return msg createpackettransmit packetno bitarray packettransmit packet_no packetno public static int packet transmit size int size int packets return size 8 uid 4 packet bit array serialized length packets 4 message header packettransmitsize _packets bitarray serializedlength _packets public static int bulk packet transmit size int size return size 8 uid 4 packet 4 message header bulkpackettransmitsize public static final message create all sent long uid message msg new message all sent msg set uid uid return msg createallsent allsent public static final message create missing packet notification long uid linked list integer missing message msg new message missing packet notification msg set uid uid msg set missing missing return msg createmissingpacketnotification linkedlist missingpacketnotification public static final message create all received long uid message msg new message all received msg set uid uid return msg createallreceived allreceived public static final message create send aborted long uid int reason string description message msg new message send aborted msg set uid uid msg set reason reason msg set description description return msg createsendaborted sendaborted public static final message createfnp bulk packet send long uid int packet no short buffer data message msg new message fnp bulk packet send msg set uid uid msg set packet no packet no msg set data data return msg createfnpbulkpacketsend packetno shortbuffer fnpbulkpacketsend packet_no packetno public static final message createfnp bulk packet send long uid int packet no byte data return createfnp bulk packet send uid packet no new short buffer data createfnpbulkpacketsend packetno createfnpbulkpacketsend packetno shortbuffer public static final message createfnp bulk send aborted long uid message msg new message fnp bulk send aborted msg set uid uid return msg createfnpbulksendaborted fnpbulksendaborted public static final message createfnp bulk receive aborted long uid message msg new message fnp bulk receive aborted msg set uid uid return msg createfnpbulkreceiveaborted fnpbulkreceiveaborted public static final message createfnp bulk received all long uid message msg new message fnp bulk received all msg set uid uid return msg createfnpbulkreceivedall fnpbulkreceivedall public static final message create test transfer send long uid message msg new message test transfer send msg set uid uid return msg createtesttransfersend testtransfersend public static final message create test transfer send ack long uid message msg new message test transfer send ack msg set uid uid return msg createtesttransfersendack testtransfersendack public static final message create test sendchk long uid string uri buffer header message msg new message test sendchk msg set uid uid msg set freenet uri uri msg set chk header header return msg createtestsendchk testsendchk freenet_uri chk_header public static final message create test request key key long id int htl message msg new message test request msg set uid id msg set freenet routing key key msg set htl htl return msg createtestrequest testrequest freenet_routing_key public static final message create test data not found long uid message msg new message test data not found msg set uid uid return msg createtestdatanotfound testdatanotfound public static final message create test data reply long uid byte headers message msg new message test data reply msg set uid uid msg set test chk headers new buffer headers return msg createtestdatareply testdatareply test_chk_headers public static final message create test sendchk ack long uid string key message msg new message test sendchk ack msg set uid uid msg set freenet uri key return msg createtestsendchkack testsendchkack freenet_uri public static final message create test data reply ack long id message msg new message test data reply ack msg set uid id return msg createtestdatareplyack testdatareplyack public static final message create test data not found ack long id message msg new message test data not found ack msg set uid id return msg createtestdatanotfoundack testdatanotfoundack public static final message create test receive completed long id boolean success string reason message msg new message test receive completed msg set uid id msg set success success msg set reason reason return msg createtestreceivecompleted testreceivecompleted public static final message create test send completed long id boolean success string reason message msg new message test send completed msg set uid id msg set success success msg set reason reason return msg createtestsendcompleted testsendcompleted public static final message create node to node message int type byte data message msg new message node to node message msg set node to node message type type msg set node to node message data new short buffer data return msg createnodetonodemessage nodetonodemessage node_to_node_message_type node_to_node_message_data shortbuffer public static final message createfnpchk data request long id short htl nodechk key message msg new message fnpchk data request msg set uid id msg set htl htl msg set freenet routing key key msg set nearest location 0 0 return msg createfnpchkdatarequest fnpchkdatarequest freenet_routing_key nearest_location public static final message createfnpssk data request long id short htl nodessk key boolean need pub key message msg new message fnpssk data request msg set uid id msg set htl htl msg set freenet routing key key msg set nearest location 0 0 msg set need pub key need pub key return msg createfnpsskdatarequest needpubkey fnpsskdatarequest freenet_routing_key nearest_location need_pub_key needpubkey public static final message createfnp rejected loop long id message msg new message fnp rejected loop msg set uid id return msg createfnprejectedloop fnprejectedloop public static final message createfnp rejected overload long id boolean is local message msg new message fnp rejected overload msg set uid id msg set is local is local return msg createfnprejectedoverload islocal fnprejectedoverload is_local islocal public static final message createfnp accepted long id message msg new message fnp accepted msg set uid id return msg createfnpaccepted fnpaccepted public static final message createfnp data not found long id message msg new message fnp data not found msg set uid id return msg createfnpdatanotfound fnpdatanotfound public static final message createfnp recently failed long id int time left message msg new message fnp recently failed msg set uid id msg set time left time left return msg createfnprecentlyfailed timeleft fnprecentlyfailed time_left timeleft public static final message createfnpchk data found long id byte buf message msg new message fnpchk data found msg set uid id msg set block headers new short buffer buf return msg createfnpchkdatafound fnpchkdatafound block_headers shortbuffer public static final message createfnp route not found long id short htl message msg new message fnp route not found msg set uid id msg set htl htl return msg createfnproutenotfound fnproutenotfound public static final message createfnp insert request long id short htl key key message msg new message fnp insert request msg set uid id msg set htl htl msg set freenet routing key key msg set nearest location 0 0 return msg createfnpinsertrequest fnpinsertrequest freenet_routing_key nearest_location public static final message createfnp insert reply long id message msg new message fnp insert reply msg set uid id return msg createfnpinsertreply fnpinsertreply public static final message createfnp data insert long uid byte headers message msg new message fnp data insert msg set uid uid msg set block headers new short buffer headers return msg createfnpdatainsert fnpdatainsert block_headers shortbuffer public static final message createfnp insert transfers completed long uid boolean any timed out message msg new message fnp insert transfers completed msg set uid uid msg set any timed out any timed out return msg createfnpinserttransferscompleted anytimedout fnpinserttransferscompleted any_timed_out anytimedout public static final message createfnp rejected timeout long uid message msg new message fnp rejected timeout msg set uid uid return msg createfnprejectedtimeout fnprejectedtimeout public static final message createfnp data insert rejected long uid short reason message msg new message fnp data insert rejected msg set uid uid msg set data insert rejected reason reason return msg createfnpdatainsertrejected fnpdatainsertrejected data_insert_rejected_reason public static final string get data insert rejected reason short reason if reason data insert rejected verify failed return verify failed else if reason data insert rejected receive failed return receive failed else if reason data insert rejected ssk error return ssk error return unknown reason code reason getdatainsertrejectedreason data_insert_rejected_verify_failed data_insert_rejected_receive_failed data_insert_rejected_ssk_error public static message createfnpssk insert request long uid short htl nodessk my key byte headers byte data byte pub key hash message msg new message fnpssk insert request msg set uid uid msg set htl htl msg set freenet routing key my key msg set nearest location 0 0 msg set block headers new short buffer headers msg set pubkey hash new short buffer pub key hash msg set data new short buffer data return msg createfnpsskinsertrequest mykey pubkeyhash fnpsskinsertrequest freenet_routing_key mykey nearest_location block_headers shortbuffer pubkey_hash shortbuffer pubkeyhash shortbuffer public static message createfnpssk insert request new long uid short htl nodessk my key message msg new message fnpssk insert request new msg set uid uid msg set htl htl msg set freenet routing key my key return msg createfnpsskinsertrequestnew mykey fnpsskinsertrequestnew freenet_routing_key mykey public static final message createfnpssk insert request headers long uid byte headers message msg new message fnpssk insert request headers msg set uid uid msg set block headers new short buffer headers return msg createfnpsskinsertrequestheaders fnpsskinsertrequestheaders block_headers shortbuffer public static final message createfnpssk insert request data long uid byte data message msg new message fnpssk insert request data msg set uid uid msg set data new short buffer data return msg createfnpsskinsertrequestdata fnpsskinsertrequestdata shortbuffer public static message createfnpssk data found headers long uid byte headers message msg new message fnpssk data found headers msg set uid uid msg set block headers new short buffer headers return msg createfnpsskdatafoundheaders fnpsskdatafoundheaders block_headers shortbuffer public static message createfnpssk data found data long uid byte data message msg new message fnpssk data found data msg set uid uid msg set data new short buffer data return msg createfnpsskdatafounddata fnpsskdatafounddata shortbuffer public static final message createfnpssk accepted long uid boolean need pub key message msg new message fnpssk accepted msg set uid uid msg set need pub key need pub key return msg createfnpsskaccepted needpubkey fnpsskaccepted need_pub_key needpubkey public static message createfnpssk pub key long uid dsa public key pubkey message msg new message fnpssk pub key msg set uid uid msg set pubkey as bytes new short buffer pubkey as padded bytes return msg createfnpsskpubkey dsapublickey fnpsskpubkey pubkey_as_bytes shortbuffer aspaddedbytes public static message createfnpssk pub key accepted long uid message msg new message fnpssk pub key accepted msg set uid uid return msg createfnpsskpubkeyaccepted fnpsskpubkeyaccepted public static message createfnp opennet completed ack long uid message msg new message fnp opennet completed ack msg set uid uid return msg createfnpopennetcompletedack fnpopennetcompletedack public static message createfnp opennet connect destination new long uid long transferuid int noderef length int padded length message msg new message fnp opennet connect destination new msg set uid uid msg set transfer uid transferuid msg set noderef length noderef length msg set padded length padded length return msg createfnpopennetconnectdestinationnew nodereflength paddedlength fnpopennetconnectdestinationnew transfer_uid noderef_length nodereflength padded_length paddedlength public static message createfnp opennet connect reply new long uid long transferuid int noderef length int padded length message msg new message fnp opennet connect reply new msg set uid uid msg set transfer uid transferuid msg set noderef length noderef length msg set padded length padded length return msg createfnpopennetconnectreplynew nodereflength paddedlength fnpopennetconnectreplynew transfer_uid noderef_length nodereflength padded_length paddedlength public static message createfnp opennet announce request long uid long transferuid int noderef length int padded length double target short htl message msg new message fnp opennet announce request msg set uid uid msg set transfer uid transferuid msg set noderef length noderef length msg set padded length padded length msg set htl htl msg set nearest location 0 0 msg set target location target return msg createfnpopennetannouncerequest nodereflength paddedlength fnpopennetannouncerequest transfer_uid noderef_length nodereflength padded_length paddedlength nearest_location target_location public static message createfnp opennet announce reply long uid long transferuid int noderef length int padded length message msg new message fnp opennet announce reply msg set uid uid msg set transfer uid transferuid msg set noderef length noderef length msg set padded length padded length return msg createfnpopennetannouncereply nodereflength paddedlength fnpopennetannouncereply transfer_uid noderef_length nodereflength padded_length paddedlength public static message createfnp opennet announce completed long uid message msg new message fnp opennet announce completed msg set uid uid return msg createfnpopennetannouncecompleted fnpopennetannouncecompleted public static message createfnp opennet disabled long uid message msg new message fnp opennet disabled msg set uid uid return msg createfnpopennetdisabled fnpopennetdisabled public static message createfnp opennet noderef rejected long uid int reject code message msg new message fnp opennet noderef rejected msg set uid uid msg set reject code reject code return msg createfnpopennetnoderefrejected rejectcode fnpopennetnoderefrejected reject_code rejectcode public static string get opennet rejected code int x switch x case noderef rejected too big return too big case noderef rejected real bigger than padded return real length bigger than padded length case noderef rejected transfer failed return transfer failed case noderef rejected invalid return invalid noderef default return unknown rejection code x getopennetrejectedcode noderef_rejected_too_big noderef_rejected_real_bigger_than_padded noderef_rejected_transfer_failed noderef_rejected_invalid public static message createfnp opennet announce node not wanted long uid message msg new message fnp opennet announce node not wanted msg set uid uid return msg createfnpopennetannouncenodenotwanted fnpopennetannouncenodenotwanted public static message createfnp offer key key key byte authenticator message msg new message fnp offer key msg set key key msg set offer authenticator new short buffer authenticator return msg createfnpofferkey fnpofferkey offer_authenticator shortbuffer public static message createfnp get offered key key key byte authenticator boolean need pubkey long uid message msg new message fnp get offered key msg set key key msg set offer authenticator new short buffer authenticator msg set need pub key need pubkey msg set uid uid return msg createfnpgetofferedkey needpubkey fnpgetofferedkey offer_authenticator shortbuffer need_pub_key needpubkey public static message createfnp get offered key invalid long uid short reason message msg new message fnp get offered key invalid msg set uid uid msg set reason reason return msg createfnpgetofferedkeyinvalid fnpgetofferedkeyinvalid public static final message createfnp ping int seq no message msg new message fnp ping msg set ping seqno seq no return msg createfnpping seqno fnpping ping_seqno seqno public static final message createfnp pong int seq no message msg new message fnp pong msg set ping seqno seq no return msg createfnppong seqno fnppong ping_seqno seqno public static final message createfnprh probe reply long uid double nearest double best short counter short unique counter short linear counter message msg new message fnprh probe reply msg set uid uid msg set nearest location nearest msg set best location best msg set counter counter msg set unique counter unique counter msg set linear counter linear counter return msg createfnprhprobereply uniquecounter linearcounter fnprhprobereply nearest_location best_location unique_counter uniquecounter linear_counter linearcounter public static final message createfnprh probe request long uid double target double nearest double best short htl message msg new message fnprh probe request msg set uid uid msg set target location target msg set nearest location nearest msg set best location best msg set htl htl return msg createfnprhproberequest fnprhproberequest target_location nearest_location best_location public static final message createfnprh return sub message double nearest double best short counter short unique counter short linear counter string reason message msg new message fnprh return sub message msg set nearest location nearest msg set best location best msg set counter counter msg set unique counter unique counter msg set linear counter linear counter msg set reason reason return msg createfnprhreturnsubmessage uniquecounter linearcounter fnprhreturnsubmessage nearest_location best_location unique_counter uniquecounter linear_counter linearcounter public static message createfnprh probe trace long uid double nearest double best short htl short counter short unique counter double my loc long swap identifier double peer locs long peerui ds short fork count short linear counter string reason long prevuid return createfnprh probe trace uid nearest best htl counter unique counter my loc swap identifier new short buffer fields doubles to bytes peer locs new short buffer fields longs to bytes peerui ds fork count linear counter reason prevuid createfnprhprobetrace uniquecounter myloc swapidentifier peerlocs peeruids forkcount linearcounter createfnprhprobetrace uniquecounter myloc swapidentifier shortbuffer doublestobytes peerlocs shortbuffer longstobytes peeruids forkcount linearcounter public static message createfnprh probe trace long uid double nearest double best short htl short counter short unique counter double my loc long swap identifier short buffer peer locs short buffer peerui ds short fork count short linear counter string reason long prevuid message msg new message fnprh probe trace msg set uid uid msg set nearest location nearest msg set best location best msg set htl htl msg set counter counter msg set unique counter unique counter msg set location my loc msg set my uid swap identifier msg set peer locations peer locs msg set peer uids peerui ds msg set fork count fork count msg set linear counter linear counter msg set reason reason msg set prev uid prevuid return msg createfnprhprobetrace uniquecounter myloc swapidentifier shortbuffer peerlocs shortbuffer peeruids forkcount linearcounter fnprhprobetrace nearest_location best_location unique_counter uniquecounter myloc my_uid swapidentifier peer_locations peerlocs peer_uids peeruids fork_count forkcount linear_counter linearcounter prev_uid public static final message createfnp swap request long uid byte buf int htl message msg new message fnp swap request msg set uid uid msg set hash new short buffer buf msg set htl htl return msg createfnpswaprequest fnpswaprequest shortbuffer public static final message createfnp swap rejected long uid message msg new message fnp swap rejected msg set uid uid return msg createfnpswaprejected fnpswaprejected public static final message createfnp swap reply long uid byte buf message msg new message fnp swap reply msg set uid uid msg set hash new short buffer buf return msg createfnpswapreply fnpswapreply shortbuffer public static final message createfnp swap commit long uid byte buf message msg new message fnp swap commit msg set uid uid msg set data new short buffer buf return msg createfnpswapcommit fnpswapcommit shortbuffer public static final message createfnp swap complete long uid byte buf message msg new message fnp swap complete msg set uid uid msg set data new short buffer buf return msg createfnpswapcomplete fnpswapcomplete shortbuffer public static final message createfnp loc change notification new double my location double locations message msg new message fnp loc change notification new short buffer dst new short buffer fields doubles to bytes locations msg set location my location msg set peer locations dst return msg createfnplocchangenotificationnew mylocation fnplocchangenotificationnew shortbuffer shortbuffer doublestobytes mylocation peer_locations public static final message createfnp routed ping long uid double target location short htl int counter byte node identity message msg new message fnp routed ping msg set routed to node fields uid target location htl node identity msg set counter counter return msg createfnproutedping targetlocation nodeidentity fnproutedping setroutedtonodefields targetlocation nodeidentity public static final message createfnp routed pong long uid int counter message msg new message fnp routed pong msg set uid uid msg set counter counter return msg createfnproutedpong fnproutedpong public static final message createfnp secret ping long uid double target location short htl short dawn htl int counter byte node identity message msg new message fnp secret ping msg set routed to node fields uid target location htl node identity msg set counter counter msg set dawn htl dawn htl return msg createfnpsecretping targetlocation dawnhtl nodeidentity fnpsecretping setroutedtonodefields targetlocation nodeidentity dawn_htl dawnhtl public static final message createfnp secret pong long uid int counter long secret message msg new message fnp secret pong msg set uid uid msg set counter counter msg set secret secret return msg createfnpsecretpong fnpsecretpong public static final message createfnp store secret long uid long secret message msg new message fnp store secret msg set uid uid msg set secret secret return msg createfnpstoresecret fnpstoresecret public static final message createfnp networkid int id message msg new message fnp networkid msg set uid id return msg createfnpnetworkid fnpnetworkid public static final message createfnp routed rejected long uid short htl message msg new message fnp routed rejected msg set uid uid msg set htl htl return msg createfnproutedrejected fnproutedrejected public static final message createfnp detectedip address peer peer message msg new message fnp detectedip address msg set external address peer return msg createfnpdetectedipaddress fnpdetectedipaddress external_address public static final message createfnp time long time message msg new message fnp time msg set time time return msg createfnptime fnptime public static final message createfnp uptime byte uptime percent message msg new message fnp uptime msg set uptime percent 48h uptime percent return msg createfnpuptime uptimepercent fnpuptime uptime_percent_48h uptimepercent public static final message createfnp sent packets int time deltas long hashes long base time message msg new message fnp sent packets msg set time deltas new short buffer fields ints to bytes time deltas msg set hashes new short buffer fields longs to bytes hashes msg set time base time return msg createfnpsentpackets timedeltas basetime fnpsentpackets time_deltas shortbuffer intstobytes timedeltas shortbuffer longstobytes basetime public static final message createfnp void message msg new message fnp void return msg createfnpvoid fnpvoid public static final message createfnp disconnect boolean remove boolean purge int message type short buffer message data message msg new message fnp disconnect msg set remove remove msg set purge purge msg set node to node message type message type msg set node to node message data message data return msg createfnpdisconnect messagetype shortbuffer messagedata fnpdisconnect node_to_node_message_type messagetype node_to_node_message_data messagedata public static final message createuom announce string main key string extra key string revocation key boolean have revocation long main jar version long extra jar version long time last tried revocation fetch int revocationdnf count long revocation key length long main jar length long extra jar length int ping time int bwlimit delay time message msg new message uom announce msg set main jar key main key msg set extra jar key extra key msg set revocation key revocation key msg set have revocation key have revocation msg set main jar version main jar version msg set extra jar version extra jar version msg set revocation key time last tried time last tried revocation fetch msg set revocation key dnf count revocationdnf count msg set revocation key file length revocation key length msg set main jar file length main jar length msg set extra jar file length extra jar length msg set ping time ping time msg set bwlimit delay time bwlimit delay time return msg createuomannounce mainkey extrakey revocationkey haverevocation mainjarversion extrajarversion timelasttriedrevocationfetch revocationdnfcount revocationkeylength mainjarlength extrajarlength pingtime bwlimitdelaytime uomannounce main_jar_key mainkey extra_jar_key extrakey revocation_key revocationkey have_revocation_key haverevocation main_jar_version mainjarversion extra_jar_version extrajarversion revocation_key_time_last_tried timelasttriedrevocationfetch revocation_key_dnf_count revocationdnfcount revocation_key_file_length revocationkeylength main_jar_file_length mainjarlength extra_jar_file_length extrajarlength ping_time pingtime bwlimit_delay_time bwlimitdelaytime public static final message createuom request revocation long uid message msg new message uom request revocation msg set uid uid return msg createuomrequestrevocation uomrequestrevocation public static final message createuom request main long uid message msg new message uom request main msg set uid uid return msg createuomrequestmain uomrequestmain public static final message createuom request extra long uid message msg new message uom request extra msg set uid uid return msg createuomrequestextra uomrequestextra public static final message createuom sending revocation long uid long length string key message msg new message uom sending revocation msg set uid uid msg set file length length msg set revocation key key return msg createuomsendingrevocation uomsendingrevocation file_length revocation_key public static final message createuom sending main long uid long length string key int version message msg new message uom sending main msg set uid uid msg set file length length msg set main jar key key msg set main jar version version return msg createuomsendingmain uomsendingmain file_length main_jar_key main_jar_version public static final message createuom sending extra long uid long length string key int version message msg new message uom sending extra msg set uid uid msg set file length length msg set extra jar key key msg set extra jar version version return msg createuomsendingextra uomsendingextra file_length extra_jar_key extra_jar_version public static final message createfnp swap locations long uids message msg new message fnp swap nodeui ds msg set node uids new short buffer fields longs to bytes uids return msg createfnpswaplocations fnpswapnodeuids node_uids shortbuffer longstobytes public static final message createfnp best routes not taken byte locs message msg new message fnp best routes not taken msg set best locations not visited new short buffer locs return msg createfnpbestroutesnottaken fnpbestroutesnottaken best_locations_not_visited shortbuffer public static final message createfnp best routes not taken double locs return createfnp best routes not taken fields doubles to bytes locs createfnpbestroutesnottaken createfnpbestroutesnottaken doublestobytes public static message createfnp best routes not taken double doubles double locs new double doubles length for int i 0 i locs length i locs i doubles i double value return createfnp best routes not taken locs createfnpbestroutesnottaken doublevalue createfnpbestroutesnottaken public static final message create routing status boolean route requests message msg new message fnp routing status msg set routing enabled route requests return msg createroutingstatus routerequests fnproutingstatus routing_enabled routerequests public static void init public single key listener key key base single file fetcher fetcher boolean dont cache short prio boolean persistent this key key this fetcher fetcher this dont cache dont cache this prio prio this persistent persistent singlekeylistener basesinglefilefetcher dontcache dontcache dontcache public long count keys if done return 0 else return 1 countkeys public short definitely want key key key byte salted key object container container client context context if key equals this key return 1 else return prio definitelywantkey saltedkey objectcontainer clientcontext public boolean dont cache return dont cache dontcache dontcache public has key listener get has key listener return fetcher haskeylistener gethaskeylistener public short get priority class object container container return prio getpriorityclass objectcontainer public sendable get get requests for key key key byte salted key object container container client context context if key equals this key return null return new sendable get fetcher sendableget getrequestsforkey saltedkey objectcontainer clientcontext sendableget public boolean handle block key key byte salted key key block found object container container client context context if key equals this key return false if persistent container activate fetcher 1 fetcher on got key key found container context if persistent container deactivate fetcher 1 synchronized this done true return true handleblock saltedkey keyblock objectcontainer clientcontext ongotkey public key list keys object container container return new key key listkeys objectcontainer public boolean persistent return persistent public boolean probably want key key key byte salted key if done return false return key equals this key probablywantkey saltedkey public synchronized void on remove done true onremove public boolean is empty return done isempty public boolean isssk return key instanceof nodessk private client context context public background block encoder queue new array list soft reference encodeable clientcontext backgroundblockencoder arraylist softreference public void set context client context context this context context setcontext clientcontext public void queue encodeable sbi object container container client context context if sbi persistent queue persistent sbi container context run persistent queue context else soft reference encodeable ref new soft reference encodeable sbi synchronized this queue add ref logger minor this queueing encode of sbi notify all objectcontainer clientcontext queuepersistent runpersistentqueue softreference softreference notifyall public void queue single block inserter sbis object container container client context context synchronized this for int i 0 i sbis length i single block inserter inserter sbis i if inserter null continue if inserter is cancelled container continue if inserter resultinguri null continue if inserter persistent continue logger minor this queueing encode of inserter soft reference encodeable ref new soft reference encodeable inserter queue add ref notify all boolean any persistent false for int i 0 i sbis length i single block inserter inserter sbis i if inserter null continue if inserter is cancelled container continue if inserter resultinguri null continue if inserter persistent continue any persistent true queue persistent inserter container context if any persistent run persistent queue context singleblockinserter objectcontainer clientcontext singleblockinserter iscancelled softreference softreference notifyall anypersistent singleblockinserter iscancelled anypersistent queuepersistent anypersistent runpersistentqueue public void run persistent queue client context context context job runner queue runner native thread low priority true runpersistentqueue clientcontext jobrunner nativethread low_priority private void queue persistent encodeable sbi object container container client context context background block encoder tag tag new background block encoder tag sbi sbi get priority class container context container store tag queuepersistent objectcontainer clientcontext backgroundblockencodertag backgroundblockencodertag getpriorityclass public void run freenet support logger os thread logpid this while true encodeable sbi null synchronized this while queue is empty try wait 100 1000 catch interrupted exception e ignore while queue is empty soft reference encodeable ref queue remove queue size 1 sbi ref get if sbi null break logger minor this encoding sbi sbi try encode null context osthread isempty interruptedexception isempty softreference tryencode public int get priority return native thread min priority getpriority nativethread min_priority public void run object container container client context context query query container query query constrain background block encoder tag class query descend nodedb handle constrain long value of context nodedb handle query descend priority order ascending query descend added time order ascending object set results query execute for int x 0 x jobs per slot results has next x background block encoder tag tag background block encoder tag results next try encodeable sbi tag inserter if sbi null continue container activate sbi 1 sbi try encode container context container deactivate sbi 1 catch throwable t logger error this caught t t finally container delete tag if results has next run persistent queue context objectcontainer clientcontext backgroundblockencodertag nodedbhandle valueof nodedbhandle orderascending addedtime orderascending objectset jobs_per_slot hasnext backgroundblockencodertag backgroundblockencodertag tryencode hasnext runpersistentqueue background block encoder tag encodeable inserter short prio client context context this inserter inserter this nodedb handle context nodedb handle this added time system current time millis this priority prio backgroundblockencodertag clientcontext nodedbhandle nodedbhandle addedtime currenttimemillis public message item message msg2 async message callback cb2 byte counter ctr peer node pn this msg msg2 this cb cb2 formatted false this ctr callback ctr this submitted system current time millis priority msg2 get spec get priority buf msg encode to packet pn messageitem asyncmessagecallback bytecounter peernode ctrcallback currenttimemillis getspec getpriority encodetopacket public message item byte data async message callback cb2 boolean formatted byte counter ctr short priority this cb cb2 this msg null this buf data this formatted formatted if formatted buf null throw new null pointer exception this ctr callback ctr this submitted system current time millis this priority priority messageitem asyncmessagecallback bytecounter nullpointerexception ctrcallback currenttimemillis return the data contents of this message item public byte get data return buf messageitem getdata public int get length return buf length getlength param length the actual number of bytes sent to send this message including our share of the packet overheads and including already reported bytes which is only used when deciding how many bytes to report to the throttle public void on sent int length nb the fact that the bytes are counted before callback notifications is important for load management if ctr callback null try ctr callback sent bytes length catch throwable t logger error this caught t reporting length sent bytes on this t if cb null for int i 0 i cb length i try cb i sent catch throwable t logger error this caught t calling sent on cb i for this t alreadyreportedbytes onsent ctrcallback ctrcallback sentbytes public short get priority return priority getpriority override public string to string return super to string formatted formatted msg msg tostring tostring public void on disconnect if cb null for int i 0 i cb length i try cb i disconnected catch throwable t logger error this caught t calling sent on cb i for this t ondisconnect private iterator t iterator public iterator wrapper iterator t iterator this iterator iterator iteratorwrapper public boolean has next return iterator has next hasnext hasnext public t next return iterator next public void remove iterator remove public class plugin down loader file extends plugin down loader file override public file check source string source return new file source plugindownloaderfile plugindownloader checksource override input stream get input stream throws io exception return new file input stream get source inputstream getinputstream ioexception fileinputstream getsource override string get plugin name string source throws plugin not found exception int slash index source last index of if slash index 1 slash index source last index of return source substring slash index 1 getpluginname pluginnotfoundexception slashindex lastindexof slashindex slashindex lastindexof slashindex override string getsha1sum throws plugin not found exception return null pluginnotfoundexception override string getsha256sum throws plugin not found exception return null pluginnotfoundexception public class async replication master file extends replication master file constructor of replication master file param storage replication storage param file local file used to store data locally param async buf size size of asynchronous buffer public async replication master file replication master storage impl storage i file file int async buf size super storage file this async buf size async buf size start asyncreplicationmasterfile replicationmasterfile asyncbufsize asyncreplicationmasterfile replicationmasterstorageimpl ifile asyncbufsize asyncbufsize asyncbufsize constructor of replication master file param file local file used to store data locally param hosts slave node hosts to which replicastion will be performed param async buf size size of asynchronous buffer param ack whether master should wait acknowledgment from slave node during trasanction commit public async replication master file i file file string hosts int async buf size boolean ack super file hosts ack this async buf size async buf size start asyncbufsize asyncreplicationmasterfile ifile asyncbufsize asyncbufsize asyncbufsize class write thread extends thread public void run async write writethread asyncwrite private void start go new object async new object thread new write thread thread start writethread public void write long pos byte buf file write pos buf for int i 0 i out length i if out i null byte data new byte 8 buf length bytes pack8 data 0 pos system arraycopy buf 0 data 8 buf length parcel p new parcel p data data p pos pos p host i try synchronized async buffered data length while buffered async buf size async wait catch interrupted exception x synchronized go if head null head tail p else tail tail next p go notify asyncbufsize interruptedexception public void async write try while true parcel p synchronized go while head null if closed return go wait p head head p next synchronized async if buffered async buf size async notify all buffered p data length int i p host while out i null try out i write p data if ack p pos 0 in i read rc buf 1 break catch io exception x out i null sockets i null n hosts 1 if handle error hosts i connect i else break catch interrupted exception x asyncwrite asyncbufsize notifyall rcbuf ioexception nhosts handleerror interruptedexception public void close try synchronized go closed true go notify thread join catch interrupted exception x super close interruptedexception private static final long serial versionuid 6026765325018137641l public parameter list serialversionuid parameterlist public parameter at int n return parameter get n public parameter get parameter int n return parameter get n getparameter public parameter get parameter string name if name null return null int n lists size for int n 0 n n lists n parameter param at n if name compare to param get name 0 return param return null getparameter nlists nlists compareto getname public string get value string name parameter param get parameter name if param null return return param get value getvalue getparameter getvalue public ssdp search request string serach target int mx set method http m search seturi set header http st serach target set header http mx integer to string mx set header http man man discover ssdpsearchrequest serachtarget setmethod m_search setheader serachtarget setheader tostring setheader public ssdp search request string serach target this serach target ssdp default msearch mx ssdpsearchrequest serachtarget serachtarget default_msearch_mx public ssdp search request this st root device ssdpsearchrequest root_device public void set local address string bind addr string ssdp addr ssdp address if host interface isi pv6 address bind addr true ssdp addr ssdp geti pv6 address set host ssdp addr ssdp port setlocaladdress bindaddr ssdpaddr hostinterface isipv6address bindaddr ssdpaddr getipv6address sethost ssdpaddr private running average avg free memory public memory checker packet sender ps int modificator this ps ps this aggressivegc modificator modificator runningaverage avgfreememory memorychecker packetsender aggressivegcmodificator protected synchronized void terminate goon false logger normal this terminating memory checker public boolean is running return goon isrunning public synchronized void start goon true logger normal this starting memory checker run public void run freenet support logger os thread logpid this if goon logger normal this goon is false killing memory checker return runtime r runtime get runtime long total memory r total memory long free memory r free memory long max memory r max memory logger normal this memory in use size util format size total memory free memory if total memory max memory max memory long max value jvm have allocated maximum memory total memory never decrease so check it only for once if avg free memory null avg free memory new simple running average 3 free memory else avg free memory report free memory if avg free memory count reports 3 avg free memory current value 4 1024 1024 average free memory 4 mb logger normal this reached threshold checking for low memory system gc system run finalization try thread sleep 10 force a context switch finalization need a cs to complete catch interrupted exception e free memory r free memory avg free memory report free memory if free memory 4 1024 1024 current free memory 4 mb logger error this memory too low trying to free some oom handler low memory int sleeptime aggressivegc modificator if sleeptime 0 we are done ps queue timed job this 120 250 30 sec return else ps queue timed job this 120l sleeptime fixme do not remove until all known memory issues fixed especially 66 this probably reduces performance but it makes memory usage more predictable this will make tracking down the sort of nasty unpredictable oo ms we are getting much easier if aggressivegc modificator 0 boolean logminor logger should log logger minor this long beforegc used memory r total memory r free memory if logminor logger minor this memory in use before gc beforegc used memory long beforegc time system current time millis system gc system run finalization long aftergc time system current time millis long aftergc used memory r total memory r free memory if logminor logger minor this memory in use after gc aftergc used memory logger minor this gc completed after aftergc time beforegc time ms and recovered beforegc used memory aftergc used memory bytes leaving aftergc used memory bytes used osthread memorychecker getruntime totalmemory totalmemory freememory freememory maxmemory maxmemory sizeutil formatsize totalmemory freememory totalmemory maxmemory maxmemory max_value totalmemory avgfreememory avgfreememory simplerunningaverage freememory avgfreememory freememory avgfreememory countreports avgfreememory currentvalue runfinalization interruptedexception freememory freememory avgfreememory freememory freememory oomhandler lowmemory aggressivegcmodificator queuetimedjob queuetimedjob ooms aggressivegcmodificator shouldlog beforegcusedmemory totalmemory freememory beforegcusedmemory beforegctime currenttimemillis runfinalization aftergctime currenttimemillis aftergcusedmemory totalmemory freememory aftergcusedmemory aftergctime beforegctime beforegcusedmemory aftergcusedmemory aftergcusedmemory public static void main string args system err println ds agroup biga to string t ds agroup biga fingerprint to string system err println d hgroupa to string t d hgroupa fingerprint to string dsagroupbiga tostring dsagroupbiga fingerprinttostring dhgroupa tostring dhgroupa fingerprinttostring public static dsa group get group int group index if group index group index big a return ds agroup biga return null dsagroup getgroup groupindex groupindex group_index_big_a dsagroupbiga protected i persistent map string term position term pos map public page ipersistentmap termposition termposmap page string uri string comment storage storage this uri uri this comment comment this status status queued this last change system current time millis storage make persistent this lastchange currenttimemillis makepersistent public synchronized void set status status status pre modify this status status post modify setstatus premodify postmodify public status get status return status getstatus public synchronized void set comment string comment pre modify this comment comment post modify setcomment premodify postmodify public string get comment return comment getcomment public string geturi return uri public long get id return id getid public void set page title string page title pre modify this page title page title post modify setpagetitle pagetitle premodify pagetitle pagetitle postmodify public string get page title return page title getpagetitle pagetitle public synchronized term position get term position term term boolean create if term pos map null term pos map get storage create map string class modify term position tp term pos map get term md5 if tp null create tp new term position get storage term pos map put term md5 tp term page set add this return tp termposition gettermposition termposmap termposmap getstorage createmap termposition termposmap termposition getstorage termposmap pageset public synchronized void clear term position term pos map null modify cleartermposition termposmap override public int hash code return int id id 32 hashcode override public boolean equals object obj if this obj return true if obj null return false if get class obj get class return false return id page obj id getclass getclass override public string to string return page id id title page title uri uri status status comment comment tostring pagetitle public int compare to page o return new long id compare to o id compareto compareto private void pre modify storage storage get storage if storage null perst root root perst root storage get root field index page coll root get page index status coll exclusive lock try coll remove this finally coll unlock premodify getstorage perstroot perstroot getroot fieldindex getpageindex exclusivelock private void post modify last change system current time millis modify storage storage get storage if storage null perst root root perst root storage get root field index page coll root get page index status coll exclusive lock try coll put this finally coll unlock postmodify lastchange currenttimemillis getstorage perstroot perstroot getroot fieldindex getpageindex exclusivelock private float m11 1 0f public check filter checkfilter set the foreground color param foreground the color see get foreground public void set foreground int foreground this foreground foreground getforeground setforeground get the foreground color return the color see set foreground public int get foreground return foreground setforeground getforeground set the background color param background the color see get background public void set background int background this background background getbackground setbackground get the background color return the color see set background public int get background return background setbackground getbackground set the x scale of the texture param x scale the scale see getx scale public void setx scale int x scale this x scale x scale xscale getxscale setxscale xscale xscale xscale get the x scale of the texture return the scale see setx scale public int getx scale return x scale setxscale getxscale xscale set the y scale of the texture param y scale the scale see gety scale public void sety scale int y scale this y scale y scale yscale getyscale setyscale yscale yscale yscale get the y scale of the texture return the scale see sety scale public int gety scale return y scale setyscale getyscale yscale set the fuzziness of the texture param fuzziness the fuzziness see get fuzziness public void set fuzziness int fuzziness this fuzziness fuzziness getfuzziness setfuzziness get the fuzziness of the texture return the fuzziness see set fuzziness public int get fuzziness return fuzziness setfuzziness getfuzziness set the angle of the texture param angle the angle of the texture angle see get angle public void set angle float angle this angle angle float cos float math cos angle float sin float math sin angle m00 cos m01 sin m10 sin m11 cos getangle setangle get the angle of the texture return the angle of the texture see set angle public float get angle return angle setangle getangle override public int filterrgb int x int y int rgb float nx m00 x m01 y x scale float ny m10 x m11 y y scale float f int nx 100000 2 int ny 100000 2 1 0f 0 0f if fuzziness 0 float fuzz fuzziness 100 0f float fx image math smooth pulse 0 fuzz 1 fuzz 1 image math mod nx 1 float fy image math smooth pulse 0 fuzz 1 fuzz 1 image math mod ny 1 f fx fy return image math mix colors f foreground background xscale yscale imagemath smoothpulse imagemath imagemath smoothpulse imagemath imagemath mixcolors override public string to string return texture checkerboard tostring class compression output public compression output bucket best compressed data compressor type best codec2 this data best compressed data this best codec best codec2 compressionoutput compressionoutput bestcompresseddata compressor_type bestcodec2 bestcompresseddata bestcodec bestcodec2 public static string encode string s string builder output new string builder s length 2 for int i 0 i s length i char c s char at i if allowed chars index of c 0 output append c else string tmp c try byte utf tmp get bytes utf 8 for int j 0 j utf length j int x utf j 0xff output append if x 16 output append 0 output append integer to hex string x catch unsupported encoding exception e throw new error impossible jvm doesn t support utf 8 e e return output to string stringbuilder stringbuilder charat allowedchars indexof getbytes tohexstring unsupportedencodingexception tostring create a new uri from a string which may contain characters which should have been encoded throws uri syntax exception if the string does not represent a valid uri even after encoding public static uri encodeuri string s throws uri syntax exception return new uri encode s urisyntaxexception urisyntaxexception private static final long serial versionuid 1 public persistence parse exception string string super string serialversionuid persistenceparseexception public persistence parse exception string string exception reason super string reason persistenceparseexception public class jsql no such field exception extends jsql runtime exception constructor of exception param target class of the target object in which field was not found param field name name of the locate field public jsql no such field exception class target string field name super dynamic lookup failed for field target field name jsqlnosuchfieldexception jsqlruntimeexception fieldname jsqlnosuchfieldexception fieldname fieldname public client hello message simple field set fs throws message invalid exception client name fs get name client expected version fs get expected version if client name null throw new message invalid exception protocol error message missing field client hello must contain a name field null false if client expected version null throw new message invalid exception protocol error message missing field client hello must contain a expected version field null false fixme check the expected version clienthellomessage simplefieldset messageinvalidexception clientname clientexpectedversion expectedversion clientname messageinvalidexception protocolerrormessage missing_field clienthello clientexpectedversion messageinvalidexception protocolerrormessage missing_field clienthello expectedversion override public simple field set get field set simple field set sfs new simple field set true sfs put single name client name sfs put single expected version client expected version return sfs simplefieldset getfieldset simplefieldset simplefieldset putsingle clientname putsingle expectedversion clientexpectedversion override public string get name return name getname override public void run fcp connection handler handler node node we know the hello is valid fcp message msg new node hello message node handler connection identifier handler output handler queue msg handler set client name client name fcpconnectionhandler fcpmessage nodehellomessage connectionidentifier outputhandler setclientname clientname override public void remove from object container container container delete this removefrom objectcontainer override protected void set up throws exception super set up identity new identity uri test true identity add context bleh m wot store and commit identity setup setup addcontext mwot storeandcommit public void test identity stored object set identity result m wot get all identities assert equals 1 result size assert equals identity result next testidentitystored objectset mwot getallidentities assertequals assertequals public void test get byuri throws malformedurl exception unknown identity exception assert equals identity m wot get identity byuri uri testgetbyuri malformedurlexception unknownidentityexception assertequals mwot getidentitybyuri public void test contexts throws invalid parameter exception assert false identity has context foo identity add context test assert true identity has context test identity remove context test assert false identity has context test todo obtain the identity from the db between each line testcontexts invalidparameterexception assertfalse hascontext addcontext asserttrue hascontext removecontext assertfalse hascontext public void test properties throws invalid parameter exception identity set property foo bar assert equals bar identity get property foo identity remove property foo try identity get property foo fail catch invalid parameter exception e testproperties invalidparameterexception setproperty assertequals getproperty removeproperty getproperty invalidparameterexception public void test persistence throws malformedurl exception unknown identity exception m wot terminate m wot null system gc system run finalization m wot new wot get database filename assert equals 1 m wot get all identities size identity stored m wot get identity byuri uri assert equals identity getid stored getid assert equals identity get requesturi stored get requesturi assert equals identity get edition stored get edition assert equals identity get nickname stored get nickname assert equals identity get added date stored get added date assert equals identity get last change date stored get last change date fixme check contexts properties testpersistence malformedurlexception unknownidentityexception mwot mwot runfinalization mwot getdatabasefilename assertequals mwot getallidentities mwot getidentitybyuri assertequals assertequals getrequesturi getrequesturi assertequals getedition getedition assertequals getnickname getnickname assertequals getaddeddate getaddeddate assertequals getlastchangedate getlastchangedate logger register log threshold callback new log threshold callback override public void should update logdebug logger should log logger debug this registerlogthresholdcallback logthresholdcallback shouldupdate shouldlog public static final string get message int reason switch reason case decode failed return decode of data failed probably was bogus at source case data not found in store return data was not in store and request was local only case internal error return internal error probably a bug case data not found return could not find the data case route not found return could not find enough nodes to be sure that the data is not out there somewhere case rejected overload return a node downstream either timed out or was overloaded retry case transfer failed return started to transfer data then failed should be rare case verify failed return node sent us invalid data case cancelled return request cancelled case recently failed return request killed by failure table due to recently dn fing on a downstream node default return unknown error code reason getmessage decode_failed data_not_found_in_store internal_error data_not_found route_not_found rejected_overload transfer_failed verify_failed recently_failed dnfing public final int code public low level get exception int code string message throwable t super message t this code code lowlevelgetexception public low level get exception int reason super get message reason this code reason lowlevelgetexception getmessage override public string to string return super to string get message code tostring tostring getmessage override public final synchronized throwable fill in stack trace if logdebug code internal error code decode failed code verify failed return super fill in stack trace return null fillinstacktrace internal_error decode_failed verify_failed fillinstacktrace get a list of fields which the database should create an index on protected static string get indexed fields return new string m truster m trustee getindexedfields mtruster mtrustee creates a trust from given parameters only for being used by the wot package and unit tests not for user interfaces param truster identity that gives the trust param trustee identity that receives the trust param value numeric value of the trust param comment a comment to explain the numeric trust value throws invalid parameter exception if the trust value is not between 100 and 100 public trust identity truster identity trustee byte value string comment throws invalid parameter exception if truster null throw new null pointer exception if trustee null throw new null pointer exception m truster truster m trustee trustee set value value set comment comment m truster trust list edition truster get edition invalidparameterexception invalidparameterexception nullpointerexception nullpointerexception mtruster mtrustee setvalue setcomment mtrustertrustlistedition getedition override public synchronized string to string return get truster get nickname trusts get trustee get nickname get value get comment tostring gettruster getnickname gettrustee getnickname getvalue getcomment return the identity that gives this trust public identity get truster return m truster gettruster mtruster return trustee the identity that receives this trust public identity get trustee return m trustee gettrustee mtrustee return value numeric value of this trust relationship public synchronized byte get value return m value getvalue mvalue param m value numeric value of this trust relationship 100 100 throws invalid parameter exception if value isn t in the range protected synchronized void set value byte new value throws invalid parameter exception if new value 100 new value 100 throw new invalid parameter exception invalid trust value m value m value new value mvalue invalidparameterexception setvalue newvalue invalidparameterexception newvalue newvalue invalidparameterexception mvalue mvalue newvalue return the comment associated to this trust relationship public synchronized string get comment return m comment getcomment mcomment param new comment comment on this trust relationship protected synchronized void set comment string new comment throws invalid parameter exception assert new comment null if new comment null new comment length 256 throw new invalid parameter exception comment is too long maximum is 256 characters m comment new comment null new comment newcomment setcomment newcomment invalidparameterexception newcomment newcomment newcomment invalidparameterexception mcomment newcomment newcomment protected synchronized void truster edition updated m truster trust list edition m truster get edition trustereditionupdated mtrustertrustlistedition mtruster getedition private boolean ismetadata public very simple get client key key2 int max retries2 fetch context ctx2 client requester parent2 super key2 max retries2 ctx2 parent2 true verysimpleget clientkey maxretries2 fetchcontext clientrequester maxretries2 override public void on failure low level get exception e object token object container container client context context boolean logminor logger should log logger minor this if logminor logger minor this on failure e e if is fatal error e code if retry container context if logminor logger minor this retrying new error debug return error e finished true synchronized waiter waiter notify all onfailure lowlevelgetexception objectcontainer clientcontext shouldlog onfailure isfatalerror notifyall override public void on success client key block block boolean from store object token object container container client context context data extract block context ismetadata block is metadata if data null return failed finished true synchronized waiter waiter notify all onsuccess clientkeyblock fromstore objectcontainer clientcontext ismetadata notifyall public bucket wait for completion throws low level get exception while finished try synchronized waiter waiter wait catch interrupted exception e ignore if error null throw error return data waitforcompletion lowlevelgetexception interruptedexception private bucket extract client key block block client context context bucket tempdata try todo this make max size a parameter 4mb hardcoded for now todo key explorer ask warn the user before displaying browser bombs fixme what is the maximum size of an decompressed 32k chunk hah 2gb is the max insertsize for a compressed single chunk its a memory browser bomb the hexdump can be 4x in size 8gb a few k for surrounding html tempdata block decode context temp bucket factory 4 1024 1024 false catch key decode exception e1 if logger should log logger minor this logger minor this decode failure e1 e1 on failure new low level get exception low level get exception decode failed null null context return null catch too big exception e logger error this should never happens e e on failure new low level get exception low level get exception internal error null null context return null catch io exception e logger error this could not capture data disk full e e on failure new low level get exception low level get exception decode failed null null context return null return tempdata clientkeyblock clientcontext keyexplorer tempbucketfactory keydecodeexception shouldlog onfailure lowlevelgetexception lowlevelgetexception decode_failed toobigexception onfailure lowlevelgetexception lowlevelgetexception internal_error ioexception onfailure lowlevelgetexception lowlevelgetexception decode_failed public boolean is metadata return ismetadata ismetadata public static boolean is fatal error int mode switch mode low level errors can be retried case low level get exception data not found case low level get exception route not found case low level get exception rejected overload case low level get exception transfer failed case low level get exception recently failed wait a bit but fine return false case low level get exception internal error maybe fatal return false wierd ones case low level get exception cancelled return true default logger error very simple get class do not know if error code mode is fatal low level get exception get message mode return false assume it isn t isfatalerror lowlevelgetexception data_not_found lowlevelgetexception route_not_found lowlevelgetexception rejected_overload lowlevelgetexception transfer_failed lowlevelgetexception recently_failed lowlevelgetexception internal_error lowlevelgetexception verysimpleget lowlevelgetexception getmessage public void on failed key listener construction exception e object container container client context context logger error this todo e e onfailed keylistenerconstructionexception objectcontainer clientcontext public final class screen composite extends rgb composite public screen composite float alpha super alpha screencomposite rgbcomposite screencomposite public composite context create context color model src color model color model dst color model rendering hints hints return new context extra alpha src color model dst color model compositecontext createcontext colormodel srccolormodel colormodel dstcolormodel renderinghints extraalpha srccolormodel dstcolormodel static class context extends rgb composite context public context float alpha color model src color model color model dst color model super alpha src color model dst color model rgbcompositecontext colormodel srccolormodel colormodel dstcolormodel srccolormodel dstcolormodel override public void composergb int src int dst float alpha int w src length for int i 0 i w i 4 int sr src i int dir dst i int sg src i 1 int dig dst i 1 int sb src i 2 int dib dst i 2 int sa src i 3 int dia dst i 3 int dor dog dob int t 255 dir 255 sr 0x80 dor 255 t 8 t 8 t 255 dig 255 sg 0x80 dog 255 t 8 t 8 t 255 dib 255 sb 0x80 dob 255 t 8 t 8 float a alpha sa 255f float ac 1 a dst i int a dor ac dir dst i 1 int a dog ac dig dst i 2 int a dob ac dib dst i 3 int sa alpha dia ac public class log threshold callback public log threshold callback logthresholdcallback logthresholdcallback public void should update shouldupdate public void schedule object container container client context context throws insert exception caller calls schedule schedule calls schedule fetcher schedule fetcher creates a fetcher set up to tell us about author errors as well as valid inserts and starts it when this completes on found edition calls schedule insert schedule insert starts a single block inserter if that succeeds we complete if that fails we increment our index and try again in the callback if that continues to fail 5 times we go back to schedule fetcher schedule fetcher container context objectcontainer clientcontext insertexception schedulefetcher schedulefetcher onfoundedition scheduleinsert scheduleinsert singleblockinserter schedulefetcher schedulefetcher schedule a fetcher to find us the latest inserted key of the usk the fetcher must be insert mode in other words it must know that we want the latest edition including author errors and so on private void schedule fetcher object container container client context context if persistent container activate pubusk 5 synchronized this if logger should log logger minor this logger minor this scheduling fetcher for pubusk geturi if finished return fetcher context usk manager get fetcher for insert dont schedule persistent pubusk clone pubusk parent priority class this parent get client container context persistent if logger should log logger minor this logger minor this scheduled fetcher if persistent container store fetcher container store this fetcher schedule container context schedulefetcher objectcontainer clientcontext shouldlog uskmanager getfetcherforinsertdontschedule priorityclass getclient shouldlog public void on found edition long l usk key object container container client context context boolean last content was metadata short codec byte his data boolean new known good boolean new slot too boolean already inserted false synchronized this edition math max l edition consecutive collisions 0 if last content was metadata is metadata his data null codec compression codec try if persistent container activate data 1 byte my data bucket tools to byte array data if arrays equals my data his data success already inserted true finished true sbi null catch io exception e logger error this could not decode e e if persistent container activate fetcher 1 container activate fetcher ctx 1 fetcher remove from container context fetcher ctx remove from container fetcher null container store this if already inserted if persistent container activate parent 1 success parent add must succeed blocks 1 container parent completed block true container context if persistent container activate cb 1 container activate pubusk 5 cb on encode pubusk copy edition this container context cb on success this container context if free data data free if persistent data remove from container else schedule insert container context onfoundedition objectcontainer clientcontext lastcontentwasmetadata hisdata newknowngood newslottoo alreadyinserted consecutivecollisions lastcontentwasmetadata ismetadata hisdata compressioncodec mydata buckettools tobytearray mydata hisdata alreadyinserted ioexception removefrom removefrom alreadyinserted addmustsucceedblocks completedblock onencode onsuccess freedata removefrom scheduleinsert private void schedule insert object container container client context context long ed no math max edition context usk manager lookup latest slot pubusk 1 if persistent container activate privusk 5 container activate pubusk 5 synchronized this if finished return edition ed no if logger should log logger minor this logger minor this scheduling insert for pubusk geturi edition sbi new single block inserter parent data compression codec privusk get insertablessk edition get inserturi ctx this is metadata source length token getchk only false true we don t use it token object container context persistent false try sbi schedule container context if persistent container store this catch insert exception e synchronized this finished true if free data if persistent container activate data 1 data free data remove from container synchronized this data null if persistent container store this cb on failure e this container context scheduleinsert objectcontainer clientcontext edno uskmanager lookuplatestslot edno shouldlog singleblockinserter compressioncodec getinsertablessk getinserturi ismetadata sourcelength getchkonly tokenobject insertexception freedata removefrom onfailure public synchronized void on success client put state state object container container client context context if persistent container activate pubusk 5 usk new edition pubusk copy edition finished true sbi null freeneturi targeturi pubusk getssk edition geturi freeneturi realuri single block inserter state geturi container context if targeturi equals realuri logger error this uri should be targeturi actually is realuri else if logger should log logger minor this logger minor this uri should be targeturi actually is realuri context usk manager update known good pubusk edition context if persistent state remove from container context if free data if persistent container activate data 1 data free if persistent data remove from container synchronized this data null if persistent container store this if persistent container activate cb 1 container store this cb on encode new edition this container context cb on success this container context finished yay onsuccess clientputstate objectcontainer clientcontext newedition singleblockinserter shouldlog uskmanager updateknowngood removefrom freedata removefrom onencode newedition onsuccess public void on failure insert exception e client put state state object container container client context context client put state oldsbi synchronized this oldsbi sbi sbi null if e get mode insert exception collision try the next slot edition consecutive collisions if persistent container store this if consecutive collisions max tried slots schedule fetcher container context else schedule insert container context else if free data if persistent container activate data 1 data free data remove from container synchronized this data null if persistent container store this if persistent container activate cb 1 cb on failure e state container context if state null persistent state remove from container context if oldsbi null oldsbi state container activate oldsbi 1 oldsbi remove from container context onfailure insertexception clientputstate objectcontainer clientcontext clientputstate getmode insertexception consecutivecollisions consecutivecollisions max_tried_slots schedulefetcher scheduleinsert freedata removefrom onfailure removefrom removefrom override public int hash code return hash code hashcode hashcode public usk inserter base client putter parent bucket data short compression codec freeneturi uri insert context ctx put completion callback cb boolean is metadata int source length int token boolean getchk only boolean add to parent object token object object container container client context context boolean free data boolean persistent throws malformedurl exception this hash code super hash code this token object token object this persistent persistent this parent parent this data data this compression codec compression codec this ctx ctx this cb cb this is metadata is metadata this source length source length this token token this getchk only getchk only if add to parent parent add block container parent add must succeed blocks 1 container parent notify clients container context privusk insertableusk create insertable uri persistent pubusk privusk getusk edition pubusk suggested edition this free data free data uskinserter baseclientputter compressioncodec insertcontext putcompletioncallback ismetadata sourcelength getchkonly addtoparent tokenobject objectcontainer clientcontext freedata malformedurlexception hashcode hashcode tokenobject tokenobject compressioncodec compressioncodec ismetadata ismetadata sourcelength sourcelength getchkonly getchkonly addtoparent addblock addmustsucceedblocks notifyclients createinsertable suggestededition freedata freedata public base client putter get parent return parent baseclientputter getparent public void cancel object container container client context context usk fetcher tag tag boolean persist persistent synchronized this if finished return finished true tag fetcher fetcher null if persistent container store this if tag null tag cancel container context if persist container activate this 1 may have been deactivated by callbacks if sbi null sbi cancel container context will call on failure which will remove from if persist container activate this 1 may have been deactivated by callbacks if free data if persistent container activate data 1 data free if persistent data remove from container synchronized this data null if persistent container store this if persistent container activate cb 1 cb on failure new insert exception insert exception cancelled this container context objectcontainer clientcontext uskfetchertag onfailure removefrom freedata removefrom onfailure insertexception insertexception public void on failure object container container client context context logger error this fetcher failed new exception debug schedule insert container context onfailure objectcontainer clientcontext scheduleinsert public synchronized void on cancelled object container container client context context if fetcher null if persistent container activate fetcher 1 container activate fetcher ctx 1 fetcher ctx remove from container fetcher remove from container context fetcher null if finished return logger error this unexpected on cancelled new exception error cancel container context oncancelled objectcontainer clientcontext removefrom removefrom oncancelled public void on encode base client key key client put state state object container container client context context ignore onencode baseclientkey clientputstate objectcontainer clientcontext public void on transition client put state old state client put state new state object container container shouldn t happen logger error this got on transition old state new state ontransition clientputstate oldstate clientputstate newstate objectcontainer ontransition oldstate newstate public void on metadata metadata m client put state state object container container client context context shouldn t happen logger error this got on metadata m state onmetadata clientputstate objectcontainer clientcontext onmetadata public void on block set finished client put state state object container container client context context ignore onblocksetfinished clientputstate objectcontainer clientcontext public object get token return token object gettoken tokenobject public void on fetchable client put state state object container container ignore onfetchable clientputstate objectcontainer public short get polling priority normal return parent get priority class getpollingprioritynormal getpriorityclass public short get polling priority progress return parent get priority class getpollingpriorityprogress getpriorityclass public void remove from object container container client context context if logger should log logger minor this logger minor this removing from database this new exception debug parent will remove self if free data data null container ext is stored data try data free catch throwable t logger error this already freed caught in remove from on this data t t data remove from container ctx is passed in cb will deal with cb will remove self token object will be removed by creator container activate privusk 5 privusk remove from container container activate pubusk 5 pubusk remove from container if fetcher null logger error this fetcher tag still present fetcher in remove from for this new exception debug container activate fetcher 1 container activate fetcher ctx 1 fetcher ctx remove from container fetcher remove from container context if sbi null logger error this sbi still present sbi in remove from for this container activate sbi 1 sbi remove from container context container delete this removefrom objectcontainer clientcontext shouldlog freedata isstored removefrom removefrom tokenobject removefrom removefrom removefrom removefrom removefrom removefrom removefrom public device list devicelist public device get device int n return device get n getdevice png filter boolean delete text boolean delete timestamp boolean checkcr cs this delete text delete text this delete timestamp delete timestamp this checkcr cs checkcr cs pngfilter deletetext deletetimestamp checkcrcs deletetext deletetext deletetimestamp deletetimestamp checkcrcs checkcrcs public bucket read filter bucket data bucket factory bf string charset hash map string string other params filter callback cb throws data filter exception io exception bucket output read filter data bf charset other params cb delete text delete timestamp checkcr cs null if output null return output if logger should log logger minor this logger minor this need to modify png bucket filtered bf make bucket 1 output stream os new buffered output stream filtered get output stream try read filter data bf charset other params cb delete text delete timestamp checkcr cs os os flush os close os null finally closer close os return filtered readfilter bucketfactory hashmap otherparams filtercallback datafilterexception ioexception readfilter otherparams deletetext deletetimestamp checkcrcs shouldlog makebucket outputstream bufferedoutputstream getoutputstream readfilter otherparams deletetext deletetimestamp checkcrcs public bucket read filter bucket data bucket factory bf string charset hash map string string other params filter callback cb boolean delete text boolean delete timestamp boolean checkcr cs output stream output throws data filter exception io exception boolean logminor logger should log logger minor this boolean logdebug logger should log logger debug this input stream is null buffered input stream bis null data input stream dis null try is data get input stream bis new buffered input stream is dis new data input stream bis check the header byte header check new byte png header length dis read fully header check if arrays equals header check png header throw an exception string message l10n invalid header string title l10n invalid header title throw new data filter exception title title p message p new html node p add child message byte array output stream baos null data output stream dos null if output null baos new byte array output stream dos new data output stream baos output write png header if logminor logger minor this writing the png header to the output bucket check the chunks see http www libpng org pub png spec 1 2 png chunks html c summary of standard chunks boolean finished false boolean has seenihdr false boolean has seeniend false boolean has seenidat false string last chunk type while finished boolean skip false if baos null baos reset string chunk type string null length of the chunk byte length bytes new byte 4 dis read fully length bytes int length length bytes 0 0xff 24 length bytes 1 0xff 16 length bytes 2 0xff 8 length bytes 3 0xff if logminor logger minor this length length if dos null dos write length bytes type of the chunk should match a za z 4 dis read fully length bytes string builder sb new string builder byte chunk type bytes new byte 4 for int i 0 i 4 i char val char length bytes i if val 65 val 99 val 97 val 122 chunk type bytes i length bytes i sb append val else string chunk name hex util bytes to hex length bytes 0 4 throw error unknown chunk the name of the chunk is invalid chunk name chunk type string sb to string if logminor logger minor this name chunk type string content of the chunk byte chunk data new byte length dis read fully chunk data 0 length if logminor if logdebug logger minor this data chunk data length 0 null hex util bytes to hex chunk data else logger minor this data chunk data length if dos null dos write chunk type bytes if dos null dos write chunk data crc of the chunk byte crc length bytes new byte 4 dis read fully crc length bytes if dos null dos write crc length bytes if checkcr cs long readcrc crc length bytes 0 0xff 24 crc length bytes 1 0xff 16 crc length bytes 2 0xff 8 crc length bytes 3 0xff 0x00000000ffffffffl crc32 crc new crc32 crc update chunk type bytes crc update chunk data long computedcrc crc get value if readcrc computedcrc skip true if logminor logger minor this crc of the chunk chunk type string doesn t match long to hex string readcrc but should be long to hex string computedcrc boolean valid chunk type false if skip ihdr equals chunk type string if has seenihdr throw error duplicate ihdr two ihdr chunks detected has seenihdr true valid chunk type true if has seenihdr throw error no ihdr chunk no ihdr chunk if skip iend equals chunk type string if has seeniend xxx impossible code path it should have throwed as iend not last chunk throw error two iend chunks detected two iend chunks detected has seeniend true valid chunk type true if skip plte equals ignore case chunk type string if has seenidat throw error plte must be before idat plte must be before idat valid chunk type true if skip idat equals ignore case chunk type string if has seenidat idat equals ignore case last chunk type throw error multiple idat chunks must be consecutive multiple idat chunks must be consecutive has seenidat true valid chunk type true if valid chunk type for int i 0 i harmless chunk types length i if harmless chunk types i equals chunk type string valid chunk type true if dis available 1 if has seeniend has seenihdr throw error missing iend or ihdr missing iend or ihdr finished true if text equals ignore case chunk type string itxt equals ignore case chunk type string ztxt equals ignore case chunk type string if delete text skip true else valid chunk type true else if delete timestamp time equals ignore case chunk type string if delete timestamp skip true else valid chunk type true if valid chunk type if logminor logger minor this skipping unknown chunk type chunk type string if output null return null skip true if skip output null return null else if skip output null if logminor logger minor this writing chunk type string baos size to the output bucket baos write to output baos flush last chunk type chunk type string if has seeniend dis available 0 throw error iend not last chunk iend not last chunk dis close catch array index out of bounds exception e throw error array index out of bounds exception while filtering array index out of bounds exception while filtering catch negative array size exception e throw error negative array size exception while filtering negative array size exception while filtering catch eof exception e throw error eof exception while filtering eof exception while filtering finally closer close dis closer close bis closer close is return data readfilter bucketfactory hashmap otherparams filtercallback deletetext deletetimestamp checkcrcs outputstream datafilterexception ioexception shouldlog shouldlog inputstream bufferedinputstream datainputstream getinputstream bufferedinputstream datainputstream headercheck pngheader readfully headercheck headercheck pngheader invalidheader invalidheadertitle datafilterexception htmlnode addchild bytearrayoutputstream dataoutputstream bytearrayoutputstream dataoutputstream pngheader hasseenihdr hasseeniend hasseenidat lastchunktype chunktypestring lengthbytes readfully lengthbytes lengthbytes lengthbytes lengthbytes lengthbytes lengthbytes readfully lengthbytes stringbuilder stringbuilder chunktypebytes lengthbytes chunktypebytes lengthbytes chunkname hexutil bytestohex lengthbytes throwerror chunkname chunktypestring tostring chunktypestring chunkdata readfully chunkdata chunkdata hexutil bytestohex chunkdata chunkdata chunktypebytes chunkdata crclengthbytes readfully crclengthbytes crclengthbytes checkcrcs crclengthbytes crclengthbytes crclengthbytes crclengthbytes chunktypebytes chunkdata getvalue chunktypestring tohexstring tohexstring validchunktype chunktypestring hasseenihdr throwerror hasseenihdr validchunktype hasseenihdr throwerror chunktypestring hasseeniend throwerror hasseeniend validchunktype equalsignorecase chunktypestring hasseenidat throwerror validchunktype equalsignorecase chunktypestring hasseenidat equalsignorecase lastchunktype throwerror hasseenidat validchunktype validchunktype harmless_chunk_types harmless_chunk_types chunktypestring validchunktype hasseeniend hasseenihdr throwerror equalsignorecase chunktypestring equalsignorecase chunktypestring equalsignorecase chunktypestring deletetext validchunktype deletetimestamp equalsignorecase chunktypestring deletetimestamp validchunktype validchunktype chunktypestring chunktypestring writeto lastchunktype chunktypestring hasseeniend throwerror arrayindexoutofboundsexception throwerror arrayindexoutofboundsexception arrayindexoutofboundsexception negativearraysizeexception throwerror negativearraysizeexception negativearraysizeexception eofexception throwerror private string l10n string key return l10n get string png filter key getstring pngfilter public bucket write filter bucket data bucket factory bf string charset hash map string string other params filter callback cb throws data filter exception io exception todo auto generated method stub return null writefilter bucketfactory hashmap otherparams filtercallback datafilterexception ioexception public static void main string arg final file fin new file tmp test png final file fout new file tmp test2 png fout delete final bucket data new file bucket fin true false false false false final bucket out new file bucket fout false true false false false try logger setup stdout logging logger minor content filter filter output output content filter filter data new array bucket factory image png new uri http 127 0 0 1 8888 null bucket tools copy output data out catch io exception e system out println bucket error e get message catch uri syntax exception e system out println internal error e get message catch invalid threshold exception e finally data free filebucket filebucket setupstdoutlogging contentfilter filteroutput contentfilter arraybucketfactory buckettools ioexception getmessage urisyntaxexception getmessage invalidthresholdexception private void throw error string short reason string reason throws data filter exception throw an exception string message invalid png if reason null message reason if short reason null message short reason data filter exception e new data filter exception short reason short reason p message p new html node p add child message if logger should log logger normal this logger normal this throwing e e throw e throwerror shortreason datafilterexception shortreason shortreason datafilterexception datafilterexception shortreason shortreason htmlnode addchild shouldlog public add peer simple field set fs this fs fs this identifier fs get identifier fs remove value identifier addpeer simplefieldset removevalue override public simple field set get field set return new simple field set true simplefieldset getfieldset simplefieldset override public string get name return name getname override public void run fcp connection handler handler node node throws message invalid exception if handler has full access throw new message invalid exception protocol error message access denied add peer requires full access identifier false string url string fs get url string file string fs get file string builder ref null buffered reader in if url string null try url url new url url string url connection uc url open connection fixme get charset from uc get content type in new buffered reader new input stream reader uc get input stream ref new string builder 1024 string line while line in read line null line line trim ref append line append n in close catch malformedurl exception e throw new message invalid exception protocol error message url parse error error parsing ref url url string e get message identifier false catch io exception e throw new message invalid exception protocol error message url parse error io error while retrieving ref url url string e get message identifier false ref new string builder ref to string trim if ref null throw new message invalid exception protocol error message ref parse error error parsing ref from url url string identifier false if equals ref to string throw new message invalid exception protocol error message ref parse error error parsing ref from url url string identifier false try fs new simple field set ref to string false true catch io exception e throw new message invalid exception protocol error message ref parse error error parsing ref from url url string e get message identifier false else if file string null file f new file file string if f is file throw new message invalid exception protocol error message not a file error the given ref file path file string is not a file identifier false try in new buffered reader new file reader f ref new string builder 1024 string line while line in read line null line line trim ref append line append n in close catch file not found exception e throw new message invalid exception protocol error message file not found file not found when retrieving ref file file string e get message identifier false catch io exception e throw new message invalid exception protocol error message file parse error io error while retrieving ref file file string e get message identifier false ref new string builder ref to string trim if ref null throw new message invalid exception protocol error message ref parse error error parsing ref from file file string identifier false if equals ref to string throw new message invalid exception protocol error message ref parse error error parsing ref from file file string identifier false try fs new simple field set ref to string false true catch io exception e throw new message invalid exception protocol error message ref parse error error parsing ref from file file string e get message identifier false fs set end marker end peer node pn boolean is opennet ref fields string to bool fs get opennet false if is opennet ref try pn node create new opennet node fs catch fs parse exception e throw new message invalid exception protocol error message ref parse error error parsing ref e get message identifier false catch opennet disabled exception e throw new message invalid exception protocol error message opennet disabled error adding ref e get message identifier false catch peer parse exception e throw new message invalid exception protocol error message ref parse error error parsing ref e get message identifier false catch reference signature verification exception e throw new message invalid exception protocol error message ref signature invalid error adding ref e get message identifier false if arrays equals pn get identity node get opennet identity throw new message invalid exception protocol error message cannot peer with self node cannot peer with itself identifier false if node add peer connection pn throw new message invalid exception protocol error message duplicate peer ref node already has a peer with that identity identifier false system out println added opennet peer pn else try pn node create new darknet node fs catch fs parse exception e throw new message invalid exception protocol error message ref parse error error parsing ref e get message identifier false catch peer parse exception e throw new message invalid exception protocol error message ref parse error error parsing ref e get message identifier false catch reference signature verification exception e throw new message invalid exception protocol error message ref signature invalid error adding ref e get message identifier false if arrays equals pn get identity node get darknet identity throw new message invalid exception protocol error message cannot peer with self node cannot peer with itself identifier false if node add peer connection pn throw new message invalid exception protocol error message duplicate peer ref node already has a peer with that identity identifier false system out println added darknet peer pn handler output handler queue new peer message pn true true identifier fcpconnectionhandler messageinvalidexception hasfullaccess messageinvalidexception protocolerrormessage access_denied addpeer urlstring filestring stringbuilder bufferedreader urlstring urlstring urlconnection openconnection getcontenttype bufferedreader inputstreamreader getinputstream stringbuilder readline malformedurlexception messageinvalidexception protocolerrormessage url_parse_error urlstring getmessage ioexception messageinvalidexception protocolerrormessage url_parse_error urlstring getmessage stringbuilder tostring messageinvalidexception protocolerrormessage ref_parse_error urlstring tostring messageinvalidexception protocolerrormessage ref_parse_error urlstring simplefieldset tostring ioexception messageinvalidexception protocolerrormessage ref_parse_error urlstring getmessage filestring filestring isfile messageinvalidexception protocolerrormessage not_a_file_error filestring bufferedreader filereader stringbuilder readline filenotfoundexception messageinvalidexception protocolerrormessage file_not_found filestring getmessage ioexception messageinvalidexception protocolerrormessage file_parse_error filestring getmessage stringbuilder tostring messageinvalidexception protocolerrormessage ref_parse_error filestring tostring messageinvalidexception protocolerrormessage ref_parse_error filestring simplefieldset tostring ioexception messageinvalidexception protocolerrormessage ref_parse_error filestring getmessage setendmarker peernode isopennetref stringtobool isopennetref createnewopennetnode fsparseexception messageinvalidexception protocolerrormessage ref_parse_error getmessage opennetdisabledexception messageinvalidexception protocolerrormessage opennet_disabled getmessage peerparseexception messageinvalidexception protocolerrormessage ref_parse_error getmessage referencesignatureverificationexception messageinvalidexception protocolerrormessage ref_signature_invalid getmessage getidentity getopennetidentity messageinvalidexception protocolerrormessage cannot_peer_with_self addpeerconnection messageinvalidexception protocolerrormessage duplicate_peer_ref createnewdarknetnode fsparseexception messageinvalidexception protocolerrormessage ref_parse_error getmessage peerparseexception messageinvalidexception protocolerrormessage ref_parse_error getmessage referencesignatureverificationexception messageinvalidexception protocolerrormessage ref_signature_invalid getmessage getidentity getdarknetidentity messageinvalidexception protocolerrormessage cannot_peer_with_self addpeerconnection messageinvalidexception protocolerrormessage duplicate_peer_ref outputhandler peermessage override public void remove from object container container throw new unsupported operation exception removefrom objectcontainer unsupportedoperationexception private float height public pinch filter pinchfilter set the angle of twirl in radians 0 means no distortion param angle the angle of twirl this is the angle by which pixels at the nearest edge of the image will move see get angle public void set angle float angle this angle angle getangle setangle get the angle of twist return the angle in radians see set angle public float get angle return angle setangle getangle set the centre of the effect in the x direction as a proportion of the image size param centrex the center see get centrex public void set centrex float centrex this centrex centrex getcentrex setcentrex get the centre of the effect in the x direction as a proportion of the image size return the center see set centrex public float get centrex return centrex setcentrex getcentrex set the centre of the effect in the y direction as a proportion of the image size param centrey the center see get centrey public void set centrey float centrey this centrey centrey getcentrey setcentrey get the centre of the effect in the y direction as a proportion of the image size return the center see set centrey public float get centrey return centrey setcentrey getcentrey set the centre of the effect as a proportion of the image size param centre the center see get centre public void set centre point2d centre this centrex float centre getx this centrey float centre gety getcentre setcentre get the centre of the effect as a proportion of the image size return the center see set centre public point2d get centre return new point2d float centrex centrey setcentre getcentre set the radius of the effect param radius the radius min value 0 see get radius public void set radius float radius this radius radius getradius setradius get the radius of the effect return the radius see set radius public float get radius return radius setradius getradius set the amount of pinch param amount the amount min value 1 max value 1 see get amount public void set amount float amount this amount amount getamount setamount get the amount of pinch return the amount see set amount public float get amount return amount setamount getamount override public buffered image filter buffered image src buffered image dst width src get width height src get height icentrex width centrex icentrey height centrey if radius 0 radius math min icentrex icentrey radius2 radius radius return super filter src dst bufferedimage bufferedimage bufferedimage getwidth getheight override protected void transform inverse int x int y float out float dx x icentrex float dy y icentrey float distance dx dx dy dy if distance radius2 distance 0 out 0 x out 1 y else float d float math sqrt distance radius2 float t float math pow math sin math pi 0 5 d amount dx t dy t float e 1 d float a angle e e float s float math sin a float c float math cos a out 0 icentrex c dx s dy out 1 icentrey s dx c dy transforminverse override public string to string return distort pinch tostring public address tracker item long time definitely no packets received long time definitely no packets sent time first received packet 1 time first sent packet 1 time last received packet 1 time last sent packet 1 packets sent 0 packets received 0 this time definitely no packets received time definitely no packets received this time definitely no packets sent time definitely no packets sent gap lengths new long track gaps gap length recv times new long track gaps addresstrackeritem timedefinitelynopacketsreceived timedefinitelynopacketssent timefirstreceivedpacket timefirstsentpacket timelastreceivedpacket timelastsentpacket packetssent packetsreceived timedefinitelynopacketsreceived timedefinitelynopacketsreceived timedefinitelynopacketssent timedefinitelynopacketssent gaplengths track_gaps gaplengthrecvtimes track_gaps public address tracker item simple field set fs throws fs parse exception time first received packet fs get long time first received packet time first sent packet fs get long time first sent packet time definitely no packets sent fs get long time definitely no packets sent time definitely no packets received fs get long time definitely no packets received time last received packet fs get long time last received packet time last sent packet fs get long time last sent packet packets sent fs get long packets sent packets received fs get long packets received simple field set gaps fs get subset gaps gap lengths new long track gaps gap length recv times new long track gaps for int i 0 i track gaps i simple field set gap gaps subset integer to string i if gap null logger normal this no more gaps at i i track gaps changed break gap lengths i gap get long length gap length recv times i gap get long received addresstrackeritem simplefieldset fsparseexception timefirstreceivedpacket getlong timefirstreceivedpacket timefirstsentpacket getlong timefirstsentpacket timedefinitelynopacketssent getlong timedefinitelynopacketssent timedefinitelynopacketsreceived getlong timedefinitelynopacketsreceived timelastreceivedpacket getlong timelastreceivedpacket timelastsentpacket getlong timelastsentpacket packetssent getlong packetssent packetsreceived getlong packetsreceived simplefieldset getsubset gaplengths track_gaps gaplengthrecvtimes track_gaps track_gaps simplefieldset tostring track_gaps gaplengths getlong gaplengthrecvtimes getlong public synchronized void sent packet long now packets sent if time first sent packet 0 time first sent packet now time last sent packet now sentpacket packetssent timefirstsentpacket timefirstsentpacket timelastsentpacket public synchronized void received packet long now packets received if time first received packet 0 time first received packet now long old time last received packet time last received packet time last received packet now establish the interval long start time start time time last sent packet start time math max start time time definitely no packets sent if include received packets start time math max start time old time last received packet start time math max start time time definitely no packets received if start time 0 return no information if now start time gap threshold not necessarily a new gap if no packets sent since last one just replace it if time last sent packet gap length recv times 0 rotate gaps array for int i track gaps 1 i 1 i gap lengths i gap lengths i 1 gap length recv times i gap length recv times i 1 else else overwrite 0 gap lengths 0 now start time gap length recv times 0 now receivedpacket packetsreceived timefirstreceivedpacket timefirstreceivedpacket oldtimelastreceivedpacket timelastreceivedpacket timelastreceivedpacket starttime starttime timelastsentpacket starttime starttime timedefinitelynopacketssent include_received_packets starttime starttime oldtimelastreceivedpacket starttime starttime timedefinitelynopacketsreceived starttime starttime gap_threshold timelastsentpacket gaplengthrecvtimes track_gaps gaplengths gaplengths gaplengthrecvtimes gaplengthrecvtimes gaplengths starttime gaplengthrecvtimes public synchronized boolean has long tunnel long horizon return gap length recv times 0 system current time millis horizon haslongtunnel gaplengthrecvtimes currenttimemillis public long longest gap long horizon long now long longest gap 0 for int i 0 i track gaps i if gap length recv times 0 now horizon continue longest gap math max longest gap gap lengths i return longest gap longestgap longestgap track_gaps gaplengthrecvtimes longestgap longestgap gaplengths longestgap public final long gap length public final long received packet at gap long gap length long received packet at this gap length gap length this received packet at received packet at gaplength receivedpacketat gaplength receivedpacketat gaplength gaplength receivedpacketat receivedpacketat public synchronized gap get gaps gap gaps new gap track gaps for int i 0 i track gaps i gaps i new gap gap lengths i gap length recv times i return gaps getgaps track_gaps track_gaps gaplengths gaplengthrecvtimes public synchronized long first received packet return time first received packet firstreceivedpacket timefirstreceivedpacket public synchronized long first sent packet return time first sent packet firstsentpacket timefirstsentpacket public synchronized long last received packet return time last received packet lastreceivedpacket timelastreceivedpacket public synchronized long last sent packet return time last sent packet lastsentpacket timelastsentpacket public synchronized long time definitely no packets sent return time definitely no packets sent timedefinitelynopacketssent timedefinitelynopacketssent public synchronized long time definitely no packets received return time definitely no packets received timedefinitelynopacketsreceived timedefinitelynopacketsreceived public synchronized long packets sent return packets sent packetssent packetssent public synchronized long packets received return packets received packetsreceived packetsreceived public synchronized boolean we sent first if time first received packet 1 return true if time first sent packet 1 return false return time first sent packet time first received packet wesentfirst timefirstreceivedpacket timefirstsentpacket timefirstsentpacket timefirstreceivedpacket public synchronized long time from startup to first sent packet if packets sent 0 return 1 return time first sent packet time definitely no packets sent timefromstartuptofirstsentpacket packetssent timefirstsentpacket timedefinitelynopacketssent public synchronized long time from startup to first received packet if packets received 0 return 1 return time first received packet time definitely no packets received timefromstartuptofirstreceivedpacket packetsreceived timefirstreceivedpacket timedefinitelynopacketsreceived public simple field set to field set simple field set fs new simple field set true fs put time first received packet time first received packet fs put time first sent packet time first sent packet fs put time definitely no packets sent time definitely no packets sent fs put time definitely no packets received time definitely no packets received fs put time last received packet time last received packet fs put time last sent packet time last sent packet fs put packets sent packets sent fs put packets received packets received simple field set gaps new simple field set true for int i 0 i track gaps i simple field set gap new simple field set true gap put length gap lengths i gap put received gap length recv times i gaps put integer to string i gap fs put gaps gaps return fs simplefieldset tofieldset simplefieldset simplefieldset timefirstreceivedpacket timefirstreceivedpacket timefirstsentpacket timefirstsentpacket timedefinitelynopacketssent timedefinitelynopacketssent timedefinitelynopacketsreceived timedefinitelynopacketsreceived timelastreceivedpacket timelastreceivedpacket timelastsentpacket timelastsentpacket packetssent packetssent packetsreceived packetsreceived simplefieldset simplefieldset track_gaps simplefieldset simplefieldset gaplengths gaplengthrecvtimes tostring private int threshold 2 public dilate filter dilatefilter set the threshold the number of neighbouring pixels for dilation to occur param threshold the new threshold see get threshold public void set threshold int threshold this threshold threshold getthreshold setthreshold return the threshold the number of neighbouring pixels for dilation to occur return the current threshold see set threshold public int get threshold return threshold setthreshold getthreshold override protected int filter pixels int width int height int in pixels rectangle transformed space int out pixels new int width height for int i 0 i iterations i int index 0 if i 0 int t in pixels in pixels out pixels out pixels t for int y 0 y height y for int x 0 x width x int pixel in pixels y width x if black function is black pixel int neighbours 0 for int dy 1 dy 1 dy int iy y dy int ioffset if 0 iy iy height ioffset iy width for int dx 1 dx 1 dx int ix x dx if dy 0 dx 0 0 ix ix width int rgb in pixels ioffset ix if black function is black rgb neighbours if neighbours threshold if colormap null pixel colormap get color float i iterations else pixel new color out pixels index pixel return out pixels filterpixels inpixels transformedspace outpixels inpixels inpixels outpixels outpixels inpixels blackfunction isblack inpixels blackfunction isblack getcolor newcolor outpixels outpixels override public string to string return binary dilate tostring public httpmu socket httpmusocket public httpmu socket string addr int port string bind addr open addr port bind addr httpmusocket bindaddr bindaddr protected void finalize close public string get local address inet address mcast addr ssdp multi group get address enumeration addrs ssdp multi if get inet addresses while addrs has more elements inet address addr inet address addrs next element if mcast addr instanceof inet6 address addr instanceof inet6 address return addr get host address if mcast addr instanceof inet4 address addr instanceof inet4 address return addr get host address return getlocaladdress inetaddress mcastaddr ssdpmultigroup getaddress ssdpmultiif getinetaddresses hasmoreelements inetaddress inetaddress nextelement mcastaddr inet6address inet6address gethostaddress mcastaddr inet4address inet4address gethostaddress public inet address get multicast inet address return ssdp multi group get address inetaddress getmulticastinetaddress ssdpmultigroup getaddress public string get multicast address return get multicast inet address get host address getmulticastaddress getmulticastinetaddress gethostaddress public boolean open string addr int port string bind addr try ssdp multi sock new multicast socket null ssdp multi sock set reuse address true inet socket address bind sock addr new inet socket address port ssdp multi sock bind bind sock addr ssdp multi group new inet socket address inet address get by name addr port ssdp multi if network interface get by inet address inet address get by name bind addr ssdp multi sock join group ssdp multi group ssdp multi if catch exception e debug warning e return false return true bindaddr ssdpmultisock multicastsocket ssdpmultisock setreuseaddress inetsocketaddress bindsockaddr inetsocketaddress ssdpmultisock bindsockaddr ssdpmultigroup inetsocketaddress inetaddress getbyname ssdpmultiif networkinterface getbyinetaddress inetaddress getbyname bindaddr ssdpmultisock joingroup ssdpmultigroup ssdpmultiif public boolean close if ssdp multi sock null return true try ssdp multi sock leave group ssdp multi group ssdp multi if ssdp multi sock null catch exception e debug warning e return false return true ssdpmultisock ssdpmultisock leavegroup ssdpmultigroup ssdpmultiif ssdpmultisock public boolean send string msg string bind addr int bind port try multicast socket msock if bind addr null 0 bind port msock new multicast socket null msock bind new inet socket address bind addr bind port else msock new multicast socket datagram packet dgm packet new datagram packet msg get bytes msg length ssdp multi group thnaks for tho beisch 11 09 04 msock set time to live 4 msock send dgm packet msock close catch exception e debug warning e return false return true bindaddr bindport multicastsocket bindaddr bindport multicastsocket inetsocketaddress bindaddr bindport multicastsocket datagrampacket dgmpacket datagrampacket getbytes ssdpmultigroup settimetolive dgmpacket public boolean send string msg return send msg null 1 public boolean post http request req string bind addr int bind port return send req to string bind addr bind port httprequest bindaddr bindport tostring bindaddr bindport public boolean post http request req return send req to string null 1 httprequest tostring public ssdp packet receive byte ssdv recv buf new byte ssdp recv message bufsize ssdp packet recv packet new ssdp packet ssdv recv buf ssdv recv buf length recv packet set local address get local address try ssdp multi sock receive recv packet get datagram packet recv packet set time stamp system current time millis catch exception e debug warning e return recv packet ssdppacket ssdvrecvbuf recv_message_bufsize ssdppacket recvpacket ssdppacket ssdvrecvbuf ssdvrecvbuf recvpacket setlocaladdress getlocaladdress ssdpmultisock recvpacket getdatagrampacket recvpacket settimestamp currenttimemillis recvpacket public final static boolean is root device string usn value if usn value null return false return usn value ends with rootdevice isrootdevice usnvalue usnvalue usnvalue endswith public final static string getudn string usn value if usn value null return int idx usn value index of if idx 0 return usn value trim string udn value new string usn value get bytes 0 idx return udn value trim usnvalue usnvalue usnvalue indexof usnvalue udnvalue usnvalue getbytes udnvalue public static void main string args throws invalid threshold exception io exception node init exception interrupted exception node node null node second node null try string ip override null if args length 0 ip override args 0 file dir new file bootstrap push pull test file util remove all dir random source random node starter global test init dir get path false logger error false file seednodes new file seednodes fref if seednodes exists seednodes length 0 seednodes can read system err println unable to read seednodes fref it doesn t exist or is empty system exit exit no seednodes file inner dir new file dir 5000 inner dir mkdir file input stream fis new file input stream seednodes file util write to fis new file inner dir seednodes fref fis close create one node executor executor new pooled executor node node starter create test node 5000 5001 dir get path true false false node default max htl 0 random executor 1000 5 1024 1024 true true true true true true true 12 1024 false true ip override node crypto disable group strip true logger setup stdout logging logger minor freenet normal freenet node node dispatcher minor freenet node fnp packet mangler minor logger get chain set threshold logger error kill logging start it node start true wait for ten nodes node system out println creating test data test size bytes bucket data node client core temp bucket factory make bucket test size output stream os data get output stream byte buf new byte 4096 for long written 0 written test size node fast weak random next bytes buf int to write int math min test size written buf length os write buf 0 to write written to write os close system out println inserting test data high level simple client client node client core make client short 0 insert block block new insert block data new client metadata freeneturi empty chk uri long start insert time system current time millis freeneturi uri try uri client insert block false null catch insert exception e system err println insert failed e e print stack trace system exit exit insert failed return long end insert time system current time millis system out println result insert took end insert time start insert time ms time util format time end insert time start insert time to uri node park bootstrap a second node file second inner dir new file dir 5002 second inner dir mkdir fis new file input stream seednodes file util write to fis new file second inner dir seednodes fref fis close executor new pooled executor second node node starter create test node 5002 5003 dir get path true false false node default max htl 0 random executor 1000 5 1024 1024 true true true true true true true 12 1024 false true ip override second node start true wait for ten nodes second node fetch the data long start fetch time system current time millis client second node client core make client short 0 try client fetch uri catch fetch exception e system err println fetch failed e e print stack trace system exit exit fetch failed return long end fetch time system current time millis system out println result fetch took end fetch time start fetch time ms time util format time end fetch time start fetch time of uri second node park system exit 0 catch throwable t system err println caught t t print stack trace try if node null node park catch throwable t1 try if second node null second node park catch throwable t1 system exit exit threw something invalidthresholdexception ioexception nodeinitexception interruptedexception secondnode ipoverride ipoverride fileutil removeall randomsource nodestarter globaltestinit getpath canread exit_no_seednodes innerdir innerdir fileinputstream fileinputstream fileutil writeto innerdir pooledexecutor nodestarter createtestnode getpath default_max_htl ipoverride nodecrypto disable_group_strip setupstdoutlogging nodedispatcher fnppacketmangler getchain setthreshold waitfortennodes test_size clientcore tempbucketfactory makebucket test_size outputstream getoutputstream test_size fastweakrandom nextbytes towrite test_size towrite towrite highlevelsimpleclient clientcore makeclient insertblock insertblock clientmetadata empty_chk_uri startinserttime currenttimemillis insertexception printstacktrace exit_insert_failed endinserttime currenttimemillis endinserttime startinserttime timeutil formattime endinserttime startinserttime secondinnerdir secondinnerdir fileinputstream fileutil writeto secondinnerdir pooledexecutor secondnode nodestarter createtestnode getpath default_max_htl ipoverride secondnode waitfortennodes secondnode startfetchtime currenttimemillis secondnode clientcore makeclient fetchexception printstacktrace exit_fetch_failed endfetchtime currenttimemillis endfetchtime startfetchtime timeutil formattime endfetchtime startfetchtime secondnode printstacktrace secondnode secondnode exit_threw_something private static void wait for ten nodes node node throws interrupted exception long start time system current time millis wait until we have 10 connected nodes int seconds 0 boolean success false while seconds 600 thread sleep 1000 int seeds node peers count seednodes int seed conns node peers get connected seed server peers vector null size int opennet peers node peers count valid peers int opennet conns node peers count connected opennet peers system err println seconds seeds seeds connected seed conns opennet peers opennet peers connected opennet conns seconds if opennet conns target peers long time taken system current time millis start time system out println result completed bootstrap target peers peers in time taken ms time util format time time taken success true break if success system err println failed to reach target peers count target peers in 10 minutes node park system exit exit failed target waitfortennodes interruptedexception starttime currenttimemillis countseednodes seedconns getconnectedseedserverpeersvector opennetpeers countvalidpeers opennetconns countconnectedopennetpeers seedconns opennetpeers opennetconns opennetconns target_peers timetaken currenttimemillis starttime target_peers timetaken timeutil formattime timetaken target_peers exit_failed_target protected n2ntm toadlet node n node client core core high level simple client client super client this node n this core core n2ntmtoadlet nodeclientcore highlevelsimpleclient override public string supported methods return get post supportedmethods override public void handle get uri uri http request request toadlet context ctx throws toadlet context closed exception io exception redirect exception if ctx is allowed full access super send error page ctx 403 unauthorized l10n get string toadlet unauthorized return if request is parameter set peernode hashcode html node page node ctx get page maker get page node l10n send message ctx html node content node ctx get page maker get content node page node string peernode name null string input hashcode string request get param peernode hashcode int input hashcode 1 try input hashcode integer value of input hashcode string int value catch number format exception e ignore here handle below if input hashcode 1 darknet peer node peer nodes node get darknet connections for int i 0 i peer nodes length i int peer hashcode peer nodes i hash code if peer hashcode input hashcode peernode name peer nodes i get name break if peernode name null content node add child create peer infobox infobox error l10n peer not found title l10n peer not found with hash hash input hashcode string this writehtml reply ctx 200 ok page node generate return hash map string string peers new hash map string string peers put input hashcode string peernode name createn2ntm send form page node content node ctx peers this writehtml reply ctx 200 ok page node generate return multi value table string string headers new multi value table string string headers put location friends ctx send reply headers 302 found headers null 0 handleget httprequest toadletcontext toadletcontextclosedexception ioexception redirectexception isallowedfullaccess senderrorpage getstring isparameterset peernode_hashcode htmlnode pagenode getpagemaker getpagenode sendmessage htmlnode contentnode getpagemaker getcontentnode pagenode peernode_name input_hashcode_string getparam peernode_hashcode input_hashcode input_hashcode valueof input_hashcode_string intvalue numberformatexception input_hashcode darknetpeernode peernodes getdarknetconnections peernodes peer_hashcode peernodes hashcode peer_hashcode input_hashcode peernode_name peernodes getname peernode_name contentnode addchild createpeerinfobox peernotfoundtitle peernotfoundwithhash input_hashcode_string writehtmlreply pagenode hashmap hashmap input_hashcode_string peernode_name createn2ntmsendform pagenode contentnode writehtmlreply pagenode multivaluetable multivaluetable sendreplyheaders private string l10n string key string pattern string value return l10n get string n2ntm toadlet key new string pattern new string value getstring n2ntmtoadlet private static string l10n string key return l10n get string n2ntm toadlet key getstring n2ntmtoadlet private static html node create peer infobox string infobox type string header string message html node infobox new html node div class infobox infobox type infobox add child div class infobox header header html node infobox content infobox add child div class infobox content infobox content add child message html node list infobox content add child ul toadlet add homepage link list list add child li add child a new string href title new string friends l10n return to friends l10n friends return infobox htmlnode createpeerinfobox infoboxtype htmlnode htmlnode infoboxtype addchild htmlnode infoboxcontent addchild infoboxcontent addchild htmlnode infoboxcontent addchild addhomepagelink addchild addchild returntofriends override public void handle post uri uri http request request toadlet context ctx throws toadlet context closed exception io exception redirect exception string pass request get part as string form password 32 if pass null pass equals core form password multi value table string string headers new multi value table string string headers put location send n2ntm ctx send reply headers 302 found headers null 0 return if ctx is allowed full access super send error page ctx 403 unauthorized l10n get string toadlet unauthorized return if request is part set send string message request get part as string message 5 1024 message message trim if message length 1024 this write text reply ctx 400 bad request l10n too long return html node page node ctx get page maker get page node l10n processing send ctx html node content node ctx get page maker get content node page node html node peer table infobox content node add child div class infobox infobox normal darknet peer node peer nodes node get darknet connections string fnam request get part as string filename 1024 file filename null if fnam null fnam length 0 filename new file fnam if filename exists filename can read peer table infobox add child l10n no such file or cannot read toadlet add homepage link peer table infobox this writehtml reply ctx 400 ok page node generate return html node peer table peer table infobox add child table class n2ntm send statuses html node peer table header row peer table add child tr peer table header row add child th l10n peer name peer table header row add child th l10n send status for int i 0 i peer nodes length i if request is part set node peer nodes i hash code darknet peer node pn peer nodes i int status if filename null try status pn send file offer filename message catch io exception e peer table infobox add child l10n no such file or cannot read toadlet add homepage link peer table infobox this writehtml reply ctx 200 ok page node generate return else status pn send text message message string send status short string send status long string send status class if status peer manager peer node status routing backed off send status short l10n delayed title send status long l10n delayed send status class n2ntm send delayed logger normal this sent n2ntm to pn get name message else if status peer manager peer node status connected send status short l10n sent title send status long l10n sent send status class n2ntm send sent logger normal this sent n2ntm to pn get name message else send status short l10n queued title send status long l10n queued send status class n2ntm send queued logger normal this queued n2ntm to pn get name message html node peer row peer table add child tr peer row add child td class peer name add child pn get name peer row add child td class send status class add child span new string title style new string send status long border bottom 1px dotted cursor help send status short html node infobox content peer table infobox add child div class n2ntm message text infobox content add child message html node list peer table infobox add child ul toadlet add homepage link list list add child li add child a new string href title new string friends l10n return to friends l10n friends this writehtml reply ctx 200 ok page node generate return multi value table string string headers new multi value table string string headers put location friends ctx send reply headers 302 found headers null 0 handlepost httprequest toadletcontext toadletcontextclosedexception ioexception redirectexception getpartasstring formpassword formpassword multivaluetable multivaluetable send_n2ntm sendreplyheaders isallowedfullaccess senderrorpage getstring ispartset getpartasstring writetextreply toolong htmlnode pagenode getpagemaker getpagenode processingsend htmlnode contentnode getpagemaker getcontentnode pagenode htmlnode peertableinfobox contentnode addchild darknetpeernode peernodes getdarknetconnections getpartasstring canread peertableinfobox addchild nosuchfileorcannotread addhomepagelink peertableinfobox writehtmlreply pagenode htmlnode peertable peertableinfobox addchild htmlnode peertableheaderrow peertable addchild peertableheaderrow addchild peername peertableheaderrow addchild sendstatus peernodes ispartset node_ peernodes hashcode darknetpeernode peernodes sendfileoffer ioexception peertableinfobox addchild nosuchfileorcannotread addhomepagelink peertableinfobox writehtmlreply pagenode sendtextmessage sendstatusshort sendstatuslong sendstatusclass peermanager peer_node_status_routing_backed_off sendstatusshort delayedtitle sendstatuslong sendstatusclass getname peermanager peer_node_status_connected sendstatusshort senttitle sendstatuslong sendstatusclass getname sendstatusshort queuedtitle sendstatuslong sendstatusclass getname htmlnode peerrow peertable addchild peerrow addchild addchild getname peerrow addchild sendstatusclass addchild sendstatuslong sendstatusshort htmlnode infoboxcontent peertableinfobox addchild infoboxcontent addchild htmlnode peertableinfobox addchild addhomepagelink addchild addchild returntofriends writehtmlreply pagenode multivaluetable multivaluetable sendreplyheaders public static void createn2ntm send form html node page node html node content node toadlet context ctx hash map string string peers throws toadlet context closed exception io exception html node infobox content node add child div new string class id new string infobox n2nbox infobox add child div class infobox header l10n send message html node message targets infobox add child div class infobox content message targets add child p l10n composing message label html node message target list message targets add child ul iterate peers for string peer name peers values message target list add child li peer name html node infobox content infobox add child div class infobox content html node message form ctx add form child infobox content send n2ntm sendn2ntm form iterate peers for string peer node hash peers key set message form add child input new string type name value new string hidden node peer node hash 1 message form add child textarea new string id name rows cols new string n2ntmtext message 8 74 message form add child br message form add child you may attach a file message form add child input new string type name value new string text filename message form add child input new string type name value new string submit send l10n send message short createn2ntmsendform htmlnode pagenode htmlnode contentnode toadletcontext hashmap toadletcontextclosedexception ioexception htmlnode contentnode addchild addchild sendmessage htmlnode messagetargets addchild messagetargets addchild composingmessagelabel htmlnode messagetargetlist messagetargets addchild peer_name messagetargetlist addchild peer_name htmlnode infoboxcontent addchild htmlnode messageform addformchild infoboxcontent send_n2ntm sendn2ntmform peernodehash keyset messageform addchild node_ peernodehash messageform addchild messageform addchild messageform addchild messageform addchild messageform addchild sendmessageshort public color get color string param name string param value color default color color color if equals param value param value null color default color else if param value index of 0 color create color from comma separated values param name param value else color create color from field value param name param value return color getcolor paramname paramvalue defaultcolor paramvalue paramvalue defaultcolor paramvalue indexof createcolorfromcommaseparatedvalues paramname paramvalue createcolorfromfieldvalue paramname paramvalue public color create color from comma separated values string param name string param value color color string color values param value split try int r integer parse int color values 0 int g integer parse int color values 1 int b integer parse int color values 2 if color values length 4 int a integer parse int color values 3 color new color r g b a else if color values length 3 color new color r g b else throw new config exception param name param value color can only have 3 rgb or 4 rgb with alpha values catch number format exception nfe throw new config exception param name param value nfe catch array index out of bounds exception aie throw new config exception param name param value aie catch illegal argument exception iae throw new config exception param name param value iae return color createcolorfromcommaseparatedvalues paramname paramvalue colorvalues paramvalue parseint colorvalues parseint colorvalues parseint colorvalues colorvalues parseint colorvalues colorvalues configexception paramname paramvalue numberformatexception configexception paramname paramvalue arrayindexoutofboundsexception configexception paramname paramvalue illegalargumentexception configexception paramname paramvalue public color create color from field value string param name string param value color color try field field class for name java awt color get field param value color color field get null catch no such field exception nsfe throw new config exception param name param value nsfe catch class not found exception cnfe throw new config exception param name param value cnfe catch illegal access exception iae throw new config exception param name param value iae return color createcolorfromfieldvalue paramname paramvalue forname getfield paramvalue nosuchfieldexception configexception paramname paramvalue classnotfoundexception configexception paramname paramvalue illegalaccessexception configexception paramname paramvalue public object get class instance string param name string param value object default instance config config object instance if equals param value param value null instance default instance else try instance class for name param value new instance catch illegal access exception iae throw new config exception param name param value iae catch class not found exception cnfe throw new config exception param name param value cnfe catch instantiation exception ie throw new config exception param name param value ie set configurable instance config return instance getclassinstance paramname paramvalue defaultinstance paramvalue paramvalue defaultinstance forname paramvalue newinstance illegalaccessexception configexception paramname paramvalue classnotfoundexception configexception paramname paramvalue instantiationexception configexception paramname paramvalue setconfigurable public font get fonts string param name string param value int font size font default fonts font fonts if equals param value param value null fonts default fonts else string font names param value split fonts new font font names length for int i 0 i font names length i fonts i new font font names i font bold font size return fonts getfonts paramname paramvalue fontsize defaultfonts paramvalue paramvalue defaultfonts fontnames paramvalue fontnames fontnames fontnames fontsize public int get positive int string param name string param value int default int int int value if equals param value param value null int value default int else try int value integer parse int param value if int value 1 throw new config exception param name param value value must be greater than or equals to 1 catch number format exception nfe throw new config exception param name param value nfe return int value getpositiveint paramname paramvalue defaultint intvalue paramvalue paramvalue intvalue defaultint intvalue parseint paramvalue intvalue configexception paramname paramvalue numberformatexception configexception paramname paramvalue intvalue public char get chars string param name string param value char default chars char chars if equals param value param value null chars default chars else chars param value to char array return chars getchars paramname paramvalue defaultchars paramvalue paramvalue defaultchars paramvalue tochararray public boolean get boolean string param name string param value boolean default value boolean boolean value if yes equals param value equals param value param value null boolean value default value else if no equals param value boolean value false else throw new config exception param name param value value must be either yes or no return boolean value getboolean paramname paramvalue defaultvalue booleanvalue paramvalue paramvalue paramvalue booleanvalue defaultvalue paramvalue booleanvalue configexception paramname paramvalue booleanvalue private void set configurable object object config config if object instanceof configurable configurable object set config config setconfigurable setconfig override public string to string string builder sb new string builder sb append super to string sb append my exponent sb append my exponent to hex string sb append my exponential sb append my exponential to hex string return sb to string tostring stringbuilder stringbuilder tostring myexponent myexponent tohexstring myexponential myexponential tohexstring tostring public diffie hellman light context native big integer my exponent native big integer my exponential this my exponent my exponent this my exponential my exponential this last used time system current time millis this logminor logger should log logger minor this diffiehellmanlightcontext nativebiginteger myexponent nativebiginteger myexponential myexponent myexponent myexponential myexponential lastusedtime currenttimemillis shouldlog public void set signature dsa signature sig this signature sig setsignature dsasignature public native big integer gethmac key native big integer peer exponential dh group group last used time system current time millis big integer p group getp native big integer shared secret native big integer peer exponential mod pow my exponent p if logminor logger minor this p hex util bi to hex p logger minor this my exponent my exponent to hex string logger minor this my exponential my exponential to hex string logger minor this peer s exponential peer exponential to hex string logger minor this g ir mod p shared secret to hex string return shared secret nativebiginteger gethmackey nativebiginteger peerexponential dhgroup lastusedtime currenttimemillis biginteger nativebiginteger sharedsecret nativebiginteger peerexponential modpow myexponent hexutil bitohex myexponent tohexstring myexponential tohexstring peerexponential tohexstring sharedsecret tohexstring sharedsecret public static boolean is valid hostname string hn boolean allowip address if allowip address debugging log messages because address identifier doesn t appear to handle all i pv6 literals correctly such as fe80 204 1234 dead beef address identifier address type address type address identifier get address type hn true logger debug null address type of hn appears to be address type if address type to string equals other the address typer thinks it s either an i pv4 or i pv6 ip address return true note it is believed that this code supports punycode based ascii compatible encoding ace idna labels as described in rfc3490 such an assertion has not be thoroughly tested if hn matches 0 9 a z a z a za z 2 6 system err println failed to match hn as a hostname or i pv4 i pv6 ip address return false return true isvalidhostname allowipaddress allowipaddress addressidentifier ipv6 addressidentifier addresstype addresstype addressidentifier getaddresstype addresstype addresstype tostring ipv4 ipv6 _ ipv4 ipv6 public final class value composite extends rgb composite public value composite float alpha super alpha valuecomposite rgbcomposite valuecomposite public composite context create context color model src color model color model dst color model rendering hints hints return new context extra alpha src color model dst color model compositecontext createcontext colormodel srccolormodel colormodel dstcolormodel renderinghints extraalpha srccolormodel dstcolormodel private float dhsb new float 3 public context float alpha color model src color model color model dst color model super alpha src color model dst color model colormodel srccolormodel colormodel dstcolormodel srccolormodel dstcolormodel override public void composergb int src int dst float alpha int w src length for int i 0 i w i 4 int sr src i int dir dst i int sg src i 1 int dig dst i 1 int sb src i 2 int dib dst i 2 int sa src i 3 int dia dst i 3 int dor dog dob color rg btohsb sr sg sb shsb color rg btohsb dir dig dib dhsb dhsb 2 shsb 2 int dorgb color hs btorgb dhsb 0 dhsb 1 dhsb 2 dor dorgb 0xff0000 16 dog dorgb 0xff00 8 dob dorgb 0xff float a alpha sa 255f float ac 1 a dst i int a dor ac dir dst i 1 int a dog ac dig dst i 2 int a dob ac dib dst i 3 int sa alpha dia ac rgbtohsb rgbtohsb hsbtorgb public final class new board page extends web page impl public new board page web interface my web interface ft own identity viewer http request request super my web interface viewer request newboardpage webpageimpl newboardpage webinterface mywebinterface ftownidentity httprequest mywebinterface public void make if m request is part set create board final int board language length 8 final int max board name length board max boardname text length board language length 1 1 for the string board language m request get part as string board language board language length string board name m request get part as string board name max board name length try board board m freetalk get message manager get or create board board language board name html node success box add content box board was created success box add child div the board todo i have no idea how to make this text appear in one line without removing the u success box add child u add child new html node a href self uri show board identity m own identity getuid name board get name board get name success box add child div was successfully created make new board page en catch invalid parameter exception e html node alert box add alert box the board could not be created alert box add child div e get message make new board page board language board name else make new board page en mrequest ispartset createboard boardlanguagelength maxboardnamelength max_boardname_text_length boardlanguagelength boardlanguage mrequest getpartasstring boardlanguage boardlanguagelength boardname mrequest getpartasstring boardname maxboardnamelength mfreetalk getmessagemanager getorcreateboard boardlanguage boardname htmlnode successbox addcontentbox successbox addchild successbox addchild addchild htmlnode self_uri showboard mownidentity getname getname successbox addchild makenewboardpage invalidparameterexception htmlnode alertbox addalertbox alertbox addchild getmessage makenewboardpage boardlanguage boardname makenewboardpage private void make new board page string board language string board name html node new board box add content box create a new board html node new board form add form child new board box self uri new board new board new board form add child input new string type name value new string hidden own identityid m own identity getuid html node language box new board form add child get content box language language box add child p the board name will be prefixed with the following language code todo locale getiso languages only returns the abbreviations figure out how to get the full names add some function to board java for getting them and use them here for that you will also need to modify get combo box to take display names and values instead of only values and using them as display names language box add child get combo box board language board get allowed language codes board language html node name box new board form add child get content box board name name box add child p please try to make the name as self explantory as possible you should split the name in categories separated by dots whenever possible for example freenet support instead of just suppport name box add child input new string type size name value new string text 128 board name board name fixme chose a resonable max board name length specify it here and in board java new board form add child input new string type name value new string submit create board create the board makenewboardpage boardlanguage boardname htmlnode newboardbox addcontentbox htmlnode newboardform addformchild newboardbox self_uri newboard newboard newboardform addchild ownidentityid mownidentity htmlnode languagebox newboardform addchild getcontentbox languagebox addchild getisolanguages getcombobox languagebox addchild getcombobox boardlanguage getallowedlanguagecodes boardlanguage htmlnode namebox newboardform addchild getcontentbox namebox addchild namebox addchild boardname boardname newboardform addchild createboard public class revocation key found user alert extends abstract user alert public revocation key found user alert string msg super false l10n get string revocation key found user alert title l10n get string revocation key found user alert text message msg l10n get string revocation key found user alert text message msg new html node l10n get string revocation key found user alert text message msg user alert critical error true null false null revocationkeyfounduseralert abstractuseralert revocationkeyfounduseralert getstring revocationkeyfounduseralert getstring revocationkeyfounduseralert getstring revocationkeyfounduseralert htmlnode getstring revocationkeyfounduseralert useralert critical_error override public void is valid boolean b we ignore it it s always valid isvalid public static base client key get base key freeneturi origuri throws malformedurl exception string key type origuri get key type if chk equals key type return new clientchk origuri if ssk equals key type return new clientssk origuri if ksk equals key type return clientksk create origuri get doc name if usk equals key type return usk create origuri throw new malformedurl exception unknown keytype from origuri baseclientkey getbasekey malformedurlexception keytype getkeytype keytype keytype keytype getdocname keytype malformedurlexception public abstract freeneturi geturi public io statistic collector targets new linked hash map string statistic entry todo only for testing this should only happen once snmp agent create snmp starter initialize logdebug logger should log logger debug this iostatisticcollector linkedhashmap statisticentry snmpagent snmpstarter shouldlog public void add info string key int inbytes int outbytes try synchronized this addinfo key inbytes outbytes catch throwable t t print stack trace addinfo _addinfo printstacktrace private void addinfo string key int inbytes int outbytes rotate if enable per address tracking statistic entry entry targets get key if entry null entry new statistic entry targets put key entry entry add data inbytes 0 inbytes 0 outbytes 0 outbytes 0 synchronized this totalbytesout outbytes 0 outbytes 0 totalbytesin inbytes 0 inbytes 0 if logdebug logger debug io statistic collector class add key inbytes outbytes totalbytesin totalbytesout _addinfo enable_per_address_tracking statisticentry statisticentry adddata iostatisticcollector public void dump info synchronized this dumpinfo dumpinfo _dumpinfo public long get totalio synchronized this return gettotalio gettotalio _gettotalio private long gettotalio long ret new long 2 synchronized this ret 0 totalbytesout ret 1 totalbytesin return ret _gettotalio public int get total statistics synchronized this return gettotalstatistics gettotalstatistics _gettotalstatistics private int gettotalstatistics string keys string targets key set to array int ret new int statistics entries 2 for int i 0 i statistics entries i ret i 0 ret i 1 0 for map entry string statistic entry entry targets entry set int inres entry get value get recieved int outres entry get value get sent for int i 0 i statistics entries i ret i 1 inres i ret i 0 outres i return ret _gettotalstatistics keyset toarray statistics_entries statistics_entries statisticentry entryset getvalue getrecieved getvalue getsent statistics_entries private void dumpinfo rotate date format df date format get date instance date format long locale france system err println date format get date instance format new date system err println new date final double divby statistics duration s 1024 for map entry string statistic entry entry targets entry set string key entry get key int inres entry get value get recieved int outres entry get value get sent system err print key substring 0 22 int tin 0 int tout 0 for int i 0 i inres length i in out in 102 4 bytes hecto bytes tin inres i tout outres i int in int tin 10 0 divby i 1 int out int tout 10 0 divby i 1 system err print i in 10 in 10 system err print o out 10 out 10 system err print t system err println system err println _dumpinfo dateformat dateformat getdateinstance dateformat dateformat getdateinstance statistics_duration_s statisticentry entryset getkey getvalue getrecieved getvalue getsent private void rotate long now system current time millis if now lastrotate statistics duration lastrotate now object keys targets key set to array if keys null return why aren t we iterating there for int i 0 i keys length i object key keys i if targets get key rotate false targets remove key fixme debugging dumpinfo currenttimemillis statistics_duration keyset toarray _dumpinfo public statistic entry create a new array and clear it recieved new int io statistic collector statistics entries 1 sent new int io statistic collector statistics entries 1 for int i 0 i recieved length i recieved i sent i 0 statisticentry iostatisticcollector statistics_entries iostatisticcollector statistics_entries public void add data int inbytes int outbytes recieved 0 inbytes sent 0 outbytes adddata public boolean rotate boolean hasdata false for int i recieved length 1 i 0 i recieved i recieved i 1 sent i sent i 1 hasdata recieved i 0 sent i 0 recieved 0 sent 0 0 return hasdata public int get recieved int retint new int io statistic collector statistics entries system arraycopy recieved 1 retint 0 io statistic collector statistics entries return retint getrecieved iostatisticcollector statistics_entries iostatisticcollector statistics_entries public int get sent int retint new int io statistic collector statistics entries system arraycopy sent 1 retint 0 io statistic collector statistics entries return retint getsent iostatisticcollector statistics_entries iostatisticcollector statistics_entries public partially received block int packets int packet size byte data if data length packets packet size throw new runtime exception length of data data length doesn t match packet number and size data data received new boolean packets for int x 0 x received length x received x true receivedcount packets packets packets packetsize packet size partiallyreceivedblock packetsize packetsize runtimeexception _data _received _received _received _receivedcount _packets _packetsize packetsize public partially received block int packets int packet size data new byte packets packet size received new boolean packets packets packets packetsize packet size partiallyreceivedblock packetsize _data packetsize _received _packets _packetsize packetsize public synchronized linked list integer add listener packet received listener listener throws aborted exception if aborted throw new aborted exception adding listener to aborted prb packetreceivedlisteners add listener linked list integer ret new linked list integer for int x 0 x packets x if received x ret add last x return ret linkedlist addlistener packetreceivedlistener abortedexception _aborted abortedexception _packetreceivedlisteners linkedlist linkedlist _packets _received addlast public synchronized boolean is received int packet no throws aborted exception if aborted throw new aborted exception prb is aborted return received packet no isreceived packetno abortedexception _aborted abortedexception _received packetno public synchronized int get num packets throws aborted exception if aborted throw new aborted exception prb is aborted return packets getnumpackets abortedexception _aborted abortedexception _packets public synchronized int get packet size throws aborted exception if aborted throw new aborted exception prb is aborted return packetsize getpacketsize abortedexception _aborted abortedexception _packetsize public void add packet int position buffer packet throws aborted exception packet received listener prls synchronized this if aborted throw new aborted exception prb is aborted if packet get length packetsize throw new runtime exception new packet size packet get length but expecting packet of size packetsize if received position return receivedcount packet copy to data position packetsize received position true fixme keep it as as an array prls packetreceivedlisteners to array new packet received listener packetreceivedlisteners size for int i 0 i prls length i packet received listener prl prls i prl packet received position addpacket abortedexception packetreceivedlistener _aborted abortedexception getlength _packetsize runtimeexception getlength _packetsize _received _receivedcount copyto _data _packetsize _received _packetreceivedlisteners toarray packetreceivedlistener _packetreceivedlisteners packetreceivedlistener packetreceived public synchronized boolean all received throws aborted exception if aborted throw new aborted exception prb is aborted return receivedcount packets allreceived abortedexception _aborted abortedexception _receivedcount _packets public synchronized byte get block throws aborted exception if aborted throw new aborted exception prb is aborted if all received throw new runtime exception tried to get block before all packets received return data getblock abortedexception _aborted abortedexception allreceived runtimeexception _data public synchronized buffer get packet int x throws aborted exception if aborted throw new aborted exception prb is aborted if received x throw new illegal state exception that packet is not received return new buffer data x packetsize packetsize getpacket abortedexception _aborted abortedexception _received illegalstateexception _data _packetsize _packetsize public synchronized void remove listener packet received listener listener packetreceivedlisteners remove listener removelistener packetreceivedlistener _packetreceivedlisteners public synchronized void abort int reason string description aborted true abortreason reason abortdescription description for packet received listener prl packetreceivedlisteners prl receive aborted reason description _aborted _abortreason _abortdescription packetreceivedlistener _packetreceivedlisteners receiveaborted public synchronized boolean is aborted return aborted isaborted _aborted public synchronized int get abort reason return abortreason getabortreason _abortreason public synchronized string get abort description return abortdescription getabortdescription _abortdescription public static interface packet received listener public void packet received int packet no packetreceivedlistener packetreceived packetno public void packet received int packet no public void receive aborted int reason string description packetreceived packetno receiveaborted will get all needed info from the plugin put it into the wrapper then the pluginstarter will be greated and the plugin fedto it starting the plugin the plugin info wrapper will then be returned param plug public static plugin info wrapper start plugin plugin manager pm string filename fred plugin plug plugin respirator pr final plugin info wrapper pi new plugin info wrapper pr plug filename final plugin starter ps new plugin starter pr pi ps set plugin pm plug class loader old class loader thread current thread get context class loader class loader plugin class loader plug get class get class loader thread current thread set context class loader plugin class loader try we must start the plugin after startup has finished runnable job if pi is threadless plugin final thread t new thread ps t set daemon true pi set thread t job new runnable public void run t start pm get ticker queue timed job job 0 else avoid np es let it init then register it plug run plugin pr pm register plug pi finally thread current thread set context class loader old class loader return pi plugininfowrapper plugininfowrapper startplugin pluginmanager fredplugin pluginrespirator plugininfowrapper plugininfowrapper pluginstarter pluginstarter setplugin classloader oldclassloader currentthread getcontextclassloader classloader pluginclassloader getclass getclassloader currentthread setcontextclassloader pluginclassloader isthreadlessplugin setdaemon setthread getticker queuetimedjob npes runplugin currentthread setcontextclassloader oldclassloader pi set thread t job new runnable public void run t start setthread final plugin info wrapper pi public plugin starter plugin respirator pr plugin info wrapper pi this pr pr this pi pi plugininfowrapper pluginstarter pluginrespirator plugininfowrapper public void set plugin plugin manager pm fred plugin plugin this plugin plugin this pm pm setplugin pluginmanager fredplugin public void run try pm register plugin pi plugin run plugin pr catch out of memory error e oom handler handleoom e catch throwable t logger normal this caught throwable while running plugin t t system err println caught throwable while running plugin t t print stack trace pi unregister pm if not already unregistered pm remove plugin pi runplugin outofmemoryerror oomhandler printstacktrace removeplugin public static salted hash freenet store construct file base dir string name store callback callback random random long max keys int bloom filter size boolean bloom counting semi ordered shutdown hook shutdown hook boolean preallocate boolean resize on start throws io exception return new salted hash freenet store base dir name callback random max keys bloom filter size bloom counting shutdown hook preallocate resize on start saltedhashfreenetstore basedir storecallback maxkeys bloomfiltersize bloomcounting semiorderedshutdownhook shutdownhook resizeonstart ioexception saltedhashfreenetstore basedir maxkeys bloomfiltersize bloomcounting shutdownhook resizeonstart private salted hash freenet store file base dir string name store callback callback random random long max keys int bloom filter size boolean bloom counting semi ordered shutdown hook shutdown hook boolean preallocate boolean resize on start throws io exception logminor logger should log logger minor this logdebug logger should log logger debug this this base dir base dir this name name this callback callback collision possible callback collision possible header block length callback header length full key length callback full key length data block length callback data length hd padding header block length data block length 512 0 0 512 header block length data block length 512 this random random store size max keys this bloom filter size bloom filter size this preallocate preallocate lock manager new lock manager create a directory it not exist this base dir mkdirs config file new file this base dir name config boolean new store load config file new store open store files base dir name file bloom file new file this base dir name bloom bloom filter bloom filter create filter bloom file bloom filter size bloom filterk bloom counting system err println bloomfilter bloom filter for name is loaded if flags flag dirty 0 system err println datastore name is dirty flags flag dirty datastore is now dirty until flush and close write config file if max keys store size if prev store size 0 store size math max prev store size store size prev store size 0 set max keys max keys true callback set store this shutdown hook add early job new thread new shutdowndb cleaner thread new cleaner cleaner status user alert new cleaner status user alert cleaner thread finish all resizing before continue if resize on start prev store size 0 cleaner global lock try lock system out println resizing datastore name try cleaner thread resize store prev store size false finally cleaner global lock unlock write config file if bloom filter need rebuild new store bloom filter resized flags flag rebuild bloom check bloom false if cleaner global lock try lock system out println bloom filter for datastore name missing mismatch rebuilding try cleaner thread rebuild bloom false finally cleaner global lock unlock write config file system err println check bloom check bloom flags flags bloom size bloom filter size keys max keys cleaner thread start saltedhashfreenetstore basedir storecallback maxkeys bloomfiltersize bloomcounting semiorderedshutdownhook shutdownhook resizeonstart ioexception shouldlog shouldlog basedir basedir collisionpossible collisionpossible headerblocklength headerlength fullkeylength fullkeylength datablocklength datalength hdpadding headerblocklength datablocklength headerblocklength datablocklength storesize maxkeys bloomfiltersize bloomfiltersize lockmanager lockmanager basedir configfile basedir newstore loadconfigfile newstore openstorefiles basedir bloomfile basedir bloomfilter bloomfilter createfilter bloomfile bloomfiltersize bloomfilterk bloomcounting bloomfilter flag_dirty flag_dirty flushandclose writeconfigfile maxkeys storesize prevstoresize storesize prevstoresize storesize prevstoresize setmaxkeys maxkeys setstore shutdownhook addearlyjob cleanerthread cleanerstatususeralert cleanerstatususeralert cleanerthread resizeonstart prevstoresize cleanergloballock trylock cleanerthread resizestore prevstoresize cleanergloballock writeconfigfile bloomfilter needrebuild newstore flag_rebuild_bloom checkbloom cleanergloballock trylock cleanerthread rebuildbloom cleanergloballock writeconfigfile checkbloom checkbloom bloomfiltersize maxkeys cleanerthread public storable block fetch byte routing key byte full key boolean dont promote throws io exception if logminor logger minor this fetch hex util bytes to hex routing key for callback try int retry 0 while config lock read lock try lock 2 time unit seconds if shutdown return null if retry 10 throw new io exception lock timeout 20s catch interrupted exception e throw new io exception interrupted e try map long condition lock map lock plain key routing key true if lock map null if logdebug logger debug this cannot lock key hex util bytes to hex routing key shutting down return null try entry entry probe entry routing key true if entry null misses increment and get return null try storable block block entry get storable block routing key full key if block null misses increment and get return null hits increment and get return block catch key verify exception e logger minor this key verification exception e misses increment and get return null finally unlock plain key routing key true lock map finally config lock read lock unlock storableblock routingkey fullkey dontpromote ioexception hexutil bytestohex routingkey configlock readlock trylock timeunit ioexception interruptedexception ioexception lockmap lockplainkey routingkey lockmap hexutil bytestohex routingkey probeentry routingkey incrementandget storableblock getstorableblock routingkey fullkey incrementandget incrementandget keyverifyexception incrementandget unlockplainkey routingkey lockmap configlock readlock find and lock an entry with a specific routing key this function would strong not strong lock the entries param routing key param with data return code entry code object throws io exception private entry probe entry byte routing key boolean with data throws io exception if check bloom if bloom filter check filter cipher manager get digested key routing key return null entry entry probe entry0 routing key store size with data if entry null prev store size 0 entry probe entry0 routing key prev store size with data if check bloom entry null bloom false pos increment and get return entry routingkey withdata ioexception probeentry routingkey withdata ioexception checkbloom bloomfilter checkfilter ciphermanager getdigestedkey routingkey probeentry0 routingkey storesize withdata prevstoresize probeentry0 routingkey prevstoresize withdata checkbloom bloomfalsepos incrementandget private entry probe entry0 byte routing key long probe store size boolean with data throws io exception entry entry null long offset get offset from plain key routing key probe store size for int i 0 i offset length i if logdebug logger debug this probing for i i offset offset i try entry read entry offset i routing key with data if entry null return entry catch eof exception e if prev store size 0 may occur on store shrinking logger error this eof exception on probe entry e continue return null probeentry0 routingkey probestoresize withdata ioexception getoffsetfromplainkey routingkey probestoresize readentry routingkey withdata eofexception prevstoresize eofexception probeentry public void put storable block block byte routing key byte full key byte data byte header boolean overwrite throws io exception key collision exception if logminor logger minor this putting hex util bytes to hex routing key name try int retry 0 while config lock read lock try lock 2 time unit seconds if shutdown return if retry 10 throw new io exception lock timeout 20s catch interrupted exception e throw new io exception interrupted e try map long condition lock map lock plain key routing key false if lock map null if logdebug logger debug this cannot lock key hex util bytes to hex routing key shutting down return try use lazy loading here this may lost data if digested routing key collide but collision possible is false should be very rare as digested routing key is a sha 256 hash entry old entry probe entry routing key false if old entry null old entry is free long old offset old entry cur offset try if collision possible return old entry sethd readhd old offset read from disk storable block old block old entry get storable block routing key full key if block equals old block return already in store else if overwrite throw new key collision exception catch key verify exception e ignore overwrite old offset with same key entry entry new entry routing key header data write entry entry old offset writes increment and get if old entry generation generation key count increment and get return entry entry new entry routing key header data long offset entry get offset for int i 0 i offset length i if offset i store file size ready is free offset i write to free block if logdebug logger debug this probing write to i i offset offset i bloom filter add key cipher manager get digested key routing key write entry entry offset i writes increment and get key count increment and get return no free blocks overwrite the first one if logdebug logger debug this collision write to i 0 offset offset 0 bloom filter add key cipher manager get digested key routing key old entry read entry offset 0 null false write entry entry offset 0 writes increment and get if old entry generation generation bloom filter remove key old entry get digested routing key else key count increment and get finally unlock plain key routing key false lock map finally config lock read lock unlock storableblock routingkey fullkey ioexception keycollisionexception hexutil bytestohex routingkey configlock readlock trylock timeunit ioexception interruptedexception ioexception lockmap lockplainkey routingkey lockmap hexutil bytestohex routingkey digestedroutingkey collisionpossible digestedroutingkey oldentry probeentry routingkey oldentry oldentry isfree oldoffset oldentry curoffset collisionpossible oldentry oldoffset storableblock oldblock oldentry getstorableblock routingkey fullkey oldblock keycollisionexception keyverifyexception routingkey writeentry oldoffset incrementandget oldentry keycount incrementandget routingkey getoffset storefilesizeready isfree bloomfilter addkey ciphermanager getdigestedkey routingkey writeentry incrementandget keycount incrementandget bloomfilter addkey ciphermanager getdigestedkey routingkey oldentry readentry writeentry incrementandget oldentry bloomfilter removekey oldentry getdigestedroutingkey keycount incrementandget unlockplainkey routingkey lockmap configlock readlock private long cur offset 1 private entry curoffset private entry byte buffer meta data buf byte buffer hd buf assert meta data buf remaining metadata length digested routing key new byte 0x20 meta data buf get digested routing key data encryptiv new byte 0x10 meta data buf get data encryptiv flag meta data buf get long store size meta data buf get long if flag entry flag plainkey 0 plain routing key new byte 0x20 meta data buf get plain routing key meta data buf position 0x60 generation meta data buf get int is encrypted true if hd buf null sethd hd buf bytebuffer metadatabuf bytebuffer hdbuf metadatabuf metadata_length digestedroutingkey metadatabuf digestedroutingkey dataencryptiv metadatabuf dataencryptiv metadatabuf getlong storesize metadatabuf getlong entry_flag_plainkey plainroutingkey metadatabuf plainroutingkey metadatabuf metadatabuf getint isencrypted hdbuf hdbuf set header data after construction param store buf param store private void sethd byte buffer hd buf assert hd buf remaining header block length data block length hd padding assert is encrypted header new byte header block length hd buf get header data new byte data block length hd buf get data storebuf bytebuffer hdbuf hdbuf headerblocklength datablocklength hdpadding isencrypted headerblocklength hdbuf datablocklength hdbuf create a new entry param plain routing key param header param data private entry byte plain routing key byte header byte data this plain routing key plain routing key flag entry flag occupied this store size salted hash freenet store this store size this generation salted hash freenet store this generation header data will be overwritten in encrypt decrypt let s make a copy here this header new byte header block length system arraycopy header 0 this header 0 header block length this data new byte data block length system arraycopy data 0 this data 0 data block length if option save plainkey flag entry flag plainkey is encrypted false plainroutingkey plainroutingkey plainroutingkey plainroutingkey entry_flag_occupied storesize saltedhashfreenetstore storesize saltedhashfreenetstore headerblocklength headerblocklength datablocklength datablocklength option_save_plainkey entry_flag_plainkey isencrypted private byte buffer to meta data buffer byte buffer out byte buffer allocate metadata length cipher manager encrypt this random out put get digested routing key out put data encryptiv out put long flag out put long store size if flag entry flag plainkey 0 plain routing key null assert plain routing key length 0x20 out put plain routing key out position 0x60 out put int generation out position 0 return out bytebuffer tometadatabuffer bytebuffer bytebuffer metadata_length ciphermanager getdigestedroutingkey dataencryptiv putlong putlong storesize entry_flag_plainkey plainroutingkey plainroutingkey plainroutingkey putint private byte buffer tohd buffer assert is encrypted should have encrypted to get data encryptiv in control buffer assert header length header block length assert data length data block length if header null data null return null byte buffer out byte buffer allocate header block length data block length hd padding out put header out put data out position 0 return out bytebuffer tohdbuffer isencrypted dataencryptiv headerblocklength datablocklength bytebuffer bytebuffer headerblocklength datablocklength hdpadding private storable block get storable block byte routing key byte full key throws key verify exception if is free header null data null return null this is a free block if cipher manager decrypt this routing key return null storable block block callback construct data header routing key full key byte block routing key block get routing key if arrays equals block routing key routing key can t recover as decrypt depends on a correct route key return null return block storableblock getstorableblock routingkey fullkey keyverifyexception isfree ciphermanager routingkey storableblock routingkey fullkey blockroutingkey getroutingkey blockroutingkey routingkey private long get offset if digested routing key null return get offset from digested key digested routing key store size else return get offset from plain key plain routing key store size getoffset digestedroutingkey getoffsetfromdigestedkey digestedroutingkey storesize getoffsetfromplainkey plainroutingkey storesize private boolean is free return flag entry flag occupied 0 isfree entry_flag_occupied byte get digested routing key if digested routing key null if plain routing key null return null else digested routing key cipher manager get digested key plain routing key return digested routing key getdigestedroutingkey digestedroutingkey plainroutingkey digestedroutingkey ciphermanager getdigestedkey plainroutingkey digestedroutingkey open all store files param base dir param name throws io exception return code true code iff this is a new datastore private boolean open store files file base dir string name throws io exception meta file new file base dir name metadata hd file new file base dir name hd boolean new store meta file exists hd file exists metaraf new random access file meta file rw metafc metaraf get channel metafc lock hdraf new random access file hd file rw hdfc hdraf get channel hdfc lock long store file size math max store size prev store size wrapper manager signal starting 10 60 1000 10minutes for filesystem that support no sparse file set store file size store file size true return new store basedir ioexception openstorefiles basedir ioexception metafile basedir hdfile basedir newstore metafile hdfile randomaccessfile metafile getchannel randomaccessfile hdfile getchannel storefilesize storesize prevstoresize wrappermanager signalstarting setstorefilesize storefilesize newstore read entry from disk before calling this function you should acquire all required locks return code null code if and only if code routing key code is not code null code and the key does not match the entry private entry read entry long offset byte routing key boolean with data throws io exception byte buffer mbf byte buffer allocate entry metadata length do int status metafc read mbf entry metadata length offset mbf position if status 1 throw new eof exception while mbf has remaining mbf flip entry entry new entry mbf null entry cur offset offset if routing key null if entry is free return null if arrays equals cipher manager get digested key routing key entry digested routing key return null if with data byte buffer hd buf readhd offset entry sethd hd buf boolean decrypted cipher manager decrypt entry routing key if decrypted return null return entry routingkey readentry routingkey withdata ioexception bytebuffer bytebuffer metadata_length metadata_length eofexception hasremaining curoffset routingkey isfree ciphermanager getdigestedkey routingkey digestedroutingkey withdata bytebuffer hdbuf hdbuf ciphermanager routingkey read header data from disk param offset throws io exception private byte buffer readhd long offset throws io exception byte buffer buf byte buffer allocate header block length data block length hd padding long pos header block length data block length hd padding offset do int status hdfc read buf pos buf position if status 1 throw new eof exception while buf has remaining buf flip return buf ioexception bytebuffer ioexception bytebuffer bytebuffer headerblocklength datablocklength hdpadding headerblocklength datablocklength hdpadding eofexception hasremaining private boolean is free long offset throws io exception entry entry read entry offset null false return entry is free isfree ioexception readentry isfree private byte get digested key from offset long offset throws io exception entry entry read entry offset null false return entry get digested routing key getdigestedkeyfromoffset ioexception readentry getdigestedroutingkey write entry to disk before calling this function you should ul li acquire all required locks li li update the entry with latest store size li ul private void write entry entry entry long offset throws io exception cipher manager encrypt entry random byte buffer bf entry to meta data buffer do int status metafc write bf entry metadata length offset bf position if status 1 throw new eof exception while bf has remaining bf entry tohd buffer if bf null long pos header block length data block length hd padding offset do int status hdfc write bf pos bf position if status 1 throw new eof exception while bf has remaining entry cur offset offset writeentry ioexception ciphermanager bytebuffer tometadatabuffer metadata_length eofexception hasremaining tohdbuffer headerblocklength datablocklength hdpadding eofexception hasremaining curoffset private void flush and close logger normal this flush and closing this store name try metafc force true metafc close catch exception e logger error this error flusing store e try hdfc force true hdfc close catch exception e logger error this error flusing store e bloom filter force flushandclose bloomfilter set preallocate storage space param preallocate public void set preallocate boolean preallocate this preallocate preallocate setpreallocate change on disk store file size param store file size private void set store file size long store file size boolean starting try long old meta len metaraf length long old hd len hdraf length final long new meta len entry metadata length store file size final long new hd len header block length data block length hd padding store file size if preallocate fill the store file with random data this won t be compressed unlike filling it with zeros so the disk space usage of the node will not change apart from temp files note that mersenne twister is not cryptographically secure in fact from 2 4kb of output you can predict the rest of the stream this is okay because an attacker knows which blocks are occupied anyway it is essential to label them to get good data retention on resizing etc on my test system phenom 2 2g hz this does approx 80mb sec if i reseed every 2kb from an aes ctr which is pointless as i just explained it does 40mb sec byte b new byte 4096 byte buffer bf byte buffer wrap b start from next 4kb boundary align to x86 page size if old meta len 4096 0 old meta len 4096 old meta len 4096 if old hd len 4096 0 old hd len 4096 old hd len 4096 this may write excess the size the set length would fix it while old meta len new meta len never write random byte to meta data this would screw up the is free function bf rewind metafc write bf old meta len old meta len 4096 byte seed new byte 64 random next bytes seed random mt new mersenne twister seed int x 0 while old hd len new hd len mt next bytes b bf rewind hdfc write bf old hd len old hd len 4096 if old hd len 1024 1024 1024l 0 random next bytes seed mt new mersenne twister seed if starting wrapper manager signal starting 5 60 1000 if x 32 0 system err println preallocating space for name old hd len new hd len store file size ready old hd len header block length data block length hd padding store file size ready store file size metaraf set length new meta len hdraf set length new hd len catch io exception e logger error this error resizing store file e storefilesize setstorefilesize storefilesize oldmetalen oldhdlen newmetalen metadata_length storefilesize newhdlen headerblocklength datablocklength hdpadding storefilesize mersennetwister 2ghz bytebuffer bytebuffer oldmetalen oldmetalen oldmetalen oldhdlen oldhdlen oldhdlen setlength oldmetalen newmetalen isfree oldmetalen oldmetalen nextbytes mersennetwister oldhdlen newhdlen nextbytes oldhdlen oldhdlen oldhdlen nextbytes mersennetwister wrappermanager signalstarting oldhdlen newhdlen storefilesizeready oldhdlen headerblocklength datablocklength hdpadding storefilesizeready storefilesize setlength newmetalen setlength newhdlen ioexception load config file return code true code iff this is a new datastore private boolean load config file throws io exception assert cipher manager null never load the configuration twice if config file exists create new byte newsalt new byte 0x10 random next bytes newsalt cipher manager new cipher manager newsalt bloom filterk bloom filter optimialk bloom filter size store size write config file return true else try try to load random access file raf new random access file config file r try byte salt new byte 0x10 raf read fully salt cipher manager new cipher manager salt store size raf read long prev store size raf read long key count set raf read long generation raf read int flags raf read int if flags flag dirty 0 flags flag rebuild bloom try bloom filterk raf read int if bloom filterk 0 bloom filterk bloom filter optimialk bloom filter size store size flags flag rebuild bloom check bloom false catch io exception e flags flag rebuild bloom return false finally closer close raf catch io exception e corrupted delete it and try again logger error this config file corrupted trying to create a new store name e system err println config file corrupted trying to create a new store name if config file exists config file delete file meta file new file base dir name metadata meta file delete return load config file last restore logger error this can t delete config file please delete the store manually name e system err println can t delete config file please delete the store manually name throw e loadconfigfile ioexception ciphermanager configfile nextbytes ciphermanager ciphermanager bloomfilterk bloomfilter bloomfiltersize storesize writeconfigfile randomaccessfile randomaccessfile configfile readfully ciphermanager ciphermanager storesize readlong prevstoresize readlong keycount readlong readint readint flag_dirty flag_rebuild_bloom bloomfilterk readint bloomfilterk bloomfilterk bloomfilter bloomfiltersize storesize flag_rebuild_bloom checkbloom ioexception flag_rebuild_bloom ioexception configfile configfile metafile basedir metafile loadconfigfile write config file private void write config file config lock write lock lock try file temp config new file config file get path tmp random access file raf new random access file temp config rw raf seek 0 raf write cipher manager get salt raf write long store size raf write long prev store size raf write long key count get raf write int generation raf write int flags raf write int bloom filterk raf write int 0 raf write long 0 raf getfd sync raf close file util rename to temp config config file catch io exception ioe logger error this error writing config file for name ioe finally config lock write lock unlock writeconfigfile configlock writelock tempconfig configfile getpath randomaccessfile randomaccessfile tempconfig ciphermanager getsalt writelong storesize writelong prevstoresize writelong keycount writeint writeint writeint bloomfilterk writeint writelong fileutil renameto tempconfig configfile ioexception configlock writelock private interface batch processor initialize void init batchprocessor call this after reading resize memory entries entries return false to abort boolean batch long entries left resize_memory_entries entriesleft call this on abort e g node shutdown void abort void abort void finish return code null code to free the entry return not modified to keep the old entry entry process entry entry not_modified public cleaner super store name cleaner native thread low priority false set priority min priority set daemon true nativethread low_priority setpriority min_priority setdaemon override public void run super run try thread sleep int cleaner period 2 cleaner period math random catch interrupted exception e if shutdown return int loop 0 while shutdown loop cleaner lock lock try long prevstoresize config lock read lock lock try prevstoresize prev store size finally config lock read lock unlock if prevstoresize 0 cleaner global lock try lock try is resizing true resize store prevstoresize true finally is resizing false cleaner global lock unlock boolean rebuildbloom config lock read lock lock try rebuildbloom flags flag rebuild bloom 0 finally config lock read lock unlock if rebuildbloom prev store size 0 cleaner global lock try lock try is rebuilding true rebuild bloom false finally is rebuilding false cleaner global lock unlock try if loop 6 0 bloom filter force catch exception e may throw io exception even if it is not defined logger error this can t force bloom filter e write config file try cleaner condition await cleaner period time unit milliseconds catch interrupted exception e logger debug this interrupted e finally cleaner lock unlock cleaner_period cleaner_period interruptedexception cleanerlock _prevstoresize configlock readlock _prevstoresize prevstoresize configlock readlock _prevstoresize cleanergloballock trylock isresizing resizestore _prevstoresize isresizing cleanergloballock _rebuildbloom configlock readlock _rebuildbloom flag_rebuild_bloom configlock readlock _rebuildbloom prevstoresize cleanergloballock trylock isrebuilding rebuildbloom isrebuilding cleanergloballock bloomfilter ioexception writeconfigfile cleanercondition cleaner_period timeunit interruptedexception cleanerlock move old entries to new location and resize store private void resize store final long prevstoresize final boolean sleep logger normal this starting datastore resize batch processor resize processer new batch processor list entry old entry list new linked list entry int optimialk public void init if store size prevstoresize set store file size store size false optimialk bloom filter optimialk bloom filter size store size config lock write lock lock try generation bloom filter fork optimialk key count set 0 finally config lock write lock unlock wrapper manager signal starting resize memory entries 30 1000 1000 public entry process entry entry int old generation entry generation if old generation generation entry generation generation key count increment and get if entry store size store size new size don t have to relocate if entry generation generation update filter bloom filter add key forked entry get digested routing key return entry else return not modified remove from store prepare for relocation if old generation generation should be impossible logger error this new generation object with wrong store size digested routing key hex util bytes to hex entry get digested routing key offset entry cur offset bloom filter remove key entry get digested routing key try entry sethd readhd entry cur offset old entry list add entry if old entry list size resize memory entries old entry list remove 0 catch io exception e logger error this error reading entry offset entry cur offset e return null int i 0 public boolean batch long entries left wrapper manager signal starting resize memory entries 30 1000 1000 if i 16 0 write config file shrink data file to current size if store size prevstoresize set store file size math max store size entries left false try to resolve the list list iterator entry it old entry list list iterator while it has next if resolve old entry it next it remove return prevstoresize prev store size public void abort bloom filter discard public void finish config lock write lock lock try if prevstoresize prev store size return bloom filter merge prev store size 0 flags flag rebuild bloom check bloom true bloom filterk optimialk finally config lock write lock unlock logger normal this finish resizing name batch process entries resize processer prevstoresize true sleep resizestore _prevstoresize batchprocessor resizeprocesser batchprocessor oldentrylist linkedlist storesize _prevstoresize setstorefilesize storesize bloomfilter bloomfiltersize storesize configlock writelock bloomfilter keycount configlock writelock wrappermanager signalstarting resize_memory_entries oldgeneration oldgeneration keycount incrementandget storesize storesize bloomfilter addkeyforked getdigestedroutingkey not_modified oldgeneration storesize digestedroutingkey hexutil bytestohex getdigestedroutingkey curoffset bloomfilter removekey getdigestedroutingkey curoffset oldentrylist oldentrylist resize_memory_entries oldentrylist ioexception curoffset entriesleft wrappermanager signalstarting resize_memory_entries writeconfigfile storesize _prevstoresize setstorefilesize storesize entriesleft listiterator oldentrylist listiterator hasnext resolveoldentry _prevstoresize prevstoresize bloomfilter configlock writelock _prevstoresize prevstoresize bloomfilter prevstoresize flag_rebuild_bloom checkbloom bloomfilterk configlock writelock batchprocessentries resizeprocesser _prevstoresize public void init if store size prevstoresize set store file size store size false optimialk bloom filter optimialk bloom filter size store size config lock write lock lock try generation bloom filter fork optimialk key count set 0 finally config lock write lock unlock wrapper manager signal starting resize memory entries 30 1000 1000 storesize _prevstoresize setstorefilesize storesize bloomfilter bloomfiltersize storesize configlock writelock bloomfilter keycount configlock writelock wrappermanager signalstarting resize_memory_entries public entry process entry entry int old generation entry generation if old generation generation entry generation generation key count increment and get if entry store size store size new size don t have to relocate if entry generation generation update filter bloom filter add key forked entry get digested routing key return entry else return not modified remove from store prepare for relocation if old generation generation should be impossible logger error this new generation object with wrong store size digested routing key hex util bytes to hex entry get digested routing key offset entry cur offset bloom filter remove key entry get digested routing key try entry sethd readhd entry cur offset old entry list add entry if old entry list size resize memory entries old entry list remove 0 catch io exception e logger error this error reading entry offset entry cur offset e return null oldgeneration oldgeneration keycount incrementandget storesize storesize bloomfilter addkeyforked getdigestedroutingkey not_modified oldgeneration storesize digestedroutingkey hexutil bytestohex getdigestedroutingkey curoffset bloomfilter removekey getdigestedroutingkey curoffset oldentrylist oldentrylist resize_memory_entries oldentrylist ioexception curoffset int i 0 public boolean batch long entries left wrapper manager signal starting resize memory entries 30 1000 1000 if i 16 0 write config file shrink data file to current size if store size prevstoresize set store file size math max store size entries left false try to resolve the list list iterator entry it old entry list list iterator while it has next if resolve old entry it next it remove return prevstoresize prev store size entriesleft wrappermanager signalstarting resize_memory_entries writeconfigfile storesize _prevstoresize setstorefilesize storesize entriesleft listiterator oldentrylist listiterator hasnext resolveoldentry _prevstoresize prevstoresize public void abort bloom filter discard bloomfilter public void finish config lock write lock lock try if prevstoresize prev store size return bloom filter merge prev store size 0 flags flag rebuild bloom check bloom true bloom filterk optimialk finally config lock write lock unlock logger normal this finish resizing name configlock writelock _prevstoresize prevstoresize bloomfilter prevstoresize flag_rebuild_bloom checkbloom bloomfilterk configlock writelock rebuild bloom filter private void rebuild bloom boolean sleep if bloom filter null return logger normal this start rebuilding bloom filter name batch processor rebuild bloom processor new batch processor int optimialk public void init optimialk bloom filter optimialk bloom filter size store size config lock write lock lock try generation bloom filter fork bloom filterk key count set 0 finally config lock write lock unlock wrapper manager signal starting resize memory entries 5 1000 1000 public entry process entry entry if entry generation generation bloom filter add key forked entry get digested routing key key count increment and get entry generation generation return entry return not modified int i 0 public boolean batch long entries left wrapper manager signal starting resize memory entries 5 1000 1000 if i 16 0 write config file return prev store size 0 public void abort bloom filter discard public void finish bloom filter merge config lock write lock lock try flags flag rebuild bloom check bloom true bloom filterk optimialk finally config lock write lock unlock logger normal this finish rebuilding bloom filter name batch process entries rebuild bloom processor store size false sleep rebuildbloom bloomfilter batchprocessor rebuildbloomprocessor batchprocessor bloomfilter bloomfiltersize storesize configlock writelock bloomfilter bloomfilterk keycount configlock writelock wrappermanager signalstarting resize_memory_entries bloomfilter addkeyforked getdigestedroutingkey keycount incrementandget not_modified entriesleft wrappermanager signalstarting resize_memory_entries writeconfigfile prevstoresize bloomfilter bloomfilter configlock writelock flag_rebuild_bloom checkbloom bloomfilterk configlock writelock batchprocessentries rebuildbloomprocessor storesize public void init optimialk bloom filter optimialk bloom filter size store size config lock write lock lock try generation bloom filter fork bloom filterk key count set 0 finally config lock write lock unlock wrapper manager signal starting resize memory entries 5 1000 1000 bloomfilter bloomfiltersize storesize configlock writelock bloomfilter bloomfilterk keycount configlock writelock wrappermanager signalstarting resize_memory_entries public entry process entry entry if entry generation generation bloom filter add key forked entry get digested routing key key count increment and get entry generation generation return entry return not modified bloomfilter addkeyforked getdigestedroutingkey keycount incrementandget not_modified int i 0 public boolean batch long entries left wrapper manager signal starting resize memory entries 5 1000 1000 if i 16 0 write config file return prev store size 0 entriesleft wrappermanager signalstarting resize_memory_entries writeconfigfile prevstoresize public void abort bloom filter discard bloomfilter public void finish bloom filter merge config lock write lock lock try flags flag rebuild bloom check bloom true bloom filterk optimialk finally config lock write lock unlock logger normal this finish rebuilding bloom filter name bloomfilter configlock writelock flag_rebuild_bloom checkbloom bloomfilterk configlock writelock private void batch process entries batch processor processor long store size boolean reverse boolean sleep entries left entries total store size long start offset step if reverse start offset 0 step resize memory entries else start offset store size 1 resize memory entries resize memory entries step resize memory entries int i 0 processor init try for long cur offset start offset cur offset 0 cur offset store size cur offset step if shutdown processor abort return if i 64 0 system err println name cleaner in progress entries total entries left entries total batch process entries cur offset resize memory entries processor entries left reverse cur offset math max store size cur offset resize memory entries 0 if processor batch entries left processor abort return try if sleep thread sleep 100 catch interrupted exception e processor abort return processor finish catch exception e processor abort batchprocessentries batchprocessor storesize entriesleft entriestotal storesize startoffset startoffset resize_memory_entries startoffset storesize resize_memory_entries resize_memory_entries resize_memory_entries curoffset startoffset curoffset curoffset storesize curoffset entriestotal entriesleft entriestotal batchprocessentries curoffset resize_memory_entries entriesleft curoffset storesize curoffset resize_memory_entries entriesleft interruptedexception read a list of items from store param offset start offset must be multiple of link file split param length number of items to read must be multiple of link file split if this excess store size read as much as possible param processor batch processor return code true code if operation complete successfully code false code otherwise e g can t acquire locks node shutting down private boolean batch process entries long offset int length batch processor processor condition locked new condition length try acquire all locks in the region will unlock in the finally block for int i 0 i length i locked i lock manager lock entry offset i if locked i null return false long start file offset offset entry metadata length long entries to read length long buf len entry metadata length entries to read byte buffer buf byte buffer allocate int buf len boolean dirty false try while buf has remaining int status metafc read buf start file offset buf position if status 1 break catch io exception ioe if shutdown return false logger error this unexpected io exception ioe buf flip try for int j 0 shutdown buf limit j entry metadata length j buf position j entry metadata length if buf remaining entry metadata length eof break byte buffer en buf buf slice en buf limit entry metadata length entry entry new entry en buf null entry cur offset offset j if entry is free continue not occupied entry new entry processor process entry if new entry null free the offset buf position j entry metadata length buf put byte buffer allocate entry metadata length key count decrement and get dirty true else if new entry not modified else write back buf position j entry metadata length buf put new entry to meta data buffer assert new entry header null not supported assert new entry data null not supported dirty true finally write back if dirty buf flip try while buf has remaining metafc write buf start file offset buf position catch io exception ioe logger error this unexpected io exception ioe return true finally unlock for int i 0 i length i if locked i null lock manager unlock entry offset i locked i file_split file_split batchprocessentries batchprocessor lockmanager lockentry startfileoffset metadata_length entriestoread buflen metadata_length entriestoread bytebuffer bytebuffer buflen hasremaining startfileoffset ioexception ioexception metadata_length metadata_length metadata_length bytebuffer enbuf enbuf metadata_length enbuf curoffset isfree newentry newentry metadata_length bytebuffer metadata_length keycount decrementandget newentry not_modified metadata_length newentry tometadatabuffer newentry newentry hasremaining startfileoffset ioexception ioexception lockmanager unlockentry put back an old entry to store file param entry return code true code if the entry have put back successfully private boolean resolve old entry entry entry map long condition lock map lock digested key entry get digested routing key false if lock map null return false try entry store size store size long offsets entry get offset check for occupied entry with same key for long offset offsets try if is free offset arrays equals get digested key from offset offset entry get digested routing key do nothing return true catch io exception e logger debug this io excception on resolve old entry e check for free entry for long offset offsets try if is free offset write entry entry offset bloom filter add key forked entry get digested routing key key count increment and get return true catch io exception e logger debug this io excception on resolve old entry e return false finally unlock digested key entry get digested routing key false lock map resolveoldentry lockmap lockdigestedkey getdigestedroutingkey lockmap storesize storesize getoffset isfree getdigestedkeyfromoffset getdigestedroutingkey ioexception ioexcception resolveoldentry isfree writeentry bloomfilter addkeyforked getdigestedroutingkey keycount incrementandget ioexception ioexcception resolveoldentry unlockdigestedkey getdigestedroutingkey lockmap private cleaner cleaner private cleaner status user alert cleaner cleaner this cleaner cleaner cleanerstatususeralert public string anchor return store cleaner name public string dismiss button text return l10n get string user alert hide dismissbuttontext getstring useralert public html node gethtml text return new html node get text htmlnode gethtmltext htmlnode gettext public short get priority class return user alert minor getpriorityclass useralert public string get short text if cleaner is resizing return l10n get string salted hash freenet store short resize progress new string name processed total new string name cleaner entries total cleaner entries left cleaner entries total else return l10n get string salted hash freenet store short rebuild progress new string name processed total new string name cleaner entries total cleaner entries left cleaner entries total getshorttext isresizing getstring saltedhashfreenetstore shortresizeprogress entriestotal entriesleft entriestotal getstring saltedhashfreenetstore shortrebuildprogress entriestotal entriesleft entriestotal public string get text if cleaner is resizing return l10n get string salted hash freenet store long resize progress new string name processed total new string name cleaner entries total cleaner entries left cleaner entries total else return l10n get string salted hash freenet store long rebuild progress new string name processed total new string name cleaner entries total cleaner entries left cleaner entries total gettext isresizing getstring saltedhashfreenetstore longresizeprogress entriestotal entriesleft entriestotal getstring saltedhashfreenetstore longrebuildprogress entriestotal entriesleft entriestotal public string get title return l10n get string salted hash freenet store cleaner alert title new string name new string name gettitle getstring saltedhashfreenetstore cleaneralerttitle public object get user identifier return null getuseridentifier public boolean is valid return cleaner is rebuilding cleaner is resizing isvalid isrebuilding isresizing public void is valid boolean validity ignore isvalid public void on dismiss ignore ondismiss public boolean should unregister on dismiss return true shouldunregisterondismiss public boolean user can dismiss return false usercandismiss public boolean is event notification return false iseventnotification public void set user alert manager user alert manager user alert manager if cleaner status user alert null user alert manager register cleaner status user alert setuseralertmanager useralertmanager useralertmanager cleanerstatususeralert useralertmanager cleanerstatususeralert public void set max keys long new store size boolean shrink now throws io exception logger normal this name resize new store size new store size shink now shrink now config lock write lock lock try if new store size this store size return if prev store size 0 logger normal this name resize already in progress ignore resize request return prev store size store size store size new store size write config file finally config lock write lock unlock if cleaner lock try lock cleaner condition signal cleaner lock unlock setmaxkeys newstoresize shrinknow ioexception newstoresize newstoresize shinknow shrinknow configlock writelock newstoresize storesize prevstoresize prevstoresize storesize storesize newstoresize writeconfigfile configlock writelock cleanerlock trylock cleanercondition cleanerlock lock all possible offsets of a key this method would release the locks if any locking operation failed param plain key return code true code if all the offsets are locked private map long condition lock plain key byte plain key boolean use prev store size return lock digested key cipher manager get digested key plain key use prev store size plainkey lockplainkey plainkey useprevstoresize lockdigestedkey ciphermanager getdigestedkey plainkey useprevstoresize private void unlock plain key byte plain key boolean use prev store size map long condition lock map unlock digested key cipher manager get digested key plain key use prev store size lock map unlockplainkey plainkey useprevstoresize lockmap unlockdigestedkey ciphermanager getdigestedkey plainkey useprevstoresize lockmap lock all possible offsets of a key this method would release the locks if any locking operation failed param digested key return code true code if all the offsets are locked private map long condition lock digested key byte digested key boolean use prev store size use a set to prevent duplicated offsets a sorted set to prevent deadlocks sorted set long offsets new tree set long long offset array get offset from digested key digested key store size for long offset offset array offsets add offset if use prev store size prev store size 0 offset array get offset from digested key digested key prev store size for long offset offset array offsets add offset map long condition locked new tree map long condition for long offset offsets condition condition lock manager lock entry offset if condition null break locked put offset condition if locked size offsets size return locked else failed remove the locks for map entry long condition e locked entry set lock manager unlock entry e get key e get value return null digestedkey lockdigestedkey digestedkey useprevstoresize sortedset treeset offsetarray getoffsetfromdigestedkey digestedkey storesize offsetarray useprevstoresize prevstoresize offsetarray getoffsetfromdigestedkey digestedkey prevstoresize offsetarray treemap lockmanager lockentry entryset lockmanager unlockentry getkey getvalue private void unlock digested key byte digested key boolean use prev store size map long condition lock map use a set to prevent duplicated offsets sorted set long offsets new tree set long long offset array get offset from digested key digested key store size for long offset offset array offsets add offset if use prev store size prev store size 0 offset array get offset from digested key digested key prev store size for long offset offset array offsets add offset for long offset offsets lock manager unlock entry offset lock map get offset lock map remove offset unlockdigestedkey digestedkey useprevstoresize lockmap sortedset treeset offsetarray getoffsetfromdigestedkey digestedkey storesize offsetarray useprevstoresize prevstoresize offsetarray getoffsetfromdigestedkey digestedkey prevstoresize offsetarray lockmanager unlockentry lockmap lockmap public class shutdowndb implements runnable public void run shutdown true lock manager shutdown cleaner lock lock try cleaner condition signal all cleaner thread interrupt finally cleaner lock unlock config lock write lock lock try flush and close flags flag dirty clean shutdown write config file finally config lock write lock unlock system out println successfully closed store name lockmanager cleanerlock cleanercondition signalall cleanerthread cleanerlock configlock writelock flushandclose flag_dirty writeconfigfile configlock writelock get offset in the hash table given a plain routing key param plain key param store size return private long get offset from plain key byte plain key long store size return get offset from digested key cipher manager get digested key plain key store size plainkey storesize getoffsetfromplainkey plainkey storesize getoffsetfromdigestedkey ciphermanager getdigestedkey plainkey storesize get offset in the hash table given a digested routing key param digested key param store size return private long get offset from digested key byte digested key long store size long key value fields bytes to long digested key long offsets new long option max probe for int i 0 i option max probe i h 141 i 2 13 i offsets i key value 141 i i 13 i long max value store size return offsets digestedkey storesize getoffsetfromdigestedkey digestedkey storesize keyvalue bytestolong digestedkey option_max_probe option_max_probe keyvalue max_value storesize private atomic long bloom false pos new atomic long public long hits return hits get atomiclong bloomfalsepos atomiclong public long misses return misses get public long writes return writes get public long key count return key count get keycount keycount public long get max keys config lock read lock lock long storesize store size config lock read lock unlock return storesize getmaxkeys configlock readlock _storesize storesize configlock readlock _storesize public long get bloom false positive return bloom false pos get getbloomfalsepositive bloomfalsepos migration public void migration from file store file file key file try system out println migrating from store file random access file storeraf new random access file store file r random access file keyraf key file exists new random access file key file r null byte header new byte header block length byte data new byte data block length byte key new byte full key length long max key storeraf length header block length data block length for int l 0 l max key l if l 1024 0 system out println migrating key l max key wrapper manager signal starting 10 60 1000 max 10 minutes for every 1024 keys boolean key read false storeraf read fully header storeraf read fully data try if keyraf null keyraf read fully key key read true catch io exception e try storable block b callback construct data header null key read key null put b b get routing key b get full key data header true catch key verify exception e system out println kve at block l catch key collision exception e system out println kce at block l catch eof exception eof done catch io exception e e print stack trace migrationfrom storefile keyfile storefile randomaccessfile randomaccessfile storefile randomaccessfile keyfile randomaccessfile keyfile headerblocklength datablocklength fullkeylength maxkey headerblocklength datablocklength maxkey maxkey wrappermanager signalstarting keyread readfully readfully readfully keyread ioexception storableblock keyread getroutingkey getfullkey keyverifyexception keycollisionexception eofexception ioexception printstacktrace public boolean probably in store byte routing key config lock read lock lock try if check bloom return true return bloom filter check filter cipher manager get digested key routing key finally config lock read lock unlock probablyinstore routingkey configlock readlock checkbloom bloomfilter checkfilter ciphermanager getdigestedkey routingkey configlock readlock public class time sorted hashtable t extends comparable t public time sorted hashtable this elements new tree set element t this value to element new hash map t element t timesortedhashtable timesortedhashtable treeset valuetoelement hashmap private static class element t extends comparable t implements comparable element t element long t t v time t value v public int compare to element t o if time o time return 1 if time o time return 1 if value null o value null return 0 if value null o value null return 1 if value null o value null return 1 return value compare to o value compareto compareto push ing an object that is already in the queue moves that object to the most recently used position but doesn t add a duplicate entry in the queue param now public final synchronized void push t value long now assert elements size value to element size if value null throw new null pointer exception element t e value to element get value if e null e new element t now value elements add e value to element put value e else elements remove e e time now elements add e assert elements size value to element size valuetoelement nullpointerexception valuetoelement valuetoelement valuetoelement public final int size return elements size public final synchronized boolean remove value t value assert elements size value to element size element t e value to element remove value if e null return false elements remove e assert elements size value to element size return true removevalue valuetoelement valuetoelement valuetoelement public final synchronized boolean contains value t key return value to element contains key key containsvalue valuetoelement containskey note that this does not automatically promote the key you have to do that by hand with push key value public final synchronized long get time t value element t e value to element remove value if e null return 1 return e time gettime valuetoelement count the number of values after specified timestamp param timestamp return value count public synchronized int count values after long t set element t s elements tail set new element t t null return s size countvaluesafter tailset remove all entries on or before the given time public final synchronized void remove before long t assert elements size value to element size set element t s elements head set new element t t null for iterator element t i s iterator i has next element t e i next value to element remove e value i remove assert elements size value to element size removebefore valuetoelement headset hasnext valuetoelement valuetoelement fixme this is broken if timestamp 1 public final synchronized e object pairs after long timestamp e values array set element t s elements tail set new element t timestamp null long time array new long s size int i 0 for element t e s time array i e time values array i e e value i return new object values array time array pairsafter valuesarray tailset timearray timearray valuesarray valuesarray timearray public class time series impl t extends time series tick extends persistent collection t implements time series t public array list t elements return new array list t this timeseriesimpl timeseries persistentcollection timeseries arraylist arraylist public object to array return elements to array toarray toarray public e e to array e arr return elements to array arr toarray toarray public boolean add t tick long time tick get time iterator iterator index iterator new key time max block time interval new key time index descent order if iterator has next insert in block block iterator next tick else add new block tick return true gettime maxblocktimeinterval descent_order hasnext insertinblock addnewblock class time series iterator extends iterable iterator t time series iterator long from long till pos 1 this till till block iterator index iterator new key from max block time interval new key till index ascent order while block iterator has next block block block block iterator next int n block used tick e block get ticks int l 0 r n while l r int i l r 1 if from e i get time l i 1 else r i assert that l r l n e l get time from if l n if e l get time till pos l curr block block return timeseriesiterator iterableiterator timeseriesiterator blockiterator maxblocktimeinterval ascent_order blockiterator hasnext blockiterator getticks gettime gettime gettime currblock public boolean has next return pos 0 hasnext public t next if pos 0 throw new no such element exception t tick t curr block get ticks pos if pos curr block used if block iterator has next curr block block block iterator next pos 0 else pos 1 return tick if curr block get ticks pos get time till pos 1 return tick nosuchelementexception currblock getticks currblock blockiterator hasnext currblock blockiterator currblock getticks gettime public void remove throw new unsupported operation exception unsupportedoperationexception class time series reverse iterator extends iterable iterator t time series reverse iterator long from long till pos 1 this from from block iterator index iterator new key from max block time interval new key till index descent order while block iterator has next block block block block iterator next int n block used tick e block get ticks int l 0 r n while l r int i l r 1 if till e i get time l i 1 else r i assert that l r l n e l get time till if l 0 if e l 1 get time from pos l 1 curr block block return timeseriesreverseiterator iterableiterator timeseriesreverseiterator blockiterator maxblocktimeinterval descent_order blockiterator hasnext blockiterator getticks gettime gettime gettime currblock public boolean has next return pos 0 hasnext public t next if pos 0 throw new no such element exception t tick t curr block get ticks pos if pos 0 if block iterator has next curr block block block iterator next pos curr block used 1 else pos 1 return tick if curr block get ticks pos get time from pos 1 return tick nosuchelementexception currblock getticks blockiterator hasnext currblock blockiterator currblock currblock getticks gettime public void remove throw new unsupported operation exception unsupportedoperationexception public iterator t iterator return iterator null null true public iterable iterator t iterator date from date till return iterator from till true iterableiterator public iterable iterator t iterator boolean ascent return iterator null null ascent iterableiterator public iterable iterator t iterator date from date till boolean ascent long low from null 0 from get time long high till null long max value till get time return ascent iterable iterator t new time series iterator low high iterable iterator t new time series reverse iterator low high iterableiterator gettime max_value gettime iterableiterator timeseriesiterator iterableiterator timeseriesreverseiterator public date get first time iterator block iterator index iterator if block iterator has next block block block block iterator next return new date block timestamp return null getfirsttime blockiterator blockiterator hasnext blockiterator public date get last time iterator block iterator index iterator null null index descent order if block iterator has next block block block block iterator next return new date block get ticks block used 1 get time return null getlasttime blockiterator descent_order blockiterator hasnext blockiterator getticks gettime public int size return int count ticks countticks public long count ticks long n 0 iterator block iterator index iterator while block iterator has next block block block block iterator next n block used return n countticks blockiterator blockiterator hasnext blockiterator public t get tick date timestamp long time timestamp get time iterator block iterator index iterator new key time max block time interval new key time index ascent order while block iterator has next block block block block iterator next int n block used tick e block get ticks int l 0 r n while l r int i l r 1 if time e i get time l i 1 else r i assert that l r l n e l get time time if l n e l get time time return t e l return null gettick gettime blockiterator maxblocktimeinterval ascent_order blockiterator hasnext blockiterator getticks gettime gettime gettime public boolean has date timestamp return get tick timestamp null gettick public int remove date from date till long low from null 0 from get time long high till null long max value till get time int n removed 0 key from key new key low max block time interval key till key new key high iterator block iterator index iterator from key till key index ascent order while block iterator has next block block block block iterator next int n block used tick e block get ticks int l 0 r n while l r int i l r 1 if low e i get time l i 1 else r i assert that l r l n e l get time low while r n e r get time high r 1 n removed 1 if l 0 r n index remove new key block timestamp block block iterator index iterator from key till key index ascent order block deallocate else if l n l r if l 0 index remove new key block timestamp block block timestamp e r get time index put new key block timestamp block block iterator index iterator from key till key index ascent order while r n e l e r block used l block modify return n removed gettime max_value gettime nremoved fromkey maxblocktimeinterval tillkey blockiterator fromkey tillkey ascent_order blockiterator hasnext blockiterator getticks gettime gettime gettime nremoved blockiterator fromkey tillkey ascent_order gettime blockiterator fromkey tillkey ascent_order nremoved private void add new block tick t block block try block block block class new instance catch exception x throw new storage error storage error constructor failure block class x block timestamp t get time block used 1 block get ticks 0 t index put new key block timestamp block addnewblock blockclass newinstance storageerror storageerror constructor_failure blockclass gettime getticks void insert in block block block tick tick long t tick get time int i n block used tick e block get ticks int l 0 r n while l r i l r 1 if t e i get time l i 1 else r i assert that l r l n e l get time t if r 0 if e n 1 get time t max block time interval n e length add new block tick return if block timestamp t index remove new key block timestamp block block timestamp t index put new key block timestamp block else if r n if t e 0 get time max block time interval n e length add new block tick return if n e length add new block e n 1 for i n i r e i e i 1 else for i n i r i e i e i 1 block used 1 e r tick block modify insertinblock gettime getticks gettime gettime gettime maxblocktimeinterval addnewblock gettime maxblocktimeinterval addnewblock addnewblock time series impl storage storage class block class long max block time interval this block class block class this max block time interval max block time interval block class name class descriptor get class name block class index storage create index long class false timeseriesimpl blockclass maxblocktimeinterval blockclass blockclass maxblocktimeinterval maxblocktimeinterval blockclassname classdescriptor getclassname blockclass createindex time series impl timeseriesimpl time series impl public void on load block class class descriptor load class get storage block class name timeseriesimpl onload blockclass classdescriptor loadclass getstorage blockclassname public void clear iterator block iterator index iterator while block iterator has next block block block block iterator next block deallocate index clear blockiterator blockiterator hasnext blockiterator public void deallocate clear index deallocate super deallocate ssk insert handler nodessk key byte data byte headers short htl peer node source long id node node long start time insert tag tag this node node this uid id this source source this start time start time this key key this htl htl this data data this headers headers this tag tag if htl 0 htl 1 byte pub key hash key get pub key hash pub key node get key pub key hash can commit false logminor logger should log logger minor this sskinserthandler peernode starttime inserttag starttime starttime pubkeyhash getpubkeyhash pubkey getkey pubkeyhash cancommit shouldlog override public string to string return super to string for uid tostring tostring public void run freenet support logger os thread logpid this try real run catch out of memory error e oom handler handleoom e catch throwable t logger error this caught t t finally if logminor logger minor this exiting insert handler run for uid node unlockuid uid true true false false false tag osthread realrun outofmemoryerror oomhandler inserthandler private void real run send accepted message accepted dmt createfnpssk accepted uid pub key null try source send async accepted null this catch not connected exception e1 if logminor logger minor this lost connection to source return if headers null try message filter mf message filter create set type dmt fnpssk insert request headers set field dmt uid uid set source source set timeout data insert timeout message msg node usm wait for mf this if msg null logger normal this failed to receive fnpssk insert request headers for uid return headers short buffer msg get object dmt block headers get data catch disconnected exception e if logminor logger minor this lost connection to source on uid return if data null try message filter mf message filter create set type dmt fnpssk insert request data set field dmt uid uid set source source set timeout data insert timeout message msg node usm wait for mf this if msg null logger normal this failed to receive fnpssk insert request data for uid return data short buffer msg get object dmt data get data catch disconnected exception e if logminor logger minor this lost connection to source on uid return if pub key null wait for pub key if logminor logger minor this waiting for pubkey on uid message filter mfpk message filter create set type dmt fnpssk pub key set field dmt uid uid set source source set timeout pubkey timeout try message pk node usm wait for mfpk this if pk null logger normal this failed to receive fnpssk pub key for uid return byte pubkey as bytes short buffer pk get object dmt pubkey as bytes get data try pub key dsa public key create pubkey as bytes if logminor logger minor this got pubkey on uid pub key message confirm dmt createfnpssk pub key accepted uid try source send async confirm null this catch not connected exception e if logminor logger minor this lost connection to source on uid return catch crypt format exception e logger error this invalid pubkey from source on uid message msg dmt createfnp data insert rejected uid dmt data insert rejected ssk error try source send sync msg this catch not connected exception ee ignore return catch disconnected exception e if logminor logger minor this lost connection to source on uid return try key set pub key pub key block new ssk block data headers key false catch ssk verify exception e1 logger error this invalid ssk from source e1 message msg dmt createfnp data insert rejected uid dmt data insert rejected ssk error try source send sync msg this catch not connected exception e ignore return ssk block stored block node fetch key false if stored block null stored block equals block try request handler sendssk stored block get raw headers stored block get raw data false pub key source uid this catch not connected exception e1 if logminor logger minor this lost connection to source on uid return catch waited too long exception e1 logger error this took too long to send ssk datareply to uid because of throttling return block stored block if logminor logger minor this got block for key for uid if htl 0 message msg dmt createfnp insert reply uid try source send sync msg this catch not connected exception e ignore can commit true finish ssk insert sender success return if htl 0 sender node make insert sender block htl uid source false true boolean received rejected overload false while true synchronized sender try if sender get status ssk insert sender not finished sender wait 5000 catch interrupted exception e ignore if received rejected overload sender received rejected overload received rejected overload true forward it message m dmt createfnp rejected overload uid false try source send sync m this catch not connected exception e if logminor logger minor this lost connection to source return if sender has recently collided forward collision data sender get data headers sender get headers try block new ssk block data headers key true catch ssk verify exception e1 is verified elsewhere throw new error impossible e1 e1 try request handler sendssk headers data false pub key source uid this catch not connected exception e1 if logminor logger minor this lost connection to source on uid return catch waited too long exception e1 logger error this took too long to send ssk datareply to uid because of bwlimiting return int status sender get status if status ssk insert sender not finished continue local rejected overload s fatal internal error counts as overload it d only create a timeout otherwise which is the same thing anyway we really need a good way to deal with nodes that constantly r o if status ssk insert sender timed out status ssk insert sender generated rejected overload status ssk insert sender internal error message msg dmt createfnp rejected overload uid true try source send sync msg this catch not connected exception e if logminor logger minor this lost connection to source return might as well store it anyway if status ssk insert sender timed out status ssk insert sender generated rejected overload can commit true finish status return if status ssk insert sender route not found status ssk insert sender route really not found message msg dmt createfnp route not found uid sender gethtl try source send sync msg this catch not connected exception e if logminor logger minor this lost connection to source return can commit true finish status return if status ssk insert sender success message msg dmt createfnp insert reply uid try source send sync msg this catch not connected exception e if logminor logger minor this lost connection to source return can commit true finish status return otherwise logger error this unknown status code sender get status string message msg dmt createfnp rejected overload uid true try source send sync msg this catch not connected exception e ignore finish status return realrun createfnpsskaccepted pubkey sendasync notconnectedexception messagefilter messagefilter settype fnpsskinsertrequestheaders setfield setsource settimeout data_insert_timeout waitfor fnpsskinsertrequestheaders shortbuffer getobject block_headers getdata disconnectedexception messagefilter messagefilter settype fnpsskinsertrequestdata setfield setsource settimeout data_insert_timeout waitfor fnpsskinsertrequestdata shortbuffer getobject getdata disconnectedexception pubkey messagefilter messagefilter settype fnpsskpubkey setfield setsource settimeout pubkey_timeout waitfor fnpsskpubkey pubkeyasbytes shortbuffer getobject pubkey_as_bytes getdata pubkey dsapublickey pubkeyasbytes pubkey createfnpsskpubkeyaccepted sendasync notconnectedexception cryptformatexception createfnpdatainsertrejected data_insert_rejected_ssk_error sendsync notconnectedexception disconnectedexception setpubkey pubkey sskblock sskverifyexception createfnpdatainsertrejected data_insert_rejected_ssk_error sendsync notconnectedexception sskblock storedblock storedblock storedblock requesthandler storedblock getrawheaders storedblock getrawdata pubkey notconnectedexception waitedtoolongexception storedblock createfnpinsertreply sendsync notconnectedexception cancommit sskinsertsender makeinsertsender receivedrejectedoverload getstatus sskinsertsender not_finished interruptedexception receivedrejectedoverload receivedrejectedoverload receivedrejectedoverload createfnprejectedoverload sendsync notconnectedexception hasrecentlycollided getdata getheaders sskblock sskverifyexception requesthandler pubkey notconnectedexception waitedtoolongexception getstatus sskinsertsender not_finished rejectedoverload r_o sskinsertsender timed_out sskinsertsender generated_rejected_overload sskinsertsender internal_error createfnprejectedoverload sendsync notconnectedexception sskinsertsender timed_out sskinsertsender generated_rejected_overload cancommit sskinsertsender route_not_found sskinsertsender route_really_not_found createfnproutenotfound sendsync notconnectedexception cancommit sskinsertsender createfnpinsertreply sendsync notconnectedexception cancommit getstatusstring createfnprejectedoverload sendsync notconnectedexception if can commit and we have received all the data and it verifies then commit it private void finish int code if logminor logger minor this finishing if can commit try node store block block get key to normalized double catch key collision exception e logger normal this collision on this if code ssk insert sender timed out code ssk insert sender generated rejected overload code ssk insert sender internal error code ssk insert sender route really not found int total sent get total sent bytes int total received get total received bytes if sender null total sent sender get total sent bytes total received sender get total received bytes if logminor logger minor this remote ssk insert cost total sent total received bytes code node node stats remote ssk insert bytes sent average report total sent node node stats remote ssk insert bytes received average report total received if code ssk insert sender success can report both sides node node stats successful ssk insert bytes sent average report total sent node node stats successful ssk insert bytes received average report total received cancommit cancommit getkey tonormalizeddouble keycollisionexception sskinsertsender timed_out sskinsertsender generated_rejected_overload sskinsertsender internal_error sskinsertsender route_really_not_found totalsent gettotalsentbytes totalreceived gettotalreceivedbytes totalsent gettotalsentbytes totalreceived gettotalreceivedbytes totalsent totalreceived nodestats remotesskinsertbytessentaverage totalsent nodestats remotesskinsertbytesreceivedaverage totalreceived sskinsertsender nodestats successfulsskinsertbytessentaverage totalsent nodestats successfulsskinsertbytesreceivedaverage totalreceived public void sent bytes int x synchronized total bytes sync total bytes sent x node node stats insert sent bytes true x sentbytes totalbytessync totalbytessent nodestats insertsentbytes public void received bytes int x synchronized total bytes sync total bytes received x node node stats insert received bytes true x receivedbytes totalbytessync totalbytesreceived nodestats insertreceivedbytes public int get total sent bytes return total bytes sent gettotalsentbytes totalbytessent public int get total received bytes return total bytes received gettotalreceivedbytes totalbytesreceived public void sent payload int x node sent payload x node node stats insert sent bytes true x sentpayload sentpayload nodestats insertsentbytes public int get priority return native thread high priority getpriority nativethread high_priority construct a feedback filter public feedback filter feedbackfilter feedbackfilter construct a feedback filter param distance the distance to move on each iteration param angle the angle to move on each iteration param rotation the amount to rotate on each iteration param zoom the amount to scale on each iteration public feedback filter float distance float angle float rotation float zoom this distance distance this angle angle this rotation rotation this zoom zoom feedbackfilter feedbackfilter specifies the angle of each iteration param angle the angle of each iteration angle see get angle public void set angle float angle this angle angle getangle setangle returns the angle of each iteration return the angle of each iteration see set angle public float get angle return angle setangle getangle specifies the distance to move on each iteration param distance the distance see get distance public void set distance float distance this distance distance getdistance setdistance get the distance to move on each iteration return the distance see set distance public float get distance return distance setdistance getdistance specifies the amount of rotation on each iteration param rotation the angle of rotation angle see get rotation public void set rotation float rotation this rotation rotation getrotation setrotation returns the amount of rotation on each iteration return the angle of rotation angle see set rotation public float get rotation return rotation setrotation getrotation specifies the amount to scale on each iteration param zoom the zoom factor see get zoom public void set zoom float zoom this zoom zoom getzoom setzoom returns the amount to scale on each iteration return the zoom factor see set zoom public float get zoom return zoom setzoom getzoom set the alpha value at the first iteration param start alpha the alpha value min value 0 max value 1 see get start alpha public void set start alpha float start alpha this start alpha start alpha startalpha getstartalpha setstartalpha startalpha startalpha startalpha get the alpha value at the first iteration return the alpha value see set start alpha public float get start alpha return start alpha setstartalpha getstartalpha startalpha set the alpha value at the last iteration param end alpha the alpha value min value 0 max value 1 see get end alpha public void set end alpha float end alpha this end alpha end alpha endalpha getendalpha setendalpha endalpha endalpha endalpha get the alpha value at the last iteration return the alpha value see set end alpha public float get end alpha return end alpha setendalpha getendalpha endalpha set the centre of the effect in the x direction as a proportion of the image size param centrex the center see get centrex public void set centrex float centrex this centrex centrex getcentrex setcentrex get the centre of the effect in the x direction as a proportion of the image size return the center see set centrex public float get centrex return centrex setcentrex getcentrex set the centre of the effect in the y direction as a proportion of the image size param centrey the center see get centrey public void set centrey float centrey this centrey centrey getcentrey setcentrey get the centre of the effect in the y direction as a proportion of the image size return the center see set centrey public float get centrey return centrey setcentrey getcentrey set the centre of the effect as a proportion of the image size param centre the center see get centre public void set centre point2d centre this centrex float centre getx this centrey float centre gety getcentre setcentre get the centre of the effect as a proportion of the image size return the center see set centre public point2d get centre return new point2d float centrex centrey setcentre getcentre set the number of iterations param iterations the number of iterations min value 0 see get iterations public void set iterations int iterations this iterations iterations getiterations setiterations get the number of iterations return the number of iterations see set iterations public int get iterations return iterations setiterations getiterations public buffered image filter buffered image src buffered image dst if dst null dst create compatible dest image src null float cx float src get width centrex float cy float src get height centrey float image radius float math sqrt cx cx cy cy float translatex float distance math cos angle float translatey float distance math sin angle float scale float math exp zoom float rotate rotation if iterations 0 graphics2d g dst create graphics g draw rendered image src null g dispose return dst graphics2d g dst create graphics g draw image src null null for int i 0 i iterations i g set rendering hint rendering hints key antialiasing rendering hints value antialias on g set rendering hint rendering hints key interpolation rendering hints value interpolation bilinear g set composite alpha composite get instance alpha composite src over image math lerp float i iterations 1 start alpha end alpha g translate cx translatex cy translatey g scale scale scale the 0001 works round a bug on windows where draw image throws an array index outof bound exception if rotation 0 g rotate rotate g translate cx cy g draw image src null null g dispose return dst bufferedimage bufferedimage bufferedimage createcompatibledestimage getwidth getheight imageradius creategraphics drawrenderedimage creategraphics drawimage setrenderinghint renderinghints key_antialiasing renderinghints value_antialias_on setrenderinghint renderinghints key_interpolation renderinghints value_interpolation_bilinear setcomposite alphacomposite getinstance alphacomposite src_over imagemath startalpha endalpha drawimage arrayindexoutofboundexception drawimage override public string to string return effects feedback tostring public testnet handler node node2 int testnet port this node node2 this testnet port testnet port logger error this starting testnet server logger error this anonymity mode off system err println starting testnet server system err println anonymity mode off system err println you have no anonymity thank you for running a testnet node this will help the developers to efficiently debug freenet by letting them and anyone else who knows how automatically fetch your log files system err println we repeat you have no anonymity whatsoever do not post anything you do not want to be associated with system err println if you want a real freenet node with anonymity turn off testnet mode system err println note this node will not connect to non testnet nodes for security reasons you can of course run a testnet node and a non testnet node separately uploader new testnet status uploader node 180000 testnethandler testnetport testnetport testnetport testnetstatusuploader public void start node executor execute this testnet handler thread uploader start system err println started testnet handler on port testnet port testnetport public void run freenet support logger os thread logpid this while true set up server socket try server new server socket testnet port logger normal this starting testnet server on port testnet port catch io exception e logger error this could not bind to testnet port testnet port node exit node init exception exit testnet failed return while server is closed try socket s server accept new testnet socket handler s start catch io exception e logger error this testnet failed to accept socket e e logger normal this testnet handler has been stopped restarting osthread serversocket testnetport testnetport ioexception testnetport nodeinitexception exit_testnet_failed isclosed testnetsockethandler ioexception public void rebind int port synchronized server try if server is closed server is bound server close this testnet port port catch io exception e logger error this error while stopping the testnet handler node exit node init exception exit testnet failed return isclosed isbound testnetport ioexception nodeinitexception exit_testnet_failed public int get port return testnet port getport testnetport private socket s public testnet socket handler socket s2 this s s2 testnetsockethandler void start node executor execute this testnet handler for s get inet address at system current time millis getinetaddress currenttimemillis public void run freenet support logger os thread logpid this boolean logminor logger should log logger minor this input stream is null output stream os null try is s get input stream os s get output stream read command input stream reader isr new input stream reader is iso 8859 1 buffered reader br new buffered reader isr string command br read line if command null return if logminor logger minor this command command file logger hook logger hook logger hook node log config handler get file logger hook if logger hook null logger error this could not serve testnet command because no file logger hook output stream writer osw new output stream writer os osw write error could not serve testnet command because no file logger hook return if command equals ignore case list if logminor logger minor this listing available logs output stream writer osw new output stream writer os iso 8859 1 logger hook list available logs osw osw close else if command starts with get if logminor logger minor this sending log command string date command substring get length date format df date format get date time instance date format short date format short locale english df set time zone time zone get time zone gmt date d try d df parse date catch parse exception e if logminor logger minor this cannot parse e for date return logger hook send log by contained date d get time os else if command equals ignore case status if logminor logger minor this sending status output stream writer osw new output stream writer os iso 8859 1 osw write node get status osw close else if command equals ignore case peers if logminor logger minor this sending references output stream writer osw new output stream writer os iso 8859 1 buffered writer bw new buffered writer osw bw write my darknet ref n n simple field set fs node export darknet public field set fs write to bw if node is opennet enabled bw write my opennet ref n n fs node export opennet public field set fs write to bw bw write n n my peers n bw write node peers get darknet peers string to string bw close else logger error this unknown testnet command command catch io exception e logger normal this failure handling testnet connection e finally if is null try is close catch io exception e ignore if os null try os close catch io exception e ignore osthread shouldlog inputstream outputstream getinputstream getoutputstream inputstreamreader inputstreamreader bufferedreader bufferedreader readline fileloggerhook loggerhook loggerhook logconfighandler getfileloggerhook loggerhook fileloggerhook outputstreamwriter outputstreamwriter fileloggerhook equalsignorecase outputstreamwriter outputstreamwriter loggerhook listavailablelogs startswith dateformat dateformat getdatetimeinstance dateformat dateformat settimezone timezone gettimezone parseexception loggerhook sendlogbycontaineddate gettime equalsignorecase outputstreamwriter outputstreamwriter getstatus equalsignorecase outputstreamwriter outputstreamwriter bufferedwriter bufferedwriter simplefieldset exportdarknetpublicfieldset writeto isopennetenabled exportopennetpublicfieldset writeto nmy getdarknetpeersstring tostring ioexception ioexception ioexception final node node testnet enabled callback node node this node node testnetenabledcallback override public boolean get return node testnet enabled testnetenabled override public void set boolean val throws invalid config value exception if node testnet enabled val return throw new invalid config value exception l10n get string testnet handler cannot enable disable on the fly invalidconfigvalueexception testnetenabled invalidconfigvalueexception getstring testnethandler cannotenabledisableonthefly override public boolean is read only return true isreadonly node node testnet port number callback node n this node n testnetportnumbercallback override public integer get return node testnet handler get port testnethandler getport override public void set integer val throws invalid config value exception if get equals val return node testnet handler rebind val invalidconfigvalueexception testnethandler public static testnet handler maybe create node node config config throws node init exception sub config testnet config new sub config node testnet config testnet config register enabled false 1 true switch it to false if we want large scale testing true testnet handler enable testnet handler enable long new testnet enabled callback node boolean enabled testnet config get boolean enabled if enabled get the testnet port testnet config register port node get darknet port number 1000 2 true false testnet handler port testnet handler port long new testnet port number callback node false int port testnet config get int port testnet config finished initialization return new testnet handler node port else testnet config finished initialization return null testnethandler maybecreate nodeinitexception subconfig testnetconfig subconfig testnetconfig testnethandler testnethandler enablelong testnetenabledcallback testnetconfig getboolean testnetconfig getdarknetportnumber testnethandler testnethandler portlong testnetportnumbercallback testnetconfig getint testnetconfig finishedinitialization testnethandler testnetconfig finishedinitialization public final static node create envelope body node envelope node env node new node soap xmlns soap delim soap envelope env node set attribute xmlns soap delim soap xmlns soap xmlns url env node set attribute soap xmlns soap delim encoding style soap encstyle url body node body node new node soap xmlns soap delim soap body env node add node body node return env node createenvelopebodynode envnode envnode setattribute xmlns_url envnode setattribute encodingstyle encstyle_url bodynode envnode addnode bodynode envnode private static parser xml parser public final static void setxml parser parser parser xml parser parser xmlparser setxmlparser xmlparser public final static parser getxml parser return xml parser getxmlparser xmlparser public int message count st message count string message name int message count this message name message name this message count message count messagecount stmessagecount messagename messagecount messagename messagename messagecount messagecount protected statistics toadlet node n node client core core high level simple client client super client this node n this core core stats node node stats peers node peers statisticstoadlet nodeclientcore highlevelsimpleclient nodestats override public string supported methods return get supportedmethods counts the peers in code peer nodes code that have the specified status param peer node statuses the peer nodes statuses param status the status to count return the number of peers that have the specified status private int get peer status count peer node status peer node statuses int status int count 0 for int peer index 0 peer count peer node statuses length peer index peer count peer index if peer node statuses peer index record status continue if peer node statuses peer index get status value status count return count peernodes peernodestatuses getpeerstatuscount peernodestatus peernodestatuses peerindex peercount peernodestatuses peerindex peercount peerindex peernodestatuses peerindex recordstatus peernodestatuses peerindex getstatusvalue private int get count seed servers peer node status peer node statuses int count 0 for int peer index 0 peer index peer node statuses length peer index if peer node statuses peer index is seed server count return count getcountseedservers peernodestatus peernodestatuses peerindex peerindex peernodestatuses peerindex peernodestatuses peerindex isseedserver private int get count seed clients peer node status peer node statuses int count 0 for int peer index 0 peer index peer node statuses length peer index if peer node statuses peer index is seed client count return count getcountseedclients peernodestatus peernodestatuses peerindex peerindex peernodestatuses peerindex peernodestatuses peerindex isseedclient override public void handle get uri uri http request request toadlet context ctx throws toadlet context closed exception io exception redirect exception if ctx is allowed full access super send error page ctx 403 l10n get string toadlet unauthorized title l10n get string toadlet unauthorized return final sub config node config node config get node gather connection statistics peer node status peer node statuses peers get peer node statuses true arrays sort peer node statuses new comparator peer node status public int compare peer node status first node peer node status second node int status difference first node get status value second node get status value if status difference 0 return status difference return 0 int number of connected get peer status count peer node statuses peer manager peer node status connected int number of routing backed off get peer status count peer node statuses peer manager peer node status routing backed off int number of too new get peer status count peer node statuses peer manager peer node status too new int number of too old get peer status count peer node statuses peer manager peer node status too old int number of disconnected get peer status count peer node statuses peer manager peer node status disconnected int number of never connected get peer status count peer node statuses peer manager peer node status never connected int number of disabled get peer status count peer node statuses peer manager peer node status disabled int number of bursting get peer status count peer node statuses peer manager peer node status bursting int number of listening get peer status count peer node statuses peer manager peer node status listening int number of listen only get peer status count peer node statuses peer manager peer node status listen only int number of seed servers get count seed servers peer node statuses int number of seed clients get count seed clients peer node statuses int number of routing disabled get peer status count peer node statuses peer manager peer node status routing disabled int number of clock problem get peer status count peer node statuses peer manager peer node status clock problem int number of conn error get peer status count peer node statuses peer manager peer node status conn error int number of disconnecting peer node status get peer status count peer node statuses peer manager peer node status disconnecting html node page node ctx get page maker get page node l10n full title new string name new string node get my name ctx html node content node ctx get page maker get content node page node fixme we need some nice images final long now system current time millis double my location node get location final long node uptime seconds now node startup time 1000 if ctx is allowed full access content node add child core alerts create summary final int mode ctx get page maker draw mode selection array core request content node double swaps node get swaps double no swaps node get no swaps html node overview table content node add child table class column html node overview table row overview table add child tr html node next table cell overview table row add child td class first node version information box html node version infobox next table cell add child div class infobox draw node version box version infobox jvm stats box html node jvm stats infobox next table cell add child div class infobox drawjvm stats box jvm stats infobox statistic gathering box html node stat gathering box next table cell add child ctx get page maker get infobox l10n statistic gathering title html node stat gathering content ctx get page maker get content node stat gathering box generate a thread dump if node is using wrapper html node thread dump form ctx add form child stat gathering content thread dump form thread dump form add child input new string type name value new string submit get thread dump l10n thread dump button bdb statistics dump html node je stats form ctx add form child stat gathering content je stats form je stats form add child input new string type name value new string submit getje stats dump l10n je dump button get logs html node logs list stat gathering content add child ul if node config config get logger get boolean enabled logs list add child li add child a new string href target new string latestlog blank l10n get logs logs list add child li add child a href translation toadlet toadlet url get override tranlation file add child l10n get string translation toadlet download translations file if mode page maker mode advanced store size box html node store size infobox next table cell add child div class infobox draw store size box store size infobox my location node uptime seconds if number of connected number of routing backed off 0 load balancing box include overall window and rt ts for each request starter group starters core request starters double window starters get window double real window starters get real window html node load stats infobox next table cell add child div class infobox load stats infobox add child div class infobox header load limiting html node load stats content load stats infobox add child div class infobox content html node load stats list load stats content add child ul load stats list add child li global window window load stats list add child li real global window real window load stats list add child li starters stats page line false false load stats list add child li starters stats page line true false load stats list add child li starters stats page line false true load stats list add child li starters stats page line true true load stats list add child li starters diagnostic throttles line false load stats list add child li starters diagnostic throttles line true psuccess box html node success rate box next table cell add child div class infobox success rate box add child div class infobox header success rates html node success rate content success rate box add child div class infobox content stats fill success rate box success rate content html node time detail box next table cell add child div class infobox time detail box add child div class infobox header detailed timings local chk fetches html node timings content time detail box add child div class infobox content stats fill detailed timings box timings content if mode page maker mode advanced number of connected number of routing backed off 0 activity box next table cell overview table row add child td class last html node activity infobox next table cell add child div class infobox draw activity box activity infobox mode page maker mode advanced node status overview box if mode page maker mode advanced html node overview infobox next table cell add child div class infobox draw overview box overview infobox node uptime seconds now swaps no swaps peer statistics box html node peer stats infobox next table cell add child div class infobox draw peer stats box peer stats infobox mode page maker mode advanced number of connected number of routing backed off number of too new number of too old number of disconnected number of never connected number of disabled number of bursting number of listening number of listen only number of seed servers number of seed clients number of routing disabled number of clock problem number of conn error number of disconnecting bandwidth box html node bandwidth infobox next table cell add child div class infobox draw bandwidth box bandwidth infobox node uptime seconds mode page maker mode advanced if mode page maker mode advanced peer routing backoff reason box html node backoff reason infobox next table cell add child div class infobox backoff reason infobox add child div class infobox header peer backoff reasons html node backoff reason content backoff reason infobox add child div class infobox content string routing backoff reasons peers get peer node routing backoff reasons if routing backoff reasons length 0 backoff reason content add child good your node is not backed off from any peers else html node reason list backoff reason content add child ul for int i 0 i routing backoff reasons length i int reason count peers get peer node routing backoff reason size routing backoff reasons i if reason count 0 reason list add child li routing backoff reasons i u00a0 reason count swap statistics box html node location swap infobox next table cell add child div class infobox draw swap stats box location swap infobox my location node uptime seconds swaps no swaps unclaimedfifo message counts box html node unclaimedfifo message counts infobox next table cell add child div class infobox draw unclaimedfifo message counts box unclaimedfifo message counts infobox html node threads priority infobox next table cell add child div class infobox draw thread priority stats box threads priority infobox next table cell overview table row add child td thread usage box html node thread usage infobox next table cell add child div class infobox thread usage infobox add child div class infobox header thread usage html node thread usag handleget httprequest toadletcontext toadletcontextclosedexception ioexception redirectexception isallowedfullaccess senderrorpage getstring unauthorizedtitle getstring subconfig nodeconfig peernodestatus peernodestatuses getpeernodestatuses peernodestatuses peernodestatus peernodestatus firstnode peernodestatus secondnode statusdifference firstnode getstatusvalue secondnode getstatusvalue statusdifference statusdifference numberofconnected getpeerstatuscount peernodestatuses peermanager peer_node_status_connected numberofroutingbackedoff getpeerstatuscount peernodestatuses peermanager peer_node_status_routing_backed_off numberoftoonew getpeerstatuscount peernodestatuses peermanager peer_node_status_too_new numberoftooold getpeerstatuscount peernodestatuses peermanager peer_node_status_too_old numberofdisconnected getpeerstatuscount peernodestatuses peermanager peer_node_status_disconnected numberofneverconnected getpeerstatuscount peernodestatuses peermanager peer_node_status_never_connected numberofdisabled getpeerstatuscount peernodestatuses peermanager peer_node_status_disabled numberofbursting getpeerstatuscount peernodestatuses peermanager peer_node_status_bursting numberoflistening getpeerstatuscount peernodestatuses peermanager peer_node_status_listening numberoflistenonly getpeerstatuscount peernodestatuses peermanager peer_node_status_listen_only numberofseedservers getcountseedservers peernodestatuses numberofseedclients getcountseedclients peernodestatuses numberofroutingdisabled getpeerstatuscount peernodestatuses peermanager peer_node_status_routing_disabled numberofclockproblem getpeerstatuscount peernodestatuses peermanager peer_node_status_clock_problem numberofconnerror getpeerstatuscount peernodestatuses peermanager peer_node_status_conn_error numberofdisconnecting peernodestatus getpeerstatuscount peernodestatuses peermanager peer_node_status_disconnecting htmlnode pagenode getpagemaker getpagenode fulltitle getmyname htmlnode contentnode getpagemaker getcontentnode pagenode currenttimemillis mylocation getlocation nodeuptimeseconds startuptime isallowedfullaccess contentnode addchild createsummary getpagemaker drawmodeselectionarray contentnode getswaps noswaps getnoswaps htmlnode overviewtable contentnode addchild htmlnode overviewtablerow overviewtable addchild htmlnode nexttablecell overviewtablerow addchild htmlnode versioninfobox nexttablecell addchild drawnodeversionbox versioninfobox htmlnode jvmstatsinfobox nexttablecell addchild drawjvmstatsbox jvmstatsinfobox htmlnode statgatheringbox nexttablecell addchild getpagemaker getinfobox statisticgatheringtitle htmlnode statgatheringcontent getpagemaker getcontentnode statgatheringbox isusingwrapper htmlnode threaddumpform addformchild statgatheringcontent threaddumpform threaddumpform addchild getthreaddump threaddumpbutton htmlnode jestatsform addformchild statgatheringcontent jestatsform jestatsform addchild getjestatsdump jedumpbutton htmlnode logslist statgatheringcontent addchild nodeconfig getboolean logslist addchild addchild _blank getlogs logslist addchild addchild translationtoadlet toadlet_url getoverridetranlationfile addchild getstring translationtoadlet downloadtranslationsfile pagemaker mode_advanced htmlnode storesizeinfobox nexttablecell addchild drawstoresizebox storesizeinfobox mylocation nodeuptimeseconds numberofconnected numberofroutingbackedoff rtts requeststartergroup requeststarters getwindow realwindow getrealwindow htmlnode loadstatsinfobox nexttablecell addchild loadstatsinfobox addchild htmlnode loadstatscontent loadstatsinfobox addchild htmlnode loadstatslist loadstatscontent addchild loadstatslist addchild loadstatslist addchild realwindow loadstatslist addchild statspageline loadstatslist addchild statspageline loadstatslist addchild statspageline loadstatslist addchild statspageline loadstatslist addchild diagnosticthrottlesline loadstatslist addchild diagnosticthrottlesline htmlnode successratebox nexttablecell addchild successratebox addchild htmlnode successratecontent successratebox addchild fillsuccessratebox successratecontent htmlnode timedetailbox nexttablecell addchild timedetailbox addchild htmlnode timingscontent timedetailbox addchild filldetailedtimingsbox timingscontent pagemaker mode_advanced numberofconnected numberofroutingbackedoff nexttablecell overviewtablerow addchild htmlnode activityinfobox nexttablecell addchild drawactivitybox activityinfobox pagemaker mode_advanced pagemaker mode_advanced htmlnode overviewinfobox nexttablecell addchild drawoverviewbox overviewinfobox nodeuptimeseconds noswaps htmlnode peerstatsinfobox nexttablecell addchild drawpeerstatsbox peerstatsinfobox pagemaker mode_advanced numberofconnected numberofroutingbackedoff numberoftoonew numberoftooold numberofdisconnected numberofneverconnected numberofdisabled numberofbursting numberoflistening numberoflistenonly numberofseedservers numberofseedclients numberofroutingdisabled numberofclockproblem numberofconnerror numberofdisconnecting htmlnode bandwidthinfobox nexttablecell addchild drawbandwidthbox bandwidthinfobox nodeuptimeseconds pagemaker mode_advanced pagemaker mode_advanced htmlnode backoffreasoninfobox nexttablecell addchild backoffreasoninfobox addchild htmlnode backoffreasoncontent backoffreasoninfobox addchild routingbackoffreasons getpeernoderoutingbackoffreasons routingbackoffreasons backoffreasoncontent addchild htmlnode reasonlist backoffreasoncontent addchild routingbackoffreasons reasoncount getpeernoderoutingbackoffreasonsize routingbackoffreasons reasoncount reasonlist addchild routingbackoffreasons reasoncount htmlnode locationswapinfobox nexttablecell addchild drawswapstatsbox locationswapinfobox mylocation nodeuptimeseconds noswaps unclaimedfifomessagecounts htmlnode unclaimedfifomessagecountsinfobox nexttablecell addchild drawunclaimedfifomessagecountsbox unclaimedfifomessagecountsinfobox htmlnode threadspriorityinfobox nexttablecell addchild drawthreadprioritystatsbox threadspriorityinfobox nexttablecell overviewtablerow addchild htmlnode threadusageinfobox nexttablecell addchild threadusageinfobox addchild htmlnode threadusag arrays sort peer node statuses new comparator peer node status public int compare peer node status first node peer node status second node int status difference first node get status value second node get status value if status difference 0 return status difference return 0 peernodestatuses peernodestatus peernodestatus firstnode peernodestatus secondnode statusdifference firstnode getstatusvalue secondnode getstatusvalue statusdifference statusdifference private void draw reject reasons box html node next table cell boolean local html node reject reasons table new html node table node stats stats node node stats boolean success local stats get local reject reasons table reject reasons table stats get reject reasons table reject reasons table if success return html node reject reasons infobox next table cell add child div class infobox reject reasons infobox add child div class infobox header local local preemptive rejection reasons reject reasons infobox add child div class infobox content add child reject reasons table drawrejectreasonsbox htmlnode nexttablecell htmlnode rejectreasonstable htmlnode nodestats nodestats getlocalrejectreasonstable rejectreasonstable getrejectreasonstable rejectreasonstable htmlnode rejectreasonsinfobox nexttablecell addchild rejectreasonsinfobox addchild rejectreasonsinfobox addchild addchild rejectreasonstable private void draw node version box html node version infobox version infobox add child div class infobox header l10n version title html node version infobox content version infobox add child div class infobox content html node version infobox list version infobox content add child ul version infobox list add child li l10n get string welcome toadlet version new string full version build rev new string version node version integer to string version build number version cvs revision if node starter ext build number node starter recommended ext build number version infobox list add child li l10n get string welcome toadlet ext version with recommended new string build recbuild rev new string integer to string node starter ext build number integer to string node starter recommended ext build number node starter ext revision number else version infobox list add child li l10n get string welcome toadlet ext version new string build rev new string integer to string node starter ext build number node starter ext revision number drawnodeversionbox htmlnode versioninfobox versioninfobox addchild versiontitle htmlnode versioninfoboxcontent versioninfobox addchild htmlnode versioninfoboxlist versioninfoboxcontent addchild versioninfoboxlist addchild getstring welcometoadlet fullversion nodeversion tostring buildnumber cvsrevision nodestarter extbuildnumber nodestarter recommended_ext_build_number versioninfoboxlist addchild getstring welcometoadlet extversionwithrecommended tostring nodestarter extbuildnumber tostring nodestarter recommended_ext_build_number nodestarter extrevisionnumber versioninfoboxlist addchild getstring welcometoadlet extversion tostring nodestarter extbuildnumber nodestarter extrevisionnumber private void drawjvm stats box html node jvm stats infobox jvm stats infobox add child div class infobox header l10n jvm info title html node jvm stats infobox content jvm stats infobox add child div class infobox content html node jvm stats list jvm stats infobox content add child ul runtime rt runtime get runtime long free memory rt free memory long total memory rt total memory long max memory rt max memory long used java mem total memory free memory long allocated java mem total memory long max java mem max memory int available cpus rt available processors int thread count stats get active thread count jvm stats list add child li l10n used memory memory size util format size used java mem true jvm stats list add child li l10n alloc memory memory size util format size allocated java mem true jvm stats list add child li l10n max memory memory size util format size max java mem true jvm stats list add child li l10n threads new string running max new string thousend point format thread count integer to string stats get thread limit jvm stats list add child li l10n cpus count integer to string available cpus jvm stats list add child li l10n java version version system get property java version jvm stats list add child li l10n jvm vendor vendor system get property java vendor jvm stats list add child li l10n jvm version version system get property java vm version jvm stats list add child li l10n os name name system get property os name jvm stats list add child li l10n os version version system get property os version jvm stats list add child li l10n os arch arch system get property os arch drawjvmstatsbox htmlnode jvmstatsinfobox jvmstatsinfobox addchild jvminfotitle htmlnode jvmstatsinfoboxcontent jvmstatsinfobox addchild htmlnode jvmstatslist jvmstatsinfoboxcontent addchild getruntime freememory freememory totalmemory totalmemory maxmemory maxmemory usedjavamem totalmemory freememory allocatedjavamem totalmemory maxjavamem maxmemory availablecpus availableprocessors threadcount getactivethreadcount jvmstatslist addchild usedmemory sizeutil formatsize usedjavamem jvmstatslist addchild allocmemory sizeutil formatsize allocatedjavamem jvmstatslist addchild maxmemory sizeutil formatsize maxjavamem jvmstatslist addchild thousendpoint threadcount tostring getthreadlimit jvmstatslist addchild tostring availablecpus jvmstatslist addchild javaversion getproperty jvmstatslist addchild jvmvendor getproperty jvmstatslist addchild jvmversion getproperty jvmstatslist addchild osname getproperty jvmstatslist addchild osversion getproperty jvmstatslist addchild osarch getproperty private void draw thread priority stats box html node node node add child div class infobox header l10n threads by priority html node threads infobox content node add child div class infobox content int active threads by priority stats get active threads by priority int waiting threads by priority stats get waiting threads by priority html node threads by priority table threads infobox content add child table border 0 html node row threads by priority table add child tr row add child th l10n priority row add child th l10n running row add child th l10n waiting for int i 0 i active threads by priority length i row threads by priority table add child tr row add child td string value of i 1 row add child td string value of active threads by priority i row add child td string value of waiting threads by priority i drawthreadprioritystatsbox htmlnode addchild threadsbypriority htmlnode threadsinfoboxcontent addchild activethreadsbypriority getactivethreadsbypriority waitingthreadsbypriority getwaitingthreadsbypriority htmlnode threadsbyprioritytable threadsinfoboxcontent addchild htmlnode threadsbyprioritytable addchild addchild addchild addchild activethreadsbypriority threadsbyprioritytable addchild addchild valueof addchild valueof activethreadsbypriority addchild valueof waitingthreadsbypriority private void draw database jobs box html node node node add child div class infobox header l10n database jobs by priority html node threads infobox content node add child div class infobox content int jobs by priority core client database executor queued jobs html node threads by priority table threads infobox content add child table border 0 html node row threads by priority table add child tr row add child th l10n priority row add child th l10n waiting for int i 0 i jobs by priority length i row threads by priority table add child tr row add child td string value of i row add child td string value of jobs by priority i drawdatabasejobsbox htmlnode addchild databasejobsbypriority htmlnode threadsinfoboxcontent addchild jobsbypriority clientdatabaseexecutor queuedjobs htmlnode threadsbyprioritytable threadsinfoboxcontent addchild htmlnode threadsbyprioritytable addchild addchild addchild jobsbypriority threadsbyprioritytable addchild addchild valueof addchild valueof jobsbypriority private void draw store size box html node store size infobox double loc long node uptime seconds store size infobox add child div class infobox header datastore html node store size infobox content store size infobox add child div class infobox content html node store size table store size infobox content add child table border 0 html node row store size table add child tr fixme non breaking space stat name row add child th row add child th store row add child th cache final long fix32kb 32 1024 long cached keys node get chk datacache key count long cached size cached keys fix32kb long store keys node get chk datastore key count long store size store keys fix32kb long max cached keys node get chk datacache get max keys long max store keys node get chk datastore get max keys long cache hits node get chk datacache hits long cache misses node get chk datacache misses long cache accesses cache hits cache misses long store hits node get chk datastore hits long store misses node get chk datastore misses long store accesses store hits store misses long cache writes node get chk datacache writes long store writes node get chk datastore writes long cache false pos node get chk datacache get bloom false positive long store false pos node get chk datastore get bloom false positive redflag don t show database version because it s not possible to get it accurately it s a public static constant so it will use the version from compile time of freenet jar row store size table add child tr row add child td keys row add child td thousend point format store keys row add child td thousend point format cached keys row store size table add child tr row add child td capacity row add child td thousend point format max store keys row add child td thousend point format max cached keys row store size table add child tr row add child td data size row add child td size util format size store size true row add child td size util format size cached size true row store size table add child tr row add child td utilization row add child td fix3p1pct format 1 0 store keys max store keys row add child td fix3p1pct format 1 0 cached keys max cached keys row store size table add child tr row add child td read requests row add child td thousend point format store accesses row add child td thousend point format cache accesses row store size table add child tr row add child td successful reads if store accesses 0 row add child td thousend point format store hits else row add child td 0 if cache accesses 0 row add child td thousend point format cache hits else row add child td 0 row store size table add child tr row add child td success rate if store accesses 0 row add child td fix1p4 format 100 0 store hits store accesses else row add child td n a if cache accesses 0 row add child td fix1p4 format 100 0 cache hits cache accesses else row add child td n a row store size table add child tr row add child td writes row add child td thousend point format store writes row add child td thousend point format cache writes overall utilization is not preserved in the new table layout store size list add child li overall size u00a0 thousend point format overall keys u00a0 u00a0 thousend point format max overall keys u00a0 size util format size overall size true u00a0 u00a0 size util format size max overall size true u00a0 overall keys 100 max overall keys row store size table add child tr row add child td access rate row add child td fix1p2 format 1 0 store accesses node uptime seconds sec row add child td fix1p2 format 1 0 cache accesses node uptime seconds sec row store size table add child tr row add child td write rate row add child td fix1p2 format 1 0 store writes node uptime seconds sec row add child td fix1p2 format 1 0 cache writes node uptime seconds sec if store false pos 1 cache false pos 1 row store size table add child tr row add child td false pos row add child td thousend point format store false pos row add child td thousend point format cache false pos location based stats double node loc 0 0 double avg cache location node node stats avg cache location current value double avg store location node node stats avg store location current value double avg cache success node node stats avg cache success current value double avg store success node node stats avg store success current value double furthest cache success node node stats furthest cache success double furthest store success node node stats furthest store success double store dist location distance node loc avg store location double cache dist location distance node loc avg cache location row store size table add child tr row add child td avg location row add child td fix1p4 format avg store location row add child td fix1p4 format avg cache location row store size table add child tr row add child td avg success loc row add child td fix1p4 format avg store success row add child td fix1p4 format avg cache success row store size table add child tr row add child td furthest success row add child td fix1p4 format furthest store success row add child td fix1p4 format furthest cache success row store size table add child tr row add child td avg distance row add child td fix1p4 format store dist row add child td fix1p4 format cache dist long cache location reports node node stats avg cache location count reports long store location reports node node stats avg store location count reports double store percent 1 0 store location reports store keys double cache percent 1 0 cache location reports cached keys cap the reported value at 100 as the decaying average does not account beyond that anyway if store percent 1 0 store percent 1 0 if cache percent 1 0 cache percent 1 0 row store size table add child tr row add child td distance stats row add child td fix3p1pct format store percent row add child td fix3p1pct format cache percent drawstoresizebox htmlnode storesizeinfobox nodeuptimeseconds storesizeinfobox addchild htmlnode storesizeinfoboxcontent storesizeinfobox addchild htmlnode storesizetable storesizeinfoboxcontent addchild htmlnode storesizetable addchild addchild addchild addchild cachedkeys getchkdatacache keycount cachedsize cachedkeys storekeys getchkdatastore keycount storesize storekeys maxcachedkeys getchkdatacache getmaxkeys maxstorekeys getchkdatastore getmaxkeys cachehits getchkdatacache cachemisses getchkdatacache cacheaccesses cachehits cachemisses storehits getchkdatastore storemisses getchkdatastore storeaccesses storehits storemisses cachewrites getchkdatacache storewrites getchkdatastore cachefalsepos getchkdatacache getbloomfalsepositive storefalsepos getchkdatastore getbloomfalsepositive storesizetable addchild addchild addchild thousendpoint storekeys addchild thousendpoint cachedkeys storesizetable addchild addchild addchild thousendpoint maxstorekeys addchild thousendpoint maxcachedkeys storesizetable addchild addchild addchild sizeutil formatsize storesize addchild sizeutil formatsize cachedsize storesizetable addchild addchild addchild storekeys maxstorekeys addchild cachedkeys maxcachedkeys storesizetable addchild addchild addchild thousendpoint storeaccesses addchild thousendpoint cacheaccesses storesizetable addchild addchild storeaccesses addchild thousendpoint storehits addchild cacheaccesses addchild thousendpoint cachehits addchild storesizetable addchild addchild storeaccesses addchild storehits storeaccesses addchild cacheaccesses addchild cachehits cacheaccesses addchild storesizetable addchild addchild addchild thousendpoint storewrites addchild thousendpoint cachewrites storesizelist addchild thousendpoint overallkeys thousendpoint maxoverallkeys sizeutil formatsize overallsize sizeutil formatsize maxoverallsize overallkeys maxoverallkeys storesizetable addchild addchild addchild storeaccesses nodeuptimeseconds addchild cacheaccesses nodeuptimeseconds storesizetable addchild addchild addchild storewrites nodeuptimeseconds addchild cachewrites nodeuptimeseconds storefalsepos cachefalsepos storesizetable addchild addchild addchild thousendpoint storefalsepos addchild thousendpoint cachefalsepos nodeloc avgcachelocation nodestats avgcachelocation currentvalue avgstorelocation nodestats avgstorelocation currentvalue avgcachesuccess nodestats avgcachesuccess currentvalue avgstoresuccess nodestats avgstoresuccess currentvalue furthestcachesuccess nodestats furthestcachesuccess furtheststoresuccess nodestats furtheststoresuccess storedist nodeloc avgstorelocation cachedist nodeloc avgcachelocation storesizetable addchild addchild addchild avgstorelocation addchild avgcachelocation storesizetable addchild addchild addchild avgstoresuccess addchild avgcachesuccess storesizetable addchild addchild addchild furtheststoresuccess addchild furthestcachesuccess storesizetable addchild addchild addchild storedist addchild cachedist cachelocationreports nodestats avgcachelocation countreports storelocationreports nodestats avgstorelocation countreports storepercent storelocationreports storekeys cachepercent cachelocationreports cachedkeys storepercent storepercent cachepercent cachepercent storesizetable addchild addchild addchild storepercent addchild cachepercent private void draw unclaimedfifo message counts box html node unclaimedfifo message counts infobox unclaimedfifo message counts infobox add child div class infobox header unclaimedfifo message counts html node unclaimedfifo message counts infobox content unclaimedfifo message counts infobox add child div class infobox content html node unclaimedfifo message counts list unclaimedfifo message counts infobox content add child ul map string integer unclaimedfifo message counts map node getusm get unclaimedfifo message counts st message count unclaimedfifo message counts array new st message count unclaimedfifo message counts map size int i 0 int total count 0 for map entry string integer e unclaimedfifo message counts map entry set string message name e get key int message count e get value total count total count message count unclaimedfifo message counts array i new st message count message name message count arrays sort unclaimedfifo message counts array new comparator st message count public int compare st message count first count st message count second count return second count message count first count message count sort in descending order for int counts array index 0 counts array count unclaimedfifo message counts array length counts array index counts array count counts array index st message count message count item unclaimedfifo message counts array counts array index int this message count message count item message count double this message percent of total double this message count double total count unclaimedfifo message counts list add child li message count item message name u00a0 this message count u00a0 fix3p1pct format this message percent of total unclaimedfifo message counts list add child li unclaimed messages considered u00a0 total count drawunclaimedfifomessagecountsbox htmlnode unclaimedfifomessagecountsinfobox unclaimedfifomessagecountsinfobox addchild htmlnode unclaimedfifomessagecountsinfoboxcontent unclaimedfifomessagecountsinfobox addchild htmlnode unclaimedfifomessagecountslist unclaimedfifomessagecountsinfoboxcontent addchild unclaimedfifomessagecountsmap getunclaimedfifomessagecounts stmessagecount unclaimedfifomessagecountsarray stmessagecount unclaimedfifomessagecountsmap totalcount unclaimedfifomessagecountsmap entryset messagename getkey messagecount getvalue totalcount totalcount messagecount unclaimedfifomessagecountsarray stmessagecount messagename messagecount unclaimedfifomessagecountsarray stmessagecount stmessagecount firstcount stmessagecount secondcount secondcount messagecount firstcount messagecount countsarrayindex countsarraycount unclaimedfifomessagecountsarray countsarrayindex countsarraycount countsarrayindex stmessagecount messagecountitem unclaimedfifomessagecountsarray countsarrayindex thismessagecount messagecountitem messagecount thismessagepercentoftotal thismessagecount totalcount unclaimedfifomessagecountslist addchild messagecountitem messagename thismessagecount thismessagepercentoftotal unclaimedfifomessagecountslist addchild totalcount arrays sort unclaimedfifo message counts array new comparator st message count public int compare st message count first count st message count second count return second count message count first count message count sort in descending order unclaimedfifomessagecountsarray stmessagecount stmessagecount firstcount stmessagecount secondcount secondcount messagecount firstcount messagecount private void draw swap stats box html node location swap infobox double location long node uptime seconds double swaps double no swaps location swap infobox add child div class infobox header location swaps int started swaps node get started swaps int swaps rejected already locked node get swaps rejected already locked int swaps rejected nowhere to go node get swaps rejected nowhere to go int swaps rejected rate limit node get swaps rejected rate limit int swaps rejected recognizedid node get swaps rejected recognizedid double loc change session node get location change session int average swap time node get average outgoing swap time int send swap interval node get send swap interval html node location swap infobox content location swap infobox add child div class infobox content html node location swap list location swap infobox content add child ul location swap list add child li location u00a0 location if swaps 0 0 location swap list add child li loc change session u00a0 fix1p6sci format loc change session location swap list add child li loc change per swap u00a0 fix1p6sci format loc change session swaps if swaps 0 0 node uptime seconds 60 location swap list add child li loc change per minute u00a0 fix1p6sci format loc change session node uptime seconds 60 0 if swaps 0 0 node uptime seconds 60 location swap list add child li swaps per minute u00a0 fix1p6sci format swaps node uptime seconds 60 0 if no swaps 0 0 node uptime seconds 60 location swap list add child li no swaps per minute u00a0 fix1p6sci format no swaps node uptime seconds 60 0 if swaps 0 0 no swaps 0 0 location swap list add child li swaps per no swaps u00a0 fix1p6sci format swaps no swaps if swaps 0 0 location swap list add child li swaps u00a0 int swaps if no swaps 0 0 location swap list add child li no swaps u00a0 int no swaps if started swaps 0 location swap list add child li started swaps u00a0 started swaps if swaps rejected already locked 0 location swap list add child li swaps rejected already locked u00a0 swaps rejected already locked if swaps rejected nowhere to go 0 location swap list add child li swaps rejected nowhere to go u00a0 swaps rejected nowhere to go if swaps rejected rate limit 0 location swap list add child li swaps rejected rate limit u00a0 swaps rejected rate limit if swaps rejected recognizedid 0 location swap list add child li swaps rejected recognizedid u00a0 swaps rejected recognizedid location swap list add child li average swap time u00a0 time util format time average swap time 2 true location swap list add child li send swap interval u00a0 time util format time send swap interval 2 true drawswapstatsbox htmlnode locationswapinfobox nodeuptimeseconds noswaps locationswapinfobox addchild startedswaps getstartedswaps swapsrejectedalreadylocked getswapsrejectedalreadylocked swapsrejectednowheretogo getswapsrejectednowheretogo swapsrejectedratelimit getswapsrejectedratelimit swapsrejectedrecognizedid getswapsrejectedrecognizedid locchangesession getlocationchangesession averageswaptime getaverageoutgoingswaptime sendswapinterval getsendswapinterval htmlnode locationswapinfoboxcontent locationswapinfobox addchild htmlnode locationswaplist locationswapinfoboxcontent addchild locationswaplist addchild locationswaplist addchild locchangesession locchangesession locationswaplist addchild locchangeperswap locchangesession nodeuptimeseconds locationswaplist addchild locchangeperminute locchangesession nodeuptimeseconds nodeuptimeseconds locationswaplist addchild swapsperminute nodeuptimeseconds noswaps nodeuptimeseconds locationswaplist addchild noswapsperminute noswaps nodeuptimeseconds noswaps locationswaplist addchild swapspernoswaps noswaps locationswaplist addchild noswaps locationswaplist addchild noswaps noswaps startedswaps locationswaplist addchild startedswaps startedswaps swapsrejectedalreadylocked locationswaplist addchild swapsrejectedalreadylocked swapsrejectedalreadylocked swapsrejectednowheretogo locationswaplist addchild swapsrejectednowheretogo swapsrejectednowheretogo swapsrejectedratelimit locationswaplist addchild swapsrejectedratelimit swapsrejectedratelimit swapsrejectedrecognizedid locationswaplist addchild swapsrejectedrecognizedid swapsrejectedrecognizedid locationswaplist addchild averageswaptime timeutil formattime averageswaptime locationswaplist addchild sendswapinterval timeutil formattime sendswapinterval protected static void draw peer stats box html node peer stats infobox boolean advanced mode enabled int number of connected int number of routing backed off int number of too new int number of too old int number of disconnected int number of never connected int number of disabled int number of bursting int number of listening int number of listen only int number of seed servers int number of seed clients int number of routing disabled int number of clock problem int number of conn error int number of disconnecting peer stats infobox add child div class infobox header l10n peer stats title html node peer stats content peer stats infobox add child div class infobox content html node peer stats list peer stats content add child ul if number of connected 0 html node peer stats connected list item peer stats list add child li add child span peer stats connected list item add child span new string class title style new string peer connected l10n dark connected border bottom 1px dotted cursor help l10n dark connected short peer stats connected list item add child span u00a0 number of connected if number of routing backed off 0 html node peer stats routing backed off list item peer stats list add child li add child span peer stats routing backed off list item add child span new string class title style new string peer backed off l10n dark advanced mode enabled backed off busy border bottom 1px dotted cursor help l10n dark advanced mode enabled backed off busy short peer stats routing backed off list item add child span u00a0 number of routing backed off if number of too new 0 html node peer stats too new list item peer stats list add child li add child span peer stats too new list item add child span new string class title style new string peer too new l10n dark too new border bottom 1px dotted cursor help l10n dark too new short peer stats too new list item add child span u00a0 number of too new if number of too old 0 html node peer stats too old list item peer stats list add child li add child span peer stats too old list item add child span new string class title style new string peer too old l10n dark too old border bottom 1px dotted cursor help l10n dark too old short peer stats too old list item add child span u00a0 number of too old if number of disconnected 0 html node peer stats disconnected list item peer stats list add child li add child span peer stats disconnected list item add child span new string class title style new string peer disconnected l10n dark not connected border bottom 1px dotted cursor help l10n dark not connected short peer stats disconnected list item add child span u00a0 number of disconnected if number of never connected 0 html node peer stats never connected list item peer stats list add child li add child span peer stats never connected list item add child span new string class title style new string peer never connected l10n dark never connected border bottom 1px dotted cursor help l10n dark never connected short peer stats never connected list item add child span u00a0 number of never connected if number of disabled 0 html node peer stats disabled list item peer stats list add child li add child span peer stats disabled list item add child span new string class title style new string peer disabled l10n dark disabled border bottom 1px dotted cursor help l10n dark disabled short peer stats disabled list item add child span u00a0 number of disabled if number of bursting 0 html node peer stats bursting list item peer stats list add child li add child span peer stats bursting list item add child span new string class title style new string peer bursting l10n dark bursting border bottom 1px dotted cursor help l10n dark bursting short peer stats bursting list item add child span u00a0 number of bursting if number of listening 0 html node peer stats listening list item peer stats list add child li add child span peer stats listening list item add child span new string class title style new string peer listening l10n dark listening border bottom 1px dotted cursor help l10n dark listening short peer stats listening list item add child span u00a0 number of listening if number of listen only 0 html node peer stats listen only list item peer stats list add child li add child span peer stats listen only list item add child span new string class title style new string peer listen only l10n dark listen only border bottom 1px dotted cursor help l10n dark listen only short peer stats listen only list item add child span u00a0 number of listen only if number of clock problem 0 html node peer stats routing disabled list item peer stats list add child li add child span peer stats routing disabled list item add child span new string class title style new string peer clock problem l10n dark clock problem border bottom 1px dotted cursor help l10n dark clock problem short peer stats routing disabled list item add child span u00a0 number of clock problem if number of conn error 0 html node peer stats routing disabled list item peer stats list add child li add child span peer stats routing disabled list item add child span new string class title style new string peer routing disabled l10n dark conn error border bottom 1px dotted cursor help l10n dark conn error short peer stats routing disabled list item add child span u00a0 number of clock problem if number of disconnecting 0 html node peer stats listen only list item peer stats list add child li add child span peer stats listen only list item add child span new string class title style new string peer disconnecting l10n dark disconnecting border bottom 1px dotted cursor help l10n dark disconnecting short peer stats listen only list item add child span u00a0 number of disconnecting if number of seed servers 0 html node peer stats seed servers list item peer stats list add child li add child span peer stats seed servers list item add child span new string class title style new string peer listening fixme l10n dark seed servers border bottom 1px dotted cursor help l10n dark seed servers short peer stats seed servers list item add child span u00a0 number of seed servers if number of seed clients 0 html node peer stats seed clients list item peer stats list add child li add child span peer stats seed clients list item add child span new string class title style new string peer listening fixme l10n dark seed clients border bottom 1px dotted cursor help l10n dark seed clients short peer stats seed clients list item add child span u00a0 number of seed clients if number of routing disabled 0 html node peer stats routing disabled list item peer stats list add child li add child span peer stats routing disabled list item add child span new string class title style new string peer routing disabled l10n dark routing disabled border bottom 1px dotted cursor help l10n dark routing disabled short peer stats routing disabled list item add child span u00a0 number of routing disabled drawpeerstatsbox htmlnode peerstatsinfobox advancedmodeenabled numberofconnected numberofroutingbackedoff numberoftoonew numberoftooold numberofdisconnected numberofneverconnected numberofdisabled numberofbursting numberoflistening numberoflistenonly numberofseedservers numberofseedclients numberofroutingdisabled numberofclockproblem numberofconnerror numberofdisconnecting peerstatsinfobox addchild peerstatstitle htmlnode peerstatscontent peerstatsinfobox addchild htmlnode peerstatslist peerstatscontent addchild numberofconnected htmlnode peerstatsconnectedlistitem peerstatslist addchild addchild peerstatsconnectedlistitem addchild peer_connected l10ndark l10ndark connectedshort peerstatsconnectedlistitem addchild numberofconnected numberofroutingbackedoff htmlnode peerstatsroutingbackedofflistitem peerstatslist addchild addchild peerstatsroutingbackedofflistitem addchild peer_backed_off l10ndark advancedmodeenabled backedoff l10ndark advancedmodeenabled backedoff peerstatsroutingbackedofflistitem addchild numberofroutingbackedoff numberoftoonew htmlnode peerstatstoonewlistitem peerstatslist addchild addchild peerstatstoonewlistitem addchild peer_too_new l10ndark toonew l10ndark toonewshort peerstatstoonewlistitem addchild numberoftoonew numberoftooold htmlnode peerstatstoooldlistitem peerstatslist addchild addchild peerstatstoooldlistitem addchild peer_too_old l10ndark tooold l10ndark toooldshort peerstatstoooldlistitem addchild numberoftooold numberofdisconnected htmlnode peerstatsdisconnectedlistitem peerstatslist addchild addchild peerstatsdisconnectedlistitem addchild peer_disconnected l10ndark notconnected l10ndark notconnectedshort peerstatsdisconnectedlistitem addchild numberofdisconnected numberofneverconnected htmlnode peerstatsneverconnectedlistitem peerstatslist addchild addchild peerstatsneverconnectedlistitem addchild peer_never_connected l10ndark neverconnected l10ndark neverconnectedshort peerstatsneverconnectedlistitem addchild numberofneverconnected numberofdisabled htmlnode peerstatsdisabledlistitem peerstatslist addchild addchild peerstatsdisabledlistitem addchild peer_disabled l10ndark l10ndark disabledshort peerstatsdisabledlistitem addchild numberofdisabled numberofbursting htmlnode peerstatsburstinglistitem peerstatslist addchild addchild peerstatsburstinglistitem addchild peer_bursting l10ndark l10ndark burstingshort peerstatsburstinglistitem addchild numberofbursting numberoflistening htmlnode peerstatslisteninglistitem peerstatslist addchild addchild peerstatslisteninglistitem addchild peer_listening l10ndark l10ndark listeningshort peerstatslisteninglistitem addchild numberoflistening numberoflistenonly htmlnode peerstatslistenonlylistitem peerstatslist addchild addchild peerstatslistenonlylistitem addchild peer_listen_only l10ndark listenonly l10ndark listenonlyshort peerstatslistenonlylistitem addchild numberoflistenonly numberofclockproblem htmlnode peerstatsroutingdisabledlistitem peerstatslist addchild addchild peerstatsroutingdisabledlistitem addchild peer_clock_problem l10ndark clockproblem l10ndark clockproblemshort peerstatsroutingdisabledlistitem addchild numberofclockproblem numberofconnerror htmlnode peerstatsroutingdisabledlistitem peerstatslist addchild addchild peerstatsroutingdisabledlistitem addchild peer_routing_disabled l10ndark connerror l10ndark connerrorshort peerstatsroutingdisabledlistitem addchild numberofclockproblem numberofdisconnecting htmlnode peerstatslistenonlylistitem peerstatslist addchild addchild peerstatslistenonlylistitem addchild peer_disconnecting l10ndark l10ndark disconnectingshort peerstatslistenonlylistitem addchild numberofdisconnecting numberofseedservers htmlnode peerstatsseedserverslistitem peerstatslist addchild addchild peerstatsseedserverslistitem addchild peer_listening l10ndark seedservers l10ndark seedserversshort peerstatsseedserverslistitem addchild numberofseedservers numberofseedclients htmlnode peerstatsseedclientslistitem peerstatslist addchild addchild peerstatsseedclientslistitem addchild peer_listening l10ndark seedclients l10ndark seedclientsshort peerstatsseedclientslistitem addchild numberofseedclients numberofroutingdisabled htmlnode peerstatsroutingdisabledlistitem peerstatslist addchild addchild peerstatsroutingdisabledlistitem addchild peer_routing_disabled l10ndark routingdisabled l10ndark routingdisabledshort peerstatsroutingdisabledlistitem addchild numberofroutingdisabled private static string l10n string key return l10n get string statistics toadlet key getstring statisticstoadlet private static string l10n dark string key return l10n get string darknet connections toadlet key l10ndark getstring darknetconnectionstoadlet private static string l10n string key string pattern string value return l10n get string statistics toadlet key new string pattern new string value getstring statisticstoadlet private static string l10n string key string patterns string values return l10n get string statistics toadlet key patterns values getstring statisticstoadlet private void draw activity box html node activity infobox boolean advanced mode enabled activity infobox add child div class infobox header l10n dark activity title html node activity infobox content activity infobox add child div class infobox content html node activity list draw activity activity infobox content node int numark fetchers node get numark fetchers if advanced mode enabled activity list null if numark fetchers 0 activity list add child li ark u00a0 fetch u00a0 requests u00a0 numark fetchers activity list add child li fetcher byusk size u00a0 node client core usk manager get fetcher byusk size activity list add child li background fetcher byusk size u00a0 node client core usk manager get background fetcher byusk size activity list add child li temporary background fetcherslru size u00a0 node client core usk manager get temporary background fetcherslru drawactivitybox htmlnode activityinfobox advancedmodeenabled activityinfobox addchild l10ndark activitytitle htmlnode activityinfoboxcontent activityinfobox addchild htmlnode activitylist drawactivity activityinfoboxcontent numarkfetchers getnumarkfetchers advancedmodeenabled activitylist numarkfetchers activitylist addchild u00a0fetch u00a0requests numarkfetchers activitylist addchild fetcherbyusksize clientcore uskmanager getfetcherbyusksize activitylist addchild backgroundfetcherbyusksize clientcore uskmanager getbackgroundfetcherbyusksize activitylist addchild temporarybackgroundfetcherslrusize clientcore uskmanager gettemporarybackgroundfetcherslru static void draw bandwidth html node activity list node node long node uptime seconds boolean is advanced mode enabled long total node collector get totalio if total 0 0 total 1 0 return long total output rate total 0 node uptime seconds long total input rate total 1 node uptime seconds long total payload node get total payload sent long total payload rate total payload node uptime seconds int percent int 100 total payload total 0 long rate node node stats get nodeio stats long delta rate 5 rate 2 1000 if delta 0 long output rate rate 3 rate 0 delta long input rate rate 4 rate 1 delta sub config node config node config get node int output bandwidth limit node config get int output bandwidth limit int input bandwidth limit node config get int input bandwidth limit if input bandwidth limit 1 input bandwidth limit output bandwidth limit 4 activity list add child li l10n input rate new string rate max new string size util format size input rate true size util format size input bandwidth limit true activity list add child li l10n output rate new string rate max new string size util format size output rate true size util format size output bandwidth limit true activity list add child li l10n total input new string total rate new string size util format size total 1 true size util format size total input rate true activity list add child li l10n total output new string total rate new string size util format size total 0 true size util format size total output rate true activity list add child li l10n payload output new string total rate percent new string size util format size total payload true size util format size total payload rate true integer to string percent if is advanced mode enabled long total bytes sentchk requests node node stats getchk request total bytes sent long total bytes sentssk requests node node stats getssk request total bytes sent long total bytes sentchk inserts node node stats getchk insert total bytes sent long total bytes sentssk inserts node node stats getssk insert total bytes sent long total bytes sent offered keys node node stats get offered keys total bytes sent long total bytes send offers node node stats get offers sent bytes sent long total bytes sent swap output node node stats get swapping total bytes sent long total bytes sent auth node node stats get total auth bytes sent long total bytes sent ack only node node stats get notification only packets sent bytes long total bytes sent resends node node stats get resend bytes sent long total bytes sentuom node node stats getuom bytes sent long total bytes sent announce node node stats get announce bytes sent long total bytes sent routing status node node stats get routing status bytes long total bytes sent network coloring node node stats get network coloring sent bytes long total bytes sent ping node node stats get ping sent bytes long total bytes sent probe request node node stats get probe request sent bytes long total bytes sent routed node node stats get routed message sent bytes long total bytes sent disconn node node stats get disconn bytes sent long total bytes sent initial node node stats get initial messages bytes sent long total bytes sent changedip node node stats get changedip bytes sent long total bytes sent node to node node node stats get node to node bytes sent long total bytes sent remaining total 0 total payload total bytes sentchk requests total bytes sentssk requests total bytes sentchk inserts total bytes sentssk inserts total bytes sent offered keys total bytes send offers total bytes sent swap output total bytes sent auth total bytes sent ack only total bytes sent resends total bytes sentuom total bytes sent announce total bytes sent routing status total bytes sent network coloring total bytes sent ping total bytes sent probe request total bytes sent routed total bytes sent disconn total bytes sent initial total bytes sent changedip total bytes sent node to node activity list add child li l10n request output new string chk ssk new string size util format size total bytes sentchk requests true size util format size total bytes sentssk requests true activity list add child li l10n insert output new string chk ssk new string size util format size total bytes sentchk inserts true size util format size total bytes sentssk inserts true activity list add child li l10n offered key output new string total offered new string size util format size total bytes sent offered keys true size util format size total bytes send offers true activity list add child li l10n swap output total size util format size total bytes sent swap output true activity list add child li l10n auth bytes total size util format size total bytes sent auth true activity list add child li l10n ack only bytes total size util format size total bytes sent ack only true activity list add child li l10n resend bytes total size util format size total bytes sent resends true activity list add child li l10n uom bytes total size util format size total bytes sentuom true activity list add child li l10n announce bytes total size util format size total bytes sent announce true activity list add child li l10n admin bytes new string routing status disconn initial changedip new string size util format size total bytes sent routing status true size util format size total bytes sent disconn true size util format size total bytes sent initial true size util format size total bytes sent changedip true activity list add child li l10n debugging bytes new string net coloring ping probe routed new string size util format size total bytes sent network coloring true size util format size total bytes sent ping true size util format size total bytes sent probe request true size util format size total bytes sent routed true activity list add child li l10n node to node bytes total size util format size total bytes sent node to node true activity list add child li l10n unaccounted bytes new string total percent new string size util format size total bytes sent remaining true integer to string int total bytes sent remaining 100 total 0 double sent overhead per second node node stats get sent overhead per second activity list add child li l10n total overhead new string rate percent new string size util format size long sent overhead per second integer to string int 100 sent overhead per second total output rate drawbandwidth htmlnode activitylist nodeuptimeseconds isadvancedmodeenabled gettotalio total_output_rate nodeuptimeseconds total_input_rate nodeuptimeseconds totalpayload gettotalpayloadsent total_payload_rate totalpayload nodeuptimeseconds totalpayload nodestats getnodeiostats output_rate input_rate subconfig nodeconfig outputbandwidthlimit nodeconfig getint outputbandwidthlimit inputbandwidthlimit nodeconfig getint inputbandwidthlimit inputbandwidthlimit inputbandwidthlimit outputbandwidthlimit activitylist addchild inputrate sizeutil formatsize input_rate sizeutil formatsize inputbandwidthlimit activitylist addchild outputrate sizeutil formatsize output_rate sizeutil formatsize outputbandwidthlimit activitylist addchild totalinput sizeutil formatsize sizeutil formatsize total_input_rate activitylist addchild totaloutput sizeutil formatsize sizeutil formatsize total_output_rate activitylist addchild payloadoutput sizeutil formatsize totalpayload sizeutil formatsize total_payload_rate tostring isadvancedmodeenabled totalbytessentchkrequests nodestats getchkrequesttotalbytessent totalbytessentsskrequests nodestats getsskrequesttotalbytessent totalbytessentchkinserts nodestats getchkinserttotalbytessent totalbytessentsskinserts nodestats getsskinserttotalbytessent totalbytessentofferedkeys nodestats getofferedkeystotalbytessent totalbytessendoffers nodestats getofferssentbytessent totalbytessentswapoutput nodestats getswappingtotalbytessent totalbytessentauth nodestats gettotalauthbytessent totalbytessentackonly nodestats getnotificationonlypacketssentbytes totalbytessentresends nodestats getresendbytessent totalbytessentuom nodestats getuombytessent totalbytessentannounce nodestats getannouncebytessent totalbytessentroutingstatus nodestats getroutingstatusbytes totalbytessentnetworkcoloring nodestats getnetworkcoloringsentbytes totalbytessentping nodestats getpingsentbytes totalbytessentproberequest nodestats getproberequestsentbytes totalbytessentrouted nodestats getroutedmessagesentbytes totalbytessentdisconn nodestats getdisconnbytessent totalbytessentinitial nodestats getinitialmessagesbytessent totalbytessentchangedip nodestats getchangedipbytessent totalbytessentnodetonode nodestats getnodetonodebytessent totalbytessentremaining totalpayload totalbytessentchkrequests totalbytessentsskrequests totalbytessentchkinserts totalbytessentsskinserts totalbytessentofferedkeys totalbytessendoffers totalbytessentswapoutput totalbytessentauth totalbytessentackonly totalbytessentresends totalbytessentuom totalbytessentannounce totalbytessentroutingstatus totalbytessentnetworkcoloring totalbytessentping totalbytessentproberequest totalbytessentrouted totalbytessentdisconn totalbytessentinitial totalbytessentchangedip totalbytessentnodetonode activitylist addchild requestoutput sizeutil formatsize totalbytessentchkrequests sizeutil formatsize totalbytessentsskrequests activitylist addchild insertoutput sizeutil formatsize totalbytessentchkinserts sizeutil formatsize totalbytessentsskinserts activitylist addchild offeredkeyoutput sizeutil formatsize totalbytessentofferedkeys sizeutil formatsize totalbytessendoffers activitylist addchild swapoutput sizeutil formatsize totalbytessentswapoutput activitylist addchild authbytes sizeutil formatsize totalbytessentauth activitylist addchild ackonlybytes sizeutil formatsize totalbytessentackonly activitylist addchild resendbytes sizeutil formatsize totalbytessentresends activitylist addchild uombytes sizeutil formatsize totalbytessentuom activitylist addchild announcebytes sizeutil formatsize totalbytessentannounce activitylist addchild adminbytes routingstatus sizeutil formatsize totalbytessentroutingstatus sizeutil formatsize totalbytessentdisconn sizeutil formatsize totalbytessentinitial sizeutil formatsize totalbytessentchangedip activitylist addchild debuggingbytes netcoloring sizeutil formatsize totalbytessentnetworkcoloring sizeutil formatsize totalbytessentping sizeutil formatsize totalbytessentproberequest sizeutil formatsize totalbytessentrouted activitylist addchild nodetonodebytes sizeutil formatsize totalbytessentnodetonode activitylist addchild unaccountedbytes sizeutil formatsize totalbytessentremaining tostring totalbytessentremaining sentoverheadpersecond nodestats getsentoverheadpersecond activitylist addchild totaloverhead sizeutil formatsize sentoverheadpersecond tostring sentoverheadpersecond total_output_rate static html node draw activity html node activity infobox content node node int num inserts node get num insert senders int num localchk inserts node get num localchk inserts int num remotechk inserts node get num remotechk inserts int num localssk inserts node get num localssk inserts int num remotessk inserts node get num remotessk inserts int num requests node get num request senders int num localchk requests node get num localchk requests int num remotechk requests node get num remotechk requests int num localssk requests node get num localssk requests int num remotessk requests node get num remotessk requests int num transferring requests node get num transferring request senders int num transferring request handlers node get num transferring request handlers int numchk offer replys node get numchk offer replies int numssk offer replys node get numssk offer replies int numchk requests num localchk requests num remotechk requests int numssk requests num localssk requests num remotessk requests int numchk inserts num localchk inserts num remotechk inserts int numssk inserts num localssk inserts num remotessk inserts int num incoming turtles node get num incoming turtles if num inserts 0 num requests 0 num transferring requests 0 numchk requests 0 numssk requests 0 numchk inserts 0 numssk inserts 0 num transferring request handlers 0 numchk offer replys 0 numssk offer replys 0 activity infobox content add child l10n no requests return null else html node activity list activity infobox content add child ul if num inserts 0 numchk inserts 0 numssk inserts 0 activity list add child li l10n get string statistics toadlet activity inserts new string total senders ch khandlers ss khandlers local new string integer to string num inserts integer to string numchk inserts integer to string numssk inserts integer to string num localchk inserts num localssk inserts if num requests 0 numchk requests 0 numssk requests 0 activity list add child li l10n get string statistics toadlet activity requests new string total senders ch khandlers ss khandlers local new string integer to string num requests integer to string numchk requests integer to string numssk requests integer to string num localchk requests num localssk requests if num transferring requests 0 num transferring request handlers 0 num incoming turtles 0 activity list add child li l10n get string statistics toadlet transferring requests new string senders receivers turtles new string integer to string num transferring requests integer to string num transferring request handlers integer to string num incoming turtles if numchk offer replys 0 numssk offer replys 0 activity list add child li l10n get string statistics toadlet offer replys new string chk ssk new string integer to string numchk offer replys integer to string numssk offer replys return activity list htmlnode drawactivity htmlnode activityinfoboxcontent numinserts getnuminsertsenders numlocalchkinserts getnumlocalchkinserts numremotechkinserts getnumremotechkinserts numlocalsskinserts getnumlocalsskinserts numremotesskinserts getnumremotesskinserts numrequests getnumrequestsenders numlocalchkrequests getnumlocalchkrequests numremotechkrequests getnumremotechkrequests numlocalsskrequests getnumlocalsskrequests numremotesskrequests getnumremotesskrequests numtransferringrequests getnumtransferringrequestsenders numtransferringrequesthandlers getnumtransferringrequesthandlers numchkofferreplys getnumchkofferreplies numsskofferreplys getnumsskofferreplies numchkrequests numlocalchkrequests numremotechkrequests numsskrequests numlocalsskrequests numremotesskrequests numchkinserts numlocalchkinserts numremotechkinserts numsskinserts numlocalsskinserts numremotesskinserts numincomingturtles getnumincomingturtles numinserts numrequests numtransferringrequests numchkrequests numsskrequests numchkinserts numsskinserts numtransferringrequesthandlers numchkofferreplys numsskofferreplys activityinfoboxcontent addchild norequests htmlnode activitylist activityinfoboxcontent addchild numinserts numchkinserts numsskinserts activitylist addchild getstring statisticstoadlet activityinserts totalsenders chkhandlers sskhandlers tostring numinserts tostring numchkinserts tostring numsskinserts tostring numlocalchkinserts numlocalsskinserts numrequests numchkrequests numsskrequests activitylist addchild getstring statisticstoadlet activityrequests totalsenders chkhandlers sskhandlers tostring numrequests tostring numchkrequests tostring numsskrequests tostring numlocalchkrequests numlocalsskrequests numtransferringrequests numtransferringrequesthandlers numincomingturtles activitylist addchild getstring statisticstoadlet transferringrequests tostring numtransferringrequests tostring numtransferringrequesthandlers tostring numincomingturtles numchkofferreplys numsskofferreplys activitylist addchild getstring statisticstoadlet offerreplys tostring numchkofferreplys tostring numsskofferreplys activitylist private void draw overview box html node overview infobox long node uptime seconds long now double swaps double no swaps overview infobox add child div class infobox header node status overview html node overview infobox content overview infobox add child div class infobox content html node overview list overview infobox content add child ul node status values int bwlimit delay time int stats get bwlimit delay time int node average ping time int stats get node average ping time double number of remote peer locations seen in swaps node get number of remote peer locations seen in swaps darknet int darknet size estimate session stats get darknet size estimate 1 int darknet size estimate24h 0 int darknet size estimate48h 0 if node uptime seconds 24 60 60 24 hours darknet size estimate24h stats get darknet size estimate now 24 60 60 1000 48 hours if node uptime seconds 48 60 60 48 hours darknet size estimate48h stats get darknet size estimate now 48 60 60 1000 48 hours opennet int opennet size estimate session stats get opennet size estimate 1 int opennet size estimate24h 0 int opennet size estimate48h 0 if node uptime seconds 24 60 60 24 hours opennet size estimate24h stats get opennet size estimate now 24 60 60 1000 48 hours if node uptime seconds 48 60 60 48 hours opennet size estimate48h stats get opennet size estimate now 48 60 60 1000 48 hours double routing miss distance stats routing miss distance current value double backed off percent stats backed off percent current value string node uptime string time util format time node uptime seconds 1000 1000 to convert to milliseconds overview list add child li bwlimit delay time u00a0 bwlimit delay time ms overview list add child li node average ping time u00a0 node average ping time ms overview list add child li darknet size estimate session u00a0 darknet size estimate session u00a0nodes if node uptime seconds 24 60 60 24 hours overview list add child li darknet size estimate24h u00a0 darknet size estimate24h u00a0nodes if node uptime seconds 48 60 60 48 hours overview list add child li darknet size estimate48h u00a0 darknet size estimate48h u00a0nodes overview list add child li opennet size estimate session u00a0 opennet size estimate session u00a0nodes if node uptime seconds 24 60 60 24 hours overview list add child li opennet size estimate24h u00a0 opennet size estimate24h u00a0nodes if node uptime seconds 48 60 60 48 hours overview list add child li opennet size estimate48h u00a0 opennet size estimate48h u00a0nodes if number of remote peer locations seen in swaps 0 0 swaps 0 0 no swaps 0 0 overview list add child li avr conn peers per node u00a0 fix6p6 format number of remote peer locations seen in swaps swaps no swaps u00a0peers overview list add child li node uptime u00a0 node uptime string overview list add child li routing miss distance u00a0 fix1p4 format routing miss distance overview list add child li backed off percent u00a0 fix3p1pct format backed off percent overview list add child li p instant reject u00a0 fix3p1pct format stats p reject incoming instantly overview list add child li unclaimedfifo size u00a0 node get unclaimedfifo size overview list add child li ram bucket pool size u00a0 size util format size core temp bucket factory get ram used size util format size core temp bucket factory get max ram used overview list add child li uptime average u00a0 fix3p1pct format node uptime get uptime drawoverviewbox htmlnode overviewinfobox nodeuptimeseconds noswaps overviewinfobox addchild htmlnode overviewinfoboxcontent overviewinfobox addchild htmlnode overviewlist overviewinfoboxcontent addchild bwlimitdelaytime getbwlimitdelaytime nodeaveragepingtime getnodeaveragepingtime numberofremotepeerlocationsseeninswaps getnumberofremotepeerlocationsseeninswaps darknetsizeestimatesession getdarknetsizeestimate darknetsizeestimate24h darknetsizeestimate48h nodeuptimeseconds darknetsizeestimate24h getdarknetsizeestimate nodeuptimeseconds darknetsizeestimate48h getdarknetsizeestimate opennetsizeestimatesession getopennetsizeestimate opennetsizeestimate24h opennetsizeestimate48h nodeuptimeseconds opennetsizeestimate24h getopennetsizeestimate nodeuptimeseconds opennetsizeestimate48h getopennetsizeestimate routingmissdistance routingmissdistance currentvalue backedoffpercent backedoffpercent currentvalue nodeuptimestring timeutil formattime nodeuptimeseconds overviewlist addchild bwlimitdelaytime bwlimitdelaytime overviewlist addchild nodeaveragepingtime nodeaveragepingtime overviewlist addchild darknetsizeestimatesession darknetsizeestimatesession nodeuptimeseconds overviewlist addchild darknetsizeestimate24h darknetsizeestimate24h nodeuptimeseconds overviewlist addchild darknetsizeestimate48h darknetsizeestimate48h overviewlist addchild opennetsizeestimatesession opennetsizeestimatesession nodeuptimeseconds overviewlist addchild opennetsizeestimate24h opennetsizeestimate24h nodeuptimeseconds overviewlist addchild opennetsizeestimate48h opennetsizeestimate48h numberofremotepeerlocationsseeninswaps noswaps overviewlist addchild avrconnpeerspernode numberofremotepeerlocationsseeninswaps noswaps overviewlist addchild nodeuptime nodeuptimestring overviewlist addchild routingmissdistance routingmissdistance overviewlist addchild backedoffpercent backedoffpercent overviewlist addchild pinstantreject prejectincominginstantly overviewlist addchild unclaimedfifosize getunclaimedfifosize overviewlist addchild rambucketpoolsize sizeutil formatsize tempbucketfactory getramused sizeutil formatsize tempbucketfactory getmaxramused overviewlist addchild uptimeaverage getuptime private void draw bandwidth box html node bandwidth infobox long node uptime seconds boolean is advanced mode enabled bandwidth infobox add child div class infobox header l10n bandwidth title html node bandwidth infobox content bandwidth infobox add child div class infobox content html node bandwidth list bandwidth infobox content add child ul draw bandwidth bandwidth list node node uptime seconds is advanced mode enabled drawbandwidthbox htmlnode bandwidthinfobox nodeuptimeseconds isadvancedmodeenabled bandwidthinfobox addchild bandwidthtitle htmlnode bandwidthinfoboxcontent bandwidthinfobox addchild htmlnode bandwidthlist bandwidthinfoboxcontent addchild drawbandwidth bandwidthlist nodeuptimeseconds isadvancedmodeenabled fixme this should probably be moved to nodestats so it can be used by fcp would have to make thread bunch public private void get thread names html node thread usage list int count 0 thread threads while true count math max stats root thread group active count count threads new thread count 2 50 stats root thread group enumerate threads if threads threads length 1 null break linked hash map string thread bunch map new linked hash map string thread bunch int total count 0 for int i 0 i threads length i if threads i null break string name threads i get name if name index of for 1 name name substring 0 name index of for if name index of 1 name name substring 0 name index of if name index of 1 name name substring 0 name index of thread bunch bunch map get name if bunch null bunch count else map put name new thread bunch name 1 total count thread bunch bunches map values to array new thread bunch map size arrays sort bunches new comparator thread bunch public int compare thread bunch b0 thread bunch b1 if b0 count b1 count return 1 if b0 count b1 count return 1 return b0 name compare to b1 name double this thread percent of total for int i 0 i bunches length i this thread percent of total double bunches i count double total count thread usage list add child li bunches i name u00a0 integer to string bunches i count u00a0 fix3p1pct format this thread percent of total threadbunch getthreadnames htmlnode threadusagelist rootthreadgroup activecount rootthreadgroup linkedhashmap threadbunch linkedhashmap threadbunch totalcount getname indexof indexof indexof indexof indexof indexof threadbunch threadbunch totalcount threadbunch toarray threadbunch threadbunch threadbunch threadbunch compareto thisthreadpercentoftotal thisthreadpercentoftotal totalcount threadusagelist addchild tostring thisthreadpercentoftotal arrays sort bunches new comparator thread bunch public int compare thread bunch b0 thread bunch b1 if b0 count b1 count return 1 if b0 count b1 count return 1 return b0 name compare to b1 name threadbunch threadbunch threadbunch compareto private static class thread bunch public thread bunch string name2 int i this name name2 this count i threadbunch threadbunch private void add node circle html node circle table double my location int histogram new int histogram length for int i 0 i histogram length i histogram i 0 html node node circle table row circle table add child tr html node node histogram legend table row circle table add child tr html node node histogram graph table row circle table add child tr html node node circle table cell node circle table row add child td new string class colspan new string first 10 html node node histogram legend cell html node node histogram graph cell html node node circle infobox content node circle table cell add child div new string style class new string position relative height peer circle radius peer circle additional free space 2 px width peer circle radius peer circle additional free space 2 px peercircle node circle infobox content add child span new string style class new string generate peer circle style string 0 false 1 0 mark node circle infobox content add child span new string style class new string generate peer circle style string 0 125 false 1 0 mark node circle infobox content add child span new string style class new string generate peer circle style string 0 25 false 1 0 mark node circle infobox content add child span new string style class new string generate peer circle style string 0 375 false 1 0 mark node circle infobox content add child span new string style class new string generate peer circle style string 0 5 false 1 0 mark node circle infobox content add child span new string style class new string generate peer circle style string 0 625 false 1 0 mark node circle infobox content add child span new string style class new string generate peer circle style string 0 75 false 1 0 mark node circle infobox content add child span new string style class new string generate peer circle style string 0 875 false 1 0 mark node circle infobox content add child span new string style class new string generate peer circle style string 0 875 false 1 0 mark node circle infobox content add child span new string style class new string position absolute top peer circle radius px left peer circle radius peer circle additional free space px mark final object known locs copy stats get known locations 1 final double locations double known locs copy 0 final long timestamps long known locs copy 1 double location long location time double strength 1 0 long now system current time millis long age 1 int histogram index int node count 0 for int i 0 i locations length i node count 1 location locations i location time timestamps i age now location time long value if age max circle age threshold age max circle age threshold strength 1 double age max circle age threshold histogram index int math floor location double value histogram length histogram histogram index node circle infobox content add child span new string style class new string generate peer circle style string location double value false strength connected x node circle infobox content add child span new string style class new string generate peer circle style string my location true 1 0 me x double histogram percent for int i 0 i histogram length i node histogram legend cell node histogram legend table row add child td node histogram graph cell node histogram graph table row add child td style height 100px node histogram legend cell add child div class histogram label add child fix1p1 format double i histogram length histogram percent double histogram i node count don t use html node here to speed things up node histogram graph cell add child div class histogram connected style height fix3pctus format histogram percent width 100 u00a0 div addnodecircle htmlnode circletable mylocation histogram_length histogram_length htmlnode nodecircletablerow circletable addchild htmlnode nodehistogramlegendtablerow circletable addchild htmlnode nodehistogramgraphtablerow circletable addchild htmlnode nodecircletablecell nodecircletablerow addchild htmlnode nodehistogramlegendcell htmlnode nodehistogramgraphcell htmlnode nodecircleinfoboxcontent nodecircletablecell addchild peer_circle_radius peer_circle_additional_free_space peer_circle_radius peer_circle_additional_free_space nodecircleinfoboxcontent addchild generatepeercirclestylestring nodecircleinfoboxcontent addchild generatepeercirclestylestring nodecircleinfoboxcontent addchild generatepeercirclestylestring nodecircleinfoboxcontent addchild generatepeercirclestylestring nodecircleinfoboxcontent addchild generatepeercirclestylestring nodecircleinfoboxcontent addchild generatepeercirclestylestring nodecircleinfoboxcontent addchild generatepeercirclestylestring nodecircleinfoboxcontent addchild generatepeercirclestylestring nodecircleinfoboxcontent addchild generatepeercirclestylestring nodecircleinfoboxcontent addchild peer_circle_radius peer_circle_radius peer_circle_additional_free_space knownlocscopy getknownlocations knownlocscopy knownlocscopy locationtime currenttimemillis histogramindex nodecount nodecount locationtime locationtime longvalue max_circle_age_threshold max_circle_age_threshold max_circle_age_threshold histogramindex doublevalue histogram_length histogramindex nodecircleinfoboxcontent addchild generatepeercirclestylestring doublevalue nodecircleinfoboxcontent addchild generatepeercirclestylestring mylocation histogrampercent histogram_length nodehistogramlegendcell nodehistogramlegendtablerow addchild nodehistogramgraphcell nodehistogramgraphtablerow addchild nodehistogramlegendcell addchild histogramlabel addchild histogram_length histogrampercent nodecount htmlnode nodehistogramgraphcell addchild histogramconnected histogrampercent private void add specialisation html node table double peer location int incoming requests count int incoming request location html node node histogram legend table row table add child tr html node node histogram graph table row table add child tr int my index int peer location incoming request location length for int i 0 i incoming request location length i html node node histogram legend cell node histogram legend table row add child td html node node histogram graph cell node histogram graph table row add child td style height 100px html node node histogram graph cell2 node histogram legend cell add child div class histogram label if i my index node histogram graph cell2 node histogram graph cell2 add child span class me node histogram graph cell2 add child fix1p1 format double i incoming request location length node histogram graph cell add child div new string class style new string histogram connected height fix3pctus format double incoming request location i incoming requests count width 100 u00a0 addspecialisation htmlnode peerlocation incomingrequestscount incomingrequestlocation htmlnode nodehistogramlegendtablerow addchild htmlnode nodehistogramgraphtablerow addchild myindex peerlocation incomingrequestlocation incomingrequestlocation htmlnode nodehistogramlegendcell nodehistogramlegendtablerow addchild htmlnode nodehistogramgraphcell nodehistogramgraphtablerow addchild htmlnode nodehistogramgraphcell2 nodehistogramlegendcell addchild histogramlabel myindex nodehistogramgraphcell2 nodehistogramgraphcell2 addchild nodehistogramgraphcell2 addchild incomingrequestlocation nodehistogramgraphcell addchild histogramconnected incomingrequestlocation incomingrequestscount private void add combined specialisation html node table double peer location int locally originating requests count int locally originating requests int remotely originating requests count int remotely originating requests assert locally originating requests length remotely originating requests length html node node histogram legend table row table add child tr html node node histogram graph table row table add child tr int my index int peer location locally originating requests length for int i 0 i locally originating requests length i html node node histogram legend cell node histogram legend table row add child td html node node histogram graph cell node histogram graph table row add child td style height 100px html node node histogram graph cell2 node histogram legend cell add child div class histogram label if i my index node histogram graph cell2 node histogram graph cell2 add child span class me node histogram graph cell2 add child fix1p1 format double i locally originating requests length node histogram graph cell add child div new string class style new string histogram connected height fix3pctus format double locally originating requests i locally originating requests count width 100 u00a0 node histogram graph cell add child div new string class style new string histogram disconnected height fix3pctus format double remotely originating requests i remotely originating requests count width 100 u00a0 addcombinedspecialisation htmlnode peerlocation locallyoriginatingrequestscount locallyoriginatingrequests remotelyoriginatingrequestscount remotelyoriginatingrequests locallyoriginatingrequests remotelyoriginatingrequests htmlnode nodehistogramlegendtablerow addchild htmlnode nodehistogramgraphtablerow addchild myindex peerlocation locallyoriginatingrequests locallyoriginatingrequests htmlnode nodehistogramlegendcell nodehistogramlegendtablerow addchild htmlnode nodehistogramgraphcell nodehistogramgraphtablerow addchild htmlnode nodehistogramgraphcell2 nodehistogramlegendcell addchild histogramlabel myindex nodehistogramgraphcell2 nodehistogramgraphcell2 addchild nodehistogramgraphcell2 addchild locallyoriginatingrequests nodehistogramgraphcell addchild histogramconnected locallyoriginatingrequests locallyoriginatingrequestscount nodehistogramgraphcell addchild histogramdisconnected remotelyoriginatingrequests remotelyoriginatingrequestscount private void add peer circle html node circle table peer node status peer node statuses double my location int histogram connected new int histogram length int histogram disconnected new int histogram length for int i 0 i histogram length i histogram connected i 0 histogram disconnected i 0 html node peer circle table row circle table add child tr html node peer histogram legend table row circle table add child tr html node peer histogram graph table row circle table add child tr html node peer circle table cell peer circle table row add child td new string class colspan new string first 10 html node peer histogram legend cell html node peer histogram graph cell html node peer circle infobox content peer circle table cell add child div new string style class new string position relative height peer circle radius peer circle additional free space 2 px width peer circle radius peer circle additional free space 2 px peercircle peer circle infobox content add child span new string style class new string generate peer circle style string 0 false 1 0 mark peer circle infobox content add child span new string style class new string generate peer circle style string 0 125 false 1 0 mark peer circle infobox content add child span new string style class new string generate peer circle style string 0 25 false 1 0 mark peer circle infobox content add child span new string style class new string generate peer circle style string 0 375 false 1 0 mark peer circle infobox content add child span new string style class new string generate peer circle style string 0 5 false 1 0 mark peer circle infobox content add child span new string style class new string generate peer circle style string 0 625 false 1 0 mark peer circle infobox content add child span new string style class new string generate peer circle style string 0 75 false 1 0 mark peer circle infobox content add child span new string style class new string position absolute top peer circle radius px left peer circle radius peer circle additional free space px mark peer node status peer node status double peer location double peer distance int histogram index int peer count peer node statuses length int new peer count 0 for int peer index 0 peer index peer count peer index peer node status peer node statuses peer index peer location peer node status get location if peer node status is searchable continue if peer location 0 0 peer location 1 0 continue new peer count peer distance location distance my location peer location histogram index int math floor peer distance histogram length 2 if peer node status is connected histogram connected histogram index else histogram disconnected histogram index peer circle infobox content add child span new string style class new string generate peer circle style string peer location false 1 0 peer node status getp reject peer node status is connected connected disconnected peer node status is opennet o x peer circle infobox content add child span new string style class new string generate peer circle style string my location true 1 0 me x double histogram percent for int i 0 i histogram length i peer histogram legend cell peer histogram legend table row add child td peer histogram graph cell peer histogram graph table row add child td style height 100px peer histogram legend cell add child div class histogram label add child fix1p2 format double i histogram length 2 histogram percent double histogram connected i new peer count peer histogram graph cell add child div new string class style new string histogram connected height fix3pctus format histogram percent width 100 u00a0 histogram percent double histogram disconnected i new peer count peer histogram graph cell add child div new string class style new string histogram disconnected height fix3pctus format histogram percent width 100 u00a0 addpeercircle htmlnode circletable peernodestatus peernodestatuses mylocation histogramconnected histogram_length histogramdisconnected histogram_length histogram_length histogramconnected histogramdisconnected htmlnode peercircletablerow circletable addchild htmlnode peerhistogramlegendtablerow circletable addchild htmlnode peerhistogramgraphtablerow circletable addchild htmlnode peercircletablecell peercircletablerow addchild htmlnode peerhistogramlegendcell htmlnode peerhistogramgraphcell htmlnode peercircleinfoboxcontent peercircletablecell addchild peer_circle_radius peer_circle_additional_free_space peer_circle_radius peer_circle_additional_free_space peercircleinfoboxcontent addchild generatepeercirclestylestring peercircleinfoboxcontent addchild generatepeercirclestylestring peercircleinfoboxcontent addchild generatepeercirclestylestring peercircleinfoboxcontent addchild generatepeercirclestylestring peercircleinfoboxcontent addchild generatepeercirclestylestring peercircleinfoboxcontent addchild generatepeercirclestylestring peercircleinfoboxcontent addchild generatepeercirclestylestring peercircleinfoboxcontent addchild peer_circle_radius peer_circle_radius peer_circle_additional_free_space peernodestatus peernodestatus peerlocation peerdistance histogramindex peercount peernodestatuses newpeercount peerindex peerindex peercount peerindex peernodestatus peernodestatuses peerindex peerlocation peernodestatus getlocation peernodestatus issearchable peerlocation peerlocation newpeercount peerdistance mylocation peerlocation histogramindex peerdistance histogram_length peernodestatus isconnected histogramconnected histogramindex histogramdisconnected histogramindex peercircleinfoboxcontent addchild generatepeercirclestylestring peerlocation peernodestatus getpreject peernodestatus isconnected peernodestatus isopennet peercircleinfoboxcontent addchild generatepeercirclestylestring mylocation histogrampercent histogram_length peerhistogramlegendcell peerhistogramlegendtablerow addchild peerhistogramgraphcell peerhistogramgraphtablerow addchild peerhistogramlegendcell addchild histogramlabel addchild histogram_length histogrampercent histogramconnected newpeercount peerhistogramgraphcell addchild histogramconnected histogrampercent histogrampercent histogramdisconnected newpeercount peerhistogramgraphcell addchild histogramdisconnected histogrampercent private string generate peer circle style string double peer location boolean offset me double strength peer location math pi 2 int offset 0 if offset me make our own peer stand out from the crowd better so we can see it easier offset 10 else offset int peer circle inner radius 1 0 strength double x peer circle additional free space peer circle radius math sin peer location peer circle radius offset double y peer circle radius math cos peer location peer circle radius offset no peer circle additional free space for y disposition return position absolute top fix3p1us format y px left fix3p1us format x px generatepeercirclestylestring peerlocation offsetme peerlocation offsetme peer_circle_inner_radius peer_circle_additional_free_space peer_circle_radius peerlocation peer_circle_radius peer_circle_radius peerlocation peer_circle_radius peer_circle_additional_free_space boolean really removed public boolean to free return freed reallyremoved tofree public boolean to remove return removed toremove public delayed free bucket persistent temp bucket factory factory bucket bucket this factory factory this bucket bucket if bucket null throw new null pointer exception delayedfreebucket persistenttempbucketfactory nullpointerexception public delayed free bucket simple field set fs random source random persistent file tracker f throws cannot create from field set exception factory f freed false bucket serializable to field set bucket util create fs subset underlying random f delayedfreebucket simplefieldset randomsource persistentfiletracker cannotcreatefromfieldsetexception serializabletofieldsetbucketutil public output stream get output stream throws io exception if freed throw new io exception already freed return bucket get output stream outputstream getoutputstream ioexception ioexception getoutputstream public input stream get input stream throws io exception if freed throw new io exception already freed return bucket get input stream inputstream getinputstream ioexception ioexception getinputstream public string get name return bucket get name getname getname public long size return bucket size public boolean is read only return bucket is read only isreadonly isreadonly public void set read only bucket set read only setreadonly setreadonly public bucket get underlying if freed return null return bucket getunderlying public void free synchronized this mutex on just this method make a separate lock if necessary to lock the above if freed return if logger should log logger minor this logger minor this freeing this underlying bucket new exception debug this factory delayed free bucket this freed true shouldlog delayedfreebucket public simple field set to field set if freed logger error this cannot serialize because already freed this return null simple field set fs new simple field set false fs put single type delayed free bucket if bucket instanceof serializable to field set bucket fs put underlying serializable to field set bucket bucket to field set else logger error this cannot serialize underlying bucket bucket return null return fs simplefieldset tofieldset simplefieldset simplefieldset putsingle delayedfreebucket serializabletofieldsetbucket serializabletofieldsetbucket tofieldset public void store to object container container bucket store to container container store this storeto objectcontainer storeto public void remove from object container container if logger should log logger minor this logger minor this removing from database this synchronized this boolean was queued freed removed if freed logger error this asking to remove from database but not freed this new exception error removed true if was queued this factory delayed free bucket this removefrom objectcontainer shouldlog wasqueued wasqueued delayedfreebucket override public string to string return super to string bucket tostring tostring public void object on activate object container container stack trace element elements thread current thread get stack trace if elements null elements length 100 system err println infinite recursion in progress if logger should log logger minor this logger minor this activating super to string bucket get class if bucket this logger error this object on activate on delayed free bucket wrapping self return cascading activation of dependancies container activate bucket 1 objectonactivate objectcontainer stacktraceelement currentthread getstacktrace shouldlog tostring getclass objectonactivate delayedfreebucket public bucket create shadow throws io exception return bucket create shadow createshadow ioexception createshadow public void real free bucket free realfree public void real remove from object container container synchronized this if really removed logger error this calling real remove from twice on this really removed true bucket remove from container container delete this realremovefrom objectcontainer reallyremoved realremovefrom reallyremoved removefrom public boolean object can new object container container if really removed logger error this object can new on this but really removed really removed already freed freed removed removed new exception debug return false return true objectcannew objectcontainer reallyremoved objectcannew reallyremoved public boolean object can update object container container if really removed logger error this object can update on this but really removed really removed already freed freed removed removed new exception debug return false return true objectcanupdate objectcontainer reallyremoved objectcanupdate reallyremoved long seek long pos curr seg 0 while pos segment curr seg size pos segment curr seg size curr seg 1 return pos currseg currseg currseg currseg public void write long pos byte b pos seek pos segment curr seg f write pos b currseg public int read long pos byte b pos seek pos return segment curr seg f read pos b currseg public void sync if no flush for int i segment length i 0 segment i f sync noflush public boolean try lock boolean shared return segment 0 f try lock shared trylock trylock public void lock boolean shared segment 0 f lock shared public void unlock segment 0 f unlock public void close for int i segment length i 0 segment i f close public multi file string segment path long segment size boolean read only boolean no flush this no flush no flush segment new multi file segment segment path length for int i 0 i segment length i multi file segment seg new multi file segment seg f new os file segment path i read only no flush seg size segment size i fixed size seg size segment i seg fixed size segment segment length 1 size segment segment length 1 size long max value multifile segmentpath segmentsize readonly noflush noflush noflush multifilesegment segmentpath multifilesegment multifilesegment osfile segmentpath readonly noflush segmentsize fixedsize fixedsize max_value public multi file multi file segment segments segment segments for int i 0 i segments length i fixed size segments i size fixed size segment segment length 1 size segment segment length 1 size long max value multifile multifilesegment fixedsize fixedsize max_value public multi file string file path boolean read only boolean no flush try stream tokenizer in new stream tokenizer new buffered reader new file reader file path file dir new file file path get parent file this no flush no flush segment new multi file segment 0 int tkn in next token do multi file segment seg new multi file segment if tkn stream tokenizer tt word tkn throw new storage error storage error file access error multifile segment name expected string path in sval tkn in next token if tkn stream tokenizer tt eof if tkn stream tokenizer tt number throw new storage error storage error file access error multifile segment size expected seg size long in nval 1024 kilobytes tkn in next token fixed size seg size if dir null file f new file path if f is absolute f new file dir path path f get path seg f new os file path read only no flush multi file segment new segment new multi file segment segment length 1 system arraycopy segment 0 new segment 0 segment length new segment segment length seg segment new segment while tkn stream tokenizer tt eof fixed size segment segment length 1 size segment segment length 1 size long max value catch io exception x throw new storage error storage error file access error multifile filepath readonly noflush streamtokenizer streamtokenizer bufferedreader filereader filepath filepath getparentfile noflush noflush multifilesegment nexttoken multifilesegment multifilesegment streamtokenizer tt_word storageerror storageerror file_access_error nexttoken streamtokenizer tt_eof streamtokenizer tt_number storageerror storageerror file_access_error nexttoken fixedsize isabsolute getpath osfile readonly noflush multifilesegment newsegment multifilesegment newsegment newsegment newsegment streamtokenizer tt_eof fixedsize max_value ioexception storageerror storageerror file_access_error public long length return fixed size segment segment length 1 f length fixedsize public class persistent resource extends persistent implements i resource public synchronized void shared lock thread curr thread thread current thread try while true if owner curr thread n writers 1 break else if n writers 0 if storage null storage lock object this n readers 1 break else wait catch interrupted exception x throw new storage error storage error lock failed persistentresource iresource sharedlock currthread currentthread currthread nwriters nwriters lockobject nreaders interruptedexception storageerror storageerror lock_failed public boolean shared lock long timeout thread curr thread thread current thread long start time system current time millis synchronized this try while true if owner curr thread n writers 1 return true else if n writers 0 if storage null storage lock object this n readers 1 return true else long curr time system current time millis if curr time start time curr time start time if start time timeout curr time return false wait start time timeout curr time catch interrupted exception x return false sharedlock currthread currentthread starttime currenttimemillis currthread nwriters nwriters lockobject nreaders currtime currenttimemillis currtime starttime currtime starttime starttime currtime starttime currtime interruptedexception public synchronized void exclusive lock thread curr thread thread current thread try while true if owner curr thread n writers 1 break else if n readers 0 n writers 0 n writers 1 owner curr thread if storage null storage lock object this break else wait catch interrupted exception x throw new storage error storage error lock failed exclusivelock currthread currentthread currthread nwriters nreaders nwriters nwriters currthread lockobject interruptedexception storageerror storageerror lock_failed public boolean exclusive lock long timeout thread curr thread thread current thread long start time system current time millis synchronized this try while true if owner curr thread n writers 1 return true else if n readers 0 n writers 0 n writers 1 owner curr thread if storage null storage lock object this return true else long curr time system current time millis if curr time start time curr time start time if start time timeout curr time return false wait start time timeout curr time catch interrupted exception x return false exclusivelock currthread currentthread starttime currenttimemillis currthread nwriters nreaders nwriters nwriters currthread lockobject currtime currenttimemillis currtime starttime currtime starttime starttime currtime starttime currtime interruptedexception public synchronized void unlock if n writers 0 if n writers 0 owner null notify all else if n readers 0 if n readers 0 notify all nwriters nwriters notifyall nreaders nreaders notifyall public synchronized void reset if n writers 0 n writers 0 n readers 0 owner null else if n readers 0 n readers 1 notify all nwriters nwriters nreaders nreaders nreaders notifyall public persistent resource persistentresource public persistent resource public persistent resource storage storage super storage persistentresource persistentresource call this function before ask server socket return true is ssl is available public static boolean available return ssf null serversocket configure ssl support param ssl config public static void init sub config ssl config int config item order 0 tracks config parameters related to a ssl ssl config register ssl enable false config item order true true ssl enable ssl enable long new boolean callback override public boolean get return enable override public void set boolean new value throws invalid config value exception if get equals new value enable new value if enable try load key store createssl context catch exception e enable false e print stack trace system out throw new invalid config value exception cannot enabled ssl config error else ssf null key store null ssl config register ssl key store datastore certs config item order true true ssl key store ssl key store long new string callback override public string get return key store override public void set string new key store throws invalid config value exception if new key store equals get string old key store key store key store new key store try load key store catch exception e key store old key store e print stack trace system out throw new invalid config value exception cannot change keystore file ssl config register ssl key store pass freenet config item order true true ssl key store pass ssl key store pass long new string callback override public string get return key store pass override public void set string new key store pass throws invalid config value exception if new key store pass equals get string old key store pass key store pass key store pass new key store pass try store key store catch exception e key store pass old key store pass e print stack trace system out throw new invalid config value exception cannot change keystore password ssl config register ssl key pass freenet config item order true true ssl key pass ssl key pass long new string callback override public string get return key pass override public void set string new key pass throws invalid config value exception if new key pass equals get string old key pass key pass key pass new key pass try certificate chain keystore get certificate chain freenet key priv key keystore get key freenet old key pass to char array keystore set key entry freenet priv key key pass to char array chain createssl context catch exception e key pass old key pass e print stack trace system out throw new invalid config value exception cannot change private key password ssl config register ssl version ss lv3 config item order true true ssl version ssl version long new string callback override public string get return version override public void set string new version throws invalid config value exception if new version equals get string old version version version new version try createssl context catch exception e version old version e print stack trace system out throw new invalid config value exception cannot change ssl version wrong value enable ssl config get boolean ssl enable key store ssl config get string ssl key store key store pass ssl config get string ssl key store pass key pass ssl config get string ssl key pass version ssl config get string ssl version try keystore key store get instance pkcs12 load key store createssl context catch exception e logger error ssl class cannot load keystore ssl is disable e sslconfig subconfig sslconfig configitemorder sslconfig sslenable configitemorder enablelong booleancallback newvalue invalidconfigvalueexception newvalue newvalue loadkeystore createsslcontext printstacktrace invalidconfigvalueexception keystore sslconfig sslkeystore configitemorder keystore keystorelong stringcallback keystore newkeystore invalidconfigvalueexception newkeystore oldkeystore keystore keystore newkeystore loadkeystore keystore oldkeystore printstacktrace invalidconfigvalueexception sslconfig sslkeystorepass configitemorder keystorepass keystorepasslong stringcallback keystorepass newkeystorepass invalidconfigvalueexception newkeystorepass oldkeystorepass keystorepass keystorepass newkeystorepass storekeystore keystorepass oldkeystorepass printstacktrace invalidconfigvalueexception sslconfig sslkeypass configitemorder keypass keypasslong stringcallback keypass newkeypass invalidconfigvalueexception newkeypass oldkeypass keypass keypass newkeypass getcertificatechain privkey getkey oldkeypass tochararray setkeyentry privkey keypass tochararray createsslcontext keypass oldkeypass printstacktrace invalidconfigvalueexception sslconfig sslversion sslv3 configitemorder versionlong stringcallback newversion invalidconfigvalueexception newversion oldversion newversion createsslcontext oldversion printstacktrace invalidconfigvalueexception sslconfig getboolean sslenable keystore sslconfig getstring sslkeystore keystorepass sslconfig getstring sslkeystorepass keypass sslconfig getstring sslkeypass sslconfig getstring sslversion keystore getinstance loadkeystore createsslcontext new boolean callback override public boolean get return enable booleancallback override public void set boolean new value throws invalid config value exception if get equals new value enable new value if enable try load key store createssl context catch exception e enable false e print stack trace system out throw new invalid config value exception cannot enabled ssl config error else ssf null key store null newvalue invalidconfigvalueexception newvalue newvalue loadkeystore createsslcontext printstacktrace invalidconfigvalueexception keystore new string callback override public string get return key store stringcallback keystore override public void set string new key store throws invalid config value exception if new key store equals get string old key store key store key store new key store try load key store catch exception e key store old key store e print stack trace system out throw new invalid config value exception cannot change keystore file newkeystore invalidconfigvalueexception newkeystore oldkeystore keystore keystore newkeystore loadkeystore keystore oldkeystore printstacktrace invalidconfigvalueexception new string callback override public string get return key store pass stringcallback keystorepass override public void set string new key store pass throws invalid config value exception if new key store pass equals get string old key store pass key store pass key store pass new key store pass try store key store catch exception e key store pass old key store pass e print stack trace system out throw new invalid config value exception cannot change keystore password newkeystorepass invalidconfigvalueexception newkeystorepass oldkeystorepass keystorepass keystorepass newkeystorepass storekeystore keystorepass oldkeystorepass printstacktrace invalidconfigvalueexception new string callback override public string get return key pass stringcallback keypass override public void set string new key pass throws invalid config value exception if new key pass equals get string old key pass key pass key pass new key pass try certificate chain keystore get certificate chain freenet key priv key keystore get key freenet old key pass to char array keystore set key entry freenet priv key key pass to char array chain createssl context catch exception e key pass old key pass e print stack trace system out throw new invalid config value exception cannot change private key password newkeypass invalidconfigvalueexception newkeypass oldkeypass keypass keypass newkeypass getcertificatechain privkey getkey oldkeypass tochararray setkeyentry privkey keypass tochararray createsslcontext keypass oldkeypass printstacktrace invalidconfigvalueexception new string callback override public string get return version stringcallback override public void set string new version throws invalid config value exception if new version equals get string old version version version new version try createssl context catch exception e version old version e print stack trace system out throw new invalid config value exception cannot change ssl version wrong value newversion invalidconfigvalueexception newversion oldversion newversion createsslcontext oldversion printstacktrace invalidconfigvalueexception create server socket with ssl support return server socket with ssl support throws io exception public static server socket create server socket throws io exception if ssf null throw new io exception ssl not initialized return ssf create server socket serversocket serversocket ioexception serversocket createserversocket ioexception ioexception createserversocket private static void load key store throws exception if enable a keystore is where keys and certificates are kept both the keystore and individual private keys should be password protected file input stream fis null try fis new file input stream key store keystore load fis key store pass to char array catch file not found exception fnfe if keystore not exist create keystore and server certificate keystore load null key store pass to char array try class cert and key gen clazz class for name sun security x509 cert and key gen constructor cert and key gen ctor cert and key gen clazz get constructor string class string class object keypair cert and key gen ctor new instance dsa sha1 withdsa class x500 name clazz class for name sun security x509 x500 name constructor x500 name ctor x500 name clazz get constructor string class string class string class string class string class string class object x500 name x500 name ctor new instance freenet freenet freenet method cert and key gen generate cert and key gen clazz get method generate int class cert and key gen generate invoke keypair 1024 method cert and key get private key cert and key gen clazz get method get private key private key priv key private key cert and key get private key invoke keypair certificate chain new certificate 1 method cert and key gen get self certificate cert and key gen clazz get method get self certificate x500 name clazz long class chain 0 certificate cert and key gen get self certificate invoke keypair x500 name 1l 365 24 60 60 keystore set key entry freenet priv key key pass to char array chain store key store createssl context catch class not found exception cnfe throw new unsupported operation exception the jvm you are using is not supported cnfe catch no such method exception nsme throw new unsupported operation exception the jvm you are using is not supported nsme finally closer close fis loadkeystore fileinputstream fileinputstream keystore keystorepass tochararray filenotfoundexception keystorepass tochararray certandkeygenclazz forname certandkeygen certandkeygenctor certandkeygenclazz getconstructor certandkeygenctor newinstance sha1withdsa x500nameclazz forname x500name x500namector x500nameclazz getconstructor x500name x500namector newinstance certandkeygengenerate certandkeygenclazz getmethod certandkeygengenerate certandkeygetprivatekey certandkeygenclazz getmethod getprivatekey privatekey privkey privatekey certandkeygetprivatekey certandkeygengetselfcertificate certandkeygenclazz getmethod getselfcertificate x500nameclazz certandkeygengetselfcertificate x500name setkeyentry privkey keypass tochararray storekeystore createsslcontext classnotfoundexception unsupportedoperationexception nosuchmethodexception unsupportedoperationexception private static void store key store throws exception if enable file output stream fos null try fos new file output stream key store keystore store fos key store pass to char array finally closer close fos storekeystore fileoutputstream fileoutputstream keystore keystorepass tochararray private static void createssl context throws exception if enable a key manager factory is used to create key managers key manager factory kmf key manager factory get instance sunx509 initialize the key manager factory to work with our keystore kmf init keystore key pass to char array an ssl context is an environment for implementing jsse it is used to create a server socket factory ssl context sslc ssl context get instance version initialize the ssl context to work with our key managers sslc init kmf get key managers null null ssf sslc get server socket factory createsslcontext keymanagerfactory keymanagerfactory keymanagerfactory getinstance keymanagerfactory keypass tochararray sslcontext serversocketfactory sslcontext sslcontext getinstance sslcontext getkeymanagers getserversocketfactory encode a string for inclusion in a uri param url string to encode param force list of characters in the form of a string which must be encoded as well as the built in param ascii if true encode all foreign letters if false leave them as is set to true if you are passing to something that needs ascii e g http headers set to false if you are using in an html page return encoded version of string public final static string encode string url string force boolean ascii string builder enc new string builder url length for int i 0 i url length i char c url char at i if safeurl characters index of c 0 ascii c 0200 force null force index of c 0 enc append c else try byte encoded c get bytes utf 8 for int j 0 j encoded length j byte b encoded j int x b 0xff if x 16 enc append 0 else enc append enc append integer to hex string x catch unsupported encoding exception e throw new error impossible jvm doesn t support utf 8 e e return enc to string stringbuilder stringbuilder charat safeurlcharacters indexof indexof getbytes tohexstring unsupportedencodingexception tostring encode a string for inclusion in a uri param url string to encode param ascii if true encode all foreign letters if false leave them as is set to true if you are passing to something that needs ascii e g http headers set to false if you are using in an html page return encoded version of string public static string encode string s boolean ascii return encode s null ascii protected connectivity toadlet high level simple client client node node node client core core super client this node node this core core connectivitytoadlet highlevelsimpleclient nodeclientcore override public string supported methods return get supportedmethods override public void handle get uri uri final http request request toadlet context ctx throws toadlet context closed exception io exception page maker page maker ctx get page maker html node page node page maker get page node l10n get string connectivity toadlet title new string node name new string core get my name ctx html node content node page maker get content node page node add alert summary box if ctx is allowed full access content node add child core alerts create summary final int mode ctx get page maker draw mode selection array core request content node add connection type box node ip detector add connection type box content node udp socket handler handlers node get packet socket handlers html node summary box page maker get infobox l10n get string connectivity toadlet summary title content node add child summary box html node summary content page maker get content node summary box html node table summary content add child table border 0 for int i 0 i handlers length i udp socket handler handler handlers i address tracker tracker handlers i get address tracker html node row table add child tr row add child td handler get title row add child td address tracker status string tracker get port forward status if mode page maker mode advanced one box per port string noreply l10n noreply string local l10n local string remote l10n remote long now system current time millis for int i 0 i handlers length i peers address tracker tracker handlers i get address tracker html node ports box page maker get infobox l10n get string connectivity toadlet by port title new string port status tunnel length new string handlers i get title address tracker status string tracker get port forward status time util format time tracker get longest send receive gap content node add child ports box html node ports content page maker get content node ports box peer address tracker item items tracker get peer address tracker items table ports content add child table html node row table add child tr row add child th l10n address title row add child th l10n sent received title row add child th l10n local remote title row add child th l10n first send lead time row add child th l10n first receive lead time for int j 0 j address tracker item track gaps j row add child th fixme is th valid for int j 0 j items length j row table add child tr peer address tracker item item items j address row add child td item peer to string sent received packets row add child td item packets sent item packets received initiator local remote fixme something more graphical e g colored cells row add child td item packets received 0 noreply item we sent first local remote lead in time to first packet sent row add child td time util format time item time from startup to first sent packet lead in time to first packet received row add child td time util format time item time from startup to first received packet gap gaps item get gaps for int k 0 k address tracker item track gaps k row add child td gaps k received packet at 0 time util format time gaps k gap length time util format time now gaps k received packet at ago fixme l10n i ps ports box page maker get infobox l10n get string connectivity toadlet byip title new string ip status tunnel length new string handlers i get title address tracker status string tracker get port forward status time util format time tracker get longest send receive gap content node add child ports box ports content page maker get content node ports box inet address address tracker item ip items tracker get inet address tracker items table ports content add child table row table add child tr row add child th l10n address title row add child th l10n sent received title row add child th l10n local remote title row add child th l10n first send lead time row add child th l10n first receive lead time for int j 0 j address tracker item track gaps j row add child th fixme is th valid for int j 0 j ip items length j row table add child tr inet address address tracker item item ip items j address row add child td item addr to string sent received packets row add child td item packets sent item packets received initiator local remote fixme something more graphical e g colored cells row add child td item packets received 0 noreply item we sent first local remote lead in time to first packet sent row add child td time util format time item time from startup to first sent packet lead in time to first packet received row add child td time util format time item time from startup to first received packet gap gaps item get gaps for int k 0 k address tracker item track gaps k row add child td gaps k received packet at 0 time util format time gaps k gap length time util format time now gaps k received packet at ago fixme l10n writehtml reply ctx 200 ok page node generate handleget httprequest toadletcontext toadletcontextclosedexception ioexception pagemaker pagemaker getpagemaker htmlnode pagenode pagemaker getpagenode getstring connectivitytoadlet nodename getmyname htmlnode contentnode pagemaker getcontentnode pagenode isallowedfullaccess contentnode addchild createsummary getpagemaker drawmodeselectionarray contentnode ipdetector addconnectiontypebox contentnode udpsockethandler getpacketsockethandlers htmlnode summarybox pagemaker getinfobox getstring connectivitytoadlet summarytitle contentnode addchild summarybox htmlnode summarycontent pagemaker getcontentnode summarybox htmlnode summarycontent addchild udpsockethandler addresstracker getaddresstracker htmlnode addchild addchild gettitle addchild addresstracker statusstring getportforwardstatus pagemaker mode_advanced currenttimemillis addresstracker getaddresstracker htmlnode portsbox pagemaker getinfobox getstring connectivitytoadlet byporttitle tunnellength gettitle addresstracker statusstring getportforwardstatus timeutil formattime getlongestsendreceivegap contentnode addchild portsbox htmlnode portscontent pagemaker getcontentnode portsbox peeraddresstrackeritem getpeeraddresstrackeritems portscontent addchild htmlnode addchild addchild addresstitle addchild sentreceivedtitle addchild localremotetitle addchild firstsendleadtime addchild firstreceiveleadtime addresstrackeritem track_gaps addchild addchild peeraddresstrackeritem addchild tostring addchild packetssent packetsreceived addchild packetsreceived wesentfirst addchild timeutil formattime timefromstartuptofirstsentpacket addchild timeutil formattime timefromstartuptofirstreceivedpacket getgaps addresstrackeritem track_gaps addchild receivedpacketat timeutil formattime gaplength timeutil formattime receivedpacketat ips portsbox pagemaker getinfobox getstring connectivitytoadlet byiptitle tunnellength gettitle addresstracker statusstring getportforwardstatus timeutil formattime getlongestsendreceivegap contentnode addchild portsbox portscontent pagemaker getcontentnode portsbox inetaddressaddresstrackeritem ipitems getinetaddresstrackeritems portscontent addchild addchild addchild addresstitle addchild sentreceivedtitle addchild localremotetitle addchild firstsendleadtime addchild firstreceiveleadtime addresstrackeritem track_gaps addchild ipitems addchild inetaddressaddresstrackeritem ipitems addchild tostring addchild packetssent packetsreceived addchild packetsreceived wesentfirst addchild timeutil formattime timefromstartuptofirstsentpacket addchild timeutil formattime timefromstartuptofirstreceivedpacket getgaps addresstrackeritem track_gaps addchild receivedpacketat timeutil formattime gaplength timeutil formattime receivedpacketat writehtmlreply pagenode private string l10n string key return l10n get string connectivity toadlet key getstring connectivitytoadlet css parser reader r writer w boolean paranoid string check filter callback cb super r w paranoid string check this cb cb this delete errors super delete errors cssparser paranoidstringcheck filtercallback paranoidstringcheck deleteerrors deleteerrors override void throw error string s throws data filter exception html filter throw filter exception s throwerror datafilterexception htmlfilter throwfilterexception override string process importurl string s throws comment exception return html filter sanitizeuri html filter strip quotes s text css null cb true processimporturl commentexception htmlfilter htmlfilter stripquotes override string processurl string s throws comment exception return html filter sanitizeuri html filter strip quotes s null null cb true commentexception htmlfilter htmlfilter stripquotes override void log string s if logger should log logger debug this logger debug this s shouldlog override void log error string s logger error this s logerror public final class boards page extends web page impl public boards page web interface my web interface ft own identity viewer http request request super my web interface viewer request todo auto generated constructor stub boardspage webpageimpl boardspage webinterface mywebinterface ftownidentity httprequest mywebinterface public final void make make boards list makeboardslist private void make boards list html node boards box add content box boards html node new board form add form child boards box self uri new board new board page new board form add child input new string type name value new string hidden own identityid m own identity getuid new board form add child input new string type name value new string submit submit new board display the list of known identities html node boards table boards box add child table border 0 html node row boards table add child tr row add child th name row add child th description row add child th messages row add child th latest message date format date format date format get instance fixme currently we show all boards we should rather show the boards which the identity has selected synchronized m freetalk get message manager iterator board boards m freetalk get message manager board iterator while boards has next board board boards next row boards table add child tr html node name cell row add child th new string align new string left name cell add child new html node a href self uri show board identity m own identity getuid name board get name board get name description row add child td new string align new string center not implemented yet message count row add child td new string align new string center integer to string board message count date of latest message row add child td new string align new string center board get latest message date null date format format board get latest message date makeboardslist htmlnode boardsbox addcontentbox htmlnode newboardform addformchild boardsbox self_uri newboard newboardpage newboardform addchild ownidentityid mownidentity newboardform addchild htmlnode boardstable boardsbox addchild htmlnode boardstable addchild addchild addchild addchild addchild dateformat dateformat dateformat getinstance mfreetalk getmessagemanager mfreetalk getmessagemanager boarditerator hasnext boardstable addchild htmlnode namecell addchild namecell addchild htmlnode self_uri showboard mownidentity getname getname addchild addchild tostring messagecount addchild getlatestmessagedate dateformat getlatestmessagedate public static void main string args throws fs parse exception peer parse exception chk encode exception invalid threshold exception node init exception reference signature verification exception interrupted exception unsupported encoding exception chk verify exception chk decode exception string name real node request insert test file wd new file name if file util remove all wd system err println mass delete failed test may not be accurate system exit exit cannot delete old data wd mkdir note global test init returns in ignored random source node starter global test init name false logger error freenet node location normal freenet node simulator real node minor freenet node insert minor freenet node request minor freenet node node minor node starter global test init name false logger error freenet node location minor freenet io comm minor freenet node node dispatcher minor freenet node simulator minor freenet node peer manager minor freenet node request sender minor node starter global test init name false logger error freenet node fnp minor freenet node packet minor freenet io comm minor freenet node peer node minor freenet node darknet peer node minor node starter global test init name false logger error true system out println busy network test inserts retrieves in quantity stress test system out println dummy random source random new dummy random source diffie hellman init random node nodes new node number of nodes logger normal real node routing test class creating nodes executor executor new pooled executor for int i 0 i number of nodes i nodes i node starter create test node 5001 i 0 name false true false max htl 20 5 random executor 500 number of nodes chk block data length chk block total headers length 100 true enable swapping false enable ulprs enable per node failure tables enable swap queueing enable packet coalescing 8000 enable foaf false null logger normal real node routing test class created node i now link them up make kleinberg network nodes start with ideal locations degree force neighbour connections logger normal real node routing test class added random links for int i 0 i number of nodes i nodes i start false system err println started node i nodes length wait for all connected nodes wait for ping average 0 95 nodes random max pings 1000 system out println system out println ping average 95 lets do some inserts requests system out println high level simple client clients new high level simple client nodes length for int i 0 i clients length i clients i nodes i client core make client request starter immediate splitfile priority class insert 100 keys into random nodes clientchk keys new clientchk insert keys string base string system current time millis for int i 0 i insert keys i system err println inserting i of insert keys int node1 random next int number of nodes node random node nodes node1 string data string base string i byte data data string get bytes utf 8 clientchk block block block clientchk block encode data false false short 1 0 clientchk chk clientchk block get client key byte enc data block get data byte enc headers block get headers clientchk block new block new clientchk block enc data enc headers chk true keys i chk logger minor real node request insert test class decoded new string new block memory decode logger normal real node request insert test class chk chk geturi logger minor real node request insert test class headers hex util bytes to hex block get headers insert it try random node client core real put block true logger error real node request insert test class inserted to node1 logger minor real node request insert test class data fields hash code enc data headers fields hash code enc headers catch freenet node low level put exception put ex logger error real node request insert test class insert failed put ex system err println insert failed put ex system exit exit insert failed now queue requests for each key on every node for int i 0 i insert keys i clientchk key keys i system err println queueing requests for i of insert keys for int j 0 j nodes length j clients j prefetch key geturi 24 60 60 1000 32768 null long total running requests 0 for int j 0 j nodes length j total running requests nodes j client core count transient queued requests system err println running requests total running requests now wait until finished how while true long total running requests 0 for int i 0 i nodes length i total running requests nodes i client core count transient queued requests system err println running requests total running requests if total running requests 0 break thread sleep 1000 system exit 0 fsparseexception peerparseexception chkencodeexception invalidthresholdexception nodeinitexception referencesignatureverificationexception interruptedexception unsupportedencodingexception chkverifyexception chkdecodeexception realnoderequestinserttest fileutil removeall exit_cannot_delete_old_data globaltestinit nodestarter globaltestinit realnode nodestarter globaltestinit nodedispatcher peermanager requestsender nodestarter globaltestinit peernode darknetpeernode nodestarter globaltestinit dummyrandomsource dummyrandomsource diffiehellman number_of_nodes realnoderoutingtest pooledexecutor number_of_nodes nodestarter createtestnode max_htl number_of_nodes chkblock data_length chkblock total_headers_length enable_swapping enable_ulprs enable_per_node_failure_tables enable_swap_queueing enable_packet_coalescing enable_foaf realnoderoutingtest makekleinbergnetwork start_with_ideal_locations force_neighbour_connections realnoderoutingtest number_of_nodes waitforallconnected waitforpingaverage max_pings highlevelsimpleclient highlevelsimpleclient clientcore makeclient requeststarter immediate_splitfile_priority_class insert_keys basestring currenttimemillis insert_keys insert_keys nextint number_of_nodes randomnode datastring basestring datastring getbytes clientchkblock clientchkblock getclientkey encdata getdata encheaders getheaders clientchkblock newblock clientchkblock encdata encheaders realnoderequestinserttest newblock memorydecode realnoderequestinserttest realnoderequestinserttest hexutil bytestohex getheaders randomnode clientcore realput realnoderequestinserttest realnoderequestinserttest hashcode encdata hashcode encheaders lowlevelputexception putex realnoderequestinserttest putex putex exit_insert_failed insert_keys insert_keys totalrunningrequests totalrunningrequests clientcore counttransientqueuedrequests totalrunningrequests totalrunningrequests totalrunningrequests clientcore counttransientqueuedrequests totalrunningrequests totalrunningrequests public abstract class storage listener this metod is called during database open when database was not close normally and has to be recovered storagelistener public void database corrupted this method is called after completion of recovery public void recovery completed databasecorrupted recoverycompleted this method is called when garbage collection is started ether explicitly by invocation of storage gc method either implicitly after allocation of some amount of memory this method is called when unreferenced object is deallocated from database it is possible to get instance of the object using code storage get object by oid code method param cls class of deallocated object param oid object identifier of deallocated object getobjectbyoid this method is called when garbage collection is completed param n deallocated objects number of deallocated objects ndeallocatedobjects handle replication error param host address of host replication to which is failed null if error jappens at slave node return code true code if host should be reconnected and attempt to send data to it should be repeated code false code if no more attmpts to communicate with this host should be performed public boolean replication error string host return false replicationerror this method is called when runtime error happen during execution of jsql query public void jsql runtime error jsql runtime exception x jsqlruntimeerror jsqlruntimeexception sequential search is performed for query execution param query execfuted query public void sequential search performed string query sequentialsearchperformed this method is called by xml exporter if database correuption or some other reasons makes export of the object not possible param oid object identified param x catched exception public class grayscale colormap implements colormap public grayscale colormap grayscalecolormap grayscalecolormap convert a value in the range 0 1 to an rgb color param v a value in the range 0 1 return an rgb color public int get color float v int n int v 255 if n 0 n 0 else if n 255 n 255 return 0xff000000 n 16 n 8 n getcolor public persistent put string identifier freeneturi uri int verbosity short priority class short upload from freeneturi targeturi short persistence type file orig filename string mime type boolean global long size string client token boolean started int max retries string target filename boolean binary blob this identifier identifier this uri uri this verbosity verbosity this priority class priority class this upload from upload from this targeturi targeturi this persistence type persistence type this orig filename orig filename this mime type mime type this global global this size size this token client token this started started this max retries max retries this target filename target filename this binary blob binary blob persistentput priorityclass uploadfrom persistencetype origfilename mimetype clienttoken maxretries targetfilename binaryblob priorityclass priorityclass uploadfrom uploadfrom persistencetype persistencetype origfilename origfilename mimetype mimetype clienttoken maxretries maxretries targetfilename targetfilename binaryblob binaryblob override public simple field set get field set simple field set fs new simple field set true fs put single identifier identifier fs put single uri uri to string false false fs put verbosity verbosity fs put priority class priority class fs put single upload from client put message upload from string upload from fs put single persistence client request persistence type string persistence type if orig filename null fs put single filename orig filename get absolute path if targeturi null fs put single targeturi targeturi to string if mime type null fs put single metadata content type mime type fs put global global if size 1 fs put data length size if token null fs put single client token token fs put started started fs put max retries max retries if target filename null fs put single target filename target filename if binary blob fs put binary blob binary blob return fs simplefieldset getfieldset simplefieldset simplefieldset putsingle putsingle tostring priorityclass priorityclass putsingle uploadfrom clientputmessage uploadfromstring uploadfrom putsingle clientrequest persistencetypestring persistencetype origfilename putsingle origfilename getabsolutepath putsingle tostring mimetype putsingle contenttype mimetype datalength putsingle clienttoken maxretries maxretries targetfilename putsingle targetfilename targetfilename binaryblob binaryblob binaryblob override public string get name return name getname override public void run fcp connection handler handler node node throws message invalid exception throw new message invalid exception protocol error message invalid message persistent put goes from server to client not the other way around identifier global fcpconnectionhandler messageinvalidexception messageinvalidexception protocolerrormessage invalid_message persistentput override public void remove from object container container container activate uri 5 uri remove from container container activate orig filename 5 container delete orig filename container activate targeturi 5 targeturi remove from container container delete this removefrom objectcontainer removefrom origfilename origfilename removefrom public sub config string prefix config config this config config this prefix prefix map new linked hash map string option has initialized false config register this subconfig linkedhashmap hasinitialized return all the options registered each includes its name used by e g webconfig public synchronized option get options return map values to array new option map size getoptions toarray public synchronized option get option string option return map get option getoption public void register option o synchronized this if o name index of simple field set multi level char 1 throw new illegal argument exception option names must not contain simple field set multi level char if map contains key o name throw new illegal argument exception already registered o name on this map put o name o config on register this o indexof simplefieldset multi_level_char illegalargumentexception simplefieldset multi_level_char containskey illegalargumentexception onregister public void register string option name int default value int sort order boolean expert boolean force write string short desc string long desc int callback cb boolean is size if cb null cb new null int callback register new int option this option name default value sort order expert force write short desc long desc cb is size optionname defaultvalue sortorder forcewrite shortdesc longdesc intcallback issize nullintcallback intoption optionname defaultvalue sortorder forcewrite shortdesc longdesc issize public void register string option name long default value int sort order boolean expert boolean force write string short desc string long desc long callback cb boolean is size if cb null cb new null long callback register new long option this option name default value sort order expert force write short desc long desc cb is size optionname defaultvalue sortorder forcewrite shortdesc longdesc longcallback issize nulllongcallback longoption optionname defaultvalue sortorder forcewrite shortdesc longdesc issize public void register string option name string default value string int sort order boolean expert boolean force write string short desc string long desc int callback cb boolean is size if cb null cb new null int callback register new int option this option name default value string sort order expert force write short desc long desc cb is size optionname defaultvaluestring sortorder forcewrite shortdesc longdesc intcallback issize nullintcallback intoption optionname defaultvaluestring sortorder forcewrite shortdesc longdesc issize public void register string option name string default value string int sort order boolean expert boolean force write string short desc string long desc long callback cb boolean is size if cb null cb new null long callback register new long option this option name default value string sort order expert force write short desc long desc cb is size optionname defaultvaluestring sortorder forcewrite shortdesc longdesc longcallback issize nulllongcallback longoption optionname defaultvaluestring sortorder forcewrite shortdesc longdesc issize public void register string option name boolean default value int sort order boolean expert boolean force write string short desc string long desc boolean callback cb if cb null cb new null boolean callback register new boolean option this option name default value sort order expert force write short desc long desc cb optionname defaultvalue sortorder forcewrite shortdesc longdesc booleancallback nullbooleancallback booleanoption optionname defaultvalue sortorder forcewrite shortdesc longdesc public void register string option name string default value int sort order boolean expert boolean force write string short desc string long desc string callback cb if cb null cb new null string callback register new string option this option name default value sort order expert force write short desc long desc cb optionname defaultvalue sortorder forcewrite shortdesc longdesc stringcallback nullstringcallback stringoption optionname defaultvalue sortorder forcewrite shortdesc longdesc public void register string option name short default value int sort order boolean expert boolean force write string short desc string long desc short callback cb boolean is size if cb null cb new null short callback register new short option this option name default value sort order expert force write short desc long desc cb is size optionname defaultvalue sortorder forcewrite shortdesc longdesc shortcallback issize nullshortcallback shortoption optionname defaultvalue sortorder forcewrite shortdesc longdesc issize public void register string option name string default value int sort order boolean expert boolean force write string short desc string long desc string arr callback cb register new string arr option this option name default value sort order expert force write short desc long desc cb optionname defaultvalue sortorder forcewrite shortdesc longdesc stringarrcallback stringarroption optionname defaultvalue sortorder forcewrite shortdesc longdesc public int get int string option name int option o synchronized this o int option map get option name return o get value getint optionname intoption intoption optionname getvalue public long get long string option name long option o synchronized this o long option map get option name return o get value getlong optionname longoption longoption optionname getvalue public boolean get boolean string option name boolean option o synchronized this o boolean option map get option name return o get value getboolean optionname booleanoption booleanoption optionname getvalue public string get string string option name string option o synchronized this o string option map get option name return o get value trim getstring optionname stringoption stringoption optionname getvalue public string get string arr string option name string arr option o synchronized this o string arr option map get option name return o get value getstringarr optionname stringarroption stringarroption optionname getvalue public short get short string option name short option o synchronized this o short option map get option name return o get value getshort optionname shortoption shortoption optionname getvalue has the object we are attached to finished initialization public boolean has finished initialization return has initialized hasfinishedinitialization hasinitialized called when the object we are attached to has finished init after this point the callbacks are authoritative for values of config variables and will be called when values are changed by the user public void finished initialization has initialized true if logger should log logger minor this logger minor this finished initialization on this prefix finishedinitialization hasinitialized shouldlog set options from a simple field set once we process an option we must remove it public void set options simple field set sfs set map entry string option entry set map entry set iterator entry string option i entry set iterator while i has next entry string option entry i next string key entry get key option o entry get value string val sfs get key if val null try o set value val catch invalid config value exception e string msg invalid config value prefix simple field set multi level char key val error e logger error this msg e system err println msg might be about logging catch node need restart exception e impossible string msg impossible prefix simple field set multi level char key val error e logger error this msg e simplefieldset setoptions simplefieldset entryset entryset entryset hasnext getkey getvalue setvalue invalidconfigvalueexception simplefieldset multi_level_char nodeneedrestartexception simplefieldset multi_level_char public simple field set export field set return export field set false simplefieldset exportfieldset exportfieldset public simple field set export field set boolean with defaults return export field set config request type current settings with defaults simplefieldset exportfieldset withdefaults exportfieldset requesttype current_settings withdefaults public simple field set export field set config request type config request type boolean with defaults simple field set fs new simple field set true suppress warnings unchecked map entry string option entries new map entry map size fixme is any locking at all necessary here after it has finished init it s constant synchronized this entries map entry set to array entries boolean logminor logger should log logger minor this if logminor logger minor this prefix prefix for int i 0 i entries length i map entry string option entry entries i string key entry get key option o entry get value if logminor logger minor this key key value o get value string default o is default if config request type config request type current settings with defaults o is default o force write if logminor logger minor this skipping key o is default continue switch config request type case current settings fs put single key o get value string break case default settings fs put single key o get default break case sort order fs put key o get sort order break case expert flag fs put key o is expert break case force write flag fs put key o is forced write break case short description fs put single key l10n get string o get short desc break case long description fs put single key l10n get string o get long desc break case data type fs put single key o get data type str break default logger error this unknown config request type value config request type break if logminor logger minor this key prefix key value o get value string return fs simplefieldset exportfieldset requesttype configrequesttype withdefaults simplefieldset simplefieldset suppresswarnings entryset toarray shouldlog getkey getvalue getvaluestring isdefault configrequesttype requesttype current_settings withdefaults isdefault forcewrite isdefault configrequesttype current_settings putsingle getvaluestring default_settings putsingle getdefault sort_order getsortorder expert_flag isexpert force_write_flag isforcedwrite short_description putsingle getstring getshortdesc long_description putsingle getstring getlongdesc data_type putsingle getdatatypestr configrequesttype getvaluestring force an option to be updated even if it hasn t changed throws invalid config value exception throws node need restart exception public void force update string option name throws invalid config value exception node need restart exception option o map get option name o force update invalidconfigvalueexception nodeneedrestartexception forceupdate optionname invalidconfigvalueexception nodeneedrestartexception optionname forceupdate public void set string name string value throws invalid config value exception node need restart exception option o map get name o set value value invalidconfigvalueexception nodeneedrestartexception setvalue public void set string name boolean value throws invalid config value exception node need restart exception boolean option o boolean option map get name o set value invalidconfigvalueexception nodeneedrestartexception booleanoption booleanoption if the option s value is equal to the provided old default then set it to the new default used to deal with changes to important options where this is not handled automatically because the option s value is written to the ini param name the name of the option param value the value of the option public void fix old default string name string value option o map get name if o get value string equals value o set default fixolddefault getvaluestring setdefault if the option s value matches the provided old default regex then set it to the new default used to deal with changes to important options where this is not handled automatically because the option s value is written to the ini param name the name of the option param value the value of the option public void fix old default regex string name string value option o map get name if o get value string matches value o set default fixolddefaultregex getvaluestring setdefault public string get prefix return prefix getprefix public int compare to sub config second if this get prefix compare to second get prefix 0 return 1 else return 1 compareto subconfig getprefix compareto getprefix public string get raw option string name if config instanceof persistent config persistent config pc persistent config config if pc finished init throw new illegal state exception get raw option name on this but persistent config has been finished init already simple field set fs pc orig config file contents if fs null return null return fs get prefix simple field set multi level char name else return null getrawoption persistentconfig persistentconfig persistentconfig finishedinit illegalstateexception getrawoption finishedinit simplefieldset origconfigfilecontents simplefieldset multi_level_char public node update manager node node config config throws invalid config value exception logminor logger should log logger minor this this node node this has been blown false should update ext node starter ext build number node starter recommended ext build number this alert new updated version available user alert this alert is valid false sub config updater config new sub config node updater config updater config register enabled wrapper manager is controlled by native wrapper 1 true false node update manager enabled node update manager enabled long new updater enabled callback was enabled on startup updater config get boolean enabled is the auto update allowed updater config register autoupdate false 2 false true node update manager install new versions node update manager install new versions long new auto update allowed callback is auto update allowed updater config get boolean autoupdate updater config register uri update uri 3 true false node update manager updateuri node update manager updateuri long new updateuri callback false try updateuri new freeneturi updater config get string uri long ver updateuri get suggested edition if ver version build number ver version build number updateuri updateuri set suggested edition ver catch malformedurl exception e throw new invalid config value exception l10n invalid updateuri error e get localized message updater config register revocationuri revocation uri 4 true false node update manager revocationuri node update manager revocationuri long new update revocationuri callback try revocationuri new freeneturi updater config get string revocationuri catch malformedurl exception e throw new invalid config value exception l10n invalid revocationuri error e get localized message updater config register exturi ext uri 5 true false node update manager exturi node update manager exturi long new updateuri callback true try exturi new freeneturi updater config get string exturi long ver exturi get suggested edition if ver node starter ext build number ver node starter ext build number exturi exturi set suggested edition ver catch malformedurl exception e throw new invalid config value exception l10n invalid exturi error e get localized message updater config finished initialization this revocation checker new revocation checker this new file node client core get persistent temp dir revocation key fblob this uom new update over mandatory manager this this uom remove old temp files max ext version node starter recommended ext build number min ext version node starter required ext build number nodeupdatemanager invalidconfigvalueexception shouldlog hasbeenblown shouldupdateext nodestarter extbuildnumber nodestarter recommended_ext_build_number updatedversionavailableuseralert isvalid subconfig updaterconfig subconfig updaterconfig wrappermanager iscontrolledbynativewrapper nodeupdatemanager nodeupdatemanager enabledlong updaterenabledcallback wasenabledonstartup updaterconfig getboolean updaterconfig nodeupdatemanager installnewversions nodeupdatemanager installnewversionslong autoupdateallowedcallback isautoupdateallowed updaterconfig getboolean updaterconfig update_uri nodeupdatemanager nodeupdatemanager updateurilong updateuricallback updaterconfig getstring getsuggestededition buildnumber buildnumber setsuggestededition malformedurlexception invalidconfigvalueexception invalidupdateuri getlocalizedmessage updaterconfig revocation_uri nodeupdatemanager nodeupdatemanager revocationurilong updaterevocationuricallback updaterconfig getstring malformedurlexception invalidconfigvalueexception invalidrevocationuri getlocalizedmessage updaterconfig ext_uri nodeupdatemanager nodeupdatemanager exturilong updateuricallback updaterconfig getstring getsuggestededition nodestarter extbuildnumber nodestarter extbuildnumber setsuggestededition malformedurlexception invalidconfigvalueexception invalidexturi getlocalizedmessage updaterconfig finishedinitialization revocationchecker revocationchecker clientcore getpersistenttempdir updateovermandatorymanager removeoldtempfiles maxextversion nodestarter recommended_ext_build_number minextversion nodestarter required_ext_build_number public void start throws invalid config value exception node client core alerts register alert enable was enabled on startup invalidconfigvalueexception clientcore wasenabledonstartup void broadcastuom announces message msg synchronized broadcastuom announces sync msg getuom announcement broadcastuom announces true node peers local broadcast msg true true ctr broadcastuomannounces broadcastuomannouncessync getuomannouncement broadcastuomannounces localbroadcast private message getuom announcement return dmt createuom announce updateuri to string exturi to string revocationuri to string has been blown main updater null 1 main updater get fetched version ext updater null 1 ext updater get fetched version revocation checker last succeeded delta revocation checker get revocationdnf counter revocation checker get blob size main updater null 1 main updater get blob size ext updater null 1 ext updater get blob size int node node stats get node average ping time int node node stats get bwlimit delay time getuomannouncement createuomannounce tostring tostring tostring hasbeenblown mainupdater mainupdater getfetchedversion extupdater extupdater getfetchedversion revocationchecker lastsucceededdelta revocationchecker getrevocationdnfcounter revocationchecker getblobsize mainupdater mainupdater getblobsize extupdater extupdater getblobsize nodestats getnodeaveragepingtime nodestats getbwlimitdelaytime public void maybe senduom announce peer node peer synchronized broadcastuom announces sync if broadcastuom announces return nothing worth announcing yet synchronized this if has been blown main updater null main updater get fetched version 0 return try peer send async getuom announcement null ctr catch not connected exception e sad but ignore it maybesenduomannounce peernode broadcastuomannouncessync broadcastuomannounces hasbeenblown mainupdater mainupdater getfetchedversion sendasync getuomannouncement notconnectedexception is auto update enabled public synchronized boolean is enabled return main updater null isenabled mainupdater enable or disable auto update param enable whether auto update should be enabled throws invalid config value exception if enable true and we are not running under the wrapper void enable boolean enable throws invalid config value exception logminor logger should log logger minor this if node is using wrapper logger normal this don t try to start the updater as we are not running under the wrapper return node updater main null ext null synchronized this boolean enabled main updater null if enabled enable return if enable kill it main updater pre kill main main updater main updater null if ext updater null ext updater pre kill ext ext updater ext updater null else if wrapper manager is controlled by native wrapper node starter ext build number 1 logger error this cannot update because not running under wrapper throw new invalid config value exception l10n no update without wrapper start it main updater new node updater this updateuri false version build number 1 integer max value main jar ext updater new node updater this exturi true node starter ext build number node starter required ext build number node starter recommended ext build number ext jar if enable if main null main kill if ext null ext kill revocation checker kill else main updater start if ext updater null ext updater start revocation checker start false invalidconfigvalueexception invalidconfigvalueexception shouldlog isusingwrapper nodeupdater mainupdater mainupdater prekill mainupdater mainupdater extupdater extupdater prekill extupdater extupdater wrappermanager iscontrolledbynativewrapper nodestarter extbuildnumber invalidconfigvalueexception noupdatewithoutwrapper mainupdater nodeupdater buildnumber max_value extupdater nodeupdater nodestarter extbuildnumber nodestarter required_ext_build_number nodestarter recommended_ext_build_number revocationchecker mainupdater extupdater extupdater revocationchecker create a node update manager called by node constructor param node the node object param config the global config object options will be added to a subconfig called node updater return a new node update manager throws invalid config value exception if there is an error in the config public static node update manager maybe create node node config config throws invalid config value exception return new node update manager node config nodeupdatemanager nodeupdatemanager invalidconfigvalueexception nodeupdatemanager maybecreate invalidconfigvalueexception nodeupdatemanager get the uri for either the freenet jar updater or the freenet ext jar updater param is ext if true return the freenet ext jar update uri if false return the freenet jar uri return see above public synchronized freeneturi geturi boolean is ext return is ext exturi updateuri isext isext isext set the uri for either the freenet jar updater or the freenet ext jar updater param is ext if true set the freenet ext jar update uri if false set the freenet jar update uri param uri the uri to set public void seturi boolean is ext freeneturi uri node updater updater synchronized this if is ext if exturi equals uri return exturi uri updater ext updater else if updateuri equals uri return updateuri uri updater main updater if updater null return updater on changeuri uri isext isext nodeupdater isext extupdater mainupdater onchangeuri return the revocation uri public synchronized freeneturi get revocationuri return revocationuri getrevocationuri set the revocation uri param uri the new revocation uri public void set revocationuri freeneturi uri synchronized this if revocationuri equals uri return this revocationuri uri revocation checker on change revocationuri setrevocationuri revocationchecker onchangerevocationuri return is auto update currently enabled public boolean is auto update allowed return is auto update allowed isautoupdateallowed isautoupdateallowed enable or disable auto update param val if true enable auto update and immediately update if an update is ready if false disable it public void set auto update allowed boolean val synchronized this if val is auto update allowed return is auto update allowed val if val if is ready to deploy update false return else return deploy off thread 0 setautoupdateallowed isautoupdateallowed isautoupdateallowed isreadytodeployupdate deployoffthread does the updater have an update ready to deploy may be called synchronized this private boolean is ready to deploy update boolean ignore revocation long now system current time millis long started millis ago synchronized this if has new main jar has new ext jar if logminor logger minor this has new main jar has new main jar has new ext jar has new ext jar return false no jar if has been blown return false duh if peers say blown return false don t immediately deploy if still fetching started millis ago now math max started fetching next main jar started fetching next ext jar if started millis ago wait for second fetch to complete if logminor logger minor this not ready still fetching return false wait for running fetch to complete int ext ver get ready ext if ext ver min ext version ext ver max ext version if logminor logger minor this invalid ext current ext ver must be between min ext version and max ext version return false if ignore revocation if now revocation checker last succeeded recent revocation interval return true if got jar time 0 now got jar time revocation fetch timeout return true if logminor logger minor this still here in is ready to deploy update apparently everything is ready except the revocation fetch so start it revocation checker start true if ignore revocation if logminor logger minor this returning true because of ignore revocation return true deploy off thread wait for second fetch to complete started millis ago return false isreadytodeployupdate ignorerevocation currenttimemillis startedmillisago hasnewmainjar hasnewextjar hasnewmainjar hasnewmainjar hasnewextjar hasnewextjar hasbeenblown peerssayblown startedmillisago startedfetchingnextmainjar startedfetchingnextextjar startedmillisago wait_for_second_fetch_to_complete extver getreadyext extver minextversion extver maxextversion extver minextversion maxextversion ignorerevocation revocationchecker lastsucceeded recent_revocation_interval gotjartime gotjartime revocation_fetch_timeout isreadytodeployupdate revocationchecker ignorerevocation ignorerevocation deployoffthread wait_for_second_fetch_to_complete startedmillisago check whether there is an update to deploy if there is do it private void deploy update logminor logger should log logger minor this try synchronized this if disabled this session string msg not deploying update because disabled for this session bad java version logger error this msg system err println msg return if has been blown string msg trying to update but key has been blown not updating message was revocation message logger error this msg system err println msg return if peers say blown string msg trying to update but at least one peer says the key has been blown not updating logger error this msg system err println msg return if is enabled if logminor logger minor this not enabled return if is auto update allowed armed if logminor logger minor this not armed return if is ready to deploy update false if logminor logger minor this not ready to deploy update return int ext ver get ready ext if ext ver min ext version ext ver max ext version if logminor logger minor this invalid ext current ext ver must be between min ext version and max ext version return if is deploying update if logminor logger minor this already deploying update return is deploying update true inner deploy update catch throwable t synchronized this is deploying update false deployupdate shouldlog disabledthissession hasbeenblown revocationmessage peerssayblown isenabled isautoupdateallowed isreadytodeployupdate extver getreadyext extver minextversion extver maxextversion extver minextversion maxextversion isdeployingupdate isdeployingupdate innerdeployupdate isdeployingupdate deploy the update inner method doesn t check anything just does it private void inner deploy update write the jars config etc then restart update deploy context ctx try ctx new update deploy context catch updater parser exception e fail update could not determine which jars are in use e get message return if write jars ctx restart ctx else if logminor logger minor this did not write jars innerdeployupdate updatedeploycontext updatedeploycontext updaterparserexception failupdate getmessage writejars write the updated jars if necessary rewrite the wrapper conf return true if this part of the update succeeded private boolean write jars update deploy context ctx what do we want to do here 1 if we have a new main jar if on windows write it to a new jar file update the wrapper conf to point to it otherwise write to a new jar file then move the new jar file over the old jar file 2 if we have a new ext jar write it to a new jar file update the wrapper conf to point to it boolean written new jar false boolean written new ext false boolean try easy way file path separator char has new ext jar file main jar ctx get main jar file new main jar ctx get new main jar if has new main jar written new jar true boolean written to temp file false try if new main jar exists if new main jar delete if new main jar exists system err println cannot write to preferred new jar location new main jar if try easy way try new main jar file create temp file freenet jar main jar get parent file catch io exception e fail update cannot write to any other location either disk full e return false try writing to it try main updater write jar to new main jar written to temp file true catch io exception e new main jar delete fail update cannot write new jar disk full e return false else try writing it to the new one even though we can t delete it main updater write jar to new main jar else main updater write jar to new main jar else if logminor logger minor this deleted old jar new main jar main updater write jar to new main jar else main updater write jar to new main jar catch io exception e fail update cannot update cannot write to try easy way temp file new jar new main jar return false if try easy way do it the easy way just rewrite the main jar if new main jar rename to main jar logger error this cannot rename temp file new main jar over original jar main jar if written to temp file fail the update otherwise we will leak disk space new main jar delete fail update cannot write to preferred new jar location and cannot rename temp file over old jar update failed return false try the hard way else system err println written new freenet jar main updater get written version return true easy way didn t work or we can t do the easy way try the hard way if has new ext jar written new ext true write the new ext jar file new ext jar ctx get new ext jar try ext updater write jar to new ext jar catch io exception e fail update cannot write new ext jar to new ext jar return false try ctx rewrite wrapper conf written new jar written new ext catch io exception e fail update cannot rewrite wrapper conf e return false catch update catastrophe exception e fail update e get message node client core alerts register new simple user alert false l10n update catastrophe title e get message l10n update catastrophe title user alert critical error return false catch updater parser exception e node client core alerts register new simple user alert false l10n update failed title e get message l10n update failed short reason e get message user alert critical error return false return true writejars updatedeploycontext writtennewjar writtennewext tryeasyway pathseparatorchar hasnewextjar mainjar getmainjar newmainjar getnewmainjar hasnewmainjar writtennewjar writtentotempfile newmainjar newmainjar newmainjar newmainjar tryeasyway newmainjar createtempfile mainjar getparentfile ioexception failupdate mainupdater writejarto newmainjar writtentotempfile ioexception newmainjar failupdate mainupdater writejarto newmainjar mainupdater writejarto newmainjar newmainjar mainupdater writejarto newmainjar mainupdater writejarto newmainjar ioexception failupdate tryeasyway newmainjar tryeasyway newmainjar renameto mainjar newmainjar mainjar writtentotempfile newmainjar failupdate mainupdater getwrittenversion hasnewextjar writtennewext newextjar getnewextjar extupdater writejarto newextjar ioexception failupdate newextjar rewritewrapperconf writtennewjar writtennewext ioexception failupdate updatecatastropheexception failupdate getmessage clientcore simpleuseralert updatecatastrophetitle getmessage updatecatastrophetitle useralert critical_error updaterparserexception clientcore simpleuseralert updatefailedtitle getmessage updatefailedshort getmessage useralert critical_error restart the node does not return private void restart update deploy context ctx if logminor logger minor this restarting node get node starter restart try thread sleep 5 60 1000 catch interrupted exception e break in case it s still restarting system err println failed to restart exiting please restart the node system exit node init exception exit restart failed updatedeploycontext getnodestarter interruptedexception nodeinitexception exit_restart_failed private void fail update string reason logger error this update failed reason system err println update failed reason this kill update alerts node client core alerts register new simple user alert true l10n update failed title l10n update failed reason reason l10n update failed short reason reason user alert error failupdate killupdatealerts clientcore simpleuseralert updatefailedtitle updatefailed updatefailedshort useralert private string l10n string key return l10n get string node update manager key getstring nodeupdatemanager private string l10n string key string pattern string value return l10n get string node update manager key pattern value getstring nodeupdatemanager called when a new jar has been downloaded param is ext if true the new jar is the ext jar if false it is the main jar param recommended ext if is ext is false the recommended ext version upper bound for the new jar or 1 if it was not specified or the parse failed param required ext if is ext is false the required ext version lower bound for the new jar or 1 if it was not specified or the parse failed void on downloaded new jar boolean is ext int required ext int recommended ext synchronized this if is ext if ext updater get fetched version node starter ext build number has new ext jar true started fetching next ext jar 1 got jar time system current time millis if logminor logger minor this got ext jar ext updater get fetched version else if main updater get fetched version version build number has new main jar true started fetching next main jar 1 got jar time system current time millis if logminor logger minor this got main jar main updater get fetched version if is ext if required ext 1 min ext version required ext if recommended ext 1 max ext version recommended ext if is ext required ext 1 recommended ext 1 ext updater set min max required ext recommended ext revocation checker start true deploy off thread revocation fetch timeout if is auto update allowed broadcastuom announces isext recommendedext isext requiredext isext ondownloadednewjar isext requiredext recommendedext isext extupdater getfetchedversion nodestarter extbuildnumber hasnewextjar startedfetchingnextextjar gotjartime currenttimemillis extupdater getfetchedversion mainupdater getfetchedversion buildnumber hasnewmainjar startedfetchingnextmainjar gotjartime currenttimemillis mainupdater getfetchedversion isext requiredext minextversion requiredext recommendedext maxextversion recommendedext isext requiredext recommendedext extupdater setminmax requiredext recommendedext revocationchecker deployoffthread revocation_fetch_timeout isautoupdateallowed broadcastuomannounces private int get ready ext int ver node starter ext build number int fetched ext updater get fetched version if fetched 0 ver fetched return ver getreadyext nodestarter extbuildnumber extupdater getfetchedversion called when the node updater starts to fetch a new version of the jar param is ext if true the new jar is the ext jar if false it is the main jar void on start fetching boolean is ext long now system current time millis synchronized this if is ext started fetching next ext jar now else started fetching next main jar now nodeupdater isext onstartfetching isext currenttimemillis isext startedfetchingnextextjar startedfetchingnextmainjar public void blow string msg node updater main ext synchronized this if has been blown logger error this the key has already been marked as blown message was revocation message new message msg return else this revocation message msg this has been blown true we must get to the lower part and show the user the message try system err println the auto updating system has been compromized system err println the auto updating system revocation key has been inserted it says revocation message catch throwable t try logger error this caught t t catch throwable t1 main main updater ext ext updater if main null main pre kill if ext null ext pre kill main updater null ext updater null if main null main kill if ext null ext kill if revocation alert null revocation alert new revocation key found user alert msg node client core alerts register revocation alert we don t need to advertize updates we are not going to do them kill update alerts uom kill alert broadcastuom announces nodeupdater hasbeenblown revocationmessage revocationmessage hasbeenblown revocationmessage mainupdater extupdater prekill prekill mainupdater extupdater revocationalert revocationalert revocationkeyfounduseralert clientcore revocationalert killupdatealerts killalert broadcastuomannounces kill all user alerts asking the user whether he wants to update private void kill update alerts node client core alerts unregister alert useralerts killupdatealerts clientcore called when the revocation checker has got 3 dn fs on the revocation key public void no revocation found deploy update may have been waiting for the revocation if we re still here we didn t update broadcastuom announces node ps queue timed job new runnable public void run revocation checker start false node random next int 24 60 60 1000 revocationchecker dnfs norevocationfound deployupdate broadcastuomannounces queuetimedjob revocationchecker nextint broadcastuom announces node ps queue timed job new runnable public void run revocation checker start false broadcastuomannounces queuetimedjob revocationchecker public void arm armed true deploy off thread 0 deployoffthread void deploy off thread long delay node ps queue timed job new runnable public void run if logminor logger minor this running deploy off thread try deploy update catch throwable t logger error this caught t trying to deploy off thread t if logminor logger minor this run deploy off thread delay deployoffthread queuetimedjob deployoffthread deployupdate deployoffthread deployoffthread node ps queue timed job new runnable public void run if logminor logger minor this running deploy off thread try deploy update catch throwable t logger error this caught t trying to deploy off thread t if logminor logger minor this run deploy off thread queuetimedjob deployoffthread deployupdate deployoffthread deployoffthread has the private key been revoked public boolean is blown return has been blown isblown hasbeenblown public boolean has new main jar return has new main jar hasnewmainjar hasnewmainjar public boolean has new ext jar return has new ext jar hasnewextjar hasnewextjar what version has been fetched this includes jar s fetched via uom because the uom code feeds its results through the main updater public int new main jar version if main updater null return 1 return main updater get fetched version mainupdater newmainjarversion mainupdater mainupdater getfetchedversion public int new ext jar version if ext updater null return 1 return ext updater get fetched version newextjarversion extupdater extupdater getfetchedversion public boolean fetching new main jar return main updater null main updater is fetching fetchingnewmainjar mainupdater mainupdater isfetching public boolean fetching new ext jar return ext updater null ext updater is fetching fetchingnewextjar extupdater extupdater isfetching public int fetching new main jar version if main updater null return 1 return main updater fetching version fetchingnewmainjarversion mainupdater mainupdater fetchingversion public int fetching new ext jar version if ext updater null return 1 return ext updater fetching version fetchingnewextjarversion extupdater extupdater fetchingversion public boolean in final check return is ready to deploy update true is ready to deploy update false infinalcheck isreadytodeployupdate isreadytodeployupdate public int get revocationdnf counter return revocation checker get revocationdnf counter getrevocationdnfcounter revocationchecker getrevocationdnfcounter what version is the node currently running public int get main version return version build number getmainversion buildnumber public int get ext version return node starter ext build number getextversion nodestarter extbuildnumber public boolean is armed return armed is auto update allowed isarmed isautoupdateallowed is the node able to update as soon as the revocation fetch has been completed public boolean can update now return is ready to deploy update true canupdatenow isreadytodeployupdate is the node able to update immediately i e not only is it ready in every other sense but also a revocation fetch has completed recently enough not to need another one public boolean can update immediately return is ready to deploy update false canupdateimmediately isreadytodeployupdate class updater enabled callback extends boolean callback override public boolean get return is enabled updaterenabledcallback booleancallback isenabled override public void set boolean val throws invalid config value exception enable val invalidconfigvalueexception class auto update allowed callback extends boolean callback override public boolean get return is auto update allowed autoupdateallowedcallback booleancallback isautoupdateallowed override public void set boolean val throws invalid config value exception set auto update allowed val invalidconfigvalueexception setautoupdateallowed boolean is ext updateuri callback boolean is ext this is ext is ext isext updateuricallback isext isext isext override public string get return geturi is ext to string false false isext tostring override public void set string val throws invalid config value exception freeneturi uri try uri new freeneturi val catch malformedurl exception e throw new invalid config value exception l10n is ext invalid exturi invalid updateuri error e get localized message seturi is ext uri invalidconfigvalueexception malformedurlexception invalidconfigvalueexception isext invalidexturi invalidupdateuri getlocalizedmessage isext public class update revocationuri callback extends string callback override public string get return get revocationuri to string false false updaterevocationuricallback stringcallback getrevocationuri tostring override public void set string val throws invalid config value exception freeneturi uri try uri new freeneturi val catch malformedurl exception e throw new invalid config value exception l10n invalid revocationuri error e get localized message set revocationuri uri invalidconfigvalueexception malformedurlexception invalidconfigvalueexception invalidrevocationuri getlocalizedmessage setrevocationuri called when a peer indicates in its uom announce that it has fetched the revocation key or failed to do so in a way suggesting that somebody knows the key param source the node which is claiming this void peer claims key blown peer node source note that update over mandatory manager manages the list of peers who think this all we have to do is cancel the update synchronized this peers say blown false armed false uomannounce peerclaimskeyblown peernode updateovermandatorymanager peerssayblown public file get main blob int version node updater updater synchronized this if has been blown return null updater main updater if updater null return null return updater get blob file version getmainblob nodeupdater hasbeenblown mainupdater getblobfile public file get ext blob int version node updater updater synchronized this if has been blown return null updater ext updater if updater null return null return updater get blob file version getextblob nodeupdater hasbeenblown extupdater getblobfile public synchronized long time remaining on check long now system current time millis return math max 0 revocation fetch timeout now got jar time timeremainingoncheck currenttimemillis revocation_fetch_timeout gotjartime final byte counter ctr new byte counter public void received bytes int x fixme bytecounter bytecounter receivedbytes public void sent bytes int x node node stats reportuom bytes sent x sentbytes nodestats reportuombytessent public void sent payload int x ignore it will be reported to sent bytes as well sentpayload sentbytes public void disable this session disabled this session true disablethissession disabledthissession protected long get started fetching next main jar timestamp return started fetching next main jar getstartedfetchingnextmainjartimestamp startedfetchingnextmainjar protected long get started fetching next ext jar timestamp return started fetching next ext jar getstartedfetchingnextextjartimestamp startedfetchingnextextjar public boolean object can new object container container logger error this not storing node update manager in database new exception error return false objectcannew objectcontainer nodeupdatemanager public static final short minor 0 public static string get version return major minor getversion public static long get real version return major 10000 minor getrealversion public static string get svn revision return svn revision getsvnrevision svnrevision public class default persistent comparator t extends i persistent comparable extends persistent comparator t public int compare members t m1 t m2 return m1 compare to m2 defaultpersistentcomparator ipersistent persistentcomparator comparemembers compareto public int compare member with key t mbr object key return mbr compare to key comparememberwithkey compareto private boolean wrap public offset filter this 0 0 true offsetfilter public offset filter int x offset int y offset boolean wrap this x offset x offset this y offset y offset this wrap wrap set edge action zero offsetfilter xoffset yoffset xoffset xoffset yoffset yoffset setedgeaction public void setx offset int x offset this x offset x offset setxoffset xoffset xoffset xoffset public int getx offset return x offset getxoffset xoffset public void sety offset int y offset this y offset y offset setyoffset yoffset yoffset yoffset public int gety offset return y offset getyoffset yoffset public void set wrap boolean wrap this wrap wrap setwrap public boolean get wrap return wrap getwrap override protected void transform inverse int x int y float out if wrap out 0 x width x offset width out 1 y height y offset height else out 0 x x offset out 1 y y offset transforminverse xoffset yoffset xoffset yoffset override public buffered image filter buffered image src buffered image dst this width src get width this height src get height if wrap while x offset 0 x offset width while y offset 0 y offset height x offset width y offset height return super filter src dst bufferedimage bufferedimage bufferedimage getwidth getheight xoffset xoffset yoffset yoffset xoffset yoffset override public string to string return distort offset tostring public class xml import exception extends exception public xml import exception int line int column string message super in line line column column message this line line this column column this message message xmlimportexception xmlimportexception public string get message text return message getmessagetext public int get line return line getline public int get column return column getcolumn public node get root node if root node null return root node if device node null return null return device node get root node getrootnode rootnode rootnode devicenode devicenode getrootnode public node get device node return device node getdevicenode devicenode public void set root node node node root node node setrootnode rootnode public void set device node node node device node node setdevicenode devicenode public device node root node device root node root device node device setuuid u pnp createuuid set wireless mode false rootnode devicenode upnp setwirelessmode public device this null null public device node device this null device public device file description file throws invalid description exception this null null load description description file descriptionfile invaliddescriptionexception loaddescription descriptionfile public device string description file name throws invalid description exception this new file description file name descriptionfilename invaliddescriptionexception descriptionfilename private mutex mutex new mutex public void lock mutex lock public void unlock mutex unlock public void setnmpr mode boolean flag node dev node get device node if dev node null return if flag true dev node set node u pnp inmpr03 u pnp inmpr03 version dev node remove node device urlbase name else dev node remove node u pnp inmpr03 setnmprmode devnode getdevicenode devnode devnode setnode upnp upnp inmpr03_version devnode removenode urlbase_name devnode removenode upnp public boolean isnmpr mode node dev node get device node if dev node null return false return dev node get node u pnp inmpr03 null true false isnmprmode devnode getdevicenode devnode devnode getnode upnp private boolean wireless mode public void set wireless mode boolean flag wireless mode flag wirelessmode setwirelessmode wirelessmode public boolean is wireless mode return wireless mode iswirelessmode wirelessmode public int getssdp announce count if isnmpr mode true is wireless mode true return u pnp inmpr03 discovery over wireless count return 1 getssdpannouncecount isnmprmode iswirelessmode upnp inmpr03_discovery_over_wireless_count private string devuuid private void setuuid string uuid devuuid uuid private string getuuid return devuuid private void updateudn setudn uuid getuuid public device get root device node root node get root node if root node null return null node dev node root node get node device elem name if dev node null return null return new device root node dev node getrootdevice rootnode getrootnode rootnode devnode rootnode getnode elem_name devnode rootnode devnode public device get parent device if is root device return null node dev node get device node device device list device dev node dev node get parent node get parent node get node device elem name return new device dev node getparentdevice isrootdevice devnode getdevicenode devicelist devnode devnode getparentnode getparentnode getnode elem_name devnode private device data get device data node node get device node device data user data device data node get user data if user data null user data new device data node set user data user data user data set node node return user data devicedata getdevicedata getdevicenode devicedata userdata devicedata getuserdata userdata userdata devicedata setuserdata userdata userdata setnode userdata private void set description file file file get device data set description file file setdescriptionfile getdevicedata setdescriptionfile public file get description file return get device data get description file getdescriptionfile getdevicedata getdescriptionfile private void set descriptionuri string uri get device data set descriptionuri uri setdescriptionuri getdevicedata setdescriptionuri private string get descriptionuri return get device data get descriptionuri getdescriptionuri getdevicedata getdescriptionuri private boolean is descriptionuri string uri string descriptionuri get descriptionuri if uri null descriptionuri null return false return descriptionuri equals uri isdescriptionuri getdescriptionuri public string get description file path file description file get description file if description file null return return description file get absolute file get parent getdescriptionfilepath descriptionfile getdescriptionfile descriptionfile descriptionfile getabsolutefile getparent public boolean load description string desc string throws invalid description exception try parser parser u pnp getxml parser root node parser parse desc string if root node null throw new invalid description exception description noroot exception device node root node get node device elem name if device node null throw new invalid description exception description norootdevice exception catch parser exception e throw new invalid description exception e if initialize loaded description false return false set description file null return true loaddescription descstring invaliddescriptionexception upnp getxmlparser rootnode descstring rootnode invaliddescriptionexception noroot_exception devicenode rootnode getnode elem_name devicenode invaliddescriptionexception norootdevice_exception parserexception invaliddescriptionexception initializeloadeddescription setdescriptionfile public boolean load description file file throws invalid description exception try parser parser u pnp getxml parser root node parser parse file if root node null throw new invalid description exception description noroot exception file device node root node get node device elem name if device node null throw new invalid description exception description norootdevice exception file catch parser exception e throw new invalid description exception e if initialize loaded description false return false set description file file return true loaddescription invaliddescriptionexception upnp getxmlparser rootnode rootnode invaliddescriptionexception noroot_exception devicenode rootnode getnode elem_name devicenode invaliddescriptionexception norootdevice_exception parserexception invaliddescriptionexception initializeloadeddescription setdescriptionfile private boolean initialize loaded description set descriptionuri default description uri set lease time default lease time sethttp port http default port thanks for oliver newell 03 23 04 if hasudn false updateudn return true initializeloadeddescription setdescriptionuri default_description_uri setleasetime default_lease_time sethttpport http_default_port public static boolean is device node node node return device elem name equals node get name isdevicenode elem_name getname public boolean is root device return get root node null true false isrootdevice getrootnode public void setssdp packet ssdp packet packet get device data setssdp packet packet setssdppacket ssdppacket getdevicedata setssdppacket public ssdp packet getssdp packet if is root device false return null return get device data getssdp packet ssdppacket getssdppacket isrootdevice getdevicedata getssdppacket public void set location string value get device data set location value setlocation getdevicedata setlocation public string get location ssdp packet packet getssdp packet if packet null return packet get location return get device data get location getlocation ssdppacket getssdppacket getlocation getdevicedata getlocation public void set lease time int value get device data set lease time value advertiser adv get advertiser if adv null announce adv restart setleasetime getdevicedata setleasetime getadvertiser public int get lease time ssdp packet packet getssdp packet if packet null return packet get lease time return get device data get lease time getleasetime ssdppacket getssdppacket getleasetime getdevicedata getleasetime public long get time stamp ssdp packet packet getssdp packet if packet null return packet get time stamp return 0 gettimestamp ssdppacket getssdppacket gettimestamp public long get elapsed time return system current time millis get time stamp 1000 getelapsedtime currenttimemillis gettimestamp public boolean is expired long elipsed time get elapsed time long lease time get lease time u pnp default expired device extra time if lease time elipsed time return true return false isexpired elipsedtime getelapsedtime leasetime getleasetime upnp default_expired_device_extra_time leasetime elipsedtime private void seturl base string value if is root device true node node get root node get node urlbase name if node null node set value value return node new node urlbase name node set value value int index 1 if get root node has nodes false index 1 get root node insert node node index seturlbase isrootdevice getrootnode getnode urlbase_name setvalue urlbase_name setvalue getrootnode hasnodes getrootnode insertnode private void updateurl base string host string url base host interface get hosturl host gethttp port seturl base url base updateurlbase urlbase hostinterface gethosturl gethttpport seturlbase urlbase public string geturl base if is root device true return get root node get node value urlbase name return geturlbase isrootdevice getrootnode getnodevalue urlbase_name private final static string device type device type public void set device type string value get device node set node device type value device_type devicetype setdevicetype getdevicenode setnode device_type public string get device type return get device node get node value device type getdevicetype getdevicenode getnodevalue device_type public boolean is device type string value if value null return false return value equals get device type isdevicetype getdevicetype private final static string friendly name friendly name public void set friendly name string value get device node set node friendly name value friendly_name friendlyname setfriendlyname getdevicenode setnode friendly_name public string get friendly name return get device node get node value friendly name getfriendlyname getdevicenode getnodevalue friendly_name private final static string manufacture manufacture public void set manufacture string value get device node set node manufacture value setmanufacture getdevicenode setnode public string get manufacture return get device node get node value manufacture getmanufacture getdevicenode getnodevalue private final static string manufacture url manufactureurl public void set manufactureurl string value get device node set node manufacture url value manufacture_url setmanufactureurl getdevicenode setnode manufacture_url public string get manufactureurl return get device node get node value manufacture url getmanufactureurl getdevicenode getnodevalue manufacture_url private final static string model description model description public void set model description string value get device node set node model description value model_description modeldescription setmodeldescription getdevicenode setnode model_description public string get model description return get device node get node value model description getmodeldescription getdevicenode getnodevalue model_description private final static string model name model name public void set model name string value get device node set node model name value model_name modelname setmodelname getdevicenode setnode model_name public string get model name return get device node get node value model name getmodelname getdevicenode getnodevalue model_name private final static string model number model number public void set model number string value get device node set node model number value model_number modelnumber setmodelnumber getdevicenode setnode model_number public string get model number return get device node get node value model number getmodelnumber getdevicenode getnodevalue model_number private final static string model url modelurl public void set modelurl string value get device node set node model url value model_url setmodelurl getdevicenode setnode model_url public string get modelurl return get device node get node value model url getmodelurl getdevicenode getnodevalue model_url private final static string serial number serial number public void set serial number string value get device node set node serial number value serial_number serialnumber setserialnumber getdevicenode setnode serial_number public string get serial number return get device node get node value serial number getserialnumber getdevicenode getnodevalue serial_number private final static string udn udn public void setudn string value get device node set node udn value getdevicenode setnode public string getudn return get device node get node value udn getdevicenode getnodevalue public boolean hasudn string udn getudn if udn null udn length 0 return false return true private final static string upc upc public void setupc string value get device node set node upc value getdevicenode setnode public string getupc return get device node get node value upc getdevicenode getnodevalue private final static string presentationurl presentationurl public void set presentationurl string value get device node set node presentationurl value setpresentationurl getdevicenode setnode public string get presentationurl return get device node get node value presentationurl getpresentationurl getdevicenode getnodevalue public device list get device list device list dev list new device list node dev list node get device node get node device list elem name if dev list node null return dev list int n node dev list node getn nodes for int n 0 n n node n node node dev list node get node n if device is device node node false continue device dev new device node dev list add dev return dev list devicelist getdevicelist devicelist devlist devicelist devlistnode getdevicenode getnode devicelist elem_name devlistnode devlist nnode devlistnode getnnodes nnode devlistnode getnode isdevicenode devlist devlist public boolean is device string name if name null return false if name ends with getudn true return true if name equals get friendly name true return true if name ends with get device type true return true return false isdevice endswith getfriendlyname endswith getdevicetype public device get device string name device list dev list get device list int dev cnt dev list size for int n 0 n dev cnt n device dev dev list get device n if dev is device name true return dev device cdev dev get device name if cdev null return cdev return null getdevice devicelist devlist getdevicelist devcnt devlist devcnt devlist getdevice isdevice getdevice public device get device by descriptionuri string uri device list dev list get device list int dev cnt dev list size for int n 0 n dev cnt n device dev dev list get device n if dev is descriptionuri uri true return dev device cdev dev get device by descriptionuri uri if cdev null return cdev return null getdevicebydescriptionuri devicelist devlist getdevicelist devcnt devlist devcnt devlist getdevice isdescriptionuri getdevicebydescriptionuri public service list get service list service list service list new service list node service list node get device node get node service list elem name if service list node null return service list int n node service list node getn nodes for int n 0 n n node n node node service list node get node n if service is service node node false continue service service new service node service list add service return service list servicelist getservicelist servicelist servicelist servicelist servicelistnode getdevicenode getnode servicelist elem_name servicelistnode servicelist nnode servicelistnode getnnodes nnode servicelistnode getnode isservicenode servicelist servicelist public service get service string name service list service list get service list int service cnt service list size for int n 0 n service cnt n service service service list get service n if service is service name true return service device list dev list get device list int dev cnt dev list size for int n 0 n dev cnt n device dev dev list get device n service service dev get service name if service null return service return null getservice servicelist servicelist getservicelist servicecnt servicelist servicecnt servicelist getservice isservice devicelist devlist getdevicelist devcnt devlist devcnt devlist getdevice getservice public service get service byscpdurl string search url service list service list get service list int service cnt service list size for int n 0 n service cnt n service service service list get service n if service isscpdurl search url true return service device list dev list get device list int dev cnt dev list size for int n 0 n dev cnt n device dev dev list get device n service service dev get service byscpdurl search url if service null return service return null getservicebyscpdurl searchurl servicelist servicelist getservicelist servicecnt servicelist servicecnt servicelist getservice searchurl devicelist devlist getdevicelist devcnt devlist devcnt devlist getdevice getservicebyscpdurl searchurl public service get service by controlurl string search url service list service list get service list int service cnt service list size for int n 0 n service cnt n service service service list get service n if service is controlurl search url true return service device list dev list get device list int dev cnt dev list size for int n 0 n dev cnt n device dev dev list get device n service service dev get service by controlurl search url if service null return service return null getservicebycontrolurl searchurl servicelist servicelist getservicelist servicecnt servicelist servicecnt servicelist getservice iscontrolurl searchurl devicelist devlist getdevicelist devcnt devlist devcnt devlist getdevice getservicebycontrolurl searchurl public service get service by event suburl string search url service list service list get service list int service cnt service list size for int n 0 n service cnt n service service service list get service n if service is event suburl search url true return service device list dev list get device list int dev cnt dev list size for int n 0 n dev cnt n device dev dev list get device n service service dev get service by event suburl search url if service null return service return null getservicebyeventsuburl searchurl servicelist servicelist getservicelist servicecnt servicelist servicecnt servicelist getservice iseventsuburl searchurl devicelist devlist getdevicelist devcnt devlist devcnt devlist getdevice getservicebyeventsuburl searchurl public service get subscriber service string uuid service list service list get service list int service cnt service list size for int n 0 n service cnt n service service service list get service n string sid service getsid if uuid equals sid true return service device list dev list get device list int dev cnt dev list size for int n 0 n dev cnt n device dev dev list get device n service service dev get subscriber service uuid if service null return service return null getsubscriberservice servicelist servicelist getservicelist servicecnt servicelist servicecnt servicelist getservice devicelist devlist getdevicelist devcnt devlist devcnt devlist getdevice getsubscriberservice public state variable get state variable string service type string name if service type null name null return null service list service list get service list int service cnt service list size for int n 0 n service cnt n service service service list get service n thanks for theo beisch 11 09 04 if service type null if service get service type equals service type false continue state variable state var service get state variable name if state var null return state var device list dev list get device list int dev cnt dev list size for int n 0 n dev cnt n device dev dev list get device n state variable state var dev get state variable service type name if state var null return state var return null statevariable getstatevariable servicetype servicetype servicelist servicelist getservicelist servicecnt servicelist servicecnt servicelist getservice servicetype getservicetype servicetype statevariable statevar getstatevariable statevar statevar devicelist devlist getdevicelist devcnt devlist devcnt devlist getdevice statevariable statevar getstatevariable servicetype statevar statevar public state variable get state variable string name return get state variable null name statevariable getstatevariable getstatevariable public action get action string name service list service list get service list int service cnt service list size for int n 0 n service cnt n service service service list get service n action list action list service get action list int action cnt action list size for int i 0 i action cnt i action action action action list get action i string action name action get name if action name null continue if action name equals name true return action device list dev list get device list int dev cnt dev list size for int n 0 n dev cnt n device dev dev list get device n action action dev get action name if action null return action return null getaction servicelist servicelist getservicelist servicecnt servicelist servicecnt servicelist getservice actionlist actionlist getactionlist actioncnt actionlist actioncnt actionlist getaction actionname getname actionname actionname devicelist devlist getdevicelist devcnt devlist devcnt devlist getdevice getaction public icon list get icon list icon list icon list new icon list node icon list node get device node get node icon list elem name if icon list node null return icon list int n node icon list node getn nodes for int n 0 n n node n node node icon list node get node n if icon is icon node node false continue icon icon new icon node icon list add icon return icon list iconlist geticonlist iconlist iconlist iconlist iconlistnode getdevicenode getnode iconlist elem_name iconlistnode iconlist nnode iconlistnode getnnodes nnode iconlistnode getnode isiconnode iconlist iconlist public icon get icon int n icon list icon list get icon list if n 0 icon list size 1 n return null return icon list get icon n geticon iconlist iconlist geticonlist iconlist iconlist geticon public string get locationurl string host return host interface get hosturl host gethttp port get descriptionuri getlocationurl hostinterface gethosturl gethttpport getdescriptionuri private string get notify devicent if is root device false return getudn return upnp rootdevice getnotifydevicent isrootdevice upnp_rootdevice private string get notify deviceusn if is root device false return getudn return getudn upnp rootdevice getnotifydeviceusn isrootdevice upnp_rootdevice private string get notify device typent return get device type getnotifydevicetypent getdevicetype private string get notify device typeusn return getudn get device type getnotifydevicetypeusn getdevicetype public final static void notify wait timer util wait random default discovery wait time notifywait timerutil waitrandom default_discovery_wait_time public void announce string bind addr string dev location get locationurl bind addr ssdp notify socket ssdp sock new ssdp notify socket bind addr ssdp notify request ssdp req new ssdp notify request ssdp req set server u pnp get server name ssdp req set lease time get lease time ssdp req set location dev location ssdp req setnts nts alive uuid device uuid upnp rootdevice if is root device true string devnt get notify devicent string devusn get notify deviceusn ssdp req setnt devnt ssdp req setusn devusn ssdp sock post ssdp req uuid device uuid urn schemas upnp org device device type v string devnt get notify device typent string devusn get notify device typeusn ssdp req setnt devnt ssdp req setusn devusn ssdp sock post ssdp req thanks for mikael hakman 04 25 05 ssdp sock close service list service list get service list int service cnt service list size for int n 0 n service cnt n service service service list get service n service announce bind addr device list child device list get device list int child device cnt child device list size for int n 0 n child device cnt n device child device child device list get device n child device announce bind addr bindaddr devlocation getlocationurl bindaddr ssdpnotifysocket ssdpsock ssdpnotifysocket bindaddr ssdpnotifyrequest ssdpreq ssdpnotifyrequest ssdpreq setserver upnp getservername ssdpreq setleasetime getleasetime ssdpreq setlocation devlocation ssdpreq isrootdevice getnotifydevicent getnotifydeviceusn ssdpreq ssdpreq ssdpsock ssdpreq devicetype getnotifydevicetypent getnotifydevicetypeusn ssdpreq ssdpreq ssdpsock ssdpreq ssdpsock servicelist servicelist getservicelist servicecnt servicelist servicecnt servicelist getservice bindaddr devicelist childdevicelist getdevicelist childdevicecnt childdevicelist childdevicecnt childdevice childdevicelist getdevice childdevice bindaddr public void announce notify wait int n host addrs host interface getn host addresses for int n 0 n n host addrs n string bind addr host interface get host address n if bind addr null bind addr length 0 continue int ssdp count getssdp announce count for int i 0 i ssdp count i announce bind addr notifywait nhostaddrs hostinterface getnhostaddresses nhostaddrs bindaddr hostinterface gethostaddress bindaddr bindaddr ssdpcount getssdpannouncecount ssdpcount bindaddr public void byebye string bind addr ssdp notify socket ssdp sock new ssdp notify socket bind addr ssdp notify request ssdp req new ssdp notify request ssdp req setnts nts byebye uuid device uuid upnp rootdevice if is root device true string devnt get notify devicent string devusn get notify deviceusn ssdp req setnt devnt ssdp req setusn devusn ssdp sock post ssdp req uuid device uuid urn schemas upnp org device device type v string devnt get notify device typent string devusn get notify device typeusn ssdp req setnt devnt ssdp req setusn devusn ssdp sock post ssdp req thanks for mikael hakman 04 25 05 ssdp sock close service list service list get service list int service cnt service list size for int n 0 n service cnt n service service service list get service n service byebye bind addr device list child device list get device list int child device cnt child device list size for int n 0 n child device cnt n device child device child device list get device n child device byebye bind addr bindaddr ssdpnotifysocket ssdpsock ssdpnotifysocket bindaddr ssdpnotifyrequest ssdpreq ssdpnotifyrequest ssdpreq isrootdevice getnotifydevicent getnotifydeviceusn ssdpreq ssdpreq ssdpsock ssdpreq devicetype getnotifydevicetypent getnotifydevicetypeusn ssdpreq ssdpreq ssdpsock ssdpreq ssdpsock servicelist servicelist getservicelist servicecnt servicelist servicecnt servicelist getservice bindaddr devicelist childdevicelist getdevicelist childdevicecnt childdevicelist childdevicecnt childdevice childdevicelist getdevice childdevice bindaddr public void byebye int n host addrs host interface getn host addresses for int n 0 n n host addrs n string bind addr host interface get host address n if bind addr null bind addr length 0 continue int ssdp count getssdp announce count for int i 0 i ssdp count i byebye bind addr nhostaddrs hostinterface getnhostaddresses nhostaddrs bindaddr hostinterface gethostaddress bindaddr bindaddr ssdpcount getssdpannouncecount ssdpcount bindaddr public boolean post search response ssdp packet ssdp packet string st string usn string local addr ssdp packet get local address device root dev get root device string root dev location root dev get locationurl local addr ssdp search response ssdp res new ssdp search response ssdp res set lease time get lease time ssdp res set date calendar get instance ssdp res setst st ssdp res setusn usn ssdp res set location root dev location thanks for brent hills 10 20 04 ssdp res setmyname get friendly name int mx ssdp packet getmx timer util wait random mx 1000 string remote addr ssdp packet get remote address int remote port ssdp packet get remote port ssdp search response socket ssdp res sock new ssdp search response socket if debug is on true ssdp res print int ssdp count getssdp announce count for int i 0 i ssdp count i ssdp res sock post remote addr remote port ssdp res return true postsearchresponse ssdppacket ssdppacket localaddr ssdppacket getlocaladdress rootdev getrootdevice rootdevlocation rootdev getlocationurl localaddr ssdpsearchresponse ssdpres ssdpsearchresponse ssdpres setleasetime getleasetime ssdpres setdate getinstance ssdpres ssdpres ssdpres setlocation rootdevlocation ssdpres getfriendlyname ssdppacket timerutil waitrandom remoteaddr ssdppacket getremoteaddress remoteport ssdppacket getremoteport ssdpsearchresponsesocket ssdpressock ssdpsearchresponsesocket ison ssdpres ssdpcount getssdpannouncecount ssdpcount ssdpressock remoteaddr remoteport ssdpres public void device search response ssdp packet ssdp packet string ssdpst ssdp packet getst if ssdpst null return boolean is root device is root device string devusn getudn if is root device true devusn usn rootdevice if st is all device ssdpst true string devnt get notify devicent int repeat cnt is root device true 3 2 for int n 0 n repeat cnt n post search response ssdp packet devnt devusn else if st is root device ssdpst true if is root device true post search response ssdp packet st root device devusn else if st isuuid device ssdpst true string devudn getudn if ssdpst equals devudn true post search response ssdp packet devudn devusn else if st isurn device ssdpst true string dev type get device type if ssdpst equals dev type true thanks for mikael hakman 04 25 05 devusn getudn dev type post search response ssdp packet dev type devusn service list service list get service list int service cnt service list size for int n 0 n service cnt n service service service list get service n service service search response ssdp packet device list child device list get device list int child device cnt child device list size for int n 0 n child device cnt n device child device child device list get device n child device device search response ssdp packet devicesearchresponse ssdppacket ssdppacket ssdppacket isrootdevice isrootdevice isrootdevice isalldevice getnotifydevicent repeatcnt isrootdevice repeatcnt postsearchresponse ssdppacket isrootdevice isrootdevice postsearchresponse ssdppacket root_device isuuiddevice postsearchresponse ssdppacket isurndevice devtype getdevicetype devtype devtype postsearchresponse ssdppacket devtype servicelist servicelist getservicelist servicecnt servicelist servicecnt servicelist getservice servicesearchresponse ssdppacket devicelist childdevicelist getdevicelist childdevicecnt childdevicelist childdevicecnt childdevice childdevicelist getdevice childdevice devicesearchresponse ssdppacket public void device search received ssdp packet ssdp packet device search response ssdp packet devicesearchreceived ssdppacket ssdppacket devicesearchresponse ssdppacket public void sethttp port int port get device data sethttp port port sethttpport getdevicedata sethttpport public int gethttp port return get device data gethttp port gethttpport getdevicedata gethttpport public void http request recieved http request http req if debug is on true http req print if http req is get request true http get request recieved http req return if http req is post request true http post request recieved http req return if http req is subscribe request true http req is unsubscribe request true subscription request sub req new subscription request http req device event subscription recieved sub req return http req return bad request httprequestrecieved httprequest httpreq ison httpreq httpreq isgetrequest httpgetrequestrecieved httpreq httpreq ispostrequest httppostrequestrecieved httpreq httpreq issubscriberequest httpreq isunsubscriberequest subscriptionrequest subreq subscriptionrequest httpreq deviceeventsubscriptionrecieved subreq httpreq returnbadrequest private synchronized byte get description data string host if isnmpr mode false updateurl base host node root node get root node if root node null return new byte 0 thanks for mikael hakman 04 25 05 string desc new string desc u pnp xml declaration desc n desc root node to string return desc get bytes getdescriptiondata isnmprmode updateurlbase rootnode getrootnode rootnode upnp xml_declaration rootnode tostring getbytes private void http get request recieved http request http req string uri http req geturi debug message http get request recieved uri if uri null http req return bad request return device emb dev service emb service byte file byte new byte 0 if is descriptionuri uri true string local addr http req get local address file byte get description data local addr else if emb dev get device by descriptionuri uri null string local addr http req get local address file byte emb dev get description data local addr else if emb service get service byscpdurl uri null file byte emb service getscpd data else http req return bad request return http response http res new http response if file util isxml file name uri true http res set content type xml content type http res set status code http status ok http res set content file byte http req post http res httpgetrequestrecieved httprequest httpreq httpreq httpgetrequestrecieved httpreq returnbadrequest embdev embservice filebyte isdescriptionuri localaddr httpreq getlocaladdress filebyte getdescriptiondata localaddr embdev getdevicebydescriptionuri localaddr httpreq getlocaladdress filebyte embdev getdescriptiondata localaddr embservice getservicebyscpdurl filebyte embservice getscpddata httpreq returnbadrequest httpresponse httpres httpresponse fileutil isxmlfilename httpres setcontenttype content_type httpres setstatuscode httpstatus httpres setcontent filebyte httpreq httpres private void http post request recieved http request http req if http req issoap action true soap request soap req new soap request http req soap action recieved http req return http req return bad request httppostrequestrecieved httprequest httpreq httpreq issoapaction soaprequest soapreq soaprequest httpreq soapactionrecieved httpreq httpreq returnbadrequest private void soap bad action recieved http request soap req soap response soap res new soap response soap res set status code http status bad request soap req post soap res soapbadactionrecieved httprequest soapreq soapresponse soapres soapresponse soapres setstatuscode httpstatus bad_request soapreq soapres private void soap action recieved http request soap req string uri soap req geturi service ctl service get service by controlurl uri if ctl service null action request crl req new action request soap req device control request recieved crl req ctl service return soap bad action recieved soap req soapactionrecieved httprequest soapreq soapreq ctlservice getservicebycontrolurl ctlservice actionrequest crlreq actionrequest soapreq devicecontrolrequestrecieved crlreq ctlservice soapbadactionrecieved soapreq private void device control request recieved control request ctl req service service if ctl req is query control true device query control recieved new query request ctl req service else device action control recieved new action request ctl req service devicecontrolrequestrecieved controlrequest ctlreq ctlreq isquerycontrol devicequerycontrolrecieved queryrequest ctlreq deviceactioncontrolrecieved actionrequest ctlreq private void invalid action control recieved control request ctl req control response act res new action response act res set fault response u pnp status invalid action ctl req post act res invalidactioncontrolrecieved controlrequest ctlreq controlresponse actres actionresponse actres setfaultresponse upnpstatus invalid_action ctlreq actres private void device action control recieved action request ctl req service service if debug is on true ctl req print string action name ctl req get action name action action service get action action name if action null invalid action control recieved ctl req return argument list action arg list action get argument list argument list req arg list ctl req get argument list action arg list set req arg list if action perform action listener ctl req false invalid action control recieved ctl req deviceactioncontrolrecieved actionrequest ctlreq ison ctlreq actionname ctlreq getactionname getaction actionname invalidactioncontrolrecieved ctlreq argumentlist actionarglist getargumentlist argumentlist reqarglist ctlreq getargumentlist actionarglist reqarglist performactionlistener ctlreq invalidactioncontrolrecieved ctlreq private void device query control recieved query request ctl req service service if debug is on true ctl req print string var name ctl req get var name if service has state variable var name false invalid action control recieved ctl req return state variable state var get state variable var name if state var perform query listener ctl req false invalid action control recieved ctl req devicequerycontrolrecieved queryrequest ctlreq ison ctlreq varname ctlreq getvarname hasstatevariable varname invalidactioncontrolrecieved ctlreq statevariable statevar getstatevariable varname statevar performquerylistener ctlreq invalidactioncontrolrecieved ctlreq private void upnp bad subscription recieved subscription request sub req int code subscription response sub res new subscription response sub res set error response code sub req post sub res upnpbadsubscriptionrecieved subscriptionrequest subreq subscriptionresponse subres subscriptionresponse subres seterrorresponse subreq subres private void device event subscription recieved subscription request sub req string uri sub req geturi service service get service by event suburl uri if service null sub req return bad request return if sub req has callback false sub req hassid false upnp bad subscription recieved sub req http status precondition failed return unsubscribe if sub req is unsubscribe request true device event unsubscription recieved service sub req return subscribe new if sub req has callback true device event new subscription recieved service sub req return subscribe renew if sub req hassid true device event renew subscription recieved service sub req return upnp bad subscription recieved sub req http status precondition failed deviceeventsubscriptionrecieved subscriptionrequest subreq subreq getservicebyeventsuburl subreq returnbadrequest subreq hascallback subreq upnpbadsubscriptionrecieved subreq httpstatus precondition_failed subreq isunsubscriberequest deviceeventunsubscriptionrecieved subreq subreq hascallback deviceeventnewsubscriptionrecieved subreq subreq deviceeventrenewsubscriptionrecieved subreq upnpbadsubscriptionrecieved subreq httpstatus precondition_failed private void device event new subscription recieved service service subscription request sub req string callback sub req get callback try new url callback catch exception e upnp bad subscription recieved sub req http status precondition failed return long time out sub req get timeout string sid subscription createsid subscriber sub new subscriber sub set deliveryurl callback sub set time out time out sub setsid sid service add subscriber sub subscription response sub res new subscription response sub res set status code http status ok sub res setsid sid sub res set timeout time out if debug is on true sub res print sub req post sub res if debug is on true sub res print service notify all state variables deviceeventnewsubscriptionrecieved subscriptionrequest subreq subreq getcallback upnpbadsubscriptionrecieved subreq httpstatus precondition_failed timeout subreq gettimeout setdeliveryurl settimeout timeout addsubscriber subscriptionresponse subres subscriptionresponse subres setstatuscode httpstatus subres subres settimeout timeout ison subres subreq subres ison subres notifyallstatevariables private void device event renew subscription recieved service service subscription request sub req string sid sub req getsid subscriber sub service get subscriber sid if sub null upnp bad subscription recieved sub req http status precondition failed return long time out sub req get timeout sub set time out time out sub renew subscription response sub res new subscription response sub res set status code http status ok sub res setsid sid sub res set timeout time out sub req post sub res if debug is on true sub res print deviceeventrenewsubscriptionrecieved subscriptionrequest subreq subreq getsubscriber upnpbadsubscriptionrecieved subreq httpstatus precondition_failed timeout subreq gettimeout settimeout timeout subscriptionresponse subres subscriptionresponse subres setstatuscode httpstatus subres subres settimeout timeout subreq subres ison subres private void device event unsubscription recieved service service subscription request sub req string sid sub req getsid subscriber sub service get subscriber sid if sub null upnp bad subscription recieved sub req http status precondition failed return service remove subscriber sub subscription response sub res new subscription response sub res set status code http status ok sub req post sub res if debug is on true sub res print deviceeventunsubscriptionrecieved subscriptionrequest subreq subreq getsubscriber upnpbadsubscriptionrecieved subreq httpstatus precondition_failed removesubscriber subscriptionresponse subres subscriptionresponse subres setstatuscode httpstatus subreq subres ison subres private http server list gethttp server list return get device data gethttp server list httpserverlist gethttpserverlist getdevicedata gethttpserverlist private ssdp search socket list getssdp search socket list return get device data getssdp search socket list ssdpsearchsocketlist getssdpsearchsocketlist getdevicedata getssdpsearchsocketlist private void set advertiser advertiser adv get device data set advertiser adv setadvertiser getdevicedata setadvertiser private advertiser get advertiser return get device data get advertiser getadvertiser getdevicedata getadvertiser public boolean start stop true http server int retry cnt 0 int bind port gethttp port http server list http server list gethttp server list while http server list open bind port false retry cnt if u pnp server retry count retry cnt return false sethttp port bind port 1 bind port gethttp port http server list add request listener this http server list start ssdp seach socket ssdp search socket list ssdp search sock list getssdp search socket list if ssdp search sock list open false return false ssdp search sock list add search listener this ssdp search sock list start announce announce advertiser advertiser adv new advertiser this set advertiser adv adv start return true retrycnt bindport gethttpport httpserverlist httpserverlist gethttpserverlist httpserverlist bindport retrycnt upnp server_retry_count retrycnt sethttpport bindport bindport gethttpport httpserverlist addrequestlistener httpserverlist ssdpsearchsocketlist ssdpsearchsocklist getssdpsearchsocketlist ssdpsearchsocklist ssdpsearchsocklist addsearchlistener ssdpsearchsocklist setadvertiser private boolean stop boolean do bye bye if do bye bye true byebye http server list http server list gethttp server list http server list stop http server list close http server list clear ssdp search socket list ssdp search sock list getssdp search socket list ssdp search sock list stop ssdp search sock list close ssdp search sock list clear advertiser adv get advertiser if adv null adv stop set advertiser null return true dobyebye dobyebye httpserverlist httpserverlist gethttpserverlist httpserverlist httpserverlist httpserverlist ssdpsearchsocketlist ssdpsearchsocklist getssdpsearchsocketlist ssdpsearchsocklist ssdpsearchsocklist ssdpsearchsocklist getadvertiser setadvertiser public boolean stop return stop true public string get interface address ssdp packet ssdp packet getssdp packet if ssdp packet null return return ssdp packet get local address getinterfaceaddress ssdppacket ssdppacket getssdppacket ssdppacket ssdppacket getlocaladdress public void set action listener action listener listener service list service list get service list int n services service list size for int n 0 n n services n service service service list get service n service set action listener listener setactionlistener actionlistener servicelist servicelist getservicelist nservices servicelist nservices servicelist getservice setactionlistener public void set query listener query listener listener service list service list get service list int n services service list size for int n 0 n n services n service service service list get service n service set query listener listener setquerylistener querylistener servicelist servicelist getservicelist nservices servicelist nservices servicelist getservice setquerylistener thanks for mikael hakman 04 25 05 public void set action listener action listener listener boolean include sub devices set action listener listener if include sub devices true device list dev list get device list int dev cnt dev list size for int n 0 n dev cnt n device dev dev list get device n dev set action listener listener true setactionlistener actionlistener includesubdevices setactionlistener includesubdevices devicelist devlist getdevicelist devcnt devlist devcnt devlist getdevice setactionlistener thanks for mikael hakman 04 25 05 public void set query listener query listener listener boolean include sub devices set query listener listener if include sub devices true device list dev list get device list int dev cnt dev list size for int n 0 n dev cnt n device dev dev list get device n dev set query listener listener true setquerylistener querylistener includesubdevices setquerylistener includesubdevices devicelist devlist getdevicelist devcnt devlist devcnt devlist getdevice setquerylistener create an instance of jmdns public jmdns impl throws io exception logger finer jmdns instance created try final inet address addr inet address get local host init addr is loopback address null addr addr get host name pjyf oct 14 2004 why do we disallow the loopback address catch final io exception e init null computer jmdnsimpl ioexception inetaddress inetaddress getlocalhost isloopbackaddress gethostname ioexception create an instance of jmdns and bind it to a specific network interface given its ip address public jmdns impl inet address addr throws io exception try init addr addr get host name catch final io exception e init null computer jmdnsimpl inetaddress ioexception gethostname ioexception initialize everything param address the interface to which jmdns binds to param name the host name of the interface private void init inet address address string name throws io exception a host name with is illegal so strip off everything and append local final int idx name index of if idx 0 name name substring 0 idx name local local host to ip address binding local host new host info address name cache new dns cache 100 listeners collections synchronized list new array list service listeners new hash map type listeners new array list services new hashtable 20 service types new hashtable 20 remind if i could pass in a name for the timer thread i would pass jmdns timer timer new timer new record reaper this start timer shutdown new thread new shutdown jmdns shutdown runtime get runtime add shutdown hook shutdown incoming listener new thread new socket listener this jmdns socket listener bind to multicast socket open multicast socket get local host start get services values inetaddress ioexception indexof localhost localhost hostinfo dnscache synchronizedlist arraylist servicelisteners hashmap typelisteners arraylist servicetypes recordreaper getruntime addshutdownhook incominglistener socketlistener socketlistener openmulticastsocket getlocalhost getservices private void start collection service infos set state dns state probing 1 incoming listener start new prober this start timer for final iterator iterator service infos iterator iterator has next try register service new service info impl service info impl iterator next catch final exception exception logger log level warning start registration exception exception serviceinfos setstate dnsstate probing_1 incominglistener serviceinfos hasnext registerservice serviceinfoimpl serviceinfoimpl private void open multicast socket host info host info throws io exception if group null group inet address get by name dns constants mdns group if socket null this close multicast socket socket new multicast socket dns constants mdns port if host info null local host get interface null socket set network interface host info get interface socket set time to live 255 socket join group group openmulticastsocket hostinfo hostinfo ioexception inetaddress getbyname dnsconstants mdns_group closemulticastsocket multicastsocket dnsconstants mdns_port hostinfo localhost getinterface setnetworkinterface hostinfo getinterface settimetolive joingroup private void close multicast socket logger finer close multicast socket if socket null close socket try socket leave group group socket close if incoming listener null incoming listener join catch final exception exception logger log level warning close multicast socket close socket exception exception socket null closemulticastsocket closemulticastsocket leavegroup incominglistener incominglistener closemulticastsocket state machine sets the state and notifies all objects that wait on jmdns public synchronized void advance state set state get state advance notify all advancestate setstate getstate notifyall sets the state and notifies all objects that wait on jmdns synchronized void revert state set state get state revert notify all revertstate setstate getstate notifyall sets the state and notifies all objects that wait on jmdns synchronized void cancel set state dns state canceled notify all setstate dnsstate notifyall returns the current state of this info public dns state get state return state dnsstate getstate return the dns cache associated with the cache variable public dns cache get cache return cache dnscache dnscache getcache see plugins mdns discovery javax jmdns jmdns get host name public string get host name return local host get name mdnsdiscovery gethostname gethostname localhost getname public host info get local host return local host hostinfo getlocalhost localhost see plugins mdns discovery javax jmdns jmdns get interface public inet address get interface throws io exception return socket get interface mdnsdiscovery getinterface inetaddress getinterface ioexception getinterface see plugins mdns discovery javax jmdns jmdns get service info java lang string java lang string public service info get service info string type string name return get service info type name 3 1000 mdnsdiscovery getserviceinfo serviceinfo getserviceinfo getserviceinfo see plugins mdns discovery javax jmdns jmdns get service info java lang string java lang string int public service info get service info string type string name int timeout final service info impl info new service info impl type name new service info resolver this info start timer try final long end system current time millis timeout long delay synchronized info while info has data delay end system current time millis 0 info wait delay catch final interrupted exception e empty return info has data info null mdnsdiscovery getserviceinfo serviceinfo getserviceinfo serviceinfoimpl serviceinfoimpl serviceinforesolver currenttimemillis hasdata currenttimemillis interruptedexception hasdata see plugins mdns discovery javax jmdns jmdns request service info java lang string java lang string public void request service info string type string name request service info type name 3 1000 mdnsdiscovery requestserviceinfo requestserviceinfo requestserviceinfo see plugins mdns discovery javax jmdns jmdns request service info java lang string java lang string int public void request service info string type string name int timeout register service type type final service info impl info new service info impl type name new service info resolver this info start timer try final long end system current time millis timeout long delay synchronized info while info has data delay end system current time millis 0 info wait delay catch final interrupted exception e empty mdnsdiscovery requestserviceinfo requestserviceinfo registerservicetype serviceinfoimpl serviceinfoimpl serviceinforesolver currenttimemillis hasdata currenttimemillis interruptedexception void handle service resolved service info impl info list list null array list list copy null synchronized service listeners list list service listeners get info type to lower case if list null list copy new array list list if list copy null final service event event new service event impl this info type info get name info for final iterator iterator list copy iterator iterator has next service listener iterator next service resolved event handleserviceresolved serviceinfoimpl arraylist listcopy servicelisteners servicelisteners tolowercase listcopy arraylist listcopy serviceevent serviceeventimpl getname listcopy hasnext servicelistener serviceresolved see plugins mdns discovery javax jmdns jmdns add service type listener plugins mdns discovery javax jmdns service type listener public void add service type listener service type listener listener throws io exception synchronized this type listeners remove listener type listeners add listener report cached service types for final iterator iterator service types values iterator iterator has next listener service type added new service event impl this string iterator next null null new type resolver this start timer mdnsdiscovery addservicetypelistener mdnsdiscovery servicetypelistener addservicetypelistener servicetypelistener ioexception typelisteners typelisteners servicetypes hasnext servicetypeadded serviceeventimpl typeresolver see plugins mdns discovery javax jmdns jmdns remove service type listener plugins mdns discovery javax jmdns service type listener public void remove service type listener service type listener listener synchronized this type listeners remove listener mdnsdiscovery removeservicetypelistener mdnsdiscovery servicetypelistener removeservicetypelistener servicetypelistener typelisteners see plugins mdns discovery javax jmdns jmdns add service listener java lang string plugins mdns discovery javax jmdns service listener public void add service listener string type service listener listener final string lotype type to lower case remove service listener lotype listener list list null synchronized service listeners list list service listeners get lotype if list null list collections synchronized list new linked list service listeners put lotype list list add listener report cached service types final list service events new array list synchronized cache for final iterator i cache iterator i has next for dns cache cache node n dns cache cache node i next n null n n next final dns record rec dns record n get value if rec type dns constants type srv if rec name ends with type service events add new service event impl this type to unqualified name type rec name null actually call listener with all service events added above for final iterator i service events iterator i has next listener service added service event impl i next create start service resolver new service resolver this type start timer mdnsdiscovery addservicelistener mdnsdiscovery servicelistener addservicelistener servicelistener tolowercase removeservicelistener servicelisteners servicelisteners synchronizedlist linkedlist servicelisteners serviceevents arraylist hasnext dnscache cachenode dnscache cachenode dnsrecord dnsrecord getvalue dnsconstants type_srv endswith serviceevents serviceeventimpl tounqualifiedname serviceevents hasnext serviceadded serviceeventimpl serviceresolver serviceresolver see plugins mdns discovery javax jmdns jmdns remove service listener java lang string plugins mdns discovery javax jmdns service listener public void remove service listener string type service listener listener type type to lower case list list null synchronized service listeners list list service listeners get type if list null list remove listener if list size 0 service listeners remove type mdnsdiscovery removeservicelistener mdnsdiscovery servicelistener removeservicelistener servicelistener tolowercase servicelisteners servicelisteners servicelisteners see plugins mdns discovery javax jmdns jmdns register service plugins mdns discovery javax jmdns service info public void register service service info info abstract throws io exception final service info impl info service info impl info abstract register service type info type bind the service to this address info server local host get name info addr local host get address synchronized this make service name unique info services put info get qualified name to lower case info new service prober this start timer try synchronized info while info get state compare to dns state announced 0 info wait catch final interrupted exception e empty logger fine register service jmdns registered service as info mdnsdiscovery registerservice mdnsdiscovery serviceinfo registerservice serviceinfo infoabstract ioexception serviceinfoimpl serviceinfoimpl infoabstract registerservicetype localhost getname localhost getaddress makeservicenameunique getqualifiedname tolowercase getstate compareto dnsstate interruptedexception registerservice see plugins mdns discovery javax jmdns jmdns unregister service plugins mdns discovery javax jmdns service info public void unregister service service info info abstract final service info impl info service info impl info abstract synchronized this services remove info get qualified name to lower case info cancel note we use this lock object to synchronize on it synchronizing on another object e g the service info does not make sense because the sole purpose of the lock is to wait until the canceler has finished if we synchronized on the service info or on the canceler we would block all accesses to synchronized methods on that object this is not what we want final object lock new object new canceler this info lock start timer remind we get a deadlock here if the canceler does not run try synchronized lock lock wait catch final interrupted exception e empty mdnsdiscovery unregisterservice mdnsdiscovery serviceinfo unregisterservice serviceinfo infoabstract serviceinfoimpl serviceinfoimpl infoabstract getqualifiedname tolowercase serviceinfo serviceinfo interruptedexception see plugins mdns discovery javax jmdns jmdns unregister all services public void unregister all services logger finer unregister all services if services size 0 return collection list synchronized this list new linked list services values services clear for final iterator iterator list iterator iterator has next service info impl iterator next cancel final object lock new object new canceler this list lock start timer remind we get a livelock here if the canceler does not run try synchronized lock if closed lock wait catch final interrupted exception e empty mdnsdiscovery unregisterallservices unregisterallservices unregisterallservices linkedlist hasnext serviceinfoimpl interruptedexception see plugins mdns discovery javax jmdns jmdns register service type java lang string public void register service type string type final string name type to lower case if service types get name null if type index of dns sd udp 0 type ends with in addr arpa collection list synchronized this service types put name type list new linked list type listeners for final iterator iterator list iterator iterator has next service type listener iterator next service type added new service event impl this type null null mdnsdiscovery registerservicetype registerservicetype tolowercase servicetypes indexof _dns _udp endswith servicetypes linkedlist typelisteners hasnext servicetypelistener servicetypeadded serviceeventimpl generate a possibly unique name for a host using the information we have in the cache return returns true if the name of the host had to be changed private boolean make host name unique dns record address host final string original name host get name system current time millis boolean collision do collision false check for collision in cache for dns cache cache node j cache find host get name to lower case j null j j next if false host name increment name host get name collision true break while collision if original name equals host get name return false else return true makehostnameunique dnsrecord originalname getname currenttimemillis dnscache cachenode getname tolowercase incrementname getname originalname getname generate a possibly unique name for a service using the information we have in the cache return returns true if the name of the service info had to be changed private boolean make service name unique service info impl info final string original qualified name info get qualified name final long now system current time millis boolean collision do collision false check for collision in cache for dns cache cache node j cache find info get qualified name to lower case j null j j next final dns record a dns record j get value if a type dns constants type srv a is expired now final dns record service s dns record service a if s port info port s server equals local host get name logger finer make service name unique jmdns make service name unique srv collision a s server s server local host get name equals s server equals local host get name info set name increment name info get name collision true break check for collision with other service infos published by jmdns final object self service services get info get qualified name to lower case if self service null self service info info set name increment name info get name collision true while collision return original qualified name equals info get qualified name makeservicenameunique serviceinfoimpl originalqualifiedname getqualifiedname currenttimemillis dnscache cachenode getqualifiedname tolowercase dnsrecord dnsrecord getvalue dnsconstants type_srv isexpired dnsrecord dnsrecord localhost getname makeservicenameunique makeservicenameunique localhost getname localhost getname setname incrementname getname selfservice getqualifiedname tolowercase selfservice selfservice setname incrementname getname originalqualifiedname getqualifiedname string increment name string name try final int l name last index of final int r name last index of if l 0 l r name name substring 0 l integer parse int name substring l 1 r 1 else name 2 catch final number format exception e name 2 return name incrementname lastindexof lastindexof parseint numberformatexception add a listener for a question the listener will receive updates of answers to the question as they arrive or from the cache if they are already available public void add listener dns listener listener dns question question final long now system current time millis add the new listener synchronized this listeners add listener report existing matched records if question null for dns cache cache node i cache find question name i null i i next final dns record c dns record i get value if question answered by c c is expired now listener update record this now c addlistener dnslistener dnsquestion currenttimemillis dnscache cachenode dnsrecord dnsrecord getvalue answeredby isexpired updaterecord remove a listener from all outstanding questions the listener will no longer receive any updates public void remove listener dns listener listener synchronized this listeners remove listener removelistener dnslistener remind method update record should receive a better name notify all listeners that a record was updated public void update record long now dns record rec we do not want to block the entire dns while we are updating the record for each listener service info list listener list null synchronized this listener list new array list listeners for final iterator iterator listener list iterator iterator has next final dns listener listener dns listener iterator next listener update record this now rec if rec type dns constants type ptr rec type dns constants type srv list service listener list null synchronized service listeners service listener list list service listeners get rec name to lower case iterate on a copy in case listeners will modify it if service listener list null service listener list new array list service listener list if service listener list null final boolean expired rec is expired now final string type rec get name final string name dns record pointer rec get alias dns record old dns record services get name to lower case if expired new record final service event event new service event impl this type to unqualified name type name null for final iterator iterator service listener list iterator iterator has next service listener iterator next service added event else expire record final service event event new service event impl this type to unqualified name type name null for final iterator iterator service listener list iterator iterator has next service listener iterator next service removed event updaterecord updaterecord dnsrecord listenerlist listenerlist arraylist listenerlist hasnext dnslistener dnslistener updaterecord dnsconstants type_ptr dnsconstants type_srv servicelistenerlist servicelisteners servicelistenerlist servicelisteners tolowercase servicelistenerlist servicelistenerlist arraylist servicelistenerlist servicelistenerlist isexpired getname dnsrecord getalias dnsrecord dnsrecord tolowercase serviceevent serviceeventimpl tounqualifiedname servicelistenerlist hasnext servicelistener serviceadded serviceevent serviceeventimpl tounqualifiedname servicelistenerlist hasnext servicelistener serviceremoved handle an incoming response cache answers and pass them on to the appropriate questions void handle response dns incoming msg throws io exception final long now system current time millis boolean host conflict detected false boolean service conflict detected false for final iterator i msg answers iterator i has next boolean is informative false dns record rec dns record i next final boolean expired rec is expired now update the cache final dns record c dns record cache get rec if c null if expired is informative true cache remove c else c resetttl rec rec c else if expired is informative true cache add rec switch rec type case dns constants type ptr handle mdns udp records if rec get name index of dns sd udp 0 if expired rec name starts with services mdns udp is informative true register service type dns record pointer rec alias continue register service type rec name break if rec get type dns constants type a rec get type dns constants type aaaa host conflict detected rec handle response this else service conflict detected rec handle response this notify the listeners if is informative update record now rec if host conflict detected service conflict detected new prober this start timer handleresponse dnsincoming ioexception currenttimemillis hostconflictdetected serviceconflictdetected hasnext isinformative dnsrecord dnsrecord isexpired dnsrecord dnsrecord isinformative isinformative dnsconstants type_ptr _mdns _udp getname indexof _dns _udp startswith _services _mdns _udp isinformative registerservicetype dnsrecord registerservicetype gettype dnsconstants type_a gettype dnsconstants type_aaaa hostconflictdetected handleresponse serviceconflictdetected handleresponse isinformative updaterecord hostconflictdetected serviceconflictdetected handle an incoming query see if we can answer any part of it given our service infos void handle query dns incoming in inet address addr int port throws io exception track known answers boolean host conflict detected false boolean service conflict detected false final long expiration time system current time millis dns constants known answer ttl for final iterator i in answers iterator i has next final dns record answer dns record i next if answer get type dns constants type a answer get type dns constants type aaaa host conflict detected answer handle query this expiration time else service conflict detected answer handle query this expiration time if planned answer null planned answer append in else if in is truncated planned answer in new responder this in addr port start if host conflict detected service conflict detected new prober this start timer handlequery dnsincoming inetaddress ioexception hostconflictdetected serviceconflictdetected expirationtime currenttimemillis dnsconstants known_answer_ttl hasnext dnsrecord dnsrecord gettype dnsconstants type_a gettype dnsconstants type_aaaa hostconflictdetected handlequery expirationtime serviceconflictdetected handlequery expirationtime plannedanswer plannedanswer istruncated plannedanswer hostconflictdetected serviceconflictdetected add an answer to a question deal with the case when the outgoing packet overflows public dns outgoing add answer dns incoming in inet address addr int port dns outgoing out dns record rec throws io exception if out null out new dns outgoing dns constants flags qr response dns constants flags aa try out add answer in rec catch final io exception e out flags dns constants flags tc out id in id out finish send out out new dns outgoing dns constants flags qr response dns constants flags aa out add answer in rec return out dnsoutgoing addanswer dnsincoming inetaddress dnsoutgoing dnsrecord ioexception dnsoutgoing dnsconstants flags_qr_response dnsconstants flags_aa addanswer ioexception dnsconstants flags_tc dnsoutgoing dnsconstants flags_qr_response dnsconstants flags_aa addanswer send an outgoing multicast dns message public void send dns outgoing out throws io exception out finish if out is empty final datagram packet packet new datagram packet out data out off group dns constants mdns port try final dns incoming msg new dns incoming packet logger finest send jmdns out msg print true catch final io exception e logger throwing get class to string send dns outgoing jmdns can not parse what it sends e final multicast socket ms socket if ms null ms is closed ms send packet dnsoutgoing ioexception isempty datagrampacket datagrampacket dnsconstants mdns_port dnsincoming dnsincoming ioexception getclass tostring dnsoutgoing multicastsocket isclosed public void start announcer new announcer this start timer startannouncer public void start renewer new renewer this start timer startrenewer public void schedule timer task task int delay timer schedule task delay timertask public void run shutdown null close recover jmdns when there is an error public void recover logger finer recover we have an io error so lets try to recover if anything happens lets close it this should cover the case of the ip address changing under our feet if dns state canceled get state synchronized this synchronize only if we are not already in process to prevent dead locks logger finer recover cleanning up stop jmdns set state dns state canceled this protects against recursive calls we need to keep a copy for reregistration final collection old service infos new array list get services values cancel all services unregister all services dispose service collectors close multicast socket close multicast socket cache clear logger finer recover all is clean all is clear now start the services try open multicast socket get local host start old service infos catch final exception exception logger log level warning recover start services exception exception logger log level warning recover we are back dnsstate getstate setstate dnsstate oldserviceinfos arraylist getservices unregisterallservices disposeservicecollectors closemulticastsocket openmulticastsocket getlocalhost oldserviceinfos see plugins mdns discovery javax jmdns jmdns close public void close if get state dns state canceled synchronized this synchronize only if we are not already in process to prevent dead locks stop jmdns set state dns state canceled this protects against recursive calls unregister all services dispose service collectors close socket close multicast socket stop the timer timer cancel remove the shutdown hook if shutdown null runtime get runtime remove shutdown hook shutdown mdnsdiscovery getstate dnsstate setstate dnsstate unregisterallservices disposeservicecollectors closemulticastsocket getruntime removeshutdownhook list cache entries for debugging only void print system out println cache cache print system out println see plugins mdns discovery javax jmdns jmdns print services public void print services system err println to string mdnsdiscovery printservices printservices tostring public string to string final string buffer a log new string buffer a log append t services if services null for final iterator k services key set iterator k has next final object key k next a log append n t t service key services get key a log append n a log append t types if service types null for final iterator k service types key set iterator k has next final object key k next a log append n t t type key service types get key a log append n a log append cache to string a log append n a log append t service collectors if service collectors null synchronized service collectors for final iterator k service collectors key set iterator k has next final object key k next a log append n t t service collector key service collectors get key service collectors clear return a log to string tostring stringbuffer alog stringbuffer alog keyset hasnext alog tservice alog alog servicetypes servicetypes keyset hasnext alog ttype servicetypes alog alog tostring alog alog servicecollectors servicecollectors servicecollectors keyset hasnext alog tservice servicecollectors servicecollectors alog tostring see plugins mdns discovery javax jmdns jmdns list java lang string public service info list string type implementation note the first time a list for a given type is requested a service collector is created which collects service infos this greatly speeds up the performance of subsequent calls to this method the caveats are that 1 the first call to this method for a given type is slow and 2 we spawn a service collector instance for each service type which increases network traffic a little service collector collector boolean new collector created synchronized service collectors collector service collector service collectors get type if collector null collector new service collector type service collectors put type collector add service listener type collector new collector created true else new collector created false after creating a new service collector we collect service infos for 200 milliseconds this should be enough time to get some service infos from the network if new collector created try thread sleep 200 catch final interrupted exception e return collector list mdnsdiscovery serviceinfo servicecollector servicecollector servicecollector newcollectorcreated servicecollectors servicecollector servicecollectors servicecollector servicecollectors addservicelistener newcollectorcreated newcollectorcreated servicecollector newcollectorcreated interruptedexception this method disposes all service collector instances which have been created by calls to method code list type code see list private void dispose service collectors logger finer dispose service collectors synchronized service collectors for final iterator i service collectors values iterator i has next final service collector collector service collector i next remove service listener collector type collector service collectors clear servicecollector disposeservicecollectors disposeservicecollectors servicecollectors servicecollectors hasnext servicecollector servicecollector removeservicelistener servicecollectors public string type public service collector string type this type type servicecollector a service has been added public void service added service event event synchronized infos event getdns request service info event get type event get name 0 serviceadded serviceevent requestserviceinfo gettype getname a service has been removed public void service removed service event event synchronized infos infos remove event get name serviceremoved serviceevent getname a service hase been resolved its details are now available in the service info record public void service resolved service event event synchronized infos infos put event get name event get info serviceinfo serviceresolved serviceevent getname getinfo returns an array of all service infos which have been collected by this service collector public service info impl list synchronized infos return service info impl infos values to array new service info impl infos size servicecollector serviceinfoimpl serviceinfoimpl toarray serviceinfoimpl public string to string final string buffer a log new string buffer synchronized infos for final iterator k infos key set iterator k has next final object key k next a log append n t t service key infos get key return a log to string tostring stringbuffer alog stringbuffer keyset hasnext alog tservice alog tostring private static string to unqualified name string type string qualified name if qualified name ends with type return qualified name substring 0 qualified name length type length 1 else return qualified name tounqualifiedname qualifiedname qualifiedname endswith qualifiedname qualifiedname qualifiedname public void set state dns state state this state state setstate dnsstate public void set task timer task task this task task settask timertask public timer task get task return task timertask gettask public map get services return services getservices public void set last throttle increment long last throttle increment this last throttle increment last throttle increment setlastthrottleincrement lastthrottleincrement lastthrottleincrement lastthrottleincrement public long get last throttle increment return last throttle increment getlastthrottleincrement lastthrottleincrement public void set throttle int throttle this throttle throttle setthrottle public int get throttle return throttle getthrottle public static random get random return random getrandom public void set io lock object io lock this io lock io lock setiolock iolock iolock iolock public object get io lock return io lock getiolock iolock public void set planned answer dns incoming planned answer this planned answer planned answer setplannedanswer dnsincoming plannedanswer plannedanswer plannedanswer public dns incoming get planned answer return planned answer dnsincoming getplannedanswer plannedanswer void set local host host info local host this local host local host setlocalhost hostinfo localhost localhost localhost public map get service types return service types getservicetypes servicetypes public void set closed boolean closed this closed closed setclosed public boolean is closed return closed isclosed public multicast socket get socket return socket multicastsocket getsocket public inet address get group return group inetaddress getgroup constructor of replication master file param storage replication storage param file local file used to store data locally public replication master file replication master storage impl storage i file file this storage file storage port storage hosts storage replication ack replicationmasterfile replicationmasterstorageimpl ifile replicationack constructor of replication master file param file local file used to store data locally param hosts slave node hosts to which replicastion will be performed param ack whether master should wait acknowledgment from slave node during trasanction commit public replication master file i file file string hosts boolean ack this null file 1 hosts ack replicationmasterfile ifile private replication master file replication master storage impl storage i file file int port string hosts boolean ack this storage storage this file file this hosts hosts this ack ack this port port mutex new object sockets new socket hosts length out new output stream hosts length if ack in new input stream hosts length rc buf new byte 1 tx buf new byte 8 page page size n hosts 0 for int i 0 i hosts length i connect i if port 0 try listen socket new server socket port catch io exception x throw new storage error storage error bad replication port listening true listen thread new thread this listen thread start replicationmasterfile replicationmasterstorageimpl ifile outputstream inputstream rcbuf txbuf pagesize nhosts listensocket serversocket ioexception storageerror storageerror bad_replication_port listenthread listenthread public void run while true socket s null try s listen socket accept catch io exception x x print stack trace synchronized mutex if listening return if s null try s set so linger true linger time catch exception x try s set tcp no delay true catch exception x add connection s listensocket ioexception printstacktrace setsolinger linger_time settcpnodelay addconnection private void add connection socket s output stream os null input stream is null try os s get output stream if ack is s get input stream catch io exception x x print stack trace return synchronized mutex int n hosts length string new hosts new string n 1 system arraycopy hosts 0 new hosts 0 n new hosts n s get remote socket address to string hosts new hosts output stream new out new output stream n 1 system arraycopy out 0 new out 0 n new out n os out new out if ack input stream new in new input stream n 1 system arraycopy in 0 new in 0 n new in n is in new in socket new sockets new socket n 1 system arraycopy sockets 0 new sockets 0 n new sockets n s sockets new sockets n hosts 1 thread sync thread new synchronize thread n sync thread run sync thread start addconnection outputstream inputstream getoutputstream getinputstream ioexception printstacktrace newhosts newhosts newhosts getremotesocketaddress tostring newhosts outputstream newout outputstream newout newout newout inputstream newin inputstream newin newin newin newsockets newsockets newsockets newsockets nhosts syncthread synchronizethread syncthread syncthread int i synchronize thread int i this i i set priority thread norm priority 1 synchronizethread setpriority norm_priority public void run long size storage get database size socket s output stream os null input stream is null synchronized mutex s sockets i if s null return os out i if ack is in i for long pos 0 pos size pos page page size page pg storage pool get page pos try synchronized s bytes pack8 tx buf 0 pos system arraycopy pg data 0 tx buf 8 page page size storage pool unfix pg os write tx buf if ack pos 0 is read rc buf 1 continue catch io exception x x print stack trace synchronized mutex if sockets i null handle error hosts i sockets i null out i null n hosts 1 return synchronized s bytes pack8 tx buf 0 replication slave storage impl repl sync try os write tx buf end of sycnhronization catch io exception x x print stack trace getdatabasesize outputstream inputstream pagesize getpage txbuf txbuf pagesize txbuf rcbuf ioexception printstacktrace handleerror nhosts txbuf replicationslavestorageimpl repl_sync txbuf ioexception printstacktrace public int get number of available hosts return n hosts getnumberofavailablehosts nhosts protected void connect int i string host hosts i int colon host index of int port integer parse int host substring colon 1 host host substring 0 colon socket socket null try int max attempts storage null storage slave connection timeout max connect attempts for int j 0 j max attempts j try socket new socket inet address get by name host port if socket null break thread sleep connection timeout catch io exception x catch interrupted exception x if socket null try try socket set so linger true linger time catch no such method error er try socket set tcp no delay true catch exception x sockets i socket out i socket get output stream if ack in i socket get input stream n hosts 1 catch io exception x handle error hosts i sockets i null out i null indexof parseint maxattempts slaveconnectiontimeout max_connect_attempts maxattempts inetaddress getbyname connection_timeout ioexception interruptedexception setsolinger linger_time nosuchmethoderror settcpnodelay getoutputstream getinputstream nhosts ioexception handleerror when overriden by base class this method perfroms socket error handling return code true code if host should be reconnected and attempt to send data to it should be repeated code false code if no more attmpts to communicate with this host should be performed public boolean handle error string host system err println failed to establish connection with host host return storage null storage listener null storage listener replication error host false handleerror replicationerror public void write long pos byte buf synchronized mutex for int i 0 i out length i while out i null try synchronized sockets i bytes pack8 tx buf 0 pos system arraycopy buf 0 tx buf 8 buf length out i write tx buf if ack pos 0 in i read rc buf 1 break catch io exception x out i null sockets i null n hosts 1 if handle error hosts i connect i else break file write pos buf txbuf txbuf txbuf rcbuf ioexception nhosts handleerror public int read long pos byte buf return file read pos buf public void sync file sync public boolean try lock boolean shared return file try lock shared trylock trylock public void lock boolean shared file lock shared public void unlock file unlock public void close if listen thread null synchronized mutex listening false try socket s new socket localhost port s close catch io exception x try listen thread join catch interrupted exception x try listen socket close catch io exception x file close bytes pack8 tx buf 0 replication slave storage impl repl close for int i 0 i out length i if sockets i null try out i write tx buf out i close if in null in i close sockets i close catch io exception x listenthread ioexception listenthread interruptedexception listensocket ioexception txbuf replicationslavestorageimpl repl_close txbuf ioexception public long length return file length private int value public data constant int string oid int value this oid oid this value value dataconstantint public string getsnmpoid return oid public object getsnmp data return new integer value getsnmpdata logger register log threshold callback new log threshold callback override public void should update logminor logger should log logger minor this registerlogthresholdcallback logthresholdcallback shouldupdate shouldlog create a new single file fetcher and register self called when following a redirect or direct from client get fixme many times where this is called internally we might be better off using a copy constructor public single file fetcher client requester parent get completion callback cb client metadata metadata client key key list string meta strings freeneturi origuri int added meta strings fetch context ctx boolean delete fetch context archive context actx archive handler ah metadata archive metadata int max retries int recursion level boolean dont tell client get long l boolean is essential bucket return bucket boolean is final object container container client context context throws fetch exception super key max retries ctx parent cb is essential false l container context delete fetch context if logminor logger minor this creating single file fetcher for key from origuri meta meta strings to string persistent persistent new exception debug this is final is final this cancelled false this return bucket return bucket this dont tell client get dont tell client get if persistent ah null ah ah clone handler this ah ah this archive metadata archive metadata this uri uri this key client key get base key uri meta strings uri list meta strings if meta strings instanceof array list persistent this meta strings array list string meta strings else always copy if persistent this meta strings new array list string meta strings this added meta strings added meta strings this client metadata metadata null metadata clone new client metadata this key key geturi if origuri null throw new null pointer exception this uri persistent origuri clone origuri this actx actx this recursion level recursion level 1 if recursion level ctx max recursion level throw new fetch exception fetch exception too much recursion too much recursion recursion level ctx max recursion level this decompressors new linked list compressor type singlefilefetcher clientget singlefilefetcher clientrequester getcompletioncallback clientmetadata clientkey metastrings addedmetastrings fetchcontext deletefetchcontext archivecontext archivehandler archivemetadata maxretries recursionlevel donttellclientget isessential returnbucket isfinal objectcontainer clientcontext fetchexception maxretries isessential deletefetchcontext singlefilefetcher metastrings tostring isfinal isfinal returnbucket returnbucket donttellclientget donttellclientget clonehandler archivemetadata archivemetadata clientkey getbasekey metastrings listmetastrings metastrings arraylist metastrings arraylist metastrings metastrings arraylist metastrings addedmetastrings addedmetastrings clientmetadata clientmetadata thiskey nullpointerexception recursionlevel recursionlevel recursionlevel maxrecursionlevel fetchexception fetchexception too_much_recursion recursionlevel maxrecursionlevel linkedlist compressor_type copy constructor modifies a few given fields don t call schedule used for things like slave fetchers for multi level metadata therefore does not remember return bucket meta strings etc public single file fetcher single file fetcher fetcher boolean persistent boolean delete fetch context metadata new meta array list string meta strings2 get completion callback callback fetch context ctx2 object container container client context context throws fetch exception don t add a block we have already fetched the data we are just handling the metadata in a different fetcher super persistent fetcher key clone key fetcher key fetcher max retries ctx2 fetcher parent callback false true fetcher token container context delete fetch context if logminor logger minor this creating single file fetcher for fetcher key meta fetcher meta strings to string new exception debug this return bucket null we expect significant further processing in the parent this is final false this dont tell client get fetcher dont tell client get this actx fetcher actx if persistent ah null ah ah clone handler this ah fetcher ah this archive metadata null this client metadata fetcher client metadata null fetcher client metadata clone new client metadata this metadata new meta this meta strings meta strings2 this added meta strings 0 this recursion level fetcher recursion level 1 if recursion level ctx max recursion level throw new fetch exception fetch exception too much recursion this this key persistent fetcher this key clone fetcher this key copy the decompressors just because a multi level metadata splitfile is compressed that doesn t mean that the data we are eventually going to fetch is this decompressors new linked list compressor type fetcher decompressors if fetcher uri null throw new null pointer exception this uri persistent fetcher uri clone fetcher uri multilevelmetadata returnbucket metastrings singlefilefetcher singlefilefetcher deletefetchcontext newmeta arraylist metastrings2 getcompletioncallback fetchcontext objectcontainer clientcontext fetchexception clonekey maxretries deletefetchcontext singlefilefetcher metastrings tostring returnbucket isfinal donttellclientget donttellclientget clonehandler archivemetadata clientmetadata clientmetadata clientmetadata clientmetadata newmeta metastrings metastrings2 addedmetastrings recursionlevel recursionlevel recursionlevel maxrecursionlevel fetchexception fetchexception too_much_recursion thiskey thiskey thiskey linkedlist compressor_type nullpointerexception splitfile or another single file fetcher etc override public void on success client key block block boolean from store object token object container container client context context if persistent container activate parent 1 container activate ctx 1 if parent instanceof client getter client getter parent add key to binary blob block container context parent completed block from store container context extract data if block null logger error this block is null from store from store token token new exception error return if key instanceof clientssk try if uri isssk uri isssk forusk if persistent container activate uri 5 freeneturi uu uri set meta string null usk forssk usk usk usk create uu context usk manager update known good usk uu get suggested edition context catch malformedurl exception e logger error this caught e e catch throwable t don t let the usk hint cause us to not succeed on the block logger error this caught t t bucket data extract block container context if data null if logminor logger minor this no data already failed if extract returns null it will call on failure first return if logminor logger minor this block block is metadata is metadata is not metadata on this if block is metadata on success new fetch result client metadata data container context else if ctx follow redirects on failure new fetch exception fetch exception invalid metadata told me not to follow redirects splitfile block false container context data free if persistent data remove from container return if parent is cancelled on failure new fetch exception fetch exception cancelled false container context data free if persistent data remove from container return if data size ctx max metadata size on failure new fetch exception fetch exception too big metadata false container context data free if persistent data remove from container return parse metadata try remove metadata container metadata metadata construct data if persistent container store this wrap handle metadata false container context data free if persistent data remove from container catch metadata parse exception e on failure new fetch exception fetch exception invalid metadata e false container context data free if persistent data remove from container return catch io exception e bucket error on failure new fetch exception fetch exception bucket error e false container context data free if persistent data remove from container return singlefilefetcher onsuccess clientkeyblock fromstore objectcontainer clientcontext clientgetter clientgetter addkeytobinaryblob completedblock fromstore fromstore fromstore issskforusk setmetastring uskforssk uskmanager updateknowngood getsuggestededition malformedurlexception onfailure ismetadata ismetadata onsuccess fetchresult clientmetadata followredirects onfailure fetchexception fetchexception invalid_metadata removefrom iscancelled onfailure fetchexception fetchexception removefrom maxmetadatasize onfailure fetchexception fetchexception too_big_metadata removefrom removemetadata wraphandlemetadata removefrom metadataparseexception onfailure fetchexception fetchexception invalid_metadata removefrom ioexception onfailure fetchexception fetchexception bucket_error removefrom override protected void on success fetch result result object container container client context context if persistent container activate decompressors 1 container activate parent 1 container activate ctx 1 container activate rcb 1 remove metadata container remove archive metadata container synchronized this so a single key listener isn t created finished true if parent is cancelled if logminor logger minor this parent is cancelled result as bucket free if persistent result as bucket remove from container on failure new fetch exception fetch exception cancelled false container context return if decompressors is empty bucket data result as bucket while decompressors is empty compressor type c decompressors remove last try long max len math max ctx max temp length ctx max output length if logminor logger minor this decompressing data size data size max length max len bucket out decompressors is empty return bucket null data c decompress data context get bucket factory parent persistent max len max len 4 out if logminor logger minor this decompressed to data size data size catch io exception e on failure new fetch exception fetch exception bucket error e false container context return catch compression output size exception e if logminor logger minor this too big limit ctx max output length temp ctx max temp length on failure new fetch exception fetch exception too big e estimated size rcb parent result get mime type false container context return result new fetch result result data if persistent container store this container store decompressors if ctx ignore too many path components meta strings is empty is final some meta strings left if added meta strings 0 should this be an error it would be useful to be able to fetch the data on the other hand such inserts could cause unpredictable results would be useful to make a redirect to the key we actually fetched rcb on failure new fetch exception fetch exception invalid metadata invalid metadata too many path components in redirects this key this container context else too many path components report to user if logminor logger minor this too many path components for uri meta meta strings to string freeneturi tryuri uri tryuri tryuri drop last meta strings meta strings size rcb on failure new fetch exception fetch exception too many path components result size rcb parent result get mime type tryuri this container context result as bucket free if persistent result as bucket remove from container return else if result size ctx max output length rcb on failure new fetch exception fetch exception too big result size rcb parent result get mime type this container context result as bucket free if persistent result as bucket remove from container else rcb on success result this container context onsuccess fetchresult objectcontainer clientcontext removemetadata removearchivemetadata singlekeylistener iscancelled asbucket asbucket removefrom onfailure fetchexception fetchexception isempty asbucket isempty compressor_type removelast maxlen maxtemplength maxoutputlength maxlen isempty returnbucket getbucketfactory maxlen maxlen ioexception onfailure fetchexception fetchexception bucket_error compressionoutputsizeexception maxoutputlength maxtemplength onfailure fetchexception fetchexception too_big estimatedsize getmimetype fetchresult ignoretoomanypathcomponents metastrings isempty isfinal addedmetastrings onfailure fetchexception fetchexception invalid_metadata thiskey too_many_path_components metastrings tostring droplastmetastrings metastrings onfailure fetchexception fetchexception too_many_path_components getmimetype asbucket asbucket removefrom maxoutputlength onfailure fetchexception fetchexception too_big getmimetype asbucket asbucket removefrom onsuccess handle the current metadata i e do something with it transition to a splitfile look up a manifest etc locking synchronized as it changes so many variables if we want to write the structure to disk we don t want this running at the same time throws fetch exception throws metadata parse exception throws archive failure exception throws archive restart exception private synchronized void handle metadata final object container container final client context context throws fetch exception metadata parse exception archive failure exception archive restart exception if persistent container activate this 2 1 s are probably redundant container activate metadata 100 container activate meta strings integer max value container activate this key 5 container activate ctx 2 for event producer and allowed mime types if ah null ah activate for execution container container activate parent 1 container activate actx 5 container activate client metadata 5 container activate rcb 1 container activate return bucket 5 if uri null if container null if container ext is active this throw new null pointer exception sfi this is active and uri is null else throw new null pointer exception sfi this is not active else throw new null pointer exception uri null on transient sfi this synchronized this if cancelled return so a single key listener isn t created finished true while true if metadata is simple manifest if logminor logger minor this is simple manifest string name if meta strings is empty throw new fetch exception fetch exception not enough path components 1 false null uri add meta strings new string else name remove meta string since metadata is a document we just replace metadata here if logminor logger minor this next meta string name length name length for this if name null if persistent metadata metadata get default document else metadata new meta metadata grab default document metadata remove from container metadata new meta container store this container store meta strings if metadata null throw new fetch exception fetch exception not enough path components 1 false null uri add meta strings new string else if persistent metadata metadata get document name this key this key push meta string name else metadata new meta metadata grab document name metadata remove from container metadata new meta freeneturi old this key this key this key this key push meta string name container store this container store meta strings container store this key old this key remove from container if metadata null throw new fetch exception fetch exception not in archive can t find name continue loop else if metadata is archive manifest if logminor logger minor this is archive manifest type metadata get archive type codec metadata get compression codec if meta strings is empty ctx returnzip manifests just return the archive whole metadata set simple redirect if persistent container store metadata continue first we need the archive metadata then parse it then we may need to fetch something from inside the archive it s more efficient to keep the existing ah if we can and it is vital in the case of binary blobs if ah null ah get key equals this key ah context archive manager make handler this key metadata get archive type metadata get compression codec parent instanceof client getter client getter parent collecting binary blob false persistent archive metadata metadata metadata null copied to archive metadata so do not need to clear it ah is set this means we are currently handling an archive bucket metadata bucket metadata bucket ah get metadata actx context archive manager if metadata bucket null try metadata metadata construct metadata bucket metadata bucket free catch io exception e bucket error throw new fetch exception fetch exception bucket error e if persistent container store this else final boolean persistent this persistent fetch archive false archive metadata archive manager metadata name new archive extract callback public void got bucket bucket data object container container client context context if persistent container activate single file fetcher this 1 if logminor logger minor this got bucket on single file fetcher this persistent persistent try metadata metadata construct data data free if persistent data remove from container wrap handle metadata true container context catch metadata parse exception e invalid metadata on failure new fetch exception fetch exception invalid metadata e false container context return catch io exception e bucket error on failure new fetch exception fetch exception bucket error e false container context return if persistent container deactivate single file fetcher this 1 public void not in archive object container container client context context if persistent container activate single file fetcher this 1 on failure new fetch exception fetch exception internal error no metadata in container cannot happen as archive manager should synthesise some false container context if persistent container deactivate single file fetcher this 1 public void on failed archive restart exception e object container container client context context if persistent container activate single file fetcher this 1 single file fetcher this on failure new fetch exception e false container context if persistent container deactivate single file fetcher this 1 public void on failed archive failure exception e object container container client context context if persistent container activate single file fetcher this 1 single file fetcher this on failure new fetch exception e false container context if persistent container deactivate single file fetcher this 1 public void remove from object container container container delete this container context will result in this function being called again if persistent container store this return metadata bucket free continue else if metadata is archive metadata redirect if logminor logger minor this is archive metadata fetch it from the archive if ah null throw new fetch exception fetch exception unknown metadata archive redirect not in an archive manifest string filename metadata get archive internal name if logminor logger minor this fetching filename bucket data bucket ah get filename actx context archive manager if data bucket null if logminor logger minor this returning data final metadata new metadata try new metadata metadata construct data bucket data bucket free catch io exception e throw new fetch exception fetch exception bucket error continue with new metadata new metadata this rcb container context return else if logminor logger minor this fetching archive this key this key metadata cannot contain pointers to files which don t exist we enforce this in archive handler therefore the archive needs to be fetched final boolean persistent this persistent fetch archive true archive metadata filename new archive extract callback public void got bucket bucket data object container container client context context if persistent container activate single file fetcher this 1 if logminor logger minor this returning data final metadata new metadata try new metadata metadata construct data continue with new metadata new metadata single file fetcher this rcb container context catch io exception e on failure new fetch exception fetch exception bucket error false container context catch metadata parse exception e on failure new fetch exception fetch exception invalid metadata false container context catch fetch exception e on failure e false container context finally data free if persistent container deactivate single file fetcher this 1 public void not in archive object container container client context context if persistent container activate single file fetcher this 1 on failure new fetch exception fetch exception not in archive false container context if persistent container deactivate single file fetcher this 1 public void on failed archive restart exception e object container container client context context if persistent container activate single file fetcher this 1 single file fetcher this on failure new fetch exception e false container context if persistent container deactivate single file fe fetchexception metadataparseexception archivefailureexception archiverestartexception handlemetadata objectcontainer clientcontext fetchexception metadataparseexception archivefailureexception archiverestartexception metastrings max_value thiskey activateforexecution clientmetadata returnbucket isactive nullpointerexception nullpointerexception nullpointerexception singlekeylistener issimplemanifest metastrings isempty fetchexception fetchexception not_enough_path_components addmetastrings removemetastring getdefaultdocument newmeta grabdefaultdocument removefrom newmeta metastrings fetchexception fetchexception not_enough_path_components addmetastrings getdocument thiskey thiskey pushmetastring newmeta grabdocument removefrom newmeta oldthiskey thiskey thiskey thiskey pushmetastring metastrings thiskey oldthiskey removefrom fetchexception fetchexception not_in_archive isarchivemanifest getarchivetype getcompressioncodec metastrings isempty returnzipmanifests setsimpleredirect getkey thiskey archivemanager makehandler thiskey getarchivetype getcompressioncodec clientgetter clientgetter collectingbinaryblob archivemetadata archivemetadata metadatabucket metadatabucket getmetadata archivemanager metadatabucket metadatabucket metadatabucket ioexception fetchexception fetchexception bucket_error fetcharchive archivemetadata archivemanager metadata_name archiveextractcallback gotbucket objectcontainer clientcontext singlefilefetcher gotbucket singlefilefetcher removefrom wraphandlemetadata metadataparseexception onfailure fetchexception fetchexception invalid_metadata ioexception onfailure fetchexception fetchexception bucket_error singlefilefetcher notinarchive objectcontainer clientcontext singlefilefetcher onfailure fetchexception fetchexception internal_error archivemanager singlefilefetcher onfailed archiverestartexception objectcontainer clientcontext singlefilefetcher singlefilefetcher onfailure fetchexception singlefilefetcher onfailed archivefailureexception objectcontainer clientcontext singlefilefetcher singlefilefetcher onfailure fetchexception singlefilefetcher removefrom objectcontainer metadatabucket isarchivemetadataredirect fetchexception fetchexception unknown_metadata getarchiveinternalname databucket archivemanager databucket newmetadata newmetadata databucket databucket ioexception fetchexception fetchexception bucket_error continuewithnewmetadata newmetadata thiskey thiskey archivehandler fetcharchive archivemetadata archiveextractcallback gotbucket objectcontainer clientcontext singlefilefetcher newmetadata newmetadata continuewithnewmetadata newmetadata singlefilefetcher ioexception onfailure fetchexception fetchexception bucket_error metadataparseexception onfailure fetchexception fetchexception invalid_metadata fetchexception onfailure singlefilefetcher notinarchive objectcontainer clientcontext singlefilefetcher onfailure fetchexception fetchexception not_in_archive singlefilefetcher onfailed archiverestartexception objectcontainer clientcontext singlefilefetcher singlefilefetcher onfailure fetchexception singlefilefe fetch archive false archive metadata archive manager metadata name new archive extract callback public void got bucket bucket data object container container client context context if persistent container activate single file fetcher this 1 if logminor logger minor this got bucket on single file fetcher this persistent persistent try metadata metadata construct data data free if persistent data remove from container wrap handle metadata true container context catch metadata parse exception e invalid metadata on failure new fetch exception fetch exception invalid metadata e false container context return catch io exception e bucket error on failure new fetch exception fetch exception bucket error e false container context return if persistent container deactivate single file fetcher this 1 fetcharchive archivemetadata archivemanager metadata_name archiveextractcallback gotbucket objectcontainer clientcontext singlefilefetcher gotbucket singlefilefetcher removefrom wraphandlemetadata metadataparseexception onfailure fetchexception fetchexception invalid_metadata ioexception onfailure fetchexception fetchexception bucket_error singlefilefetcher public void not in archive object container container client context context if persistent container activate single file fetcher this 1 on failure new fetch exception fetch exception internal error no metadata in container cannot happen as archive manager should synthesise some false container context if persistent container deactivate single file fetcher this 1 notinarchive objectcontainer clientcontext singlefilefetcher onfailure fetchexception fetchexception internal_error archivemanager singlefilefetcher public void on failed archive restart exception e object container container client context context if persistent container activate single file fetcher this 1 single file fetcher this on failure new fetch exception e false container context if persistent container deactivate single file fetcher this 1 onfailed archiverestartexception objectcontainer clientcontext singlefilefetcher singlefilefetcher onfailure fetchexception singlefilefetcher public void on failed archive failure exception e object container container client context context if persistent container activate single file fetcher this 1 single file fetcher this on failure new fetch exception e false container context if persistent container deactivate single file fetcher this 1 onfailed archivefailureexception objectcontainer clientcontext singlefilefetcher singlefilefetcher onfailure fetchexception singlefilefetcher container deactivate single file fetcher this 1 public void remove from object container container container delete this singlefilefetcher removefrom objectcontainer fetch archive true archive metadata filename new archive extract callback public void got bucket bucket data object container container client context context if persistent container activate single file fetcher this 1 if logminor logger minor this returning data final metadata new metadata try new metadata metadata construct data continue with new metadata new metadata single file fetcher this rcb container context catch io exception e on failure new fetch exception fetch exception bucket error false container context catch metadata parse exception e on failure new fetch exception fetch exception invalid metadata false container context catch fetch exception e on failure e false container context finally data free if persistent container deactivate single file fetcher this 1 fetcharchive archivemetadata archiveextractcallback gotbucket objectcontainer clientcontext singlefilefetcher newmetadata newmetadata continuewithnewmetadata newmetadata singlefilefetcher ioexception onfailure fetchexception fetchexception bucket_error metadataparseexception onfailure fetchexception fetchexception invalid_metadata fetchexception onfailure singlefilefetcher public void not in archive object container container client context context if persistent container activate single file fetcher this 1 on failure new fetch exception fetch exception not in archive false container context if persistent container deactivate single file fetcher this 1 notinarchive objectcontainer clientcontext singlefilefetcher onfailure fetchexception fetchexception not_in_archive singlefilefetcher public void on failed archive restart exception e object container container client context context if persistent container activate single file fetcher this 1 single file fetcher this on failure new fetch exception e false container context if persistent container deactivate single file fetcher this 1 onfailed archiverestartexception objectcontainer clientcontext singlefilefetcher singlefilefetcher onfailure fetchexception singlefilefetcher public void on failed archive failure exception e object container container client context context if persistent container activate single file fetcher this 1 single file fetcher this on failure new fetch exception e false container context if persistent container deactivate single file fetcher this 1 onfailed archivefailureexception objectcontainer clientcontext singlefilefetcher singlefilefetcher onfailure fetchexception singlefilefetcher container deactivate single file fetcher this 1 public void remove from object container container container delete this singlefilefetcher removefrom objectcontainer fetch archive true archive metadata filename new archive extract callback public void got bucket bucket data object container container client context context if persistent container activate single file fetcher this 1 if logminor logger minor this returning data bucket out try data will not be freed until client is finished with it if return bucket null if persistent container activate return bucket 5 out return bucket bucket tools copy data out data free if persistent data remove from container else out data catch io exception e on failure new fetch exception fetch exception bucket error false container context return return the data on success new fetch result client metadata out container context if persistent container deactivate single file fetcher this 1 fetcharchive archivemetadata archiveextractcallback gotbucket objectcontainer clientcontext singlefilefetcher returnbucket returnbucket returnbucket buckettools removefrom ioexception onfailure fetchexception fetchexception bucket_error onsuccess fetchresult clientmetadata singlefilefetcher public void not in archive object container container client context context if persistent container activate single file fetcher this 1 on failure new fetch exception fetch exception not in archive false container context if persistent container deactivate single file fetcher this 1 notinarchive objectcontainer clientcontext singlefilefetcher onfailure fetchexception fetchexception not_in_archive singlefilefetcher public void on failed archive restart exception e object container container client context context if persistent container activate single file fetcher this 1 single file fetcher this on failure new fetch exception e false container context if persistent container deactivate single file fetcher this 1 onfailed archiverestartexception objectcontainer clientcontext singlefilefetcher singlefilefetcher onfailure fetchexception singlefilefetcher public void on failed archive failure exception e object container container client context context if persistent container activate single file fetcher this 1 single file fetcher this on failure new fetch exception e false container context if persistent container deactivate single file fetcher this 1 onfailed archivefailureexception objectcontainer clientcontext singlefilefetcher singlefilefetcher onfailure fetchexception singlefilefetcher container deactivate single file fetcher this 1 public void remove from object container container container delete this singlefilefetcher removefrom objectcontainer private void continue with new metadata metadata new metadata get completion callback callback object container container client context context throws fetch exception final single file fetcher f new single file fetcher this persistent false new metadata new array list string meta strings callback ctx container context clear our own metadata so it can be garbage collected it will be replaced by whatever is fetched the new fetcher has our metadata so we don t need to remove metadata metadata null if persistent container store this if persistent container store f we must transition to the sub fetcher so that if the request is cancelled it will get deleted parent on transition this f container f wrap handle metadata true container context if persistent container deactivate f 1 return continuewithnewmetadata newmetadata getcompletioncallback objectcontainer clientcontext fetchexception singlefilefetcher singlefilefetcher newmetadata arraylist metastrings removemetadata ontransition wraphandlemetadata private string remove meta string string name meta strings remove 0 if added meta strings 0 added meta strings return name removemetastring metastrings addedmetastrings addedmetastrings private void add decompressor compressor type codec if logminor logger minor this adding decompressor codec on this new exception debug decompressors add codec adddecompressor compressor_type private void fetch archive boolean for data metadata meta string element archive extract callback callback final object container container client context context throws fetch exception metadata parse exception archive failure exception archive restart exception if logminor logger minor this fetch archive fetch the archive how spawn a separate single file fetcher which fetches the archive then calls our callback which unpacks the archive then reschedules us metadata new meta metadata meta clone new meta set simple redirect final single file fetcher f f new single file fetcher this persistent true new meta new array list string new archive fetcher callback for data element callback new fetch context ctx fetch context set return archives true null container context if persistent container store f if logminor logger minor this fetch archive f fetch the archive the archive fetcher callback will unpack it and either call the element callback or just go back around handle metadata on this which will see that the data is now available we need to transition here so that everything gets deleted if we are cancelled during the archive fetch phase if persistent container activate parent 1 parent on transition this f container f wrap handle metadata true container context if persistent container deactivate f 1 fetcharchive fordata archiveextractcallback objectcontainer clientcontext fetchexception metadataparseexception archivefailureexception archiverestartexception fetcharchive singlefilefetcher newmeta newmeta setsimpleredirect singlefilefetcher singlefilefetcher newmeta arraylist archivefetchercallback fordata fetchcontext fetchcontext set_return_archives fetcharchive handlemetadata ontransition wraphandlemetadata call handle metadata and deal with any resulting exceptions private void wrap handle metadata final boolean not finalized size object container container final client context context if persistent inner wrap handle metadata not finalized size container context else if context job runner on database thread context job runner queue new db job public void run object container container client context context if container ext is active single file fetcher this logger error this already active in sff callback single file fetcher this container activate single file fetcher this 1 inner wrap handle metadata not finalized size container context container deactivate single file fetcher this 1 parent get priority class false else inner wrap handle metadata not finalized size container context handlemetadata wraphandlemetadata notfinalizedsize objectcontainer clientcontext innerwraphandlemetadata notfinalizedsize jobrunner ondatabasethread jobrunner dbjob objectcontainer clientcontext isactive singlefilefetcher singlefilefetcher singlefilefetcher innerwraphandlemetadata notfinalizedsize singlefilefetcher getpriorityclass innerwraphandlemetadata notfinalizedsize context job runner queue new db job public void run object container container client context context if container ext is active single file fetcher this logger error this already active in sff callback single file fetcher this container activate single file fetcher this 1 inner wrap handle metadata not finalized size container context container deactivate single file fetcher this 1 jobrunner dbjob objectcontainer clientcontext isactive singlefilefetcher singlefilefetcher singlefilefetcher innerwraphandlemetadata notfinalizedsize singlefilefetcher protected void inner wrap handle metadata boolean not finalized size object container container client context context try handle metadata container context catch metadata parse exception e on failure new fetch exception fetch exception invalid metadata e false container context catch fetch exception e if not finalized size e set not finalized size on failure e false container context catch archive failure exception e on failure new fetch exception e false container context catch archive restart exception e on failure new fetch exception e false container context innerwraphandlemetadata notfinalizedsize objectcontainer clientcontext handlemetadata metadataparseexception onfailure fetchexception fetchexception invalid_metadata fetchexception notfinalizedsize setnotfinalizedsize onfailure archivefailureexception onfailure fetchexception archiverestartexception onfailure fetchexception archive fetcher callback boolean was fetching final data string element archive extract callback cb this was fetching final data was fetching final data this element element this callback cb this persistent single file fetcher this persistent archivefetchercallback wasfetchingfinaldata archiveextractcallback wasfetchingfinaldata wasfetchingfinaldata singlefilefetcher public void on success fetch result result client get state state object container container client context context if persistent run directly we are running on some thread somewhere don t worry about it inner success result container context else boolean was active we are running on the database thread add a tag unpack on a separate thread copy the data to a persistent bucket then schedule on the database thread remove the tag and call the callback was active container ext is active single file fetcher this if was active container activate single file fetcher this 1 container activate parent 1 parent on transition state single file fetcher this container if persistent container activate actx 1 ah activate for execution container ah extract persistent off thread result as bucket true actx element callback container context if was active container deactivate single file fetcher this 1 if state null state remove from container context container delete this onsuccess fetchresult clientgetstate objectcontainer clientcontext innersuccess wasactive wasactive isactive singlefilefetcher wasactive singlefilefetcher ontransition singlefilefetcher activateforexecution extractpersistentoffthread asbucket wasactive singlefilefetcher removefrom private void inner success fetch result result object container container client context context try ah extract to cache result as bucket actx element callback context archive manager container context catch archive failure exception e single file fetcher this on failure new fetch exception e false container context return catch archive restart exception e single file fetcher this on failure new fetch exception e false container context return finally result as bucket free if persistent result as bucket remove from container if callback null return wrap handle metadata true container context innersuccess fetchresult objectcontainer clientcontext extracttocache asbucket archivemanager archivefailureexception singlefilefetcher onfailure fetchexception archiverestartexception singlefilefetcher onfailure fetchexception asbucket asbucket removefrom wraphandlemetadata public void on failure fetch exception e client get state state object container container client context context boolean was active true if persistent was active container ext is active single file fetcher this if was active container activate single file fetcher this 1 force fatal as the fetcher is presumed to have made a reasonable effort single file fetcher this on failure e true container context if was active container deactivate single file fetcher this 1 if persistent if state null state remove from container context container delete this callback remove from container onfailure fetchexception clientgetstate objectcontainer clientcontext wasactive wasactive isactive singlefilefetcher wasactive singlefilefetcher singlefilefetcher onfailure wasactive singlefilefetcher removefrom removefrom public void on block set finished client get state state object container container client context context boolean was active true if persistent was active container ext is active single file fetcher this if was active container activate single file fetcher this 1 if persistent container activate rcb 1 if was fetching final data rcb on block set finished single file fetcher this container context if was active container deactivate single file fetcher this 1 onblocksetfinished clientgetstate objectcontainer clientcontext wasactive wasactive isactive singlefilefetcher wasactive singlefilefetcher wasfetchingfinaldata onblocksetfinished singlefilefetcher wasactive singlefilefetcher public void on transition client get state old state client get state new state object container container ignore ontransition clientgetstate oldstate clientgetstate newstate objectcontainer public void on expectedmime string mime object container container client context context ignore onexpectedmime objectcontainer clientcontext public void on expected size long size object container container client context context boolean was active true if persistent was active container ext is active single file fetcher this if was active container activate single file fetcher this 1 if persistent container activate rcb 1 rcb on expected size size container context if was active container deactivate single file fetcher this 1 onexpectedsize objectcontainer clientcontext wasactive wasactive isactive singlefilefetcher wasactive singlefilefetcher onexpectedsize wasactive singlefilefetcher public void on finalized metadata object container container ignore onfinalizedmetadata objectcontainer private final boolean persistent multi level metadata callback this persistent single file fetcher this persistent multilevelmetadatacallback singlefilefetcher public void on success fetch result result client get state state object container container client context context boolean was active true if persistent was active container ext is active single file fetcher this container activate single file fetcher this 1 container activate parent 1 try parent on transition state single file fetcher this container metadata meta metadata construct result as bucket remove metadata container synchronized single file fetcher this metadata meta if persistent container store meta container store single file fetcher this wrap handle metadata true container context catch metadata parse exception e single file fetcher this on failure new fetch exception fetch exception invalid metadata e false container context catch io exception e bucket error single file fetcher this on failure new fetch exception fetch exception bucket error e false container context finally result as bucket free if persistent result as bucket remove from container if was active container deactivate single file fetcher this 1 if persistent if state null state remove from container context container delete this onsuccess fetchresult clientgetstate objectcontainer clientcontext wasactive wasactive isactive singlefilefetcher singlefilefetcher ontransition singlefilefetcher asbucket removemetadata singlefilefetcher singlefilefetcher wraphandlemetadata metadataparseexception singlefilefetcher onfailure fetchexception fetchexception invalid_metadata ioexception singlefilefetcher onfailure fetchexception fetchexception bucket_error asbucket asbucket removefrom wasactive singlefilefetcher removefrom public void on failure fetch exception e client get state state object container container client context context boolean was active true if persistent was active container ext is active single file fetcher this container activate single file fetcher this 1 pass it on fetcher is assumed to have retried as appropriate already so this is fatal single file fetcher this on failure e true container context if was active container deactivate single file fetcher this 1 if persistent if state null state remove from container context conceivably remove from could deactivate this so don t recheck container delete this onfailure fetchexception clientgetstate objectcontainer clientcontext wasactive wasactive isactive singlefilefetcher singlefilefetcher singlefilefetcher onfailure wasactive singlefilefetcher removefrom removefrom public void on block set finished client get state state object container container client context context ignore as we are fetching metadata here onblocksetfinished clientgetstate objectcontainer clientcontext public void on transition client get state old state client get state new state object container container ignore ontransition clientgetstate oldstate clientgetstate newstate objectcontainer public void on expectedmime string mime object container container client context context ignore onexpectedmime objectcontainer clientcontext public void on expected size long size object container container client context context boolean was active true boolean cb was active true if persistent was active container ext is active single file fetcher this container activate single file fetcher this 1 cb was active container ext is active rcb container activate rcb 1 rcb on expected size size container context if was active container deactivate single file fetcher this 1 if cb was active container deactivate rcb 1 onexpectedsize objectcontainer clientcontext wasactive cbwasactive wasactive isactive singlefilefetcher singlefilefetcher cbwasactive isactive onexpectedsize wasactive singlefilefetcher cbwasactive public void on finalized metadata object container container ignore onfinalizedmetadata objectcontainer override public boolean ignore store return ctx ignore store ignorestore ignorestore create a fetcher for a key public static client get state create client requester requester get completion callback cb freeneturi uri fetch context ctx archive context actx int max retries int recursion level boolean dont tell client get long l boolean is essential bucket return bucket boolean is final object container container client context context throws malformedurl exception fetch exception base client key key base client key get base key uri if uri has meta strings ctx allow splitfiles false ctx follow redirects false return bucket null key instanceof client key return new simple single file fetcher client key key max retries ctx requester cb is essential false l container context false if key instanceof client key return new single file fetcher requester cb null client key key new array list string uri list meta strings uri 0 ctx false actx null null max retries recursion level dont tell client get l is essential return bucket is final container context else return usk create requester cb usk key new array list string uri list meta strings ctx actx max retries recursion level dont tell client get l is essential return bucket is final container context clientgetstate clientrequester getcompletioncallback fetchcontext archivecontext maxretries recursionlevel donttellclientget isessential returnbucket isfinal objectcontainer clientcontext malformedurlexception fetchexception baseclientkey baseclientkey getbasekey hasmetastrings allowsplitfiles followredirects returnbucket clientkey simplesinglefilefetcher clientkey maxretries isessential clientkey singlefilefetcher clientkey arraylist listmetastrings maxretries recursionlevel donttellclientget isessential returnbucket isfinal uskcreate arraylist listmetastrings maxretries recursionlevel donttellclientget isessential returnbucket isfinal private static client get state usk create client requester requester get completion callback cb usk usk array list string meta strings fetch context ctx archive context actx int max retries int recursion level boolean dont tell client get long l boolean is essential bucket return bucket boolean is final object container container client context context throws fetch exception if usk suggested edition 0 return the latest known version but at least suggested edition long edition context usk manager lookup known good usk if edition usk suggested edition background fetch start background fetch first so can pick up updates in the datastore during registration context usk manager start temporary background fetcher usk context ctx true edition context usk manager lookup known good usk if edition usk suggested edition if logminor logger minor single file fetcher class redirecting to edition edition cb on failure new fetch exception fetch exception permanent redirect usk copy edition geturi add meta strings meta strings null container context return null else transition to single file fetcher get completion callback mycb new usk proxy completion callback usk cb requester persistent want to update the latest known good iff the fetch succeeds single file fetcher sf new single file fetcher requester mycb null usk getssk meta strings usk geturi add meta strings meta strings 0 ctx false actx null null max retries recursion level dont tell client get l is essential return bucket is final container context return sf else cb on failure new fetch exception fetch exception permanent redirect usk copy edition geturi add meta strings meta strings null container context return null else do a thorough blocking search usk fetcher tag tag context usk manager get fetcher usk copy usk suggested edition ctx false requester persistent new myusk fetcher callback requester cb usk meta strings ctx actx max retries recursion level dont tell client get l return bucket requester persistent false container context if is essential requester add must succeed blocks 1 container return tag clientgetstate uskcreate clientrequester getcompletioncallback arraylist metastrings fetchcontext archivecontext maxretries recursionlevel donttellclientget isessential returnbucket isfinal objectcontainer clientcontext fetchexception suggestededition suggestededition uskmanager lookupknowngood suggestededition uskmanager starttemporarybackgroundfetcher uskmanager lookupknowngood suggestededition singlefilefetcher onfailure fetchexception fetchexception permanent_redirect addmetastrings metastrings singlefilefetcher getcompletioncallback uskproxycompletioncallback singlefilefetcher singlefilefetcher metastrings addmetastrings metastrings maxretries recursionlevel donttellclientget isessential returnbucket isfinal onfailure fetchexception fetchexception permanent_redirect addmetastrings metastrings uskfetchertag uskmanager getfetcher suggestededition myuskfetchercallback metastrings maxretries recursionlevel donttellclientget returnbucket isessential addmustsucceedblocks public myusk fetcher callback client requester requester get completion callback cb usk usk array list string meta strings fetch context ctx archive context actx int max retries int recursion level boolean dont tell client get long l bucket return bucket boolean persistent this parent requester this cb cb this usk usk this meta strings meta strings this ctx ctx this actx actx this max retries max retries this recursion level recursion level this dont tell client get dont tell client get this token l this return bucket return bucket this persistent persistent myuskfetchercallback clientrequester getcompletioncallback arraylist metastrings fetchcontext archivecontext maxretries recursionlevel donttellclientget returnbucket metastrings metastrings maxretries maxretries recursionlevel recursionlevel donttellclientget donttellclientget returnbucket returnbucket public void on found edition long l usk newusk object container container client context context boolean metadata short codec byte data boolean new known good boolean new slot too if persistent container activate this 2 clientssk key usk getssk l try if l usk suggested edition single file fetcher sf new single file fetcher parent cb null key meta strings key geturi add meta strings meta strings 0 ctx false actx null null max retries recursion level 1 dont tell client get token false return bucket true container context sf schedule container context if persistent remove from container else cb on failure new fetch exception fetch exception permanent redirect newusk geturi add meta strings meta strings null container context if persistent remove from container catch fetch exception e cb on failure e null container context if persistent remove from container onfoundedition objectcontainer clientcontext newknowngood newslottoo suggestededition singlefilefetcher singlefilefetcher metastrings addmetastrings metastrings maxretries recursionlevel donttellclientget returnbucket removefrom onfailure fetchexception fetchexception permanent_redirect addmetastrings metastrings removefrom fetchexception onfailure removefrom private void remove from object container container container delete meta strings container delete this container activate usk 5 usk remove from container removefrom objectcontainer metastrings removefrom public void on failure object container container client context context if persistent container activate this 2 cb on failure new fetch exception fetch exception data not found no usk found null container context if persistent remove from container onfailure objectcontainer clientcontext onfailure fetchexception fetchexception data_not_found removefrom public void on cancelled object container container client context context if persistent container activate this 2 cb on failure new fetch exception fetch exception cancelled string null null container context if persistent remove from container oncancelled objectcontainer clientcontext onfailure fetchexception fetchexception removefrom public short get polling priority normal return parent get priority class getpollingprioritynormal getpriorityclass public short get polling priority progress return parent get priority class getpollingpriorityprogress getpriorityclass override public void remove from object container container client context context if logminor logger minor this remove from on this container activate uri 5 uri remove from container if this key null container activate this key 5 this key remove from container if ah null ah activate for execution container ah remove from container container activate meta strings 1 meta strings clear container delete meta strings container activate client metadata 1 client metadata remove from container actx is global to the client request not our problem container activate decompressors 1 decompressors clear remove metadata container remove archive metadata container container delete decompressors super remove from container context removefrom objectcontainer clientcontext removefrom removefrom thiskey thiskey thiskey removefrom activateforexecution removefrom metastrings metastrings metastrings clientmetadata clientmetadata removefrom clientrequest removemetadata removearchivemetadata removefrom private void remove metadata object container container if persistent return if logminor logger minor this remove metadata on this if metadata null return container activate metadata 1 metadata remove from container metadata null removemetadata objectcontainer removemetadata removefrom private void remove archive metadata object container container if persistent return if logminor logger minor this remove archive metadata on this if archive metadata null return container activate archive metadata 1 archive metadata remove from container archive metadata null removearchivemetadata objectcontainer removearchivemetadata archivemetadata archivemetadata archivemetadata removefrom archivemetadata public message type string name short priority this name priority false messagetype public message type string name short priority boolean internal name name this priority priority internal only internal integer id integer value of name hash code if specs contains key id throw new runtime exception a message type by the name of name already exists specs put id this messagetype _name internalonly valueof hashcode _specs containskey runtimeexception _specs public void unregister specs remove integer value of name hash code _specs valueof _name hashcode public void add linked list field string name class parameter linkedlisttypes put name parameter add field name linked list class addlinkedlistfield _linkedlisttypes addfield linkedlist public void add field string name class type fields put name type orderedfields add last name addfield _fields _orderedfields addlast public void add routed to node message fields add field dmt uid long class add field dmt target location double class add field dmt htl short class add field dmt node identity short buffer class addroutedtonodemessagefields addfield addfield target_location addfield addfield node_identity shortbuffer public boolean check type string field name object field value if field value null return false class def class fields get field name class value class field value get class if def class value class return true if def class is assignable from value class return true return false checktype fieldname fieldvalue fieldvalue defclass _fields fieldname valueclass fieldvalue getclass defclass valueclass defclass isassignablefrom valueclass public class type of string field return fields get field typeof _fields override public boolean equals object o if o instanceof message type return false we can only register one message type for each name so we can do here return message type o name name messagetype messagetype messagetype _name _name override public int hash code return name hash code hashcode _name hashcode public static message type get spec integer specid if specs contains key specid logger error message type class unrecognised message type received specid return null return specs get specid messagetype getspec _specs containskey messagetype _specs public string get name return name getname _name public map string class get fields return fields getfields _fields public linked list string get ordered fields return orderedfields linkedlist getorderedfields _orderedfields public map string class get linked list types return linkedlisttypes getlinkedlisttypes _linkedlisttypes return true if this message is internal only if this is the case any incoming messages in udp form of this spec will be silently discarded public boolean is internal only return internal only isinternalonly internalonly public short get priority return priority getpriority get current version in version history current version can be explicitely set by set version or result of last check out is used as current version public synchronized v get current return current setversion checkout getcurrent set new current version in version history param version new current version in version history it must belong to version history public synchronized void set current v version current version modify setcurrent checkout current version create successor of the current version this version has to be checked in in order to be placed in version history return checked out version public synchronized v checkout assert that current is checked in return v current new version ischeckedin newversion get root version return root version in this version history public synchronized v get root return versions get 0 getroot get latest version before specified date param timestamp deadline if code null code then the latest version in version history will be returned return version with the largest timestamp less than or equal to specified code timestamp code public synchronized v get latest before date timestamp if timestamp null return versions get versions size 1 int l 0 n versions size r n long t timestamp get time 1 while l r int m l r 1 if versions get m get date get time t l m 1 else r m return r 0 versions get r 1 null getlatestbefore gettime getdate gettime get earliest version after specified date param timestamp deadline if code null code then root version will be returned return version with the smallest timestamp greater than or equal to specified code timestamp code public synchronized v get earliest after date timestamp if timestamp null return versions get 0 int l 0 n versions size r n long t timestamp get time while l r int m l r 1 if versions get m get date get time t l m 1 else r m return r n versions get r null getearliestafter gettime getdate gettime get version with specified label if there are more than one version marked with this label then the latest one will be returned param label version label return latest version with specified label public synchronized v get version by label string label for int i versions size i 0 v v versions get i if v has label label return v return null getversionbylabel haslabel get version with specified id param id version id return version with specified id public synchronized v get version by id string id for int i versions size i 0 v v versions get i if v get id equals id return v return null getversionbyid getid get all versions in version history return array of versions sorted by date public synchronized version get all versions return versions to array new version versions size getallversions toarray get iterator through all version in version history iteration is started from the root version and performed in direction of increaing version timestamp this iterator supports remove method return version iterator public synchronized iterator v iterator return versions iterator create new version history param root root version public version history v root versions root get storage v create link 1 versions add root current root current history this versionhistory getstorage createlink construct a fill filter public fill filter this 0xff000000 fillfilter fillfilter construct a fill filter param color the fill color public fill filter int color this fill color color fillfilter fillfilter fillcolor set the fill color param fill color the fill color see get fill color public void set fill color int fill color this fill color fill color fillcolor getfillcolor setfillcolor fillcolor fillcolor fillcolor get the fill color return the fill color see set fill color public int get fill color return fill color setfillcolor getfillcolor fillcolor override public int filterrgb int x int y int rgb return fill color fillcolor public security levels node node persistent config config this node node sub config my config new sub config security levels config int sort order 0 network threat level callback new my callback network threat level override public string get synchronized security levels this return network threat level name public string get possible values network threat level values network threat level values string names new string values length for int i 0 i names length i names i values i name return names override protected network threat level get value return network threat level override protected void set value string val throws invalid config value exception network threat level new value parse network threat level val if new value null throw new invalid config value exception invalid value for network threat level val synchronized security levels this network threat level new value my config register network threat level high sort order false true security levels network threat level short security levels network threat level network threat level callback network threat level net level network threat level value of my config get string network threat level if my config get raw option network threat level null network threat level net level else call all the callbacks so that the config is consistent with the threat level set threat level net level friends threat level callback new my callback friends threat level override public string get synchronized security levels this return friends threat level name public string get possible values friends threat level values friends threat level values string names new string values length for int i 0 i names length i names i values i name return names override protected friends threat level get value return friends threat level override protected void set value string val throws invalid config value exception friends threat level new value friends threat level value of val if new value null throw new invalid config value exception invalid value for friends threat level val synchronized security levels this friends threat level new value my config register friends threat level normal sort order false true security levels friends threat level short security levels friends threat level friends threat level callback friends threat level friends level friends threat level value of my config get string friends threat level if my config get raw option friends threat level null friends threat level friends level else call all the callbacks so that the config is consistent with the threat level set threat level friends level physical threat level callback new my callback physical threat level override public string get synchronized security levels this return physical threat level name public string get possible values physical threat level values physical threat level values string names new string values length for int i 0 i names length i names i values i name return names override protected physical threat level get value return physical threat level override protected void set value string val throws invalid config value exception physical threat level new value physical threat level value of val if new value null throw new invalid config value exception invalid value for physical threat level val synchronized security levels this physical threat level new value my config register physical threat level normal sort order false true security levels physical threat level short security levels physical threat level physical threat level callback physical threat level phys level physical threat level value of my config get string physical threat level if my config get raw option physical threat level null physical threat level phys level else call all the callbacks so that the config is consistent with the threat level set threat level phys level my config finished initialization securitylevels persistentconfig subconfig myconfig subconfig sortorder networkthreatlevelcallback mycallback network_threat_level securitylevels networkthreatlevel getpossiblevalues network_threat_level network_threat_level network_threat_level getvalue networkthreatlevel setvalue invalidconfigvalueexception network_threat_level newvalue parsenetworkthreatlevel newvalue invalidconfigvalueexception securitylevels networkthreatlevel newvalue myconfig networkthreatlevel sortorder securitylevels networkthreatlevelshort securitylevels networkthreatlevel networkthreatlevelcallback network_threat_level netlevel network_threat_level valueof myconfig getstring networkthreatlevel myconfig getrawoption networkthreatlevel networkthreatlevel netlevel setthreatlevel netlevel friendsthreatlevelcallback mycallback friends_threat_level securitylevels friendsthreatlevel getpossiblevalues friends_threat_level friends_threat_level friends_threat_level getvalue friendsthreatlevel setvalue invalidconfigvalueexception friends_threat_level newvalue friends_threat_level valueof newvalue invalidconfigvalueexception securitylevels friendsthreatlevel newvalue myconfig friendsthreatlevel sortorder securitylevels friendsthreatlevelshort securitylevels friendsthreatlevel friendsthreatlevelcallback friends_threat_level friendslevel friends_threat_level valueof myconfig getstring friendsthreatlevel myconfig getrawoption friendsthreatlevel friendsthreatlevel friendslevel setthreatlevel friendslevel physicalthreatlevelcallback mycallback physical_threat_level securitylevels physicalthreatlevel getpossiblevalues physical_threat_level physical_threat_level physical_threat_level getvalue physicalthreatlevel setvalue invalidconfigvalueexception physical_threat_level newvalue physical_threat_level valueof newvalue invalidconfigvalueexception securitylevels physicalthreatlevel newvalue myconfig physicalthreatlevel sortorder securitylevels physicalthreatlevelshort securitylevels physicalthreatlevel physicalthreatlevelcallback physical_threat_level physlevel physical_threat_level valueof myconfig getstring physicalthreatlevel myconfig getrawoption physicalthreatlevel physicalthreatlevel physlevel setthreatlevel physlevel myconfig finishedinitialization override public string get synchronized security levels this return network threat level name securitylevels networkthreatlevel public string get possible values network threat level values network threat level values string names new string values length for int i 0 i names length i names i values i name return names getpossiblevalues network_threat_level network_threat_level override protected network threat level get value return network threat level network_threat_level getvalue networkthreatlevel override protected void set value string val throws invalid config value exception network threat level new value parse network threat level val if new value null throw new invalid config value exception invalid value for network threat level val synchronized security levels this network threat level new value setvalue invalidconfigvalueexception network_threat_level newvalue parsenetworkthreatlevel newvalue invalidconfigvalueexception securitylevels networkthreatlevel newvalue override public string get synchronized security levels this return friends threat level name securitylevels friendsthreatlevel public string get possible values friends threat level values friends threat level values string names new string values length for int i 0 i names length i names i values i name return names getpossiblevalues friends_threat_level friends_threat_level override protected friends threat level get value return friends threat level friends_threat_level getvalue friendsthreatlevel override protected void set value string val throws invalid config value exception friends threat level new value friends threat level value of val if new value null throw new invalid config value exception invalid value for friends threat level val synchronized security levels this friends threat level new value setvalue invalidconfigvalueexception friends_threat_level newvalue friends_threat_level valueof newvalue invalidconfigvalueexception securitylevels friendsthreatlevel newvalue override public string get synchronized security levels this return physical threat level name securitylevels physicalthreatlevel public string get possible values physical threat level values physical threat level values string names new string values length for int i 0 i names length i names i values i name return names getpossiblevalues physical_threat_level physical_threat_level override protected physical threat level get value return physical threat level physical_threat_level getvalue physicalthreatlevel override protected void set value string val throws invalid config value exception physical threat level new value physical threat level value of val if new value null throw new invalid config value exception invalid value for physical threat level val synchronized security levels this physical threat level new value setvalue invalidconfigvalueexception physical_threat_level newvalue physical_threat_level valueof newvalue invalidconfigvalueexception securitylevels physicalthreatlevel newvalue public synchronized void add network threat level listener security level listener network threat level listener network threat level callback add listener listener addnetworkthreatlevellistener securitylevellistener network_threat_level networkthreatlevelcallback addlistener public synchronized void add friends threat level listener security level listener friends threat level listener friends threat level callback add listener listener addfriendsthreatlevellistener securitylevellistener friends_threat_level friendsthreatlevelcallback addlistener public synchronized void add physical threat level listener security level listener physical threat level listener physical threat level callback add listener listener addphysicalthreatlevellistener securitylevellistener physical_threat_level physicalthreatlevelcallback addlistener private final array list security level listener t listeners my callback listeners new array list security level listener t arraylist securitylevellistener mycallback arraylist securitylevellistener public void add listener security level listener t listener if listeners contains listener logger error this already have listener listener in this return listeners add listener addlistener securitylevellistener override public void set string val throws invalid config value exception node need restart exception t old level get value set value val t new level get value on set old level new level invalidconfigvalueexception nodeneedrestartexception oldlevel getvalue setvalue newlevel getvalue onset oldlevel newlevel void on set t old level t new level for security level listener t listener listeners listener on change old level new level onset oldlevel newlevel securitylevellistener onchange oldlevel newlevel protected abstract void set value string val throws invalid config value exception setvalue invalidconfigvalueexception protected abstract void set value string val throws invalid config value exception protected abstract t get value setvalue invalidconfigvalueexception getvalue public network threat level get network threat level return network threat level network_threat_level getnetworkthreatlevel networkthreatlevel public friends threat level get friends threat level return friends threat level friends_threat_level getfriendsthreatlevel friendsthreatlevel public physical threat level get physical threat level return physical threat level physical_threat_level getphysicalthreatlevel physicalthreatlevel public static network threat level parse network threat level string arg try return network threat level value of arg catch illegal argument exception e return null network_threat_level parsenetworkthreatlevel network_threat_level valueof illegalargumentexception public static friends threat level parse friends threat level string arg try return friends threat level value of arg catch illegal argument exception e return null friends_threat_level parsefriendsthreatlevel friends_threat_level valueof illegalargumentexception public static physical threat level parse physical threat level string arg try return physical threat level value of arg catch illegal argument exception e return null physical_threat_level parsephysicalthreatlevel physical_threat_level valueof illegalargumentexception if changing to the new threat level is a potential problem warn the user and include a checkbox for confirmation param new threat level return public html node get confirm warning network threat level new threat level string checkbox name if new threat level network threat level return null not going to be changed html node parent new html node div if new threat level network threat level high network threat level network threat level maximum new threat level network threat level maximum if node peers get darknet peers length 0 parent add child p l10n no friends warning if new threat level network threat level maximum html node p parent add child p l10n addl10n substitution p security levels maximum network threat level warning new string bold bold new string b b parent add child input new string type name value new string checkbox checkbox name off l10n no friends checkbox return parent else if node peers count connected darknet peers 0 parent add child p l10n no connected friends warning added integer to string node peers get darknet peers length if new threat level network threat level maximum html node p parent add child p l10n addl10n substitution p security levels maximum network threat level warning new string bold bold new string b b parent add child input new string type name value new string checkbox checkbox name off l10n no connected friends checkbox return parent else if node peers count connected darknet peers 10 parent add child p l10n few connected friends warning new string connected added new string integer to string node peers count connected darknet peers integer to string node peers get darknet peers length if new threat level network threat level maximum html node p parent add child p l10n addl10n substitution p security levels maximum network threat level warning new string bold bold new string b b parent add child input new string type name value new string checkbox checkbox name off l10n few connected friends checkbox return parent else if new threat level network threat level low parent add child p l10n network threat level low warning parent add child input new string type name value new string checkbox checkbox name off l10n network threat level low checkbox return parent don t warn on switching to normal if new threat level network threat level maximum html node p parent add child p l10n addl10n substitution p security levels maximum network threat level warning new string bold bold new string b b p add child l10n addl10n substitution p security levels max security you need friends new string bold bold new string b b parent add child input new string type name value new string checkbox checkbox name off l10n maximum network threat level checkbox return parent return null newthreatlevel htmlnode getconfirmwarning network_threat_level newthreatlevel checkboxname newthreatlevel networkthreatlevel htmlnode htmlnode newthreatlevel network_threat_level networkthreatlevel network_threat_level newthreatlevel network_threat_level getdarknetpeers addchild nofriendswarning newthreatlevel network_threat_level htmlnode addchild addl10nsubstitution securitylevels maximumnetworkthreatlevelwarning addchild checkboxname nofriendscheckbox countconnecteddarknetpeers addchild noconnectedfriendswarning tostring getdarknetpeers newthreatlevel network_threat_level htmlnode addchild addl10nsubstitution securitylevels maximumnetworkthreatlevelwarning addchild checkboxname noconnectedfriendscheckbox countconnecteddarknetpeers addchild fewconnectedfriendswarning tostring countconnecteddarknetpeers tostring getdarknetpeers newthreatlevel network_threat_level htmlnode addchild addl10nsubstitution securitylevels maximumnetworkthreatlevelwarning addchild checkboxname fewconnectedfriendscheckbox newthreatlevel network_threat_level addchild networkthreatlevellowwarning addchild checkboxname networkthreatlevellowcheckbox newthreatlevel network_threat_level htmlnode addchild addl10nsubstitution securitylevels maximumnetworkthreatlevelwarning addchild addl10nsubstitution securitylevels maxsecurityyouneedfriends addchild checkboxname maximumnetworkthreatlevelcheckbox public html node get confirm warning friends threat level new friends level string checkbox name if new friends level friends threat level return null not going to be changed if new friends level friends threat level high html node parent new html node div parent add child p l10n high friends threat level warning parent add child input new string type name value new string checkbox checkbox name off l10n high friends threat level checkbox return parent return null htmlnode getconfirmwarning friends_threat_level newfriendslevel checkboxname newfriendslevel friendsthreatlevel newfriendslevel friends_threat_level htmlnode htmlnode addchild highfriendsthreatlevelwarning addchild checkboxname highfriendsthreatlevelcheckbox private string l10n string string return l10n get string security levels string getstring securitylevels private string l10n string string string pattern string value return l10n get string security levels string pattern value getstring securitylevels private string l10n string string string patterns string values return l10n get string security levels string patterns values getstring securitylevels public void set threat level network threat level new threat level if new threat level null throw new null pointer exception network threat level old level synchronized this old level network threat level network threat level new threat level network threat level callback on set old level new threat level setthreatlevel network_threat_level newthreatlevel newthreatlevel nullpointerexception network_threat_level oldlevel oldlevel networkthreatlevel networkthreatlevel newthreatlevel networkthreatlevelcallback onset oldlevel newthreatlevel public void set threat level friends threat level new threat level if new threat level null throw new null pointer exception friends threat level old level synchronized this old level friends threat level friends threat level new threat level friends threat level callback on set old level new threat level setthreatlevel friends_threat_level newthreatlevel newthreatlevel nullpointerexception friends_threat_level oldlevel oldlevel friendsthreatlevel friendsthreatlevel newthreatlevel friendsthreatlevelcallback onset oldlevel newthreatlevel public void set threat level physical threat level new threat level if new threat level null throw new null pointer exception physical threat level old level synchronized this old level physical threat level physical threat level new threat level physical threat level callback on set old level new threat level setthreatlevel physical_threat_level newthreatlevel newthreatlevel nullpointerexception physical_threat_level oldlevel oldlevel physicalthreatlevel physicalthreatlevel newthreatlevel physicalthreatlevelcallback onset oldlevel newthreatlevel public static string localised name network threat level new threat level return l10n get string security levels network threat level name new threat level name localisedname network_threat_level newthreatlevel getstring securitylevels networkthreatlevel newthreatlevel public static string localised name friends threat level new friends level return l10n get string security levels friends threat level name new friends level name localisedname friends_threat_level newfriendslevel getstring securitylevels friendsthreatlevel newfriendslevel public static string localised name physical threat level new physical level return l10n get string security levels physical threat level name new physical level name localisedname physical_threat_level newphysicallevel getstring securitylevels physicalthreatlevel newphysicallevel public void register user alert user alert manager alerts alerts register new user alert public string anchor return seclevels public string dismiss button text return l10n get string user alert hide public html node gethtml text html node div new html node div html node ul div add child ul ul add child li l10n user alert network threat level level localised name network threat level ul add child li l10n user alert friends threat level level localised name friends threat level ul add child li l10n user alert physical threat level level localised name physical threat level div add child br l10n addl10n substitution div security levels user alert extro new string link link new string a href config mode config toadlet mode security levels a return div public short get priority class return user alert warning public string get short text return l10n user alert short text new string network friends physical new string localised name network threat level localised name friends threat level localised name physical threat level public string get text return gethtml text get content public string get title return l10n title public object get user identifier return null public boolean is event notification return false public boolean is valid return true public void is valid boolean validity ignore public void on dismiss ignore public boolean should unregister on dismiss return true public boolean user can dismiss return true registeruseralert useralertmanager useralert dismissbuttontext getstring useralert htmlnode gethtmltext htmlnode htmlnode htmlnode addchild addchild useralertnetworkthreatlevel localisedname networkthreatlevel addchild useralertfriendsthreatlevel localisedname friendsthreatlevel addchild useralertphysicalthreatlevel localisedname physicalthreatlevel addchild addl10nsubstitution securitylevels useralertextro configtoadlet mode_security_levels getpriorityclass useralert getshorttext useralertshorttext localisedname networkthreatlevel localisedname friendsthreatlevel localisedname physicalthreatlevel gettext gethtmltext getcontent gettitle getuseridentifier iseventnotification isvalid isvalid ondismiss shouldunregisterondismiss usercandismiss alerts register new user alert public string anchor return seclevels useralert public string dismiss button text return l10n get string user alert hide dismissbuttontext getstring useralert public html node gethtml text html node div new html node div html node ul div add child ul ul add child li l10n user alert network threat level level localised name network threat level ul add child li l10n user alert friends threat level level localised name friends threat level ul add child li l10n user alert physical threat level level localised name physical threat level div add child br l10n addl10n substitution div security levels user alert extro new string link link new string a href config mode config toadlet mode security levels a return div htmlnode gethtmltext htmlnode htmlnode htmlnode addchild addchild useralertnetworkthreatlevel localisedname networkthreatlevel addchild useralertfriendsthreatlevel localisedname friendsthreatlevel addchild useralertphysicalthreatlevel localisedname physicalthreatlevel addchild addl10nsubstitution securitylevels useralertextro configtoadlet mode_security_levels public short get priority class return user alert warning getpriorityclass useralert public string get short text return l10n user alert short text new string network friends physical new string localised name network threat level localised name friends threat level localised name physical threat level getshorttext useralertshorttext localisedname networkthreatlevel localisedname friendsthreatlevel localisedname physicalthreatlevel public string get text return gethtml text get content gettext gethtmltext getcontent public string get title return l10n title gettitle public object get user identifier return null getuseridentifier public boolean is event notification return false iseventnotification public boolean is valid return true isvalid public void is valid boolean validity ignore isvalid public void on dismiss ignore ondismiss public boolean should unregister on dismiss return true shouldunregisterondismiss public boolean user can dismiss return true usercandismiss private static final long serial versionuid 1 public duplicate identity exception string message super message serialversionuid duplicateidentityexception override public own introduction puzzle generate puzzle introduction puzzle store store own identity inserter throws io exception byte array output stream out new byte array output stream 10 1024 todo find out the maximum size of the captchas and put it here try buffered image img captcha create image text imageio write img jpg out date date of insertion current timeutc get synchronized store own introduction puzzle puzzle new own introduction puzzle inserter puzzle type captcha image jpeg out to byte array text date of insertion store get free index inserter date of insertion store store and commit puzzle return puzzle return null finally closer close out ownintroductionpuzzle generatepuzzle introductionpuzzlestore ownidentity ioexception bytearrayoutputstream bytearrayoutputstream bufferedimage createimage dateofinsertion currenttimeutc ownintroductionpuzzle ownintroductionpuzzle puzzletype tobytearray dateofinsertion getfreeindex dateofinsertion storeandcommit public udp socket handler int listen port inet address bindto node node long startup time string title io statistic collector collector throws socket exception this node node this collector collector this title title bindto bindto keep the updater code in just commented out for now we may want to be able to do on line updates if updater has resource sock datagram socket updater get resource else this listen port listen port sock new datagram socket listen port bindto int sz sock get receive buffer size if sz 65536 sock set receive buffer size 65536 try exit reasonably quickly sock set reuse address true catch socket exception e throw new runtime exception e only used for debugging no need to seed from yarrow drop random node fast weak random logminor logger should log logger minor this logdebug logger should log logger debug this tracker address tracker create node last bootid node get node dir listen port tracker start send startup time udpsockethandler listenport inetaddress startuptime iostatisticcollector socketexception _bindto hasresource _sock datagramsocket getresource listenport listenport _sock datagramsocket listenport _sock getreceivebuffersize _sock setreceivebuffersize _sock setreuseaddress socketexception runtimeexception droprandom fastweakrandom shouldlog shouldlog addresstracker lastbootid getnodedir listenport startsend startuptime must be called or we will npe in run public void set low level filter incoming packet filter f low level filter f setlowlevelfilter incomingpacketfilter lowlevelfilter public inet address get bind to return bindto inetaddress getbindto _bindto public string get title return title gettitle public void run listen for packets synchronized this thread thread current thread tracker start receive system current time millis try run loop catch throwable t impossible it keeps on exiting we get the below but not this try system err print t get class get name system err println catch throwable tt try system err print t get message system err println catch throwable tt try system gc system run finalization system gc system run finalization catch throwable tt try runtime r runtime get runtime system err print r free memory system err println system err print r total memory system err println catch throwable tt try t print stack trace catch throwable tt finally system err println run exiting for udp socket handler on port sock get local port logger error this run exiting for udp socket handler on port sock get local port synchronized this isdone true thread null notify all _thread currentthread startreceive currenttimemillis runloop getclass getname getmessage runfinalization runfinalization getruntime freememory totalmemory printstacktrace udpsockethandler _sock getlocalport udpsockethandler _sock getlocalport _isdone _thread notifyall private void run loop byte buf new byte max receive size datagram packet packet new datagram packet buf buf length while active true synchronized this if active return finished try real run packet catch out of memory error e oom handler handleoom e system err println will retry above failed operation catch throwable t system err println caught t t print stack trace system err logger error this caught t t runloop max_receive_size datagrampacket datagrampacket _active _active realrun outofmemoryerror oomhandler printstacktrace private void real run datagram packet packet single receiving thread boolean got packet get packet packet long now system current time millis if got packet long start time system current time millis peer peer new peer packet get address packet get port tracker received packet from peer long end time system current time millis if end time start time 50 if end time start time 3000 logger error this packet creation took end time start time ms else if logminor logger minor this packet creation took end time start time ms byte data packet get data int offset packet get offset int length packet get length try if logminor logger minor this processing packet of length length from peer start time system current time millis low level filter process data offset length peer now end time system current time millis if end time start time 50 if end time start time 3000 logger error this processing packet took end time start time ms else if logminor logger minor this processing packet took end time start time ms if logminor logger minor this successfully handled packet length length catch throwable t logger error this caught t from low level filter t else if logdebug logger debug this no packet received realrun datagrampacket gotpacket getpacket currenttimemillis gotpacket starttime currenttimemillis getaddress getport receivedpacketfrom endtime currenttimemillis endtime starttime endtime starttime endtime starttime endtime starttime getdata getoffset getlength starttime currenttimemillis lowlevelfilter endtime currenttimemillis endtime starttime endtime starttime endtime starttime endtime starttime lowlevelfilter private boolean get packet datagram packet packet try sock receive packet collector add info packet get address packet get port packet get length 0 fixme use packet get length udp headers length catch socket timeout exception e1 return false catch io exception e2 if active closed just return silently return false else throw new runtime exception e2 if logminor logger minor this received packet return true getpacket datagrampacket _sock addinfo getaddress getport getlength getlength udp_headers_length sockettimeoutexception ioexception _active runtimeexception send a block of encoded bytes to a peer this is called by send and by incoming packet filter process outgoing param block to send the data block to send param destination the peer to send it to public void send packet byte block to send peer destination boolean allow local addresses throws local address exception assert block to send null if active logger error this trying to send packet but no longer active it is essential that for recording accurate address tracker data that we don t send any more packets after shutdown return there should be no dns needed here but go ahead if we can but complain doing it if destination get address false allow local addresses null logger error this tried sending to destination without pre looked up ip address needs a real peer get hostname null destination get port new exception error if destination get address true allow local addresses null logger error this tried sending to bad destination address null destination get port new exception error return if dropprobability 0 if drop random next int dropprobability 0 if logminor logger minor this dropped sock get local port destination get port return inet address address destination get address false allow local addresses assert address null int port destination get port datagram packet packet new datagram packet block to send block to send length packet set address address packet set port port try sock send packet tracker sent packet to destination collector add info address port 0 block to send length udp headers length if logminor logger minor this sent packet length block to send length to address port catch io exception e if packet get address instanceof inet6 address logger normal this error while sending packet to i pv6 address destination e e else logger error this error while sending packet to destination e e incomingpacketfilter processoutgoing blocktosend sendpacket blocktosend allowlocaladdresses localaddressexception blocktosend _active addresstracker getaddress allowlocaladdresses gethostname getport getaddress allowlocaladdresses getport _dropprobability droprandom nextint _dropprobability _sock getlocalport getport inetaddress getaddress allowlocaladdresses getport datagrampacket datagrampacket blocktosend blocktosend setaddress setport _sock sentpacketto addinfo blocktosend udp_headers_length blocktosend ioexception getaddress inet6address ipv6 return the maximum packet size supported by this socket manager not including transport udp ip headers public int get max packet size fixme what about passing a peer node though and doing it on a per peer basis how pmtu would require jni although it might be worth it final int min advertisedmtu node ip detector get minimum detectedmtu we don t want the mtu detection thingy to prevent us to send packet transmits if disablemtu detection min advertisedmtu min mtu if disablemtu detection logger error this it shouldn t happen we disabled the mtu detection algorithm because the advertised mtu is smallish node ip detector get minimum detectedmtu disablemtu detection true return max allowed mtu udp headers length else return math min max allowed mtu min advertisedmtu udp headers length udp ip header is 28 bytes socketmanager getmaxpacketsize peernode minadvertisedmtu ipdetector getminimumdetectedmtu packettransmits disablemtudetection minadvertisedmtu min_mtu disablemtudetection ipdetector getminimumdetectedmtu disablemtudetection max_allowed_mtu udp_headers_length max_allowed_mtu minadvertisedmtu udp_headers_length public int get packet send threshold return get max packet size 100 getpacketsendthreshold getmaxpacketsize public void start synchronized this if active return started true start time system current time millis node executor execute this udp socket handler for port listen port _active _started starttime currenttimemillis udpsockethandler listenport public void close logger normal this closing new exception error synchronized this active false sock close if started return while isdone try wait 2000 catch interrupted exception e e print stack trace tracker store data node bootid node get node dir listen port _active _sock _started _isdone interruptedexception printstacktrace storedata getnodedir listenport public int get drop probability return dropprobability getdropprobability _dropprobability public void set drop probability int drop probability dropprobability drop probability setdropprobability dropprobability _dropprobability dropprobability public int get port number return sock get local port getportnumber _sock getlocalport override public string to string return sock get local address sock get local port tostring _sock getlocaladdress _sock getlocalport public int get headers length return udp headers length getheaderslength udp_headers_length public address tracker get address tracker return tracker addresstracker getaddresstracker public void rescan port forward tracker rescan rescanportforward public int get detected connectivity status return tracker get port forward status getdetectedconnectivitystatus getportforwardstatus public int get priority return native thread max priority getpriority nativethread max_priority public long get start time return start time getstarttime starttime private final boolean delete on free public temp file bucket long id filename generator generator this id generator true true deleteonfree tempfilebucket filenamegenerator constructor for the temp file bucket object subclasses can call this constructor param delete on exit set if you want the bucket deleted on shutdown passed to the parent base file bucket you must also override delete on exit and implement your own create shadow param delete on free true for a normal temp bucket false for a shadow protected temp file bucket long id filename generator generator boolean delete on exit boolean delete on free super generator get filename id delete on exit this filenameid id this generator generator this delete on free delete on free synchronized this log debug logger should log logger debug this system err println f proxy servlet temp file bucket created f get absolute path synchronized this if log debug logger debug this initializing temp file bucket get file delete on exit delete on exit tempfilebucket deleteonexit basefilebucket deleteonexit createshadow deleteonfree tempfilebucket filenamegenerator deleteonexit deleteonfree getfilename deleteonexit deleteonfree deleteonfree logdebug shouldlog fproxyservlet tempfilebucket getabsolutepath logdebug tempfilebucket getfile deleteonexit deleteonexit override protected boolean delete on finalize make sure finalize wacks temp file if it is not explictly freed return delete on free not if shadow deleteonfinalize deleteonfree override public simple field set to field set if delete on finalize return null not persistent for subclasses i e persistent temp file bucket return super to field set simplefieldset tofieldset deleteonfinalize persistenttempfilebucket tofieldset override protected boolean create file only return false createfileonly override protected boolean delete on free return delete on free deleteonfree deleteonfree override public file get file return generator get filename filenameid getfile getfilename public boolean is read only return read only isreadonly readonly public void set read only read only true setreadonly readonly override protected boolean delete on exit return true deleteonexit public void store to object container container container store generator container store this storeto objectcontainer public void remove from object container container if logger should log logger minor this logger minor this removing from database this filename generator is a global we don t need to worry about it container delete this removefrom objectcontainer shouldlog filenamegenerator public bucket create shadow throws io exception temp file bucket ret new temp file bucket filenameid generator true false ret set read only if get file exists logger error this file does not exist when creating shadow get file return ret createshadow ioexception tempfilebucket tempfilebucket setreadonly getfile getfile public ssdp packet byte buf int length dgm packet new datagram packet buf length ssdppacket dgmpacket datagrampacket private datagram packet dgm packet null public datagram packet get datagram packet return dgm packet datagrampacket dgmpacket datagrampacket getdatagrampacket dgmpacket private string local addr public void set local address string addr local addr addr localaddr setlocaladdress localaddr public string get local address return local addr getlocaladdress localaddr private long time stamp public void set time stamp long value time stamp value timestamp settimestamp timestamp public long get time stamp return time stamp gettimestamp timestamp public inet address get remote inet address return get datagram packet get address inetaddress getremoteinetaddress getdatagrampacket getaddress public string get remote address thanks for theo beisch 11 09 04 return get datagram packet get address get host address getremoteaddress getdatagrampacket getaddress gethostaddress public int get remote port return get datagram packet get port getremoteport getdatagrampacket getport public byte get data if packet bytes null return packet bytes datagram packet packet get datagram packet int packet len packet get length string packet data new string packet get data 0 packet len packet bytes packet data get bytes return packet bytes getdata packetbytes packetbytes datagrampacket getdatagrampacket packetlen getlength packetdata getdata packetlen packetbytes packetdata getbytes packetbytes public string get host return http header get value get data http host gethost httpheader getvalue getdata public string get cache control return http header get value get data http cache control getcachecontrol httpheader getvalue getdata cache_control public string get location return http header get value get data http location getlocation httpheader getvalue getdata public string getman return http header get value get data http man httpheader getvalue getdata public string getst return http header get value get data http st httpheader getvalue getdata public string getnt return http header get value get data http nt httpheader getvalue getdata public string getnts return http header get value get data http nts httpheader getvalue getdata public string get server return http header get value get data http server getserver httpheader getvalue getdata public string getusn return http header get value get data http usn httpheader getvalue getdata public int getmx return http header get integer value get data http mx httpheader getintegervalue getdata public inet address get host inet address string addr str 127 0 0 1 string host get host int canma idx host last index of if 0 canma idx addr str host substring 0 canma idx if addr str char at 0 addr str addr str substring 1 addr str length if addr str char at addr str length 1 addr str addr str substring 0 addr str length 1 inet socket address isockaddr new inet socket address addr str 0 return isockaddr get address inetaddress gethostinetaddress addrstr gethost canmaidx lastindexof canmaidx addrstr canmaidx addrstr charat addrstr addrstr addrstr addrstr charat addrstr addrstr addrstr addrstr inetsocketaddress inetsocketaddress addrstr getaddress public boolean is root device if nt is root device getnt true return true thanks for theo beisch 11 01 04 if st is root device getst true return true return usn is root device getusn isrootdevice isrootdevice isrootdevice isrootdevice public boolean is discover return man is discover getman isdiscover isdiscover public boolean is alive return nts is alive getnts isalive isalive public boolean is bye bye return nts is bye bye getnts isbyebye isbyebye public int get lease time return ssdp get lease time get cache control getleasetime getleasetime getcachecontrol public string to string return new string get data tostring getdata get a list of fields which the database should create an index on public static string get indexed fields fixme find out whether indexes are sorted if not remove the date and valid until time return new string mid m inserter m date of insertion m valid until time m was solved m was inserted getindexedfields validuntiltime minserter mdateofinsertion mvaliduntiltime mwassolved mwasinserted for construction from a received puzzle param new type param new data suppress warnings deprecation public introduction puzzle identity new inserter string newid puzzle type new type string new mime type byte new data long my valid until time date my date of insertion int my index assert new inserter null newid null new type null new mime type null new mime type equals new data null new data length 0 my valid until time current timeutc get in millis my date of insertion null my date of insertion get time current timeutc get in millis my index 0 mid newid m inserter new inserter m type new type m mime type new mime type m date of insertion new date my date of insertion get year my date of insertion get month my date of insertion get date m valid until time my valid until time m index my index m data new data m was solved false m solution null m solver null m was inserted false if check consistency false throw new illegal argument exception corrupted puzzle received newtype newdata suppresswarnings introductionpuzzle newinserter puzzletype newtype newmimetype newdata myvaliduntiltime mydateofinsertion myindex newinserter newtype newmimetype newmimetype newdata newdata myvaliduntiltime currenttimeutc getinmillis mydateofinsertion mydateofinsertion gettime currenttimeutc getinmillis myindex minserter newinserter mtype newtype mmimetype newmimetype mdateofinsertion mydateofinsertion getyear mydateofinsertion getmonth mydateofinsertion getdate mvaliduntiltime myvaliduntiltime mindex myindex mdata newdata mwassolved msolution msolver mwasinserted checkconsistency illegalargumentexception used by the introduction client for guessing the request ur is of puzzles to be able to download them public static freeneturi generate requesturi identity inserter date date of insertion int index assert date of insertion before current timeutc get assert index 0 fixme i did not really understand the javadoc of freeneturi please verify that the following code actually creates an uri which looks like the one i specified in the javadoc above this function thanks string day of insertion synchronized m date format day of insertion m date format format date of insertion freeneturi baseuri inserter get requesturi set key type ssk baseuri baseuri set doc name wot wot name introduction context day of insertion index return baseuri set meta string null introductionclient uris generaterequesturi dateofinsertion dateofinsertion currenttimeutc dayofinsertion mdateformat dayofinsertion mdateformat dateofinsertion getrequesturi setkeytype setdocname wot_name introduction_context dayofinsertion setmetastring get the uri where this puzzle was downloaded from public freeneturi get requesturi return generate requesturi m inserter m date of insertion m index getrequesturi generaterequesturi minserter mdateofinsertion mindex get the date of a puzzle from it s uri used for being able to query the database for an existing introduction puzzle object when a new one was downloaded public static date get date from requesturi freeneturi requesturi throws parse exception string tokens requesturi get doc name split synchronized m date format return m date format parse tokens 2 introductionpuzzleobject getdatefromrequesturi parseexception getdocname mdateformat mdateformat get the index of a puzzle from it s uri used for being able to query the database for an existing introduction puzzle object when a new one was downloaded public static int get index from requesturi freeneturi requesturi string tokens requesturi get doc name split return integer parse int tokens 3 introductionpuzzleobject getindexfromrequesturi getdocname parseint get the id of a puzzle from the uri of it s solution used for querying the database for the associated puzzle after a solution was fetched or inserted successfully public static string getid from solutionuri freeneturi uri return uri get doc name split 2 getidfromsolutionuri getdocname public string getid return mid public puzzle type get type return m type puzzletype gettype mtype public string get mime type return m mime type getmimetype mmimetype public byte get data return m data getdata mdata public identity get inserter return m inserter getinserter minserter public date get date of insertion return m date of insertion getdateofinsertion mdateofinsertion public long get valid until time return m valid until time getvaliduntiltime mvaliduntiltime public int get index return m index getindex mindex however if one only knows this class and not how it is used by the rest its logical to synchronize it used by the introduction client to mark a puzzle as solved param solver the identity which solved the puzzle correctly param solution the solution which was passed by the solver throws invalid parameter exception if the puzzle was already solved public synchronized void set solved own identity solver string solution throws invalid parameter exception if m was solved throw new invalid parameter exception puzzle is already solved todo create a special exception for that m was solved true m solver solver m solution solution introductionclient invalidparameterexception setsolved ownidentity invalidparameterexception mwassolved invalidparameterexception mwassolved msolver msolution public synchronized boolean was solved return m was solved wassolved mwassolved however if one only knows this class and not how it is used by the rest its logical to synchronize it get the own identity which solved this puzzle used by the introduction client for inserting identity introductions public synchronized own identity get solver assert m was solved return m solver ownidentity introductionclient ownidentity getsolver mwassolved msolver get the uri at which to insert the solution of this puzzle if you have solved it at which the solution is trying to be fetched format ksk wot introduction id guess of solution id the id of the puzzle which itself contains the uuid of the puzzle and the id of the inserter guess of solution the guess of the solution which is passed to the function public synchronized freeneturi get solutionuri if m solution null throw new runtime exception the puzzle is not solved return new freeneturi ksk wot wot name introduction context mid m solution guessofsolution guessofsolution getsolutionuri msolution runtimeexception wot_name introduction_context msolution public synchronized boolean was inserted return m was inserted wasinserted mwasinserted public synchronized void set inserted if m was inserted throw new runtime exception the puzzle was already inserted m was inserted true setinserted mwasinserted runtimeexception mwasinserted fixme check for validity of the jpeg suppress warnings deprecation public boolean check consistency boolean result true if mid null logger error this mid null result false else verify the uid if m inserter null string inserterid m inserter getid if mid ends with inserterid false logger error this mid does not start with inserterid mid result false verification that the rest of the id is an uuid is not necessary if a client inserts a puzzle with the id just being his identity id or other bogus stuff he will just shoot himself in the foot by possibly only allowing 1 puzzle of him to be available because the databases of the downloaders check whether the id already exists if m type null logger error this m type null result false if m mime type null m mime type equals image jpeg logger error this m mime type m mime type result false if new date m valid until time before new date 2008 1900 10 10 logger error this m valid until time new date m valid until time result false if m data null m data length 100 logger error this m data m data result false if m inserter null logger error this m inserter null result false if m date of insertion null m date of insertion before new date 2008 1900 10 10 m date of insertion after current timeutc get logger error this m date of insertion m date of insertion current time current timeutc get result false if m index 0 logger error this m index m index result false return result suppresswarnings checkconsistency minserter minserter endswith mtype mtype mmimetype mmimetype mmimetype mmimetype mvaliduntiltime mvaliduntiltime mvaliduntiltime mdata mdata mdata mdata minserter minserter mdateofinsertion mdateofinsertion mdateofinsertion currenttimeutc mdateofinsertion mdateofinsertion currenttime currenttimeutc mindex mindex mindex private float scale 4 public diffuse filter set edge action clamp diffusefilter setedgeaction specifies the scale of the texture param scale the scale of the texture min value 1 max value 100 see get scale public void set scale float scale this scale scale getscale setscale returns the scale of the texture return the scale of the texture see set scale public float get scale return scale setscale getscale override protected void transform inverse int x int y float out int angle int math random 255 float distance float math random out 0 x distance sin table angle out 1 y distance cos table angle transforminverse sintable costable override public buffered image filter buffered image src buffered image dst sin table new float 256 cos table new float 256 for int i 0 i 256 i float angle image math two pi i 256f sin table i float scale math sin angle cos table i float scale math cos angle return super filter src dst bufferedimage bufferedimage bufferedimage sintable costable imagemath two_pi sintable costable override public string to string return distort diffuse tostring public persistent blob temp bucket factory long block size2 long nodedb handle2 file storage file2 block size block size2 nodedb handle nodedb handle2 storage file storage file2 persistentblobtempbucketfactory blocksize2 nodedbhandle2 storagefile2 blocksize blocksize2 nodedbhandle nodedbhandle2 storagefile storagefile2 void on init object container container db job runner job runner2 random fast weak random file storage file2 long block size2 ticker ticker throws io exception container activate storage file 100 file old file file util get canonical file new file storage file get path db4o argh file new file file util get canonical file new file storage file2 get path if block size block size2 throw new illegal state exception my block size is block size2 but stored block size is block size for same file storage file if old file equals new file file separator char old file get path to lower case equals new file get path to lower case old file get path equals new file get path if file util move to storage file storage file2 false throw new io exception unable to move temp blob file from storage file to storage file2 raf new random access file storage file rw channel raf get channel not committed blobs new tree map long persistent blob temp bucket free slots new tree map long persistent blob temp bucket tag almost free slots new tree map long persistent blob temp bucket tag shadows new tree map long persistent blob temp bucket job runner job runner2 weak random source fast weak random free jobs new hash set db job this ticker ticker maybe shrink container diagnostics long size try size channel size catch io exception e1 logger error this unable to find size of temp blob storage file e1 e1 return size size block size long blocks size block size long ptr blocks 1 long used 0 long range start long min value persistent blob temp bucket tag first in range null for long l 0 l ptr l synchronized this if free slots contains key l continue if not committed blobs contains key l continue if almost free slots contains key l continue query query container query query constrain persistent blob temp bucket tag class query descend index constrain l object set persistent blob temp bucket tag tags query execute if tags has next persistent blob temp bucket tag tag tags next if tag is free used if tag bucket null tag is free logger error this no bucket but flagged as not free index l tag bucket if tag bucket null tag is free logger error this has bucket but flagged as free index l tag bucket if tag is free if range start long min value range start l first in range tag else if range start long min value system out println range range start to l 1 first is first in range range start long min value first in range null continue logger error this found empty slot l when scanning the blob file because tags in database length of file persistent blob temp bucket tag tag new persistent blob temp bucket tag persistent blob temp bucket factory this l container store tag synchronized this free slots put ptr tag if range start long min value system out println range range start to ptr 1 system err println persistent blobs blocks blocks used used oninit objectcontainer dbjobrunner jobrunner2 fastweakrandom storagefile2 blocksize2 ioexception storagefile oldfile fileutil getcanonicalfile storagefile getpath newfile fileutil getcanonicalfile storagefile2 getpath blocksize blocksize2 illegalstateexception blocksize2 blocksize storagefile oldfile newfile separatorchar oldfile getpath tolowercase newfile getpath tolowercase oldfile getpath newfile getpath fileutil moveto storagefile storagefile2 ioexception storagefile storagefile2 randomaccessfile storagefile getchannel notcommittedblobs treemap persistentblobtempbucket freeslots treemap persistentblobtempbuckettag almostfreeslots treemap persistentblobtempbuckettag treemap persistentblobtempbucket jobrunner jobrunner2 weakrandomsource fastweakrandom freejobs hashset dbjob maybeshrink ioexception blocksize blocksize rangestart min_value persistentblobtempbuckettag firstinrange freeslots containskey notcommittedblobs containskey almostfreeslots containskey persistentblobtempbuckettag objectset persistentblobtempbuckettag hasnext persistentblobtempbuckettag isfree isfree isfree isfree rangestart min_value rangestart firstinrange rangestart min_value rangestart firstinrange rangestart min_value firstinrange persistentblobtempbuckettag persistentblobtempbuckettag persistentblobtempbucketfactory freeslots rangestart min_value rangestart public string get name return storage file get path getname storagefile getpath public void run object container container client context context int added 0 while true boolean logminor logger should log logger minor this synchronized persistent blob temp bucket factory this if free slots size max free return long size try size channel size catch io exception e1 logger error this unable to find size of temp blob storage file e1 e1 return size size block size long blocks size block size long ptr blocks 1 for long l 0 l block size 16383 l 16384 query query container query query constrain persistent blob temp bucket tag class query descend is free constrain true and query descend index constrain l smaller object set persistent blob temp bucket tag tags query execute long not committed synchronized persistent blob temp bucket factory this while tags has next persistent blob temp bucket tag tag tags next if tag is free logger error this tag not free tag index if tag bucket null logger error this tag flagged non free yet has no bucket for index tag index tag is free true else continue if tag bucket null logger error this query returned tag with valid bucket continue if tag factory persistent blob temp bucket factory this continue if not committed blobs contains key tag index continue if almost free slots contains key tag index continue if free slots contains key tag index continue if tag bucket null logger error this bucket is occupied but not in not committed blobs tag tag bucket continue if logminor logger minor this adding slot tag index to free slots has a free tag and no taken tag free slots put tag index tag added if added max free return fixme the issue below has been marked as fixed in the db4o bugtracker can this be resolved now checking for slots marked occupied with bucket null is nontrivial because constraining to null doesn t work causes an oom with a large database because it does not use the index and therefore instantiates every object and oo ms see http tracker db4o com browse cor 1446 check that the number of tags is equal to the size of the file if logminor logger minor this checking number of tags against file size query query container query query constrain persistent blob temp bucket tag class object set persistent blob temp bucket tag tags query execute long indb tags size if logminor logger minor this checked size tags null if indb ptr logger error this tags in database indb but size of file allows ptr recover exhaustive index search this can cause very long pauses but should only happen if there is a bug for long l 0 l ptr l synchronized this if free slots contains key l continue if not committed blobs contains key l continue if almost free slots contains key l continue query container query query constrain persistent blob temp bucket tag class query descend index constrain l tags query execute if tags has next continue logger error this found empty slot l when scanning the blob file because tags in database length of file persistent blob temp bucket tag tag new persistent blob temp bucket tag persistent blob temp bucket factory this l container store tag synchronized this free slots put ptr tag added if added max free return db job free job null synchronized this if free jobs is empty free job free jobs iterator next free jobs remove free job if free job null container activate free job 1 system err println freeing some space by running free job logger minor this freeing some space by running free job free job run container context continue lets extend the file fixme if physical security is low just set the length possibly padding will nonrandom nulls on unix long add blocks math min 8192 blocks 10 32 long extend by add blocks block size long written 0 byte buf new byte 4096 byte buffer buffer byte buffer wrap buf while written extend by weak random source next bytes buf int bytes left int math min extend by written integer max value if bytes left buf length buffer limit bytes left try written channel write buffer size written buffer clear catch io exception e break query container query query constrain persistent blob temp bucket tag class query descend index constrain blocks 1 greater and query descend factory constrain persistent blob temp bucket factory this hash set long taken null object set persistent blob temp bucket tag results query execute while results has next persistent blob temp bucket tag tag results next if tag is free logger error this block already exists beyond the end of the file yet is occupied block tag index if taken null taken new hash set long taken add tag index for int i 0 i add blocks i ptr blocks i if taken null taken contains ptr continue persistent blob temp bucket tag tag new persistent blob temp bucket tag persistent blob temp bucket factory this ptr container store tag synchronized persistent blob temp bucket factory this if logminor logger minor this adding slot ptr to free slots while extending storage file free slots put ptr tag return objectcontainer clientcontext shouldlog persistentblobtempbucketfactory freeslots max_free ioexception blocksize blocksize blocksize persistentblobtempbuckettag isfree objectset persistentblobtempbuckettag notcommitted persistentblobtempbucketfactory hasnext persistentblobtempbuckettag isfree isfree persistentblobtempbucketfactory notcommittedblobs containskey almostfreeslots containskey freeslots containskey notcommittedblobs freeslots freeslots max_free ooms persistentblobtempbuckettag objectset persistentblobtempbuckettag freeslots containskey notcommittedblobs containskey almostfreeslots containskey persistentblobtempbuckettag hasnext persistentblobtempbuckettag persistentblobtempbuckettag persistentblobtempbucketfactory freeslots max_free dbjob freejob freejobs isempty freejob freejobs freejobs freejob freejob freejob freejob freejob freejob addblocks extendby addblocks blocksize bytebuffer bytebuffer extendby weakrandomsource nextbytes bytesleft extendby max_value bytesleft bytesleft ioexception persistentblobtempbuckettag persistentblobtempbucketfactory hashset objectset persistentblobtempbuckettag hasnext persistentblobtempbuckettag isfree hashset addblocks persistentblobtempbuckettag persistentblobtempbuckettag persistentblobtempbucketfactory persistentblobtempbucketfactory freeslots freeslots return a bucket or null in various failure cases public persistent blob temp bucket make bucket find a free slot synchronized this if free slots is empty long slot free slots first key persistent blob temp bucket tag tag free slots remove slot if not committed blobs get slot null almost free slots get slot null logger error this slot slot already occupied by a not committed blob despite being in free slots return null persistent blob temp bucket bucket new persistent blob temp bucket this block size slot tag false not committed blobs put slot bucket if logger should log logger minor this logger minor this using slot slot for bucket return bucket job runner run blocking slot finder native thread high priority synchronized this if free slots is empty long slot free slots first key persistent blob temp bucket tag tag free slots remove slot if not committed blobs get slot null almost free slots get slot null logger error this slot slot already occupied by a not committed blob despite being in free slots return null persistent blob temp bucket bucket new persistent blob temp bucket this block size slot tag false not committed blobs put slot bucket if logger should log logger minor this logger minor this using slot slot for bucket after waiting return bucket logger error this returning null unable to create a bucket for some reason node will fallback to file based buckets return null persistentblobtempbucket makebucket freeslots isempty freeslots firstkey persistentblobtempbuckettag freeslots notcommittedblobs almostfreeslots freeslots persistentblobtempbucket persistentblobtempbucket blocksize notcommittedblobs shouldlog jobrunner runblocking slotfinder nativethread high_priority freeslots isempty freeslots firstkey persistentblobtempbuckettag freeslots notcommittedblobs almostfreeslots freeslots persistentblobtempbucket persistentblobtempbucket blocksize notcommittedblobs shouldlog public synchronized void free bucket long index persistent blob temp bucket bucket if logger should log logger minor this logger minor this freeing index index for bucket new exception debug not committed blobs remove index bucket on free if bucket persisted if it hasn t been written to the database it doesn t need to be removed so remove from won t be called free slots put index bucket tag persistent blob temp bucket shadow shadows get index if shadow null shadow freed freebucket persistentblobtempbucket shouldlog notcommittedblobs onfree removefrom freeslots persistentblobtempbucket public synchronized void remove persistent blob temp bucket bucket object container container if logger should log logger minor this logger minor this removing bucket bucket for slot bucket index from database new exception debug long index bucket index persistent blob temp bucket tag tag bucket tag if tag null if container ext is active bucket logger error this bucket not active in remove bucket new exception error container activate bucket 1 tag bucket tag index bucket index else this is impossible yet saces has seen it in practice lets get some detail logger error this no tag on bucket removing bucket index index new exception error query query container query query constrain persistent blob temp bucket tag class query descend index constrain index object set persistent blob temp bucket tag results query execute if results has next logger error this tag does not exist for index index else tag results next if tag index index crazy things are happening may as well check the impossible logger error this invalid index should be index but is tag index if tag is free logger error this found tag but is free tag if tag bucket null logger error this found tag but no bucket tag else if tag bucket bucket logger error this tag links to bucket but bucket doesn t link to tag else tag bucket bucket logger error this serious error tag belongs to a different bucket container activate tag 1 if bucket persisted maybe shrink container return if bucket freed logger error this removing bucket bucket for slot bucket index but not freed new exception debug not committed blobs put index bucket else almost free slots put index tag tag bucket null tag is free true container store tag container delete bucket bucket on remove maybe shrink container persistentblobtempbucket objectcontainer shouldlog persistentblobtempbuckettag isactive persistentblobtempbuckettag objectset persistentblobtempbuckettag hasnext isfree maybeshrink notcommittedblobs almostfreeslots isfree onremove maybeshrink void maybe shrink object container container boolean logminor logger should log logger minor this if logminor logger minor this maybe shrink long now system current time millis long new blocks synchronized this if now last checked end 60 1000 if logminor logger minor this maybe shrink inner check whether there is a big white space at the end of the file long size try size channel size catch io exception e1 logger error this unable to find size of temp blob storage file e1 e1 return size size block size long blocks size block size if blocks 32 if logminor logger minor this not shrinking blob file not larger than a megabyte last checked end now queue maybe shrink return long last not committed not committed blobs is empty 0 not committed blobs last key long last almost freed almost free slots is empty 0 almost free slots last key if last not committed last almost freed if logminor logger minor this last almost freed last almost freed replacing last not committed last not committed last not committed last almost freed double full double last not committed double blocks if full 0 8 if logminor logger minor this not shrinking last not committed block is at full 100 last not committed of blocks last checked end now queue maybe shrink return query for the non free tag with the highest value this query can return a vast number of objects and it s all kept in ram in immediate mode fixme lazy query mode may help but would likely require changes to other code in the meantime lets try from the end going backwards by a manageable number of slots at a time long last committed 1 for long threshold blocks 4096 threshold 4095 threshold 4096 query query container query query constrain persistent blob temp bucket tag class query descend is free constrain false query descend index order descending query descend index constrain threshold greater object set persistent blob temp bucket tag tags query execute if tags is empty no used slots after threshold continue else last committed tags next index logger normal this last committed block is last committed break if last committed 1 no used slots at all there may be some not committed though logger normal this no used slots in persistent temp file but last not committed last not committed last committed 0 full double last committed double blocks if full 0 8 if logminor logger minor this not shrinking last committed block is at full 100 last checked end now queue maybe shrink return long last block math max last committed last not committed must be 10 free at end new blocks long last block 32 1 1 new blocks math max new blocks 32 if new blocks blocks if logminor logger minor this not shrinking would shrink from blocks to new blocks last checked end now queue maybe shrink return system err println shrinking blob file from blocks to new blocks for long l new blocks l blocks l free slots remove l for long l free slots key set if l new blocks logger error this removing free slot l over the current block limit last checked end now queue maybe shrink else return try channel truncate new blocks block size catch io exception e system err println shrinking blob file failed system err println e e print stack trace logger error this shrinking blob file failed e e query query container query query constrain persistent blob temp bucket tag class query descend index constrain new blocks greater object set persistent blob temp bucket tag tags query execute while tags has next container delete tags next maybeshrink objectcontainer shouldlog maybeshrink currenttimemillis newblocks lastcheckedend maybeshrink ioexception blocksize blocksize lastcheckedend queuemaybeshrink lastnotcommitted notcommittedblobs isempty notcommittedblobs lastkey lastalmostfreed almostfreeslots isempty almostfreeslots lastkey lastnotcommitted lastalmostfreed lastalmostfreed lastnotcommitted lastnotcommitted lastalmostfreed lastnotcommitted lastnotcommitted lastcheckedend queuemaybeshrink lastcommitted persistentblobtempbuckettag isfree orderdescending objectset persistentblobtempbuckettag isempty lastcommitted lastcommitted lastcommitted lastnotcommitted lastcommitted lastcommitted lastcheckedend queuemaybeshrink lastblock lastcommitted lastnotcommitted newblocks lastblock newblocks newblocks newblocks newblocks lastcheckedend queuemaybeshrink newblocks newblocks freeslots freeslots keyset newblocks lastcheckedend queuemaybeshrink newblocks blocksize ioexception printstacktrace persistentblobtempbuckettag newblocks objectset persistentblobtempbuckettag hasnext private void queue maybe shrink ticker queue timed job new runnable public void run job runner queue new db job public void run object container container client context context maybe shrink container native thread norm priority 1 true 61 1000 queuemaybeshrink queuetimedjob jobrunner dbjob objectcontainer clientcontext maybeshrink nativethread norm_priority public void run job runner queue new db job public void run object container container client context context maybe shrink container native thread norm priority 1 true jobrunner dbjob objectcontainer clientcontext maybeshrink nativethread norm_priority job runner queue new db job public void run object container container client context context maybe shrink container jobrunner dbjob objectcontainer clientcontext maybeshrink public void store persistent blob temp bucket bucket object container container if logger should log logger minor this logger minor this storing bucket bucket for slot bucket index to database long index bucket index persistent blob temp bucket tag tag bucket tag container activate tag 1 if tag bucket null tag bucket bucket logger error this slot index already occupied tag bucket for tag index throw new illegal state exception slot index already occupied tag bucket bucket tag is free false container store tag container store bucket synchronized this not committed blobs remove index persistentblobtempbucket objectcontainer shouldlog persistentblobtempbuckettag illegalstateexception isfree notcommittedblobs public synchronized void post commit int free now free slots size int sz free now almost free slots size if sz max free iterator map entry long persistent blob temp bucket tag it almost free slots entry set iterator for int i free now i max free it has next i map entry long persistent blob temp bucket tag entry it next free slots put entry get key entry get value else free slots put all almost free slots almost free slots clear postcommit freenow freeslots freenow almostfreeslots max_free persistentblobtempbuckettag almostfreeslots entryset freenow max_free hasnext persistentblobtempbuckettag freeslots getkey getvalue freeslots putall almostfreeslots almostfreeslots public bucket create shadow persistent blob temp bucket bucket long index bucket index long i index synchronized this if shadows contains key i return null persistent blob temp bucket shadow new persistent blob temp bucket this block size index null true shadow size bucket size shadows put i shadow return shadow createshadow persistentblobtempbucket containskey persistentblobtempbucket persistentblobtempbucket blocksize public synchronized void free shadow long index persistent blob temp bucket bucket persistent blob temp bucket temp shadows remove index if temp bucket logger error this freed wrong shadow temp should be bucket shadows put index temp freeshadow persistentblobtempbucket persistentblobtempbucket public void add blob free callback db job job synchronized this free jobs add job addblobfreecallback dbjob freejobs public void remove blob free callback db job job synchronized this free jobs remove job removeblobfreecallback dbjob freejobs public service info resolver jmdns impl jmdns impl service info impl info this jmdns impl jmdns impl this info info info set dns this jmdns impl this jmdns impl add listener info new dns question info get qualified name dns constants type any dns constants class in serviceinforesolver jmdnsimpl jmdnsimpl serviceinfoimpl jmdnsimpl jmdnsimpl setdns jmdnsimpl jmdnsimpl addlistener dnsquestion getqualifiedname dnsconstants type_any dnsconstants class_in public void start timer timer timer schedule this dns constants query wait interval dns constants query wait interval dnsconstants query_wait_interval dnsconstants query_wait_interval public void run try if this jmdns impl get state dns state announced if count 3 info has data long now system current time millis dns outgoing out new dns outgoing dns constants flags qr query out add question new dns question info get qualified name dns constants type srv dns constants class in out add question new dns question info get qualified name dns constants type txt dns constants class in if info get server null out add question new dns question info get server dns constants type a dns constants class in out add answer dns record this jmdns impl get cache get info get qualified name dns constants type srv dns constants class in now out add answer dns record this jmdns impl get cache get info get qualified name dns constants type txt dns constants class in now if info get server null out add answer dns record this jmdns impl get cache get info get server dns constants type a dns constants class in now this jmdns impl send out else after three queries we can quit this cancel this jmdns impl remove listener info else if this jmdns impl get state dns state canceled this cancel this jmdns impl remove listener info catch throwable e logger log level warning run exception e this jmdns impl recover jmdnsimpl getstate dnsstate hasdata currenttimemillis dnsoutgoing dnsoutgoing dnsconstants flags_qr_query addquestion dnsquestion getqualifiedname dnsconstants type_srv dnsconstants class_in addquestion dnsquestion getqualifiedname dnsconstants type_txt dnsconstants class_in getserver addquestion dnsquestion getserver dnsconstants type_a dnsconstants class_in addanswer dnsrecord jmdnsimpl getcache getqualifiedname dnsconstants type_srv dnsconstants class_in addanswer dnsrecord jmdnsimpl getcache getqualifiedname dnsconstants type_txt dnsconstants class_in getserver addanswer dnsrecord jmdnsimpl getcache getserver dnsconstants type_a dnsconstants class_in jmdnsimpl jmdnsimpl removelistener jmdnsimpl getstate dnsstate jmdnsimpl removelistener jmdnsimpl protected volatile boolean finished init public persistent config simple field set initial contents this orig config file contents initial contents finishedinit persistentconfig simplefieldset initialcontents origconfigfilecontents initialcontents finished initialization so any remaining options must be invalid override public synchronized void finished init finished init true if orig config file contents null return iterator string i orig config file contents key iterator while i has next string key i next logger error this unknown option key value orig config file contents get key orig config file contents null finishedinit finishedinit origconfigfilecontents origconfigfilecontents keyiterator hasnext origconfigfilecontents origconfigfilecontents public simple field set export field set return export field set false simplefieldset exportfieldset exportfieldset public simple field set export field set boolean with defaults return export field set config request type current settings with defaults simplefieldset exportfieldset withdefaults exportfieldset requesttype current_settings withdefaults public simple field set export field set config request type config request type boolean with defaults simple field set fs new simple field set true sub config configs synchronized this fixme maybe keep a cache of this configs configs by prefix values to array new sub config configs by prefix size sub config current for int i 0 i configs length i current configs i simple field set scfs current export field set config request type with defaults fs tput current prefix scfs return fs simplefieldset exportfieldset requesttype configrequesttype withdefaults simplefieldset simplefieldset subconfig configsbyprefix toarray subconfig configsbyprefix subconfig simplefieldset exportfieldset configrequesttype withdefaults override public void on register sub config config option o string val name synchronized this if finished init throw new illegal state exception on register config o called after finished init if orig config file contents null return name config prefix simple field set multi level char o name val orig config file contents get name orig config file contents remove value name if val null return try o set initial value val trim catch invalid config value exception e logger error this could not parse config option name e e onregister subconfig finishedinit illegalstateexception onregister finishedinit origconfigfilecontents simplefieldset multi_level_char origconfigfilecontents origconfigfilecontents removevalue setinitialvalue invalidconfigvalueexception return a copy of the sfs as read by the config framework return a sfs or null if initialization is finished public synchronized simple field set get simple field set return orig config file contents null null new simple field set orig config file contents simplefieldset getsimplefieldset origconfigfilecontents simplefieldset origconfigfilecontents final string keyword private clientksk string keyword byte pub key hash dsa public key pub key dsa private key priv key byte keyword hash throws malformedurl exception super keyword pub key hash pub key priv key keyword hash key algo aes pcfb 256 sha256 this keyword keyword pubkeyhash dsapublickey pubkey dsaprivatekey privkey keywordhash malformedurlexception pubkeyhash pubkey privkey keywordhash algo_aes_pcfb_256_sha256 override public freeneturi geturi return new freeneturi ksk keyword public static insertable clientssk create freeneturi uri if uri get key type equals ksk throw new illegal argument exception return create uri get doc name insertableclientssk getkeytype illegalargumentexception getdocname public static clientksk create string keyword message digest md256 sha256 get message digest try byte keyword hash try keyword hash md256 digest keyword get bytes utf 8 catch unsupported encoding exception e throw new error impossible jvm doesn t support utf 8 e e mersenne twister mt new mersenne twister keyword hash dsa private key priv key new dsa private key global ds agroup biga mt dsa public key pub key new dsa public key global ds agroup biga priv key byte pub key hash md256 digest pub key as bytes try return new clientksk keyword pub key hash pub key priv key keyword hash catch malformedurl exception e throw new error e finally sha256 return message digest md256 messagedigest getmessagedigest keywordhash keywordhash getbytes unsupportedencodingexception mersennetwister mersennetwister keywordhash dsaprivatekey privkey dsaprivatekey dsagroupbiga dsapublickey pubkey dsapublickey dsagroupbiga privkey pubkeyhash pubkey asbytes pubkeyhash pubkey privkey keywordhash malformedurlexception returnmessagedigest private int seed 0 public scratch filter scratchfilter public void set angle float angle this angle angle setangle public float get angle return angle getangle public void set angle variation float angle variation this angle variation angle variation setanglevariation anglevariation anglevariation anglevariation public float get angle variation return angle variation getanglevariation anglevariation public void set density float density this density density setdensity public float get density return density getdensity public void set length float length this length length setlength public float get length return length getlength public void set width float width this width width setwidth public float get width return width getwidth public void set color int color this color color setcolor public int get color return color getcolor public void set seed int seed this seed seed setseed public int get seed return seed getseed public buffered image filter buffered image src buffered image dst if dst null dst create compatible dest image src null int width src get width int height src get height int num scratches int density width height 100 array list lines new array list float l length width random random new random seed graphics2d g dst create graphics g set rendering hint rendering hints key antialiasing rendering hints value antialias on g set color new color color g set stroke new basic stroke this width for int i 0 i num scratches i float x width random next float float y height random next float float a angle image math two pi angle variation random next float 0 5f float s float math sin a l float c float math cos a l float x1 x c float y1 y s float x2 x c float y2 y s g draw line int x1 int y1 int x2 int y2 lines add new line2d float x1 y1 x2 y2 g dispose if false int in pixels getrgb src 0 0 width height null int in pixels new int width height int index 0 for int y 0 y height y for int x 0 x width x float sx x sy y for int i 0 i num scratches i line2d float l line2d float lines get i float dot l x2 l x1 sx l x1 l y2 l y1 sy l y1 if dot 0 in pixels index 1 i index colormap colormap new linear colormap index 0 for int y 0 y height y for int x 0 x width x float f float in pixels index 0x7fffffff 0x7fffffff in pixels index colormap get color f index setrgb dst 0 0 width height in pixels return dst bufferedimage bufferedimage bufferedimage createcompatibledestimage getwidth getheight numscratches arraylist arraylist creategraphics setrenderinghint renderinghints key_antialiasing renderinghints value_antialias_on setcolor setstroke basicstroke numscratches nextfloat nextfloat imagemath two_pi anglevariation nextfloat drawline inpixels inpixels numscratches inpixels linearcolormap inpixels inpixels getcolor inpixels override public string to string return render scratches tostring public static void setup plugin respirator pr xml librarian xl search pr pr search xl xl pluginrespirator xmllibrarian searches for the string in the specified index in case of a folder searches in all included indices param out param search string to be searched param indexuri param stylesheet public static void search str string builder out string search string indexuri throws exception search search to lower case if search equals out append give a valid string to search n return try get search result string search words search split p l n return results in order list uri wrapper hs null search for each string in the search list only the common results to all words are returned as final result try index idx new index indexuri pr idx fetch hs idx search search words catch fetch exception e out append p could not fetch sub index for html encoder encode search e get message p n logger normal xl p could not fetch sub index for html encoder encode search in html encoder encode indexuri e to string p n e catch exception e out append p could not complete search for html encoder encode search e to string p n out append string value of e get stack trace logger error xl could not complete search for search in indexuri e to string e output results int results 0 out append table class librarian results tr n iterator uri wrapper it hs iterator try while it has next uri wrapper o it next string showurl o uri string showtitle o descr if showtitle trim length 0 showtitle not available if showtitle equals not available showtitle showurl string description html encoder encode o descr if description equals not available description description replace all n lt b b r r gt br description description replace all nbsp description description replace all lt a za z gt showurl html encoder encode showurl if showurl length 60 showurl showurl substring 0 15 hellip showurl replace first string realurl o uri starts with o uri realurl html encoder encode realurl out append p n table class librarian result width 100 border 1 tr td align center bgcolor d0d0d0 class librarian result url n out append a href append realurl append title append o uri append append showtitle append a n out append td tr tr td align left class librarian result summary n out append td tr table n results catch exception e out append could not display results for search e to string logger error xl could not display search results for search e to string e out append tr table n out append p span class librarian summary found text found span span class librarian summary found number append results append results span p n catch exception e logger error xl could not complete search for search in indexuri e to string e e print stack trace searchstr stringbuilder tolowercase searchwords uriwrapper searchwords fetchexception htmlencoder getmessage htmlencoder htmlencoder tostring htmlencoder tostring valueof getstacktrace tostring uriwrapper hasnext uriwrapper htmlencoder replaceall replaceall replaceall htmlencoder replacefirst startswith htmlencoder tostring tostring tostring printstacktrace searches for the string in the specified index in case of a folder searches in all included indices param out param search string to be searched param indexuri this function will be made to only return placeholder with xmlhttp request callbacks it will start a separate thread to search and all out append s will act on progress public static void search str async string builder out string search string indexuri progress progress logs append searching with progress on search br check search term is valid search search to lower case if search equals out append give a valid string to search n logs append give a valid string to search br return need to put xml http callback for loading results out append div id librarian search results n div n search searcher new search search indexuri progress searcher start xmlhttprequest searchstrasync stringbuilder tolowercase xmlhttp progress progress private search string search string indexuri progress progress this search search this indexuri indexuri this progress progress public void run try string search words search split p l n return results in order list uri wrapper hs null search for each string in the search list only the common results to all words are returned as final result try index idx new index indexuri pr progress set fetching index logs append fetching index br n idx fetch progress progress set searching in index logs append searching in index br n hs idx search search words progress progress set formatting results catch fetch exception e progress done could not fetch sub index for html encoder encode search html encoder encode e get message n logger normal xl could not fetch sub index for search in indexuri e to string n e return catch exception e progress done could not complete search for html encoder encode search html encoder encode e to string n html encoder encode string value of e get stack trace logger error xl could not complete search for search in indexuri e to string e return output results int results 0 string builder out new string builder out append table class librarian results tr n iterator uri wrapper it hs iterator try while it has next uri wrapper o it next string showurl o uri string showtitle o descr if showtitle trim length 0 showtitle not available if showtitle equals not available showtitle showurl string description html encoder encode o descr if description equals not available description description replace all n lt b b r r gt br description description replace all nbsp description description replace all lt a za z gt showurl html encoder encode showurl if showurl length 60 showurl showurl substring 0 15 hellip showurl replace first string realurl o uri starts with o uri realurl html encoder encode realurl out append p n table class librarian result width 100 border 1 tr td align center bgcolor d0d0d0 class librarian result url n out append a href append realurl append title append o uri append append showtitle append a n out append td tr tr td align left class librarian result summary n out append td tr table n results catch exception e progress done could not display results for search e to string logger error xl could not display search results for search e to string e out append tr table n out append p span class librarian summary found text found span span class librarian summary found number append results append results span p n progress done complete out to string catch exception e progress done could not complete search for search in indexuri e to string logger error xl could not complete search for search in indexuri e to string e e print stack trace searchwords uriwrapper searchwords fetchexception htmlencoder htmlencoder getmessage tostring htmlencoder htmlencoder tostring htmlencoder valueof getstacktrace tostring stringbuilder stringbuilder uriwrapper hasnext uriwrapper htmlencoder replaceall replaceall replaceall htmlencoder replacefirst startswith htmlencoder tostring tostring tostring tostring tostring printstacktrace private long written public counted output stream output stream arg0 super arg0 countedoutputstream outputstream override public void write int x throws io exception super write x written ioexception override public void write byte buf throws io exception write buf 0 buf length ioexception override public void write byte buf int offset int length throws io exception out write buf offset length written length ioexception public long written return written public librarian handler string word list uri wrapper fileuris throws exception this fileuris fileuris this word word md5 xml librarian md5 word librarianhandler uriwrapper xmllibrarian public void set document locator locator value setdocumentlocator public void end document throws sax exception enddocument saxexception public void start document throws sax exception found match false uris new hash map string string titles new hash map string string startdocument saxexception found_match hashmap hashmap public void start element string name spaceuri string local name string raw name attributes attrs throws sax exception if raw name null raw name local name string elt name raw name gives the maximum number of digits of md5 used for creating subindices if elt name equals prefix prefix integer parse int attrs get value value if elt name equals sub index try here we need to match and see if any of the subindices match the required substring of the word for int i 0 i prefix i if md5 substring 0 prefix i equals attrs get value key prefix match md5 substring 0 prefix i logger normal this match found prefix match logger minor this word searched word prefix matcheed prefix match break catch exception e logger error this md5 of the word word could not be calculated e to string e if elt name equals files processing word false if elt name equals keywords processing word true looks for the word in the given subindex file if the word is found then the parser fetches the corresponding file elements if elt name equals word try found match false string match attrs get value v if match equals word found match true if attrs get value v equals word found match true logger minor this word searched word matched catch exception e logger error this word key doesn t match e to string e if elt name equals file try file writer outp new file writer logfile true outp write word searched word found match found match processing word processing word n outp close catch exception e if processing word true found match true uri wrapper uri new uri wrapper try uri uri uris get attrs get value id logger minor this word searched word file id uri uri uri descr not available synchronized this if titles contains key attrs get value id uri descr titles get attrs get value id if uri uri equals uri descr uri descr not available else uri descr not available if fileuris null fileuris add uri catch exception e logger error this index format may be outdated e to string e else if processing word false try string id attrs get value id string key attrs get value key int l attrs get length string title synchronized this if l 3 try title attrs get value title file writer outp new file writer logfile true outp write found title title n outp close titles put id title catch exception e logger error this index format not compatible e to string e uris put id key string words string uris values to array new string uris size catch exception e logger error this file id and key could not be retrieved may be due to format clash e startelement namespaceuri localname rawname saxexception rawname rawname localname elt_name rawname elt_name parseint getvalue elt_name subindex getvalue prefixmatch prefixmatch prefixmatch tostring elt_name processingword elt_name processingword fileelements elt_name found_match getvalue found_match getvalue found_match tostring elt_name filewriter filewriter found_match found_match processingword processingword processingword found_match uriwrapper uriwrapper getvalue containskey getvalue getvalue tostring processingword getvalue getvalue getlength getvalue filewriter filewriter tostring toarray public string get prefix match return prefix match getprefixmatch prefixmatch link occurrences document document storage storage i persistent obj super storage this obj obj occurrences storage create link ipersistent createlink inverse list storage db int oid document occurrences doc super int class true docs db create link 1 docs add doc oids new int 1 oids 0 oid assign oid db 0 false inverselist documentoccurrences createlink assignoid inverse list inverselist inverse list public int size return oids null oids length super size inverselist int first if oids null return oids 0 map entry entry map entry entry iterator null null index ascent order next return integer entry get key int value entryiterator ascent_order getkey intvalue int last if oids null return oids oids length 1 map entry entry map entry entry iterator null null index descent order next return integer entry get key int value entryiterator descent_order getkey intvalue int i inverst list iterator int pos i pos inverstlistiterator public boolean has next return i oids length hasnext public object next final int j i return new map entry public object get key return new integer oids j public object get value return docs get j public object set value object value return null public object set key object key return null getkey getvalue setvalue setkey final int j i return new map entry public object get key return new integer oids j getkey return new map entry public object get key return new integer oids j public object get value return docs get j getkey getvalue public object get key return new integer oids j public object get value return docs get j public object set value object value return null getkey getvalue setvalue public object get value return docs get j public object set value object value return null public object set key object key return null getvalue setvalue setkey public void remove iterator iterator int oid int os oids if os null int l 0 r os length while l r int m l r 1 if os m oid l m 1 else r m return new inverst list iterator r else return entry iterator new key oid null index ascent order inverstlistiterator entryiterator ascent_order void add int oid document occurrences doc int os oids if os null os length btree threshold if os null for int i 0 i os length i super put new key os i docs get i oids null docs null super put new key oid doc else int l 0 n os length r n while l r int m l r 1 if os m oid l m 1 else r m os new int n 1 system arraycopy oids 0 os 0 r os r oid system arraycopy oids r os r 1 n r docs insert r doc documentoccurrences btree_threshold void remove int oid int os oids if os null int l 0 n os length r n while l r int m l r 1 if os m oid l m 1 else r m assert that r n os r oid docs remove r oids new int n 1 system arraycopy os 0 oids 0 r system arraycopy os r 1 oids r n r 1 else super remove new key oid public void add full text searchable obj add obj obj get text obj get language fulltextsearchable gettext getlanguage public void add i persistent obj reader text string language occurrence occurrences try occurrences helper parse text text catch io exception x throw new storage error storage error full text index error x delete obj if occurrences length 0 document doc new document get storage obj documents put new key obj doc arrays sort occurrences string word occurrences 0 word int i 0 for int j 1 j occurrences length j occurrence occ occurrences j if occ word equals word add reference doc word occurrences i j language word occ word i j add reference doc word occurrences i occurrences length language ipersistent parsetext ioexception storageerror storageerror full_text_index_error getstorage addreference addreference private final void add reference document doc string word occurrence occurrences int from int till document occurrences d new document occurrences d occurrences new int till from d n words in document occurrences length for int i from i till i d occurrences i from occurrences i position occurrences i kind occ kind offset int oid doc obj get oid inverse list list inverse list inverse index get word if list null list new inverse list get storage oid d inverse index put word list else list add oid d d list list doc occurrences add d addreference documentoccurrences documentoccurrences nwordsindocument occ_kind_offset getoid inverselist inverselist inverseindex inverselist getstorage inverseindex private final void add reference document doc string word occurrence occurrences int from int till string language string normal forms helper get normal forms word language boolean is normal form false for int i 0 i normal forms length i if word equals normal forms i is normal form true add reference doc normal forms i occurrences from till if is normal form add reference doc word occurrences from till addreference normalforms getnormalforms isnormalform normalforms normalforms isnormalform addreference normalforms isnormalform addreference public void delete i persistent obj key key new key obj document doc document documents get key if doc null for int i 0 n doc occurrences size i n i document occurrences d document occurrences doc occurrences get i d list remove obj get oid d deallocate documents remove key doc deallocate ipersistent documentoccurrences documentoccurrences getoid public int get number of words return inverse index size getnumberofwords inverseindex public int get number of documents return documents size getnumberofdocuments public full text search result search string query string language int max results int time limit return search helper parse query query language max results time limit fulltextsearchresult maxresults timelimit parsequery maxresults timelimit keyword list string word this word word kwd len word length same as 1 keywordlist kwdlen sameas full text query expr public int compare to object o return weight expression weight o weight fulltextquery compareto expressionweight public void visit full text query match op q q wno kwd list size keyword list kwd new keyword list q word kwd list inverse list inverse index get q word kwd list add kwd fulltextquerymatchop kwdlist keywordlist keywordlist inverselist inverseindex kwdlist int calculate weight full text query query switch query op case full text query and return calculate weight full text query binary op query left case full text query near int shift strict match bonus for full text query q full text query binary op query right q op full text query near q full text query binary op q right shift strict match bonus return shift 32 0 calculate weight full text query binary op query left shift case full text query or int left weight calculate weight full text query binary op query left int right weight calculate weight full text query binary op query right return left weight right weight left weight right weight case full text query match case full text query strict match inverse list list kwds full text query match op query wno list return list null 0 list size default return integer max value calculateweight fulltextquery fulltextquery calculateweight fulltextquerybinaryop fulltextquery strict_match_bonus fulltextquery fulltextquerybinaryop fulltextquery fulltextquerybinaryop strict_match_bonus calculateweight fulltextquerybinaryop fulltextquery leftweight calculateweight fulltextquerybinaryop rightweight calculateweight fulltextquerybinaryop leftweight rightweight leftweight rightweight fulltextquery fulltextquery strict_match inverselist fulltextquerymatchop max_value full text query optimize full text query query switch query op case full text query and case full text query near int op query op int n conjuncts 1 full text query q query while q full text query binary op q right op op n conjuncts 1 expression weight conjuncts new expression weight n conjuncts 1 q query for int i 0 i n conjuncts i full text query binary op and full text query binary op q conjuncts i new expression weight conjuncts i expr optimize and left conjuncts i weight calculate weight conjuncts i expr q and right conjuncts n conjuncts new expression weight conjuncts n conjuncts expr optimize q conjuncts n conjuncts weight calculate weight conjuncts n conjuncts expr arrays sort conjuncts if op full text query and eliminate duplicates int n 0 j 1 inverse list list null for int i 0 i n conjuncts i q conjuncts i expr if q instanceof full text query match op full text query match op match full text query match op q if n 0 kwds match wno list list j match wno list kwds j list conjuncts n conjuncts i else kwds match wno same as j else conjuncts n conjuncts i n conjuncts n 1 else calculate distance between keywords int kwd pos 0 for int i 0 i n conjuncts i q conjuncts i expr if q instanceof full text query match op full text query match op match full text query match op q kwds match wno kwd offset match pos kwd pos kwd pos match pos if n conjuncts 0 return conjuncts 0 expr else q query int i 0 while true full text query binary op and full text query binary op q and left conjuncts i expr if i n conjuncts q and right else and right conjuncts i expr break break case full text query or full text query binary op or full text query binary op query or left optimize or left or right optimize or right break case full text query not full text query unary op not full text query unary op query not opd optimize not opd break default return query fulltextquery fulltextquery fulltextquery fulltextquery nconjuncts fulltextquery fulltextquerybinaryop nconjuncts expressionweight expressionweight nconjuncts nconjuncts fulltextquerybinaryop fulltextquerybinaryop expressionweight calculateweight nconjuncts expressionweight nconjuncts nconjuncts calculateweight nconjuncts fulltextquery inverselist nconjuncts fulltextquerymatchop fulltextquerymatchop fulltextquerymatchop sameas nconjuncts kwdpos nconjuncts fulltextquerymatchop fulltextquerymatchop fulltextquerymatchop kwdoffset kwdpos kwdpos nconjuncts fulltextquerybinaryop fulltextquerybinaryop nconjuncts fulltextquery fulltextquerybinaryop fulltextquerybinaryop fulltextquery fulltextqueryunaryop fulltextqueryunaryop int intersect int doc full text query query int left right switch query op case full text query and case full text query near do left intersect doc full text query binary op query left if left integer max value return left doc intersect left full text query binary op query right while left doc doc integer max value return doc case full text query or left intersect doc full text query binary op query left right intersect doc full text query binary op query right return left right left right case full text query match case full text query strict match keyword list kwd kwds full text query match op query wno if kwd curr doc doc return kwd curr doc iterator iterator kwd iterator if iterator null if iterator has next map entry entry map entry iterator next int next doc integer entry get key int value if next doc doc kwd curr entry entry kwd curr doc next doc return next doc else kwd curr entry null kwd curr doc 0 return integer max value if kwd list null kwd iterator iterator kwd list iterator doc if iterator has next map entry entry map entry iterator next doc integer entry get key int value kwd curr entry entry kwd curr doc doc return doc kwd curr entry null kwd curr doc 0 return integer max value case full text query not int next doc intersect doc full text query unary op query opd if next doc doc doc 1 return doc default return doc fulltextquery fulltextquery fulltextquery fulltextquerybinaryop max_value fulltextquerybinaryop max_value fulltextquery fulltextquerybinaryop fulltextquerybinaryop fulltextquery fulltextquery strict_match keywordlist fulltextquerymatchop currdoc currdoc hasnext nextdoc getkey intvalue nextdoc currentry currdoc nextdoc nextdoc currentry currdoc max_value hasnext getkey intvalue currentry currdoc currentry currdoc max_value fulltextquery nextdoc fulltextqueryunaryop nextdoc int calculate estimation full text query query int n results switch query op case full text query and case full text query near int left calculate estimation full text query binary op query left n results int right calculate estimation full text query binary op query right n results return left right left right case full text query or int left calculate estimation full text query binary op query left n results int right calculate estimation full text query binary op query right n results return left right left right case full text query match case full text query strict match keyword list kwd kwds full text query match op query wno if kwd curr doc 0 return 0 else int curr kwd curr doc int first kwd list first int last kwd list last int estimation n results last first 1 curr first 1 if estimation kwd list size estimation kwd list size return estimation case full text query not return documents size return 0 calculateestimation fulltextquery nresults fulltextquery fulltextquery calculateestimation fulltextquerybinaryop nresults calculateestimation fulltextquerybinaryop nresults fulltextquery calculateestimation fulltextquerybinaryop nresults calculateestimation fulltextquerybinaryop nresults fulltextquery fulltextquery strict_match keywordlist fulltextquerymatchop currdoc currdoc nresults fulltextquery double evaluate int doc full text query query double left right switch query op case full text query near case full text query and left evaluate doc full text query binary op query left right evaluate doc full text query binary op query right n occurrences 0 return left 0 right 0 1 left right case full text query or left evaluate doc full text query binary op query left right evaluate doc full text query binary op query right return left right left right case full text query match case full text query strict match keyword list kwd kwds full text query match op query wno if kwd curr doc doc return 1 document occurrences d document occurrences kwd curr entry get value int occ d occurrences kwd occ occ int frequency occ length if query op full text query strict match if n occurrences 0 n occurrences frequency if occurrences null occurrences length frequency occurrences new int frequency for int i 0 i frequency i occurrences i occ i occ position mask else int n pairs 0 int dst occurrences int occ1 dst 0 int occ2 occ 0 occ position mask int i 0 j 0 int offs kwd kwd offset while true if occ1 offs occ2 if occ1 offs 1 occ2 dst n pairs occ2 if j n occurrences break occ1 dst j else if i frequency break occ2 occ i occ position mask n occurrences n pairs if n pairs 0 return 1 int total number of documents documents size int n relevant documents kwd list size int total number of words inverse index size double idf math log double total number of documents n relevant documents double average words double total number of words total number of documents double density frequency math log 1 density magic average words d n words in document double word weight density idf double word score 1 for int i 0 i frequency i word score word weight occurrence kind weight occ i occ kind offset return math log word score case full text query not double rank evaluate doc full text query unary op query opd return rank 0 1 0 default return 1 fulltextquery fulltextquery fulltextquery fulltextquerybinaryop fulltextquerybinaryop noccurrences fulltextquery fulltextquerybinaryop fulltextquerybinaryop fulltextquery fulltextquery strict_match keywordlist fulltextquerymatchop currdoc documentoccurrences documentoccurrences currentry getvalue fulltextquery strict_match noccurrences noccurrences occ_position_mask npairs occ_position_mask kwdoffset npairs noccurrences occ_position_mask noccurrences npairs npairs totalnumberofdocuments nrelevantdocuments totalnumberofwords inverseindex totalnumberofdocuments nrelevantdocuments averagewords totalnumberofwords totalnumberofdocuments density_magic averagewords nwordsindocument wordweight wordscore wordscore wordweight occurrencekindweight occ_kind_offset wordscore fulltextquery fulltextqueryunaryop void build occurrence kind weight table occurrence kind weight new float 256 float weights helper get occurrence kind weights occurrence kind weight 0 1 0f for int i 1 i 256 i float weight 0 for int j 0 j weights length j if i 1 j 0 weight weights j occurrence kind weight i weight buildoccurrencekindweighttable occurrencekindweight getoccurrencekindweights occurrencekindweight occurrencekindweight double calculate nearness keyword list kwds this kwds int n kwds kwds length if n kwds 2 return 0 for int i 0 i n kwds i if kwds i occ null int j kwds i same as if j 0 kwds j occ null kwds i occ kwds j occ else return 0 kwds i occ pos 0 double max nearness 0 int swap penalty helper get word swap penalty while true int min pos integer max value double nearness 0 keyword list first null keyword list prev null for int i 0 i n kwds i keyword list curr kwds i if curr occ pos curr occ length if prev null int offset curr occ curr occ pos prev occ prev occ pos if offset 0 offset offset curr kwd len swap penalty else offset prev kwd len if offset 2 offset 1 nearness 1 math sqrt offset if curr occ curr occ pos min pos min pos curr occ curr occ pos first curr prev curr if first null break first occ pos 1 if nearness max nearness max nearness nearness return max nearness calculatenearness keywordlist nkwds nkwds nkwds sameas occpos maxnearness swappenalty getwordswappenalty minpos max_value keywordlist keywordlist nkwds keywordlist occpos occpos occpos kwdlen swappenalty kwdlen occpos minpos minpos occpos occpos maxnearness maxnearness maxnearness void reset n occurrences 0 for int i 0 i kwds length i kwds i occ null noccurrences full text search result search full text query query int max results int time limit if query null query is constrained return null long start system current time millis build occurrence kind weight table kwd list new array list query visit this kwds keyword list kwd list to array new keyword list kwd list size query optimize query system out println query to string full text search hit hits new full text search hit max results int curr doc 1 int n results 0 float nearness weight helper get nearness weight boolean no more matches false while n results max results system current time millis start time limit curr doc intersect curr doc query if curr doc integer max value no more matches true break reset double kwd rank evaluate curr doc query if kwd rank 0 double nearness calculate nearness float rank float kwd rank 1 calculate nearness nearness weight system out println kwd rank kwd rank nearness nearness total rank rank hits n results new full text search hit get storage curr doc rank curr doc 1 int estimation if n results max results full text search hit real hits new full text search hit n results system arraycopy hits 0 real hits 0 n results hits real hits if no more matches estimation n results else if query instanceof full text query match op estimation kwds 0 list size else estimation calculate estimation query n results arrays sort hits return new full text search result hits estimation fulltextsearchresult fulltextquery maxresults timelimit isconstrained currenttimemillis buildoccurrencekindweighttable kwdlist arraylist keywordlist kwdlist toarray keywordlist kwdlist tostring fulltextsearchhit fulltextsearchhit maxresults currdoc nresults nearnessweight getnearnessweight nomorematches nresults maxresults currenttimemillis timelimit currdoc currdoc currdoc max_value nomorematches kwdrank currdoc kwdrank calculatenearness kwdrank calculatenearness nearnessweight kwdrank kwdrank nresults fulltextsearchhit getstorage currdoc currdoc nresults maxresults fulltextsearchhit realhits fulltextsearchhit nresults realhits nresults realhits nomorematches nresults fulltextquerymatchop calculateestimation nresults fulltextsearchresult public full text search result search full text query query int max results int time limit full text search engine engine new full text search engine return engine search query max results time limit fulltextsearchresult fulltextquery maxresults timelimit fulltextsearchengine fulltextsearchengine maxresults timelimit public full text search helper get helper return helper fulltextsearchhelper gethelper public full text index impl storage storage full text search helper helper super storage this helper helper inverse index storage create index string class true documents storage create index i persistent class true fulltextindeximpl fulltextsearchhelper inverseindex createindex createindex ipersistent private full text index impl fulltextindeximpl public toadlet context impl socket sock multi value table string string headers bucket factory bf page maker page maker toadlet container container throws io exception this headers headers this closed false sock output stream sock get output stream remote addr sock get inet address if logger should log logger debug this logger debug this connection from remote addr this bf bf this pagemaker page maker this container container toadletcontextimpl multivaluetable bucketfactory pagemaker pagemaker toadletcontainer ioexception sockoutputstream getoutputstream remoteaddr getinetaddress shouldlog remoteaddr pagemaker private void close closed true private void send method not allowed string method boolean should disconnect throws toadlet context closed exception io exception if closed throw new toadlet context closed exception multi value table string string mvt new multi value table string string mvt put allow get put send error sock output stream 405 method not allowed l10n method not allowed should disconnect mvt sendmethodnotallowed shoulddisconnect toadletcontextclosedexception ioexception toadletcontextclosedexception multivaluetable multivaluetable senderror sockoutputstream methodnotallowed shoulddisconnect private static string l10n string key return l10n get string toadlet context impl key getstring toadletcontextimpl private static string l10n string key string pattern string value return l10n get string toadlet context impl key new string pattern new string value getstring toadletcontextimpl send an error message caller provides the http code reason string and a message which will become the title and the h1 ed contents of the error page private static void send error output stream os int code string http reason string message boolean should disconnect multi value table string string mvt throws io exception sendhtml error os code http reason html head title message title head body h1 message h1 body should disconnect mvt senderror outputstream httpreason shoulddisconnect multivaluetable ioexception sendhtmlerror httpreason shoulddisconnect send an error message containing full html from a string param os the output stream to send the message to param code the http status code param http reason the http reason string for the http status code do not make stuff up use the official reason string or some browsers may break param html message the html string to send param disconnect whether to disconnect from the client afterwards param mvt any additional headers throws io exception if we could not send the error message private static void sendhtml error output stream os int code string http reason string html message boolean disconnect multi value table string string mvt throws io exception if mvt null mvt new multi value table string string byte message bytes html message get bytes utf 8 send reply headers os code http reason mvt text html charset utf 8 message bytes length null disconnect os write message bytes outputstream httpreason htmlmessage ioexception sendhtmlerror outputstream httpreason htmlmessage multivaluetable ioexception multivaluetable messagebytes htmlmessage getbytes sendreplyheaders httpreason messagebytes messagebytes private void send no toadlet error boolean should disconnect throws toadlet context closed exception io exception if closed throw new toadlet context closed exception send error sock output stream 404 not found l10n no such toadlet should disconnect null sendnotoadleterror shoulddisconnect toadletcontextclosedexception ioexception toadletcontextclosedexception senderror sockoutputstream nosuchtoadlet shoulddisconnect private static void senduri parse error output stream os boolean should disconnect throwable e throws io exception string writer sw new string writer print writer pw new print writer sw e print stack trace pw pw close string message html head title l10n uri parse error title title head body p html encoder encode e get message p pre n sw to string sendhtml error os 400 bad request message should disconnect null senduriparseerror outputstream shoulddisconnect ioexception stringwriter stringwriter printwriter printwriter printstacktrace uriparseerrortitle htmlencoder getmessage tostring sendhtmlerror shoulddisconnect public void send reply headers int reply code string reply description multi value table string string mvt string mime type long content length throws toadlet context closed exception io exception send reply headers reply code reply description mvt mime type content length null sendreplyheaders replycode replydescription multivaluetable mimetype contentlength toadletcontextclosedexception ioexception sendreplyheaders replycode replydescription mimetype contentlength public void send reply headers int reply code string reply description multi value table string string mvt string mime type long content length date m time throws toadlet context closed exception io exception if closed throw new toadlet context closed exception if sent reply headers throw new illegal state exception already sent headers sent reply headers true send reply headers sock output stream reply code reply description mvt mime type content length m time should disconnect sendreplyheaders replycode replydescription multivaluetable mimetype contentlength mtime toadletcontextclosedexception ioexception toadletcontextclosedexception sentreplyheaders illegalstateexception sentreplyheaders sendreplyheaders sockoutputstream replycode replydescription mimetype contentlength mtime shoulddisconnect public page maker get page maker return pagemaker pagemaker getpagemaker public multi value table string string get headers return headers multivaluetable getheaders static void send reply headers output stream sock output stream int reply code string reply description multi value table string string mvt string mime type long content length date m time boolean disconnect throws io exception construct headers if mvt null mvt new multi value table string string if mime type null if mime type equals ignore case text html mvt put content type mime type charset utf 8 else mvt put content type mime type if content length 0 mvt put content length long to string content length string expires time if m time null expires time thu 01 jan 1970 00 00 00 gmt else use an expiry time of 1 day somewhat arbitrarily expires time makehttp date m time get time 24 60 60 1000 mvt put expires expires time string now string makehttp date system current time millis string last mod string if m time null last mod string now string else last mod string makehttp date m time get time mvt put last modified last mod string mvt put date now string if m time null mvt put pragma no cache mvt put cache control max age 0 must revalidate no cache no store post check 0 pre check 0 if disconnect mvt put connection close else mvt put connection keep alive string builder buf new string builder 1024 buf append http 1 1 buf append reply code buf append buf append reply description buf append r n for enumeration string e mvt keys e has more elements string key e next element object list mvt get array key key fix key key for int i 0 i list length i string val string list i buf append key buf append buf append val buf append r n buf append r n sock output stream write buf to string get bytes us ascii sendreplyheaders outputstream sockoutputstream replycode replydescription multivaluetable mimetype contentlength mtime ioexception multivaluetable mimetype mimetype equalsignorecase mimetype mimetype contentlength tostring contentlength expirestime mtime expirestime expirestime makehttpdate mtime gettime expirestime nowstring makehttpdate currenttimemillis lastmodstring mtime lastmodstring nowstring lastmodstring makehttpdate mtime gettime lastmodstring nowstring mtime stringbuilder stringbuilder replycode replydescription hasmoreelements nextelement getarray fixkey sockoutputstream tostring getbytes private static string makehttp date long time for http gmt utc simple date format sdf new simple date format eee dd mmm yyyy hh mm ss gmt locale us sdf set time zone tz utc return sdf format new date time makehttpdate simpledateformat simpledateformat settimezone tz_utc fix key case to be conformant to http expectations note that http is case insensitive on header names but we may as well send something as close to the spec as possible in case of broken clients private static string fix key string key string builder sb new string builder key length char prev 0 for int i 0 i key length i char c key char at i if i 0 prev c character to upper case c sb append c prev c return sb to string fixkey stringbuilder stringbuilder charat touppercase tostring handle an incoming connection blocking obviously public static void handle socket sock toadlet container container page maker page maker try input stream is new buffered input stream sock get input stream 4096 line reading input stream lis new line reading input stream is while true string first line lis read line 32768 128 false iso 8859 1 or us ascii not utf 8 if first line null sock close return else if first line equals continue boolean logminor logger should log logger minor toadlet context impl class if logminor logger minor toadlet context impl class first line first line string split first line split if split length 3 throw new parse exception could not parse request line split length split length first line if split 2 starts with http 1 throw new parse exception unrecognized protocol split 2 uri uri try uri uri pre encoder encodeuri split 1 normalize if logminor logger minor toadlet context impl class uri uri path uri get path host uri get host frag uri get fragment port uri get port query uri get query scheme uri get scheme catch uri syntax exception e senduri parse error sock get output stream true e return string method split 0 multi value table string string headers new multi value table string string while true string line lis read line 32768 128 false iso 8859 or us ascii not utf 8 if line null sock close return system out println length line length line if line length 0 break int index line index of if index 0 throw new parse exception missing in request header field string before line substring 0 index to lower case string after line substring index 1 after after trim headers put before after boolean disconnect should disconnect after handled split 2 equals http 1 0 headers container enable persistent connections boolean allow post container allow posts bucket factory bf container get bucket factory toadlet context impl ctx new toadlet context impl sock headers bf page maker container ctx should disconnect disconnect if we re handling a post copy the data into a bucket now before we go into the redirect loop bucket data if method equals post string slen headers get content length if slen null send error sock get output stream 400 bad request l10n no content length inpost true null return long len try len integer parse int slen if len 0 throw new number format exception content length less than 0 catch number format exception e send error sock get output stream 400 bad request l10n cannot parse content length with error error e to string true null return if allow post container public gateway mode ctx is allowed full access data bf make bucket len bucket tools copy from data is len else file util skip fully is len ctx send method not allowed post true ctx close return else we re not doing to use it but we have to keep the compiler happy data null handle it try boolean redirect true while redirect don t go around the loop unless set explicitly redirect false toadlet t try t container find toadlet uri catch permanent redirect exception e toadlet write permanent redirect ctx found elsewhere e newuri toascii string break if t null ctx send no toadlet error ctx should disconnect break http request impl req new http request impl uri data ctx try if method equals get t handle get uri req ctx ctx close else if method equals post t handle post uri req ctx else ctx send method not allowed method ctx should disconnect ctx close catch redirect exception re uri re newuri redirect true finally req free parts if ctx should disconnect sock close return finally if data null data free catch parse exception e try send error sock get output stream 400 bad request l10n parse error with error error e get message true null catch io exception e1 ignore catch too long exception e try send error sock get output stream 400 bad request l10n headers line too long true null catch io exception e1 ignore catch io exception e return catch toadlet context closed exception e logger error toadlet context impl class toadlet context closed exception while handling connection return catch throwable t logger error toadlet context impl class caught error t handling socket t toadletcontainer pagemaker pagemaker inputstream bufferedinputstream getinputstream linereadinginputstream linereadinginputstream firstline readline _not_ firstline firstline shouldlog toadletcontextimpl toadletcontextimpl firstline firstline parseexception firstline startswith parseexception uripreencoder toadletcontextimpl getpath gethost getfragment getport getquery getscheme urisyntaxexception senduriparseerror getoutputstream multivaluetable multivaluetable readline indexof parseexception tolowercase shoulddisconnectafterhandled enablepersistentconnections allowpost allowposts bucketfactory getbucketfactory toadletcontextimpl toadletcontextimpl pagemaker shoulddisconnect senderror getoutputstream nocontentlengthinpost parseint numberformatexception numberformatexception senderror getoutputstream cannotparsecontentlengthwitherror tostring allowpost publicgatewaymode isallowedfullaccess makebucket buckettools copyfrom fileutil skipfully sendmethodnotallowed findtoadlet permanentredirectexception writepermanentredirect toasciistring sendnotoadleterror shoulddisconnect httprequestimpl httprequestimpl handleget handlepost sendmethodnotallowed shoulddisconnect redirectexception freeparts shoulddisconnect parseexception senderror getoutputstream parseerrorwitherror getmessage ioexception toolongexception senderror getoutputstream headerslinetoolong ioexception ioexception toadletcontextclosedexception toadletcontextimpl toadletcontextclosedexception toadletcontextimpl should the connection be closed after handling this request param ishttp10 did the client specify http 1 0 param headers client headers return true if the connection should be closed private static boolean should disconnect after handled boolean ishttp10 multi value table string string headers string connection headers get connection if connection null if connection equals ignore case close return true if connection equals ignore case keep alive return false if ishttp10 true return true else http 1 1 return false shoulddisconnectafterhandled multivaluetable equalsignorecase equalsignorecase private static final long serial versionuid 1 parse exception string string super string serialversionuid parseexception public void write data byte data int offset int length throws toadlet context closed exception io exception if closed throw new toadlet context closed exception sock output stream write data offset length writedata toadletcontextclosedexception ioexception toadletcontextclosedexception sockoutputstream public void write data byte data throws toadlet context closed exception io exception write data data 0 data length writedata toadletcontextclosedexception ioexception writedata public void write data bucket data throws toadlet context closed exception io exception if closed throw new toadlet context closed exception bucket tools copy to data sock output stream long max value writedata toadletcontextclosedexception ioexception toadletcontextclosedexception buckettools copyto sockoutputstream max_value public bucket factory get bucket factory return bf bucketfactory getbucketfactory public html node add form child html node parent node string target string name return container add form child parent node target name htmlnode addformchild htmlnode parentnode addformchild parentnode public boolean is allowed full access return container is allowed full access remote addr isallowedfullaccess isallowedfullaccess remoteaddr public boolean do robots return container do robots dorobots dorobots public void force disconnect this should disconnect true forcedisconnect shoulddisconnect public toadlet container get container return container toadletcontainer getcontainer public static long version 1 static string get svn revision return svn revision getsvnrevision svnrevision static long get version return version getversion public static void main string args system out println system out println svn revision system out println system out println get version svnrevision getversion public static boolean is valid address inet address i boolean include local addresses in noderefs if i is any local address wildcard address 0 0 0 0 ignore return false else if i is link local address i is loopback address i is site local address if include local addresses in noderefs return true else return false else if i is multicast address ignore return false else byte ip address bytes i get address if ip address bytes length 4 ip address bytes 0 0 return false first octet of i pv4 address cannot be zero as 0 0 0 0 8 has been reserved since at least rfc790 also java throws an io exception when they re used return true isvalidaddress inetaddress includelocaladdressesinnoderefs isanylocaladdress islinklocaladdress isloopbackaddress issitelocaladdress includelocaladdressesinnoderefs ismulticastaddress ipaddressbytes getaddress ipaddressbytes ipaddressbytes ipv4 ioexception public class persistent stub implements i persistent public void load throw new storage error storage error access to stub persistentstub ipersistent storageerror storageerror access_to_stub public void load and modify load modify loadandmodify public final boolean is raw return true israw public final boolean is modified return false ismodified public final boolean is deleted return false isdeleted public final boolean is persistent return true ispersistent public void make persistent storage storage throw new storage error storage error access to stub makepersistent storageerror storageerror access_to_stub public void store throw new storage error storage error access to stub storageerror storageerror access_to_stub public void modify throw new storage error storage error access to stub storageerror storageerror access_to_stub public persistent stub storage storage int oid this storage storage this oid oid persistentstub public final int get oid return oid getoid public void deallocate throw new storage error storage error access to stub storageerror storageerror access_to_stub public boolean recursive loading return true recursiveloading public final storage get storage return storage getstorage public boolean equals object o return o instanceof i persistent i persistent o get oid oid ipersistent ipersistent getoid public int hash code return oid hashcode public void on load onload public void on store onstore public void invalidate throw new storage error storage error access to stub storageerror storageerror access_to_stub transient int oid public void assign oid storage storage int oid boolean raw throw new storage error storage error access to stub assignoid storageerror storageerror access_to_stub public object clone throws clone not supported exception persistent stub p persistent stub super clone p oid 0 return p clonenotsupportedexception persistentstub persistentstub public void read external java io object input s throws java io io exception class not found exception oid s read int readexternal objectinput ioexception classnotfoundexception readint public void write external java io object output s throws java io io exception s write int oid writeexternal objectoutput ioexception writeint public class invalid address override user alert extends abstract user alert public invalid address override user alert node n super false null null null null short 0 true null false null this node n invalidaddressoverrideuseralert abstractuseralert invalidaddressoverrideuseralert final node node override public string get title return l10n unknown address title gettitle unknownaddresstitle override public string get text return l10n unknown address gettext unknownaddress private string l10n string key return l10n get string invalid address override user alert key getstring invalidaddressoverrideuseralert override public html node gethtml text sub config sc node config get node option o sc get option ip address override html node text node new html node div l10n addl10n substitution text node invalid address override user alert unknown address with config link new string link link new string a href config a html node form node text node add child form new string action method new string config post form node add child input new string type name value new string hidden form password node client core form password html node list node form node add child ul class config html node item node list node add child li item node add child span class configshortdesc l10n get string o get short desc add child input new string type name value new string text sc get prefix ip address override o get value string item node add child span class configlongdesc l10n get string o get long desc form node add child input new string type value new string submit l10n get string user alert apply form node add child input new string type value new string reset l10n get string user alert reset return text node htmlnode gethtmltext subconfig getoption ipaddressoverride htmlnode textnode htmlnode addl10nsubstitution textnode invalidaddressoverrideuseralert unknownaddresswithconfiglink htmlnode formnode textnode addchild formnode addchild formpassword clientcore formpassword htmlnode listnode formnode addchild htmlnode itemnode listnode addchild itemnode addchild getstring getshortdesc addchild getprefix ipaddressoverride getvaluestring itemnode addchild getstring getlongdesc formnode addchild getstring useralert formnode addchild getstring useralert textnode override public short get priority class return user alert error getpriorityclass useralert override public string get short text return l10n unknown address short getshorttext unknownaddressshort public class argument data extends node data public argument data argumentdata nodedata argumentdata private string value public string get value return value getvalue public void set value string value this value value setvalue public dsa public key dsa group g big integer y if y signum 1 throw new illegal argument exception this y y this group g if y compare to g getp 0 throw new illegal argument exception y must be p but y y p g getp dsapublickey dsagroup biginteger illegalargumentexception compareto illegalargumentexception use this constructor if you have a hex ed version of y already available will save some conversions and string allocations public dsa public key dsa group g string y as hex string throws number format exception this y new native big integer y as hex string 16 if y signum 1 throw new illegal argument exception this group g if g null throw new null pointer exception dsapublickey dsagroup yashexstring numberformatexception nativebiginteger yashexstring illegalargumentexception nullpointerexception public dsa public key dsa group g dsa private key p this g g getg mod pow p getx g getp dsapublickey dsagroup dsaprivatekey modpow public dsa public key input stream is throws io exception crypt format exception group dsa group dsa group read is y util readmpi is if y compare to group getp 0 throw new illegal argument exception y must be p but y y p group getp dsapublickey inputstream ioexception cryptformatexception dsagroup dsagroup compareto illegalargumentexception public dsa public key byte pubkey bytes throws io exception crypt format exception this new byte array input stream pubkey bytes dsapublickey pubkeybytes ioexception cryptformatexception bytearrayinputstream pubkeybytes private dsa public key dsa public key key fingerprint null regen when needed this y new native big integer 1 key y to byte array this group key group clone key dsapublickey dsapublickey nativebiginteger tobytearray clonekey public static dsa public key create byte pubkey as bytes throws crypt format exception try return new dsa public key new byte array input stream pubkey as bytes catch io exception e throw new crypt format exception e dsapublickey pubkeyasbytes cryptformatexception dsapublickey bytearrayinputstream pubkeyasbytes ioexception cryptformatexception public big integer gety return y biginteger public big integer getp return group getp biginteger public big integer getq return group getq biginteger public big integer getg return group getg biginteger override public string key type return dsa p keytype nope this is fine public dsa group get group return group dsagroup getgroup public static crypto key read input stream i throws io exception crypt format exception return new dsa public key i cryptokey inputstream ioexception cryptformatexception dsapublickey public int key id return y int value keyid intvalue public string to long string return y hex util bi to hex y tolongstring hexutil bitohex override public byte as bytes byte group bytes group as bytes byte ybytes util mp ibytes y byte bytes new byte group bytes length ybytes length system arraycopy group bytes 0 bytes 0 group bytes length system arraycopy ybytes 0 bytes group bytes length ybytes length return bytes asbytes groupbytes asbytes mpibytes groupbytes groupbytes groupbytes groupbytes public byte as bytes hash byte hash sha256 digest as bytes return hash asbyteshash asbytes public byte as padded bytes byte as bytes as bytes if as bytes length padded size return as bytes if as bytes length padded size throw new error cannot fit key in padded size real size is as bytes length byte padded new byte padded size system arraycopy as bytes 0 padded 0 as bytes length return padded aspaddedbytes asbytes asbytes asbytes padded_size asbytes asbytes padded_size padded_size asbytes padded_size asbytes asbytes override public byte fingerprint synchronized this if fingerprint null fingerprint fingerprint new big integer y return fingerprint biginteger public boolean equals dsa public key o if this o not necessary but a very cheap optimization return true return y equals o y group equals o group dsapublickey override public int hash code return y hash code group hash code hashcode hashcode hashcode override public boolean equals object o if this o not necessary but a very cheap optimization return true else if o null o get class this get class return false return y equals dsa public key o y group equals dsa public key o group getclass getclass dsapublickey dsapublickey public int compare to object other if other instanceof dsa public key return gety compare to dsa public key other gety else return 1 compareto dsapublickey compareto dsapublickey public simple field set as field set simple field set fs new simple field set true fs put single y base64 encode y to byte array return fs simplefieldset asfieldset simplefieldset simplefieldset putsingle tobytearray public static dsa public key create simple field set set dsa group group throws illegal base64 exception native big integer x new native big integer 1 base64 decode set get y return new dsa public key group x dsapublickey simplefieldset dsagroup illegalbase64exception nativebiginteger nativebiginteger dsapublickey public byte get full key return as bytes hash getfullkey asbyteshash public byte get routing key return as bytes hash getroutingkey asbyteshash public dsa public key clone key return new dsa public key this dsapublickey clonekey dsapublickey public void remove from object container container container delete y group remove from container container delete this removefrom objectcontainer removefrom public final class lighten composite extends rgb composite public lighten composite float alpha super alpha lightencomposite rgbcomposite lightencomposite public composite context create context color model src color model color model dst color model rendering hints hints return new context extra alpha src color model dst color model compositecontext createcontext colormodel srccolormodel colormodel dstcolormodel renderinghints extraalpha srccolormodel dstcolormodel static class context extends rgb composite context public context float alpha color model src color model color model dst color model super alpha src color model dst color model rgbcompositecontext colormodel srccolormodel colormodel dstcolormodel srccolormodel dstcolormodel override public void composergb int src int dst float alpha int w src length for int i 0 i w i 4 int sr src i int dir dst i int sg src i 1 int dig dst i 1 int sb src i 2 int dib dst i 2 int sa src i 3 int dia dst i 3 int dor dog dob dor dir sr dir sr dog dig sg dig sg dob dib sb dib sb float a alpha sa 255f float ac 1 a dst i int a dor ac dir dst i 1 int a dog ac dig dst i 2 int a dob ac dib dst i 3 int sa alpha dia ac public synchronized void load if oid 0 state raw 0 storage load object this loadobject public synchronized void load and modify load modify loadandmodify public final boolean is raw return state raw 0 israw public final boolean is modified return state dirty 0 ismodified public final boolean is deleted return state deleted 0 isdeleted public final boolean is persistent return oid 0 ispersistent public void make persistent storage storage if oid 0 storage make persistent this makepersistent makepersistent public void store if state raw 0 throw new storage error storage error access to stub if storage null storage store object this state dirty storageerror storageerror access_to_stub storeobject public void modify if state dirty 0 oid 0 if state raw 0 throw new storage error storage error access to stub assert that state deleted 0 storage modify object this state dirty storageerror storageerror access_to_stub modifyobject public persistent public persistent public persistent storage storage this storage storage public final int get oid return oid getoid public void deallocate if oid 0 storage deallocate object this deallocateobject public boolean recursive loading return true recursiveloading public final storage get storage return storage getstorage public boolean equals object o if oid 0 return super equals o return o instanceof i persistent i persistent o get oid oid ipersistent ipersistent getoid public int hash code return oid hashcode public void on load onload public void on store onstore public void invalidate state dirty state raw protected void finalize if state dirty 0 oid 0 storage store finalized object this state deleted storefinalizedobject public void assign oid storage storage int oid boolean raw this oid oid this storage storage if raw state raw else state raw assignoid protected void clear state state 0 oid 0 clearstate public object clone throws clone not supported exception persistent p persistent super clone p oid 0 p state 0 return p clonenotsupportedexception public void read external java io object input s throws java io io exception class not found exception oid s read int readexternal objectinput ioexception classnotfoundexception readint public void write external java io object output s throws java io io exception if s instanceof storage impl persistent object output stream make persistent storage impl persistent object output stream s get storage s write int oid writeexternal objectoutput ioexception storageimpl persistentobjectoutputstream makepersistent storageimpl persistentobjectoutputstream getstorage writeint public final class negation composite extends rgb composite public negation composite float alpha super alpha negationcomposite rgbcomposite negationcomposite public composite context create context color model src color model color model dst color model rendering hints hints return new context extra alpha src color model dst color model compositecontext createcontext colormodel srccolormodel colormodel dstcolormodel renderinghints extraalpha srccolormodel dstcolormodel static class context extends rgb composite context public context float alpha color model src color model color model dst color model super alpha src color model dst color model rgbcompositecontext colormodel srccolormodel colormodel dstcolormodel srccolormodel dstcolormodel override public void composergb int src int dst float alpha int w src length for int i 0 i w i 4 int sr src i int dir dst i int sg src i 1 int dig dst i 1 int sb src i 2 int dib dst i 2 int sa src i 3 int dia dst i 3 int dor dog dob dor 255 math abs 255 sr dir dog 255 math abs 255 sg dig dob 255 math abs 255 sb dib float a alpha sa 255f float ac 1 a dst i int a dor ac dir dst i 1 int a dog ac dig dst i 2 int a dob ac dib dst i 3 int sa alpha dia ac no point having an identifier really public shutdown message throws message invalid exception shutdownmessage messageinvalidexception override public simple field set get field set return null simplefieldset getfieldset override public string get name return name getname override public void run fcp connection handler handler node node throws message invalid exception if handler has full access throw new message invalid exception protocol error message access denied shutdown requires full access null false fcp message msg new protocol error message protocol error message shutting down true the node is shutting down node false handler output handler queue msg node exit received fcp shutdown message fcpconnectionhandler messageinvalidexception hasfullaccess messageinvalidexception protocolerrormessage access_denied fcpmessage protocolerrormessage protocolerrormessage shutting_down outputhandler override public void remove from object container container container delete this removefrom objectcontainer param my web interface a reference to the web interface which created the page used to get resources the page needs param my request the request sent by the user public configuration page web interface my web interface http request my request super my web interface my request todo auto generated constructor stub mywebinterface webinterface myrequest configurationpage webinterface mywebinterface httprequest myrequest mywebinterface myrequest fixme maybe use or steal freenet clients http config toadlet public void make html node list1 new html node ul html node list2 new html node ul config config wot get config synchronized config string int keys config get all int keys string string keys config get all string keys arrays sort int keys arrays sort string keys for string key int keys list1 add child new html node li key config get int key for string key string keys list1 add child new html node li key config get string key html node box add content box configuration box add child list1 box add child list2 configtoadlet htmlnode htmlnode htmlnode htmlnode getconfig intkeys getallintkeys stringkeys getallstringkeys intkeys stringkeys intkeys addchild htmlnode getint stringkeys addchild htmlnode getstring htmlnode addcontentbox addchild addchild private volatile boolean isprng ready false public startup toadlet static toadlet static toadlet super null this static toadlet static toadlet isprngready startuptoadlet statictoadlet statictoadlet statictoadlet statictoadlet override public void handle get uri uri http request req toadlet context ctx throws toadlet context closed exception io exception redirect exception if we don t disconnect we will have pipelining issues ctx force disconnect string path uri get path if path starts with static toadlet root url static toadlet null static toadlet handle get uri req ctx else string desc l10n get string startup toadlet title html node page node ctx get page maker get page node desc false ctx html node head node ctx get page maker get head node page node head node add child meta new string http equiv content new string refresh 20 url html node content node ctx get page maker get content node page node if isprng ready html node prng infobox content node add child ctx get page maker get infobox infobox error l10n get string startup toadlet entropy error title html node prng infobox content ctx get page maker get content node prng infobox prng infobox content add child l10n get string startup toadlet entropy error content html node infobox content node add child ctx get page maker get infobox infobox error desc html node infobox content ctx get page maker get content node infobox infobox content add child l10n get string startup toadlet is starting up welcome toadlet maybe display wrapper logfile ctx content node todo send a retry after header writehtml reply ctx 503 desc page node generate handleget httprequest toadletcontext toadletcontextclosedexception ioexception redirectexception forcedisconnect getpath startswith statictoadlet root_url statictoadlet statictoadlet handleget getstring startuptoadlet htmlnode pagenode getpagemaker getpagenode htmlnode headnode getpagemaker getheadnode pagenode headnode addchild htmlnode contentnode getpagemaker getcontentnode pagenode isprngready htmlnode prnginfobox contentnode addchild getpagemaker getinfobox getstring startuptoadlet entropyerrortitle htmlnode prnginfoboxcontent getpagemaker getcontentnode prnginfobox prnginfoboxcontent addchild getstring startuptoadlet entropyerrorcontent htmlnode contentnode addchild getpagemaker getinfobox htmlnode infoboxcontent getpagemaker getcontentnode infoboxcontent addchild getstring startuptoadlet isstartingup welcometoadlet maybedisplaywrapperlogfile contentnode writehtmlreply pagenode override public string supported methods return get supportedmethods public void set isprng ready isprng ready true setisprngready isprngready public class ridgedfbm implements function2d public float evaluate float x float y return 1 math abs noise noise2 x y public inet address address tracker item long time definitely no packets received long time definitely no packets sent inet address addr super time definitely no packets received time definitely no packets sent this addr addr inetaddressaddresstrackeritem timedefinitelynopacketsreceived timedefinitelynopacketssent inetaddress timedefinitelynopacketsreceived timedefinitelynopacketssent override public simple field set to field set simple field set fs super to field set fs put overwrite address addr get host address return fs simplefieldset tofieldset simplefieldset tofieldset putoverwrite gethostaddress public inet address address tracker item simple field set fs throws fs parse exception super fs try addr inet address get by name fs get string address catch unknown host exception e fs parse exception ex new fs parse exception unknown domain name in address e ex init cause e throw ex inetaddressaddresstrackeritem simplefieldset fsparseexception inetaddress getbyname getstring unknownhostexception fsparseexception fsparseexception initcause public void test init trust tree throws malformedurl exception invalid parameter exception unknown identity exception not in trust tree exception m wot create own identity uria uria a true test this also initializes the trust tree assert true m wot get all non own identities size 0 assert true m wot get all own identities size 1 assert true m wot get all trusts size 0 assert true m wot get all scores size 1 own identity a m wot get own identity byuri uria score score m wot get score a a assert true score get score 100 assert true score get rank 0 assert true score get capacity 100 assert true score get tree owner a assert true score get target a empty the database fixme this is not needed because database based test does that in set up right object set object all db query by example new object while all has next db delete all next testinittrusttree malformedurlexception invalidparameterexception unknownidentityexception notintrusttreeexception mwot createownidentity asserttrue mwot getallnonownidentities asserttrue mwot getallownidentities asserttrue mwot getalltrusts asserttrue mwot getallscores ownidentity mwot getownidentitybyuri mwot getscore asserttrue getscore asserttrue getrank asserttrue getcapacity asserttrue gettreeowner asserttrue gettarget databasebasedtest setup objectset querybyexample hasnext public void test set trust1 throws invalid parameter exception malformedurl exception own identity a new own identity uria uria a true identity b new identity urib b true we store them manually so that the wot does not initialize the trust tree m wot getdb store a 5 m wot getdb store b 5 with a s trust tree not initialized b shouldn t get a score m wot set trust a b byte 10 foo assert true m wot get all non own identities size 1 assert true m wot get all own identities size 1 assert true m wot get all trusts size 1 assert true m wot get all scores size 0 testsettrust1 invalidparameterexception malformedurlexception ownidentity ownidentity mwot mwot mwot settrust asserttrue mwot getallnonownidentities asserttrue mwot getallownidentities asserttrue mwot getalltrusts asserttrue mwot getallscores public void test set trust2 throws malformedurl exception invalid parameter exception duplicate trust exception not trusted exception not in trust tree exception own identity a m wot create own identity uria uria a true test initializes it s trust tree identity b new identity urib b true m wot getdb store b 5 m wot set trust a b byte 100 foo check we have the correct number of objects assert true m wot get all non own identities size 1 assert true m wot get all own identities size 1 assert true m wot get all trusts size 1 assert true m wot get all scores size 2 check the trust object trust t m wot get trust a b assert true t get truster a assert true t get trustee b assert true t get value 100 assert true t get comment equals foo check a s score object score scorea m wot get score a a assert true scorea get score 100 assert true scorea get rank 0 assert true scorea get capacity 100 check b s score object score scoreb m wot get score a b assert true scoreb get score 100 assert true scoreb get rank 1 assert true scoreb get capacity 40 change the trust value and comment m wot set trust a b byte 50 bar check we have the correct number of objects assert true m wot get all non own identities size 1 assert true m wot get all own identities size 1 assert true m wot get all trusts size 1 assert true m wot get all scores size 2 check the trust object t m wot get trust a b assert true t get truster a assert true t get trustee b assert true t get value 50 assert true t get comment equals bar check a s score object scorea m wot get score a a assert true scorea get score 100 assert true scorea get rank 0 assert true scorea get capacity 100 check b s score object scoreb m wot get score a b assert true scoreb get score 50 assert true scoreb get rank 1 assert true scoreb get capacity 40 empty the database fixme this is not needed because database based test does that in set up right object set object all db query by example new object while all has next db delete all next testsettrust2 malformedurlexception invalidparameterexception duplicatetrustexception nottrustedexception notintrusttreeexception ownidentity mwot createownidentity mwot mwot settrust asserttrue mwot getallnonownidentities asserttrue mwot getallownidentities asserttrue mwot getalltrusts asserttrue mwot getallscores mwot gettrust asserttrue gettruster asserttrue gettrustee asserttrue getvalue asserttrue getcomment mwot getscore asserttrue getscore asserttrue getrank asserttrue getcapacity mwot getscore asserttrue getscore asserttrue getrank asserttrue getcapacity mwot settrust asserttrue mwot getallnonownidentities asserttrue mwot getallownidentities asserttrue mwot getalltrusts asserttrue mwot getallscores mwot gettrust asserttrue gettruster asserttrue gettrustee asserttrue getvalue asserttrue getcomment mwot getscore asserttrue getscore asserttrue getrank asserttrue getcapacity mwot getscore asserttrue getscore asserttrue getrank asserttrue getcapacity databasebasedtest setup objectset querybyexample hasnext public void test remove trust throws malformedurl exception invalid parameter exception unknown identity exception not in trust tree exception ext object container db m wot getdb own identity a m wot create own identity uria uria a true test identity b new identity urib b true do not init the trust tree identity c new identity uric c true do not init the trust tree db store b db store c m wot set trust a b byte 100 foo m wot set trust b c byte 50 bar check we have the correct number of objects assert true m wot get all own identities size 1 assert true m wot get all non own identities size 2 assert true m wot get all trusts size 2 assert true m wot get all scores size 3 check a s score object score scorea m wot get score a a assert true scorea get score 100 assert true scorea get rank 0 assert true scorea get capacity 100 check b s score object score scoreb m wot get score a b assert true scoreb get score 100 assert true scoreb get rank 1 assert true scoreb get capacity 40 check c s score object score scorec m wot get score a c assert true scorec get score 20 assert true scorec get rank 2 assert true scorec get capacity 16 m wot set trust a b byte 1 bastard check we have the correct number of objects assert true m wot get all own identities size 1 assert true m wot get all non own identities size 2 assert true m wot get all trusts size 2 assert true m wot get all scores size 2 check a s score object scorea m wot get score a a assert true scorea get score 100 assert true scorea get rank 0 assert true scorea get capacity 100 check b s score object scoreb m wot get score a b assert true scoreb get score 1 assert true scoreb get rank 1 assert true scoreb get capacity 0 c should not have a score anymore try m wot get score a c fail catch not in trust tree exception e empty the database fixme this is not needed because database based test does that in set up right object set object all db query by example new object while all has next db delete all next testremovetrust malformedurlexception invalidparameterexception unknownidentityexception notintrusttreeexception extobjectcontainer mwot ownidentity mwot createownidentity mwot settrust mwot settrust asserttrue mwot getallownidentities asserttrue mwot getallnonownidentities asserttrue mwot getalltrusts asserttrue mwot getallscores mwot getscore asserttrue getscore asserttrue getrank asserttrue getcapacity mwot getscore asserttrue getscore asserttrue getrank asserttrue getcapacity mwot getscore asserttrue getscore asserttrue getrank asserttrue getcapacity mwot settrust asserttrue mwot getallownidentities asserttrue mwot getallnonownidentities asserttrue mwot getalltrusts asserttrue mwot getallscores mwot getscore asserttrue getscore asserttrue getrank asserttrue getcapacity mwot getscore asserttrue getscore asserttrue getrank asserttrue getcapacity mwot getscore notintrusttreeexception databasebasedtest setup objectset querybyexample hasnext public void test trust loop throws malformedurl exception invalid parameter exception not in trust tree exception ext object container db m wot getdb own identity a m wot create own identity uria uria a true test identity b new identity urib b true do not init the trust tree identity c new identity uric c true do not init the trust tree db store b db store c m wot set trust a b byte 100 foo m wot set trust b c byte 50 bar m wot set trust c a byte 100 bleh m wot set trust c b byte 50 oops check we have the correct number of objects assert true m wot get all own identities size 1 assert true m wot get all non own identities size 2 assert true m wot get all trusts size 4 assert true m wot get all scores size 3 check a s score object score scorea m wot get score a a assert true scorea get score 100 assert true scorea get rank 0 assert true scorea get capacity 100 check b s score object score scoreb m wot get score a b assert true scoreb get score 108 assert true scoreb get rank 1 assert true scoreb get capacity 40 check c s score object score scorec m wot get score a c assert true scorec get score 20 assert true scorec get rank 2 assert true scorec get capacity 16 testtrustloop malformedurlexception invalidparameterexception notintrusttreeexception extobjectcontainer mwot ownidentity mwot createownidentity mwot settrust mwot settrust mwot settrust mwot settrust asserttrue mwot getallownidentities asserttrue mwot getallnonownidentities asserttrue mwot getalltrusts asserttrue mwot getallscores mwot getscore asserttrue getscore asserttrue getrank asserttrue getcapacity mwot getscore asserttrue getscore asserttrue getrank asserttrue getcapacity mwot getscore asserttrue getscore asserttrue getrank asserttrue getcapacity public void test own indentities trust throws malformedurl exception invalid parameter exception not in trust tree exception own identity a m wot create own identity uria uria a true test own identity b m wot create own identity urib urib b true test m wot set trust a b byte 100 foo m wot set trust b a byte 100 bar check we have the correct number of objects assert true m wot get all own identities size 2 assert true m wot get all non own identities size 0 assert true m wot get all trusts size 2 assert true m wot get all scores size 4 check a s own score object score scorea m wot get score a a assert true scorea get score 100 assert true scorea get rank 0 assert true scorea get capacity 100 check a s score object score score afromb m wot get score b a assert true score afromb get score 100 assert true score afromb get rank 1 assert true score afromb get capacity 40 check b s own score object score scoreb m wot get score a a assert true scoreb get score 100 assert true scoreb get rank 0 assert true scoreb get capacity 100 check b s score object score score bfroma m wot get score b a assert true score bfroma get score 100 assert true score bfroma get rank 1 assert true score bfroma get capacity 40 testownindentitiestrust malformedurlexception invalidparameterexception notintrusttreeexception ownidentity mwot createownidentity ownidentity mwot createownidentity mwot settrust mwot settrust asserttrue mwot getallownidentities asserttrue mwot getallnonownidentities asserttrue mwot getalltrusts asserttrue mwot getallscores mwot getscore asserttrue getscore asserttrue getrank asserttrue getcapacity scoreafromb mwot getscore asserttrue scoreafromb getscore asserttrue scoreafromb getrank asserttrue scoreafromb getcapacity mwot getscore asserttrue getscore asserttrue getrank asserttrue getcapacity scorebfroma mwot getscore asserttrue scorebfroma getscore asserttrue scorebfroma getrank asserttrue scorebfroma getcapacity final boolean ssk public offer reply tag boolean isssk super ssk isssk offerreplytag override public void log still present long uid string buffer sb new string buffer sb append still present after append time util format time age sb append ssk append ssk logger error this sb to string logstillpresent stringbuffer stringbuffer timeutil formattime tostring public configurable persister persistable t sub config node config string option name string default filename int sort order boolean expert boolean force write string short desc string long desc packet sender ps file base dir throws node init exception super t ps node config register option name new file base dir default filename to string sort order expert force write short desc long desc new string callback override public string get return persist target to string override public void set string val throws invalid config value exception set throttles val string throttle file node config get string option name try set throttles throttle file catch invalid config value exception e2 throw new node init exception node init exception exit throttle file error e2 get message configurablepersister subconfig nodeconfig optionname defaultfilename sortorder forcewrite shortdesc longdesc packetsender basedir nodeinitexception nodeconfig optionname basedir defaultfilename tostring sortorder forcewrite shortdesc longdesc stringcallback persisttarget tostring invalidconfigvalueexception setthrottles throttlefile nodeconfig getstring optionname setthrottles throttlefile invalidconfigvalueexception nodeinitexception nodeinitexception exit_throttle_file_error getmessage node config register option name new file base dir default filename to string sort order expert force write short desc long desc new string callback override public string get return persist target to string nodeconfig optionname basedir defaultfilename tostring sortorder forcewrite shortdesc longdesc stringcallback persisttarget tostring override public void set string val throws invalid config value exception set throttles val invalidconfigvalueexception setthrottles private void set throttles string val throws invalid config value exception file f new file val file tmp new file f to string tmp while true if f exists if f can read f can write throw new invalid config value exception l10n exists cannot read write tmp break else try if f create new file if f exists continue throw new invalid config value exception l10n does not exist cannot create tmp catch io exception e throw new invalid config value exception l10n does not exist cannot create tmp while true if tmp exists if tmp can read tmp can write throw new invalid config value exception l10n exists cannot read write tmp break else try tmp create new file catch io exception e throw new invalid config value exception l10n does not exist cannot create tmp synchronized this persist target f persist temp tmp setthrottles invalidconfigvalueexception tostring canread canwrite invalidconfigvalueexception existscannotreadwrite createnewfile invalidconfigvalueexception doesnotexistcannotcreate ioexception invalidconfigvalueexception doesnotexistcannotcreate canread canwrite invalidconfigvalueexception existscannotreadwrite createnewfile ioexception invalidconfigvalueexception doesnotexistcannotcreate persisttarget persisttemp private string l10n string key return l10n get string configurable persister key getstring configurablepersister private static int adjust float color float factor float gamma if color 0 0 return 0 return int math round 255 math pow color factor gamma convert a wavelength to an rgb value param wavelength wavelength in nanometres return the rgb value public static int wavelength torgb float wavelength float gamma 0 80f float r g b factor int w int wavelength if w 380 r 0 0f g 0 0f b 0 0f else if w 440 r wavelength 440 440 380 g 0 0f b 1 0f else if w 490 r 0 0f g wavelength 440 490 440 b 1 0f else if w 510 r 0 0f g 1 0f b wavelength 510 510 490 else if w 580 r wavelength 510 580 510 g 1 0f b 0 0f else if w 645 r 1 0f g wavelength 645 645 580 b 0 0f else if w 780 r 1 0f g 0 0f b 0 0f else r 0 0f g 0 0f b 0 0f let the intensity fall off near the vision limits if 380 w w 419 factor 0 3f 0 7f wavelength 380 420 380 else if 420 w w 700 factor 1 0f else if 701 w w 780 factor 0 3f 0 7f 780 wavelength 780 700 else factor 0 0f int ir adjust r factor gamma int ig adjust g factor gamma int ib adjust b factor gamma return 0xff000000 ir 16 ig 8 ib wavelengthtorgb public static file persistent config construct file persistent config file f throws io exception file filename f file temp filename new file f get path tmp return new file persistent config load filename temp filename filename temp filename filepersistentconfig constructfilepersistentconfig ioexception tempfilename getpath filepersistentconfig tempfilename tempfilename static simple field set load file filename file temp filename throws io exception boolean filename exists filename exists boolean temp filename exists temp filename exists if filename exists filename can write logger error file persistent config class warning cannot write to config file filename system err println warning cannot write to config file filename if temp filename exists temp filename can write logger error file persistent config class warning cannot write to config tempfile temp filename system err println warning cannot write to config tempfile temp filename if filename exists if filename can read filename length 0 try return initial load filename catch file not found exception e system err println cannot open config file filename e checking for temp file temp filename catch eof exception e system err println empty config file filename end of file other ioe s indicate a more serious problem else we probably won t be able to write it either system err println cannot read config file filename if temp filename exists if temp filename can read temp filename length 0 try return initial load temp filename catch file not found exception e system err println cannot open temp config file either temp filename e other ioe s indicate a more serious problem else system err println cannot read temp config file temp filename throw new io exception cannot read temp config file temp filename system err println no config file found creating new filename return null simplefieldset tempfilename ioexception filenameexists tempfilenameexists tempfilename filenameexists canwrite filepersistentconfig tempfilenameexists tempfilename canwrite filepersistentconfig tempfilename tempfilename filenameexists canread initialload filenotfoundexception tempfilename eofexception tempfilename tempfilename canread tempfilename initialload tempfilename filenotfoundexception tempfilename tempfilename ioexception tempfilename protected file persistent config simple field set origfs file fnam file temp throws io exception super origfs this filename fnam this temp filename temp filepersistentconfig simplefieldset ioexception tempfilename load the config file into a simple field set throws io exception private static simple field set initial load file to read throws io exception if to read null return null file input stream fis null buffered input stream bis null line reading input stream lis null try fis new file input stream to read bis new buffered input stream fis lis new line reading input stream bis config file is utf 8 too return new simple field set lis 1024 1024 128 true true true true fixme advanced users may edit the config file hence true finally closer close lis closer close bis closer close fis simplefieldset ioexception simplefieldset initialload toread ioexception toread fileinputstream bufferedinputstream linereadinginputstream fileinputstream toread bufferedinputstream linereadinginputstream simplefieldset override public void register sub config sc super register sc subconfig override public void store if finished init logger minor this initialization not finished refusing to write config new exception error return try synchronized store sync inner store catch io exception e string err cannot store config e logger error this err e system err println err e print stack trace finishedinit storesync innerstore ioexception printstacktrace don t call without taking store sync first protected final void inner store throws io exception if finished init throw new illegal state exception should not happen simple field set fs export field set if logger should log logger minor this logger minor this fs fs file output stream fos null try fos new file output stream temp filename synchronized this fs write to fos file util rename to temp filename filename finally closer close fos storesync innerstore ioexception finishedinit illegalstateexception simplefieldset exportfieldset shouldlog fileoutputstream fileoutputstream tempfilename writeto fileutil renameto tempfilename public class hex util private static boolean logdebug logger logger instance should log logger debug hex util class private hex util hexutil instanceshouldlog hexutil hexutil converts a byte array into a string of lower case hex chars param bs a byte array param off the index of the first byte to read param length the number of bytes to read return the string of hex chars public static final string bytes to hex byte bs int off int length if bs length off bs length off length throw new illegal argument exception string builder sb new string builder length 2 bytes to hex append bs off length sb return sb to string bytestohex illegalargumentexception stringbuilder stringbuilder bytestohexappend tostring public static final void bytes to hex append byte bs int off int length string builder sb if bs length off bs length off length throw new illegal argument exception sb ensure capacity sb length length 2 for int i off i off length i sb append character for digit bs i 4 0xf 16 sb append character for digit bs i 0xf 16 bytestohexappend stringbuilder illegalargumentexception ensurecapacity fordigit fordigit public static final string bytes to hex byte bs return bytes to hex bs 0 bs length bytestohex bytestohex public static final byte hex to bytes string s return hex to bytes s 0 hextobytes hextobytes public static final byte hex to bytes string s int off byte bs new byte off 1 s length 2 hex to bytes s bs off return bs hextobytes hextobytes converts a string of hex characters into an array of bytes param s a string of hex characters upper case or lower of even length param out a byte array of length at least s length 2 off param off the first byte to write of the array public static final void hex to bytes string s byte out int off throws number format exception index out of bounds exception int slen s length if slen 2 0 s 0 s if out length off slen 2 throw new index out of bounds exception output buffer too small for input out length off slen 2 safe to assume the string is even length byte b1 b2 for int i 0 i slen i 2 b1 byte character digit s char at i 16 b2 byte character digit s char at i 1 16 if b1 0 b2 0 throw new number format exception out off i 2 byte b1 4 b2 hextobytes numberformatexception indexoutofboundsexception indexoutofboundsexception charat charat numberformatexception pack the bits in ba into a byte param ba the bit set param size how many bits shall be taken into account starting from the lsb public final static byte bits to bytes bit set ba int size int bytes alloc count bytes for bits size byte b new byte bytes alloc string builder sb null if logdebug sb new string builder 8 bytes alloc todo should it be 2 8 bytes alloc here for int i 0 i b length i short s 0 for int j 0 j 8 j int idx i 8 j boolean val idx size 1 false ba get idx s val 1 j 0 if logdebug sb append val 1 0 if s 255 throw new illegal state exception wtf s s b i byte s if logdebug logger debug hex util class bytes bytes alloc returned from bits to bytes ba size bytes to hex b for sb to string return b bitset bitstobytes bitset bytesalloc countbytesforbits bytesalloc stringbuilder stringbuilder bytesalloc bytesalloc illegalstateexception hexutil bytesalloc bitstobytes bytestohex tostring pack the bits in ba into a byte then convert that to a hex string and return it public final static string bits to hex string bit set ba int size return bytes to hex bits to bytes ba size bitstohexstring bitset bytestohex bitstobytes return the number of bytes required to represent the bitset public static int count bytes for bits int size brackets matter here takes precedence over the rest return size 8 size 8 0 0 1 countbytesforbits read bits from a byte array into a bitset param b the byte to read from param ba the bitset to write to public static void bytes to bits byte b bit set ba int max size if logdebug logger debug hex util class bytes to bits bytes to hex b ba max size int x 0 for int i 0 i b length i for int j 0 j 8 j if x max size break int mask 1 j boolean value mask b i 0 ba set x value x bytestobits bitset maxsize hexutil bytestobits bytestohex maxsize maxsize read a hex string of bits and write it into a bitset param s hex string of the stored bits param ba the bitset to store the bits in param length the maximum number of bits to store public static void hex to bits string s bit set ba int length byte b hex to bytes s bytes to bits b ba length hextobits bitset hextobytes bytestobits write a reasonably short big integer to a stream param integer the big integer to write param out the stream to write it to public static void write big integer big integer integer data output stream out throws io exception if integer signum 1 dump negative big integer logger error true throw new illegal state exception negative big integer byte buf integer to byte array if buf length short max value throw new illegal state exception too long buf length out write short short buf length out write buf biginteger biginteger writebiginteger biginteger dataoutputstream ioexception biginteger illegalstateexception biginteger tobytearray max_value illegalstateexception writeshort read a reasonably short big integer from a data input stream param dis the stream to read from return a big integer public static big integer read big integer data input stream dis throws io exception short i dis read short if i 0 throw new io exception invalid big integer length i byte buf new byte i dis read fully buf return new big integer 1 buf biginteger datainputstream biginteger biginteger readbiginteger datainputstream ioexception readshort ioexception biginteger readfully biginteger turn a big integer into a hex string big integer to string 16 np es on sun jdk 1 4 2 05 the bugs in their big are getting seriously irritating public static string bi to hex big integer bi return bytes to hex bi to byte array biginteger biginteger tostring npes 2_05 bitohex biginteger bytestohex tobytearray public splitfile progress event int total blocks int succeed blocks int failed blocks int fatally failed blocks int min successful blocks boolean finalized total this total blocks total blocks this succeed blocks succeed blocks this failed blocks failed blocks this fatally failed blocks fatally failed blocks this min successful blocks min successful blocks this finalized total finalized total if logger should log logger minor this logger minor this created splitfile progress event total total blocks succeed succeed blocks failed failed blocks fatally fatally failed blocks min success min successful blocks finalized finalized total splitfileprogressevent totalblocks succeedblocks failedblocks fatallyfailedblocks minsuccessfulblocks finalizedtotal totalblocks totalblocks succeedblocks succeedblocks failedblocks failedblocks fatallyfailedblocks fatallyfailedblocks minsuccessfulblocks minsuccessfulblocks finalizedtotal finalizedtotal shouldlog splitfileprogressevent totalblocks succeedblocks failedblocks fatallyfailedblocks minsuccessfulblocks finalizedtotal public string get description string builder sb new string builder sb append completed if min successful blocks 0 succeed blocks 0 min successful blocks 1 if min successful blocks 0 if logger global get threshold logger minor logger error this min successful blocks 0 succeed blocks succeed blocks total blocks total blocks failed blocks failed blocks fatally failed blocks fatally failed blocks finalized total finalized total else logger error this min successful blocks 0 succeed blocks succeed blocks total blocks total blocks failed blocks failed blocks fatally failed blocks fatally failed blocks finalized total finalized total new exception debug else sb append 100 succeed blocks min successful blocks sb append sb append sb append succeed blocks sb append sb append min successful blocks sb append failed sb append failed blocks sb append fatally sb append fatally failed blocks sb append total sb append total blocks sb append sb append finalized total finalized total return sb to string getdescription stringbuilder stringbuilder minsuccessfulblocks succeedblocks minsuccessfulblocks minsuccessfulblocks globalgetthreshold minsuccessfulblocks succeedblocks succeedblocks totalblocks totalblocks failedblocks failedblocks fatallyfailedblocks fatallyfailedblocks finalizedtotal finalizedtotal minsuccessfulblocks succeedblocks succeedblocks totalblocks totalblocks failedblocks failedblocks fatallyfailedblocks fatallyfailedblocks finalizedtotal finalizedtotal succeedblocks minsuccessfulblocks succeedblocks minsuccessfulblocks failedblocks fatallyfailedblocks totalblocks finalizedtotal tostring public int get code return code getcode public void remove from object container container container delete this removefrom objectcontainer public uri generated message freeneturi uri string identifier boolean global this uri uri this identifier identifier this global global urigeneratedmessage override public simple field set get field set simple field set fs new simple field set true fs put single uri uri to string fs put single identifier identifier fs put global global return fs simplefieldset getfieldset simplefieldset simplefieldset putsingle tostring putsingle override public string get name return uri generated getname urigenerated override public void run fcp connection handler handler node node throws message invalid exception throw new message invalid exception protocol error message invalid message uri generated goes from server to client not the other way around identifier false fcpconnectionhandler messageinvalidexception messageinvalidexception protocolerrormessage invalid_message urigenerated override public void remove from object container container container activate uri 5 uri remove from container container delete this removefrom objectcontainer removefrom public static long allocate byte bitmap int begin int end long obj bit size long hole bit size 0 for int i begin i end i int mask bitmap i 0xff if hole bit size first hole size mask obj bit size bitmap i byte 1 int obj bit size hole bit size 1 long pos long i 8 hole bit size if hole bit size 0 while hole bit size 8 0 bitmap i byte 0xff bitmap i 1 byte 1 int hole bit size 1 return pos else if bitmap max hole size mask obj bit size int hole bit offset max hole offset mask bitmap i byte 1 int obj bit size 1 hole bit offset return long i 8 hole bit offset else if last hole size mask 8 hole bit size 8 else hole bit size last hole size mask return 1 objbitsize holebitsize holebitsize firstholesize objbitsize objbitsize holebitsize holebitsize holebitsize holebitsize holebitsize maxholesize objbitsize holebitoffset maxholeoffset objbitsize holebitoffset holebitoffset lastholesize holebitsize holebitsize lastholesize public static int locate bitmap end byte bitmap int offs while offs 0 bitmap offs 0 return offs locatebitmapend public static int locate hole end byte bitmap int offs while offs bitmap length bitmap offs 1 return offs bitmap length offs bitmap length locateholeend public static void free byte bitmap long obj bit pos long obj bit size int bit offs int obj bit pos 7 int offs int obj bit pos 3 if obj bit size 8 bit offs obj bit size 8 bit offs bitmap offs 1 bit offs 1 while obj bit size 8 0 bitmap offs byte 0 bitmap offs byte 1 int obj bit size 8 1 else bitmap offs byte 1 int obj bit size 1 bit offs objbitpos objbitsize bitoffs objbitpos objbitpos objbitsize bitoffs objbitsize bitoffs bitoffs objbitsize objbitsize objbitsize bitoffs public static void reserve byte bitmap long obj bit pos long obj bit size while obj bit size 0 bitmap int obj bit pos 3 1 int obj bit pos 7 obj bit pos 1 objbitpos objbitsize objbitsize objbitpos objbitpos objbitpos protected final boolean reversed comparator by status string sort by boolean reversed this sort by sort by this reversed reversed comparatorbystatus sortby sortby sortby public int compare peer node status first node peer node status second node int result 0 boolean is set true if sort by null result custom compare first node second node sort by is set result 0 else is set false if is set int status difference first node get status value second node get status value if status difference 0 result status difference 0 1 1 else result last resort compare first node second node if result 0 return 0 else if reversed is reversed true return result 0 1 1 else is reversed false return result 0 1 1 peernodestatus firstnode peernodestatus secondnode isset sortby customcompare firstnode secondnode sortby isset isset isset statusdifference firstnode getstatusvalue secondnode getstatusvalue statusdifference statusdifference lastresortcompare firstnode secondnode isreversed isreversed j16sdiz long max value 1 would overflow and become negative private int compare longs long long1 long long2 int diff long value of long1 compare to long2 if diff 0 return 0 else return diff 0 1 1 max_value comparelongs valueof compareto private int compare ints int int1 int int2 int diff integer value of int1 compare to int2 if diff 0 return 0 else return diff 0 1 1 compareints valueof compareto protected int custom compare peer node status first node peer node status second node string sort by2 if sort by equals address return first node get peer address compare to ignore case second node get peer address else if sort by equals location return compare locations first node second node else if sort by equals version return version get arbitrary build number first node get version 1 version get arbitrary build number second node get version 1 else if sort by equals backoff return double compare first node get backed off percent second node get backed off percent else if sort by equals overload p return double compare first node getp reject second node getp reject else if sort by equals idle return compare longs first node get time last connection completed second node get time last connection completed else if sort by equals time routable return double compare first node get percent time routable connection second node get percent time routable connection else if sort by equals total traffic long total1 first node get total input bytes first node get total output bytes long total2 second node get total input bytes second node get total output bytes return compare longs total1 total2 else if sort by equals total traffic since startup long total1 first node get total input since startup first node get total output since startup long total2 second node get total input since startup second node get total output since startup return compare longs total1 total2 else if sort by equals selection percentage return double compare first node get selection rate second node get selection rate else if sort by equals time delta return compare longs first node get clock delta second node get clock delta else if sort by equals uptime return compare ints first node get reported uptime percentage second node get reported uptime percentage else return 0 customcompare peernodestatus firstnode peernodestatus secondnode sortby2 sortby firstnode getpeeraddress comparetoignorecase secondnode getpeeraddress sortby comparelocations firstnode secondnode sortby getarbitrarybuildnumber firstnode getversion getarbitrarybuildnumber secondnode getversion sortby firstnode getbackedoffpercent secondnode getbackedoffpercent sortby overload_p firstnode getpreject secondnode getpreject sortby comparelongs firstnode gettimelastconnectioncompleted secondnode gettimelastconnectioncompleted sortby time_routable firstnode getpercenttimeroutableconnection secondnode getpercenttimeroutableconnection sortby total_traffic firstnode gettotalinputbytes firstnode gettotaloutputbytes secondnode gettotalinputbytes secondnode gettotaloutputbytes comparelongs sortby total_traffic_since_startup firstnode gettotalinputsincestartup firstnode gettotaloutputsincestartup secondnode gettotalinputsincestartup secondnode gettotaloutputsincestartup comparelongs sortby selection_percentage firstnode getselectionrate secondnode getselectionrate sortby time_delta comparelongs firstnode getclockdelta secondnode getclockdelta sortby compareints firstnode getreporteduptimepercentage secondnode getreporteduptimepercentage private int compare locations peer node status first node peer node status second node double diff first node get location second node get location can occasionally be the same and we must have a consistent sort order if double min value 2 math abs diff return 0 return diff 0 1 1 comparelocations peernodestatus firstnode peernodestatus secondnode firstnode getlocation secondnode getlocation min_value default comparison after taking into account status protected int last resort compare peer node status first node peer node status second node return compare locations first node second node lastresortcompare peernodestatus firstnode peernodestatus secondnode comparelocations firstnode secondnode override public string supported methods if this accept ref posts return get post else return get supportedmethods acceptrefposts protected connections toadlet node n node client core core high level simple client client super client this node n this core core this stats n node stats this peers n peers connectionstoadlet nodeclientcore highlevelsimpleclient nodestats abstract simple column end column headers boolean advanced mode enabled simplecolumn endcolumnheaders advancedmodeenabled abstract class simple column abstract protected void draw column html node peer row peer node status peer node status simplecolumn drawcolumn htmlnode peerrow peernodestatus peernodestatus abstract class simple column abstract protected void draw column html node peer row peer node status peer node status abstract public string get sort string simplecolumn drawcolumn htmlnode peerrow peernodestatus peernodestatus getsortstring abstract protected void draw column html node peer row peer node status peer node status abstract public string get sort string abstract public string get title key drawcolumn htmlnode peerrow peernodestatus peernodestatus getsortstring gettitlekey abstract public string get sort string abstract public string get title key abstract public string get explanation key getsortstring gettitlekey getexplanationkey override public void handle get uri uri final http request request toadlet context ctx throws toadlet context closed exception io exception redirect exception string path uri get path if path ends with myref fref simple field set fs get noderef string writer sw new string writer fs write to sw multi value table string string extra headers new multi value table string string force download to disk extra headers put content disposition attachment filename myref fref this write reply ctx 200 application x freenet reference ok extra headers sw to string return if path ends with myref txt simple field set fs get noderef string writer sw new string writer fs write to sw this write text reply ctx 200 ok sw to string return if ctx is allowed full access super send error page ctx 403 l10n get string toadlet unauthorized title l10n get string toadlet unauthorized return final boolean f proxy javascript enabled node isf proxy javascript enabled boolean draw message types path ends with displaymessagetypes html gather connection statistics peer node status peer node statuses get peer node statuses draw message types arrays sort peer node statuses comparator request get param sort by null request is parameter set reversed int number of connected peer node status get peer status count peer node statuses peer manager peer node status connected int number of routing backed off peer node status get peer status count peer node statuses peer manager peer node status routing backed off int number of too new peer node status get peer status count peer node statuses peer manager peer node status too new int number of too old peer node status get peer status count peer node statuses peer manager peer node status too old int number of disconnected peer node status get peer status count peer node statuses peer manager peer node status disconnected int number of never connected peer node status get peer status count peer node statuses peer manager peer node status never connected int number of disabled peer node status get peer status count peer node statuses peer manager peer node status disabled int number of bursting peer node status get peer status count peer node statuses peer manager peer node status bursting int number of listening peer node status get peer status count peer node statuses peer manager peer node status listening int number of listen only peer node status get peer status count peer node statuses peer manager peer node status listen only int number of clock problem peer node status get peer status count peer node statuses peer manager peer node status clock problem int number of conn error peer node status get peer status count peer node statuses peer manager peer node status conn error int number of disconnecting peer node status get peer status count peer node statuses peer manager peer node status disconnecting int number of routing disabled peer node status get peer status count peer node statuses peer manager peer node status routing disabled int number of simple connected number of connected number of routing backed off int number of not connected number of too new number of too old number of disconnected number of never connected number of disabled number of bursting number of listening number of listen only number of clock problem number of conn error string title count string null if node is advanced mode enabled title count string number of connected number of routing backed off number of too new number of too old number of routing disabled number of not connected else title count string number of not connected number of simple connected 0 string value of number of simple connected html node page node ctx get page maker get page node get page title title count string node get my name ctx html node content node ctx get page maker get content node page node fixme we need some nice images long now system current time millis if ctx is allowed full access content node add child core alerts create summary final int mode ctx get page maker draw mode selection array core request content node if peer node statuses length 0 node status values long node uptime seconds now node startup time 1000 int bwlimit delay time int stats get bwlimit delay time int node average ping time int stats get node average ping time int network size estimate session stats get darknet size estimate 1 int network size estimate recent 0 if node uptime seconds 48 60 60 48 hours network size estimate recent stats get darknet size estimate now 48 60 60 1000 48 hours decimal format fix4 new decimal format 0 0000 double routing miss distance stats routing miss distance current value double backed off percent stats backed off percent current value string node uptime string time util format time node uptime seconds 1000 1000 to convert to milliseconds begin overview table html node overview table content node add child table class column html node overview table row overview table add child tr html node next table cell overview table row add child td class first node status overview box if mode page maker mode advanced html node overview infobox next table cell add child div class infobox overview infobox add child div class infobox header node status overview html node overview infobox content overview infobox add child div class infobox content html node overview list overview infobox content add child ul overview list add child li bwlimit delay time u00a0 bwlimit delay time ms overview list add child li node average ping time u00a0 node average ping time ms overview list add child li darknet size estimate session u00a0 network size estimate session u00a0nodes if node uptime seconds 48 60 60 48 hours overview list add child li darknet size estimate recent u00a0 network size estimate recent u00a0nodes overview list add child li node uptime u00a0 node uptime string overview list add child li routing miss distance u00a0 fix4 format routing miss distance overview list add child li backed off percent u00a0 fix1 format backed off percent overview list add child li p instant reject u00a0 fix1 format stats p reject incoming instantly next table cell overview table row add child td activity box int numark fetchers node get numark fetchers html node activity infobox next table cell add child div class infobox activity infobox add child div class infobox header l10n activity title html node activity infobox content activity infobox add child div class infobox content html node activity list statistics toadlet draw activity activity infobox content node if mode page maker mode advanced activity list null if numark fetchers 0 activity list add child li ark u00a0 fetch u00a0 requests u00a0 numark fetchers statistics toadlet draw bandwidth activity list node node uptime seconds mode page maker mode advanced next table cell mode page maker mode advanced overview table row add child td overview table row add child td class last peer statistics box html node peer stats infobox next table cell add child div class infobox statistics toadlet draw peer stats box peer stats infobox mode page maker mode advanced number of connected number of routing backed off number of too new number of too old number of disconnected number of never connected number of disabled number of bursting number of listening number of listen only 0 0 number of routing disabled number of clock problem number of conn error number of disconnecting peer routing backoff reason box if mode page maker mode advanced next table cell overview table row add child td class last html node backoff reason infobox next table cell add child div class infobox backoff reason infobox add child div class infobox header peer backoff reasons html node backoff reason content backoff reason infobox add child div class infobox content string routing backoff reasons peers get peer node routing backoff reasons if routing backoff reasons length 0 backoff reason content add child good your node is not backed off from any peers else html node reason list backoff reason content add child ul for int i 0 i routing backoff reasons length i int reason count peers get peer node routing backoff reason size routing backoff reasons i if reason count 0 reason list add child li routing backoff reasons i u00a0 reason count end overview table boolean enable peer actions show peer actions box begin peer table if f proxy javascript enabled string builder js buf new string builder fixme there s probably some icky javascript in here this is the first thing that worked for me feel free to fix up to javascript guru standards js buf append function peer note change n js buf append var theobj document get element by id action n js buf append var length theobj options length n js buf append for var i 0 i length i n js buf append if theobj options i update notes n js buf append theobj options i select true n js buf append else n js buf append theobj options i select false n js buf append n js buf append n js buf append theobj value update handleget httprequest toadletcontext toadletcontextclosedexception ioexception redirectexception getpath endswith simplefieldset getnoderef stringwriter stringwriter writeto multivaluetable extraheaders multivaluetable extraheaders writereply extraheaders tostring endswith simplefieldset getnoderef stringwriter stringwriter writeto writetextreply tostring isallowedfullaccess senderrorpage getstring unauthorizedtitle getstring fproxyjavascriptenabled isfproxyjavascriptenabled drawmessagetypes endswith peernodestatus peernodestatuses getpeernodestatuses drawmessagetypes peernodestatuses getparam sortby isparameterset numberofconnected peernodestatus getpeerstatuscount peernodestatuses peermanager peer_node_status_connected numberofroutingbackedoff peernodestatus getpeerstatuscount peernodestatuses peermanager peer_node_status_routing_backed_off numberoftoonew peernodestatus getpeerstatuscount peernodestatuses peermanager peer_node_status_too_new numberoftooold peernodestatus getpeerstatuscount peernodestatuses peermanager peer_node_status_too_old numberofdisconnected peernodestatus getpeerstatuscount peernodestatuses peermanager peer_node_status_disconnected numberofneverconnected peernodestatus getpeerstatuscount peernodestatuses peermanager peer_node_status_never_connected numberofdisabled peernodestatus getpeerstatuscount peernodestatuses peermanager peer_node_status_disabled numberofbursting peernodestatus getpeerstatuscount peernodestatuses peermanager peer_node_status_bursting numberoflistening peernodestatus getpeerstatuscount peernodestatuses peermanager peer_node_status_listening numberoflistenonly peernodestatus getpeerstatuscount peernodestatuses peermanager peer_node_status_listen_only numberofclockproblem peernodestatus getpeerstatuscount peernodestatuses peermanager peer_node_status_clock_problem numberofconnerror peernodestatus getpeerstatuscount peernodestatuses peermanager peer_node_status_conn_error numberofdisconnecting peernodestatus getpeerstatuscount peernodestatuses peermanager peer_node_status_disconnecting numberofroutingdisabled peernodestatus getpeerstatuscount peernodestatuses peermanager peer_node_status_routing_disabled numberofsimpleconnected numberofconnected numberofroutingbackedoff numberofnotconnected numberoftoonew numberoftooold numberofdisconnected numberofneverconnected numberofdisabled numberofbursting numberoflistening numberoflistenonly numberofclockproblem numberofconnerror titlecountstring isadvancedmodeenabled titlecountstring numberofconnected numberofroutingbackedoff numberoftoonew numberoftooold numberofroutingdisabled numberofnotconnected titlecountstring numberofnotconnected numberofsimpleconnected valueof numberofsimpleconnected htmlnode pagenode getpagemaker getpagenode getpagetitle titlecountstring getmyname htmlnode contentnode getpagemaker getcontentnode pagenode currenttimemillis isallowedfullaccess contentnode addchild createsummary getpagemaker drawmodeselectionarray contentnode peernodestatuses nodeuptimeseconds startuptime bwlimitdelaytime getbwlimitdelaytime nodeaveragepingtime getnodeaveragepingtime networksizeestimatesession getdarknetsizeestimate networksizeestimaterecent nodeuptimeseconds networksizeestimaterecent getdarknetsizeestimate decimalformat decimalformat routingmissdistance routingmissdistance currentvalue backedoffpercent backedoffpercent currentvalue nodeuptimestring timeutil formattime nodeuptimeseconds htmlnode overviewtable contentnode addchild htmlnode overviewtablerow overviewtable addchild htmlnode nexttablecell overviewtablerow addchild pagemaker mode_advanced htmlnode overviewinfobox nexttablecell addchild overviewinfobox addchild htmlnode overviewinfoboxcontent overviewinfobox addchild htmlnode overviewlist overviewinfoboxcontent addchild overviewlist addchild bwlimitdelaytime bwlimitdelaytime overviewlist addchild nodeaveragepingtime nodeaveragepingtime overviewlist addchild darknetsizeestimatesession networksizeestimatesession nodeuptimeseconds overviewlist addchild darknetsizeestimaterecent networksizeestimaterecent overviewlist addchild nodeuptime nodeuptimestring overviewlist addchild routingmissdistance routingmissdistance overviewlist addchild backedoffpercent backedoffpercent overviewlist addchild pinstantreject prejectincominginstantly nexttablecell overviewtablerow addchild numarkfetchers getnumarkfetchers htmlnode activityinfobox nexttablecell addchild activityinfobox addchild activitytitle htmlnode activityinfoboxcontent activityinfobox addchild htmlnode activitylist statisticstoadlet drawactivity activityinfoboxcontent pagemaker mode_advanced activitylist numarkfetchers activitylist addchild u00a0fetch u00a0requests numarkfetchers statisticstoadlet drawbandwidth activitylist nodeuptimeseconds pagemaker mode_advanced nexttablecell pagemaker mode_advanced overviewtablerow addchild overviewtablerow addchild htmlnode peerstatsinfobox nexttablecell addchild statisticstoadlet drawpeerstatsbox peerstatsinfobox pagemaker mode_advanced numberofconnected numberofroutingbackedoff numberoftoonew numberoftooold numberofdisconnected numberofneverconnected numberofdisabled numberofbursting numberoflistening numberoflistenonly numberofroutingdisabled numberofclockproblem numberofconnerror numberofdisconnecting pagemaker mode_advanced nexttablecell overviewtablerow addchild htmlnode backoffreasoninfobox nexttablecell addchild backoffreasoninfobox addchild htmlnode backoffreasoncontent backoffreasoninfobox addchild routingbackoffreasons getpeernoderoutingbackoffreasons routingbackoffreasons backoffreasoncontent addchild htmlnode reasonlist backoffreasoncontent addchild routingbackoffreasons reasoncount getpeernoderoutingbackoffreasonsize routingbackoffreasons reasoncount reasonlist addchild routingbackoffreasons reasoncount enablepeeractions showpeeractionsbox fproxyjavascriptenabled stringbuilder jsbuf stringbuilder jsbuf peernotechange jsbuf getelementbyid jsbuf jsbuf jsbuf update_notes jsbuf jsbuf jsbuf jsbuf jsbuf jsbuf update_ protected abstract boolean accept ref posts acceptrefposts protected abstract boolean accept ref posts where to redirect to if there is an error protected abstract string default redirect location acceptrefposts defaultredirectlocation override public void handle post uri uri final http request request toadlet context ctx throws toadlet context closed exception io exception redirect exception boolean logminor logger should log logger minor this if accept ref posts super send error page ctx 403 unauthorized l10n get string toadlet unauthorized return if ctx is allowed full access super send error page ctx 403 unauthorized l10n get string toadlet unauthorized return string pass request get part as string form password 32 if pass null pass equals core form password multi value table string string headers new multi value table string string headers put location default redirect location ctx send reply headers 302 found headers null 0 if logminor logger minor this no password pass should be core form password return if request is part set add add a new node string urltext request get part as string url 200 urltext urltext trim string reftext request get part as string ref integer max value reftext reftext trim if reftext length 200 reftext request get part as string reffile integer max value reftext reftext trim string private comment null if is opennet private comment request get part as string peer private note 250 trim string builder ref new string builder 1024 if urltext length 0 fetch reference from a url buffered reader in null try url url new url urltext url connection uc url open connection fixme get charset encoding from uc get content type in new buffered reader new input stream reader uc get input stream string line while line in read line null ref append line append n catch io exception e this send error page ctx 200 l10n failed to add node title l10n get string darknet connections toadlet cant fetch noderefurl new string url new string urltext return finally if in null in close else if reftext length 0 read from post data or file upload this slightly scary looking regexp chops any extra characters off the beginning or ends of lines and removes extra line breaks ref new string builder reftext replace all w r n end t r n 1 n else this send error page ctx 200 l10n failed to add node title l10n no ref orurl request free parts return ref new string builder ref to string trim request free parts split the references string because the peers are added individually string nodes to add ref to string split end the peer s additions results map peer addition return codes integer results new hash map peer addition return codes integer for int i 0 i nodes to add length i we need to trim then concat end to the node s reference this way we have a normal reference the split removes the end s peer addition return codes result add new node nodes to add i trim concat n end private comment store the result if results contains key result false results put result integer value of 0 results put result results get result 1 html node page node ctx get page maker get page node l10n report of node addition ctx html node content node ctx get page maker get content node page node we create a table to show the results html node detailed status box new html node table header of the table detailed status box add child new html node tr add children new html node new html node th l10n result name new html node th l10n num of results html node status box table detailed status box add child new html node tbody iterate through the return codes for peer addition return codes return code peer addition return codes values if results contains key return code add a tr and 2 td with the name of the code and the number of occasions it happened if the code is ok we use green red elsewhere status box table add child new html node tr style color return code peer addition return codes ok green red add children new html node new html node td l10n peer addition code return code to string new html node td results get return code to string html node infobox content node add child ctx get page maker get infobox infobox l10n report of node addition html node infobox content ctx get page maker get content node infobox infobox content add child detailed status box infobox content add child br infobox content add child a href l10n return to prev page infobox content add child br add homepage link infobox content writehtml reply ctx 500 l10n report of node addition page node generate multi value table string string headers new multi value table string string headers put location default redirect location ctx send reply headers 302 found headers null 0 return else handle alt post uri request ctx logminor handlepost httprequest toadletcontext toadletcontextclosedexception ioexception redirectexception shouldlog acceptrefposts senderrorpage getstring isallowedfullaccess senderrorpage getstring getpartasstring formpassword formpassword multivaluetable multivaluetable defaultredirectlocation sendreplyheaders formpassword ispartset getpartasstring getpartasstring max_value getpartasstring max_value privatecomment isopennet privatecomment getpartasstring peerprivatenote stringbuilder stringbuilder bufferedreader urlconnection openconnection getcontenttype bufferedreader inputstreamreader getinputstream readline ioexception senderrorpage failedtoaddnodetitle getstring darknetconnectionstoadlet cantfetchnoderefurl stringbuilder replaceall senderrorpage failedtoaddnodetitle noreforurl freeparts stringbuilder tostring freeparts nodestoadd tostring peeradditionreturncodes hashmap peeradditionreturncodes nodestoadd peeradditionreturncodes addnewnode nodestoadd nend privatecomment containskey valueof htmlnode pagenode getpagemaker getpagenode reportofnodeaddition htmlnode contentnode getpagemaker getcontentnode pagenode htmlnode detailedstatusbox htmlnode detailedstatusbox addchild htmlnode addchildren htmlnode htmlnode resultname htmlnode numofresults htmlnode statusboxtable detailedstatusbox addchild htmlnode peeradditionreturncodes returncode peeradditionreturncodes containskey returncode statusboxtable addchild htmlnode returncode peeradditionreturncodes addchildren htmlnode htmlnode peeradditioncode returncode tostring htmlnode returncode tostring htmlnode contentnode addchild getpagemaker getinfobox reportofnodeaddition htmlnode infoboxcontent getpagemaker getcontentnode infoboxcontent addchild detailedstatusbox infoboxcontent addchild infoboxcontent addchild returntoprevpage infoboxcontent addchild addhomepagelink infoboxcontent writehtmlreply reportofnodeaddition pagenode multivaluetable multivaluetable defaultredirectlocation sendreplyheaders handlealtpost adds a new node if any error arises it returns the appropriate return code param node reference the reference to the new node param private comment the private comment when adding a darknet node return the result of the addition private peer addition return codes add new node string node reference string private comment simple field set fs try fs new simple field set node reference to string false true if fs get end marker ends with end return peer addition return codes wrong encoding fs set end marker end it s always end the regex above doesn t always grok this catch io exception e return peer addition return codes cant parse catch throwable t return peer addition return codes internal error peer node pn try if is opennet pn node create new opennet node fs else pn node create new darknet node fs darknet peer node pn set private darknet comment note private comment catch fs parse exception e1 return peer addition return codes cant parse catch peer parse exception e1 return peer addition return codes cant parse catch reference signature verification exception e1 return peer addition return codes invalid signature catch throwable t return peer addition return codes internal error if arrays equals pn get identity node get darknet identity return peer addition return codes try to add self if this node add peer connection pn return peer addition return codes already in reference return peer addition return codes ok nodereference privatecomment peeradditionreturncodes addnewnode nodereference privatecomment simplefieldset simplefieldset nodereference tostring getendmarker endswith peeradditionreturncodes wrong_encoding setendmarker ioexception peeradditionreturncodes cant_parse peeradditionreturncodes internal_error peernode isopennet createnewopennetnode createnewdarknetnode darknetpeernode setprivatedarknetcommentnote privatecomment fsparseexception peeradditionreturncodes cant_parse peerparseexception peeradditionreturncodes cant_parse referencesignatureverificationexception peeradditionreturncodes invalid_signature peeradditionreturncodes internal_error getidentity getdarknetidentity peeradditionreturncodes try_to_add_self addpeerconnection peeradditionreturncodes already_in_reference peeradditionreturncodes adding a darknet node or an opennet node protected abstract boolean is opennet isopennet rest of handle post method supplied by subclass throws io exception throws toadlet context closed exception throws redirect exception protected void handle alt post uri uri http request request toadlet context ctx boolean logminor throws toadlet context closed exception io exception redirect exception do nothing we only support adding nodes handle get uri new http request impl uri ctx handlepost ioexception toadletcontextclosedexception redirectexception handlealtpost httprequest toadletcontext toadletcontextclosedexception ioexception redirectexception handleget httprequestimpl what should the heading before more detailed be on the peers table protected abstract string get peer list title getpeerlisttitle protected abstract string get peer list title should there be a checkbox for each peer and draw peer action select box be called directly after drawing the peers list protected abstract boolean show peer actions box getpeerlisttitle drawpeeractionselectbox showpeeractionsbox if show peer actions box is true this will be called directly after drawing the peers table a form has been added and checkboxes added for each peer this function should draw the rest of the form any additional controls and one or more submit buttons showpeeractionsbox protected abstract void draw peer action select box html node peer form boolean advanced mode enabled protected abstract boolean should draw noderef box boolean advanced mode enabled drawpeeractionselectbox htmlnode peerform advancedmodeenabled shoulddrawnoderefbox advancedmodeenabled private void draw noderef box html node content node toadlet context ctx html node reference infobox content node add child div class infobox infobox normal html node header reference infobox reference infobox add child div class infobox header fixme better way to deal with this sort of thing l10n addl10n substitution header reference infobox darknet connections toadlet my reference header new string linkref linkref linktext linktext new string a href myref fref a a href myref txt a html node reference infobox content reference infobox add child div class infobox content html node warning sentence reference infobox content add child p l10n addl10n substitution warning sentence darknet connections toadlet reference copy warning new string bold bold new string b b reference infobox content add child pre id reference get noderef to string n drawnoderefbox htmlnode contentnode toadletcontext htmlnode referenceinfobox contentnode addchild htmlnode headerreferenceinfobox referenceinfobox addchild addl10nsubstitution headerreferenceinfobox darknetconnectionstoadlet myreferenceheader htmlnode referenceinfoboxcontent referenceinfobox addchild htmlnode warningsentence referenceinfoboxcontent addchild addl10nsubstitution warningsentence darknetconnectionstoadlet referencecopywarning referenceinfoboxcontent addchild getnoderef tostring protected abstract string get page title string title count string string my name getpagetitle titlecountstring myname draw the add a peer box this comes immediately after the main peers table and before the noderef box implementors may skip it by not doing anything in this method protected void draw add peer box html node content node toadlet context ctx begin peer addition box html node peer addition infobox content node add child div class infobox infobox normal peer addition infobox add child div class infobox header l10n add peer title html node peer addition content peer addition infobox add child div class infobox content html node peer addition form ctx add form child peer addition content add peer form peer addition form add child l10n paste reference peer addition form add child br peer addition form add child textarea new string id name rows cols new string reftext ref 8 74 peer addition form add child br peer addition form add child l10n url reference peer addition form add child input new string id type name new string refurl text url peer addition form add child br peer addition form add child l10n file reference peer addition form add child input new string id type name new string reffile file reffile peer addition form add child br if is opennet peer addition form add child l10n enter description peer addition form add child input new string id type name size maxlength value new string peer private note text peer private note 16 250 peer addition form add child br peer addition form add child input new string type name value new string submit add l10n add drawaddpeerbox htmlnode contentnode toadletcontext htmlnode peeradditioninfobox contentnode addchild peeradditioninfobox addchild addpeertitle htmlnode peeradditioncontent peeradditioninfobox addchild htmlnode peeradditionform addformchild peeradditioncontent addpeerform peeradditionform addchild pastereference peeradditionform addchild peeradditionform addchild peeradditionform addchild peeradditionform addchild urlreference peeradditionform addchild peeradditionform addchild peeradditionform addchild filereference peeradditionform addchild peeradditionform addchild isopennet peeradditionform addchild enterdescription peeradditionform addchild peerprivatenote peerprivatenote peeradditionform addchild peeradditionform addchild protected comparator peer node status comparator string sort by boolean reversed return new comparator by status sort by reversed peernodestatus sortby comparatorbystatus sortby abstract protected peer node status get peer node statuses boolean no heavy peernodestatus getpeernodestatuses noheavy abstract protected peer node status get peer node statuses boolean no heavy abstract protected simple field set get noderef peernodestatus getpeernodestatuses noheavy simplefieldset getnoderef private void draw row html node peer table peer node status peer node status boolean advanced mode enabled boolean f proxy javascript enabled long now string path boolean enable peer actions simple column end cols boolean draw message types double total selection rate double selection rate peer node status get selection rate int peer selection percentage 0 if total selection rate 0 peer selection percentage int selection rate 100 total selection rate html node peer row peer table add child tr class darknet connections peer selection percentage peer node selection percentage warning warning normal if enable peer actions check box column peer row add child td class peer marker add child input new string type name new string checkbox node peer node status hash code status column string status string peer node status get status name if advanced mode enabled peer node status get status value peer manager peer node status routing backed off status string busy peer row add child td class peer status add child span class peer node status get statuscss name l10n get string connections toadlet node status status string peer node status is fetchingark draw name column peer row peer node status address column if advanced mode enabled string ping time if peer node status is connected ping time int peer node status get average ping time ms peer row add child td class peer address add child peer node status get peer address null peer node status get peer address peer node status get peer port l10n unknown address ping time version column if peer node status get status value peer manager peer node status never connected peer node status is public invalid version peer node status is public reverse invalid version don t draw attention to a version problem if never connected peer row add child td class peer version add child span class peer version problem integer to string peer node status get simple version else peer row add child td class peer version add child integer to string peer node status get simple version location column if advanced mode enabled html node location node peer row add child td class peer location location node add child b string value of peer node status get location location node add child br double peers loc peer node status get peers location if peers loc null for double loc peers loc location node add child i string value of loc add child br if advanced mode enabled backoff column html node backoff cell peer row add child td class peer backoff backoff cell add child fix1 format peer node status get backed off percent int backoff int math max peer node status get routing backed off until now 0 don t list the backoff as zero before it s actually zero if backoff 0 backoff 1000 backoff 1000 backoff cell add child string value of backoff 1000 string value of peer node status get routing backoff length 1000 backoff cell add child peer node status get last backoff reason null peer node status get last backoff reason overload probability column html node p reject cell peer row add child td class peer backoff fixme p reject cell add child fix1 format peer node status getp reject idle column long idle peer node status get time last routable if peer node status is routable idle peer node status get time last connection completed else if peer node status get status value peer manager peer node status never connected idle peer node status get peer added time if peer node status is connected now idle 2 7 24 60 60 long 1000 2 weeks peer row add child td class peer idle add child span class peer idle old idle to string now idle else peer row add child td class peer idle idle to string now idle if has private note column draw private note column peer row peer node status f proxy javascript enabled if advanced mode enabled percent of time connected column peer row add child td class peer idle fixme add child fix1 format peer node status get percent time routable connection selection stats peer row add child td class peer idle fixme add child total selection rate 0 peer selection percentage n a total traffic column peer row add child td class peer idle fixme add child size util format size peer node status get total input bytes size util format size peer node status get total output bytes size util format size peer node status get resend bytes sent total traffic column startup peer row add child td class peer idle fixme add child size util format size peer node status get total input since startup size util format size peer node status get total output since startup congestion control packet throttle t peer node status get throttle string val if t null val none else val int 1000 0 t get delay 1024 0 b sec delay t get delay ms rtt t get round trip time ms window t get window size peer row add child td class peer idle fixme add child val time delta peer row add child td class peer idle fixme add child time util format time peer node status get clock delta peer row add child td class peer idle fixme add child peer node status get reported uptime percentage if end cols null for int i 0 i end cols length i end cols i draw column peer row peer node status if draw message types draw message types peer table peer node status drawrow htmlnode peertable peernodestatus peernodestatus advancedmodeenabled fproxyjavascriptenabled enablepeeractions simplecolumn endcols drawmessagetypes totalselectionrate selectionrate peernodestatus getselectionrate peerselectionpercentage totalselectionrate peerselectionpercentage selectionrate totalselectionrate htmlnode peerrow peertable addchild darknet_connections_ peerselectionpercentage peernode selection_percentage_warning enablepeeractions peerrow addchild addchild node_ peernodestatus hashcode statusstring peernodestatus getstatusname advancedmodeenabled peernodestatus getstatusvalue peermanager peer_node_status_routing_backed_off statusstring peerrow addchild addchild peernodestatus getstatuscssname getstring connectionstoadlet nodestatus statusstring peernodestatus isfetchingark drawnamecolumn peerrow peernodestatus advancedmodeenabled pingtime peernodestatus isconnected pingtime peernodestatus getaveragepingtime peerrow addchild addchild peernodestatus getpeeraddress peernodestatus getpeeraddress peernodestatus getpeerport unknownaddress pingtime peernodestatus getstatusvalue peermanager peer_node_status_never_connected peernodestatus ispublicinvalidversion peernodestatus ispublicreverseinvalidversion peerrow addchild addchild peer_version_problem tostring peernodestatus getsimpleversion peerrow addchild addchild tostring peernodestatus getsimpleversion advancedmodeenabled htmlnode locationnode peerrow addchild locationnode addchild valueof peernodestatus getlocation locationnode addchild peersloc peernodestatus getpeerslocation peersloc peersloc locationnode addchild valueof addchild advancedmodeenabled htmlnode backoffcell peerrow addchild backoffcell addchild peernodestatus getbackedoffpercent peernodestatus getroutingbackedoffuntil backoffcell addchild valueof valueof peernodestatus getroutingbackofflength backoffcell addchild peernodestatus getlastbackoffreason peernodestatus getlastbackoffreason htmlnode prejectcell peerrow addchild prejectcell addchild peernodestatus getpreject peernodestatus gettimelastroutable peernodestatus isroutable peernodestatus gettimelastconnectioncompleted peernodestatus getstatusvalue peermanager peer_node_status_never_connected peernodestatus getpeeraddedtime peernodestatus isconnected peerrow addchild addchild peer_idle_old idletostring peerrow addchild idletostring hasprivatenotecolumn drawprivatenotecolumn peerrow peernodestatus fproxyjavascriptenabled advancedmodeenabled peerrow addchild addchild peernodestatus getpercenttimeroutableconnection peerrow addchild addchild totalselectionrate peerselectionpercentage peerrow addchild addchild sizeutil formatsize peernodestatus gettotalinputbytes sizeutil formatsize peernodestatus gettotaloutputbytes sizeutil formatsize peernodestatus getresendbytessent peerrow addchild addchild sizeutil formatsize peernodestatus gettotalinputsincestartup sizeutil formatsize peernodestatus gettotaloutputsincestartup packetthrottle peernodestatus getthrottle getdelay getdelay getroundtriptime getwindowsize peerrow addchild addchild peerrow addchild addchild timeutil formattime peernodestatus getclockdelta peerrow addchild addchild peernodestatus getreporteduptimepercentage endcols endcols endcols drawcolumn peerrow peernodestatus drawmessagetypes drawmessagetypes peertable peernodestatus is there a name column abstract protected boolean has name column hasnamecolumn abstract protected boolean has name column draw the name column if there is one this will be directly after the status column abstract protected void draw name column html node peer row peer node status peer node status hasnamecolumn drawnamecolumn htmlnode peerrow peernodestatus peernodestatus abstract protected void draw name column html node peer row peer node status peer node status is there a private note column abstract protected boolean has private note column drawnamecolumn htmlnode peerrow peernodestatus peernodestatus hasprivatenotecolumn abstract protected boolean has private note column draw the private note column abstract protected void draw private note column html node peer row peer node status peer node status boolean f proxy javascript enabled hasprivatenotecolumn drawprivatenotecolumn htmlnode peerrow peernodestatus peernodestatus fproxyjavascriptenabled private void draw message types html node peer table peer node status peer node status html node message count row peer table add child tr class message status message count row add child td colspan 2 html node message count cell message count row add child td colspan 9 total table row width 2 from above colspan html node message count table message count cell add child table class message count html node count header row message count table add child tr count header row add child th message count header row add child th incoming count header row add child th outgoing list string message names new array list string map string long message counts new hash map string long for map entry string long entry peer node status get local messages received entry set string message name entry get key long message count entry get value message names add message name message counts put message name new long message count long value of 0 for map entry string long entry peer node status get local messages sent entry set string message name entry get key long message count entry get value if message names contains message name message names add message name long existing counts message counts get message name if existing counts null message counts put message name new long long value of 0 message count else existing counts 1 message count collections sort message names new comparator string public int compare string first string second return first compare to ignore case second for iterator string message names iterator message names iterator message names iterator has next string message name message names iterator next long message count message counts get message name html node message row message count table add child tr message row add child td message name message row add child td class right align string value of message count 0 message row add child td class right align string value of message count 1 drawmessagetypes htmlnode peertable peernodestatus peernodestatus htmlnode messagecountrow peertable addchild messagecountrow addchild htmlnode messagecountcell messagecountrow addchild htmlnode messagecounttable messagecountcell addchild htmlnode countheaderrow messagecounttable addchild countheaderrow addchild countheaderrow addchild countheaderrow addchild messagenames arraylist messagecounts hashmap peernodestatus getlocalmessagesreceived entryset messagename getkey messagecount getvalue messagenames messagename messagecounts messagename messagecount valueof peernodestatus getlocalmessagessent entryset messagename getkey messagecount getvalue messagenames messagename messagenames messagename existingcounts messagecounts messagename existingcounts messagecounts messagename valueof messagecount existingcounts messagecount messagenames comparetoignorecase messagenamesiterator messagenames messagenamesiterator hasnext messagename messagenamesiterator messagecount messagecounts messagename htmlnode messagerow messagecounttable addchild messagerow addchild messagename messagerow addchild valueof messagecount messagerow addchild valueof messagecount collections sort message names new comparator string public int compare string first string second return first compare to ignore case second messagenames comparetoignorecase private string idle to string long now long idle if idle 0 return long idle milliseconds now idle return time util format time idle milliseconds idletostring idlemilliseconds timeutil formattime idlemilliseconds private static string l10n string string return l10n get string darknet connections toadlet string getstring darknetconnectionstoadlet private string sort string boolean is reversed string type return is reversed sort by type sort by type reversed sortstring isreversed isreversed sortby sortby public final class pin light composite extends rgb composite public pin light composite float alpha super alpha pinlightcomposite rgbcomposite pinlightcomposite public composite context create context color model src color model color model dst color model rendering hints hints return new context extra alpha src color model dst color model compositecontext createcontext colormodel srccolormodel colormodel dstcolormodel renderinghints extraalpha srccolormodel dstcolormodel static class context extends rgb composite context public context float alpha color model src color model color model dst color model super alpha src color model dst color model rgbcompositecontext colormodel srccolormodel colormodel dstcolormodel srccolormodel dstcolormodel override public void composergb int src int dst float alpha int w src length for int i 0 i w i 4 int sr src i int dir dst i int sg src i 1 int dig dst i 1 int sb src i 2 int dib dst i 2 int sa src i 3 int dia dst i 3 int dor dog dob dor sr 127 math max sr dir math min sr dir dog sg 127 math max sg dig math min sg dig dob sb 127 math max sb dib math min sb dib float a alpha sa 255f float ac 1 a dst i int a dor ac dir dst i 1 int a dog ac dig dst i 2 int a dob ac dib dst i 3 int sa alpha dia ac public symlinker toadlet high level simple client client final node node super client this node node tslconfig new sub config toadletsymlinker node config tslconfig register symlinks null 9 true false symlinker toadlet symlinks symlinker toadlet symlinks long new string arr callback override public string get return get config load string override public void set string val throws invalid config value exception if store dir equals new file val return fixme throw new invalid config value exception cannot set the plugins that s loaded override public boolean is read only return true string fns tslconfig get string arr symlinks if fns null for string fn fns string tuple fn split if tuple length 2 add link tuple 0 tuple 1 false tslconfig finished initialization add link sl search plugins plugins librarian false add link sl gallery plugins plugins test gallery false symlinkertoadlet highlevelsimpleclient subconfig symlinkertoadlet symlinkertoadlet symlinkslong stringarrcallback getconfigloadstring invalidconfigvalueexception storedir invalidconfigvalueexception isreadonly getstringarr addlink finishedinitialization addlink addlink testgallery tslconfig register symlinks null 9 true false symlinker toadlet symlinks symlinker toadlet symlinks long new string arr callback override public string get return get config load string symlinkertoadlet symlinkertoadlet symlinkslong stringarrcallback getconfigloadstring override public void set string val throws invalid config value exception if store dir equals new file val return fixme throw new invalid config value exception cannot set the plugins that s loaded invalidconfigvalueexception storedir invalidconfigvalueexception override public boolean is read only return true isreadonly public boolean add link string alias string target boolean store boolean ret synchronized link map if link map put alias target alias ret true else ret false logger normal this adding link alias target if store node client core store config return ret addlink linkmap linkmap clientcore storeconfig public boolean remove link string alias boolean store boolean ret synchronized link map object o if o link map remove alias null ret true else ret false logger normal this removing link alias o if store node client core store config return ret removelink linkmap linkmap clientcore storeconfig private string get config load string string retarr new string link map size synchronized link map int i 0 for map entry string string entry link map entry set retarr i entry get key entry get value return retarr getconfigloadstring linkmap linkmap linkmap entryset getkey getvalue override public string supported methods return get supportedmethods override public void handle get uri uri http request request toadlet context ctx throws toadlet context closed exception io exception redirect exception string path uri get path string foundkey null string foundtarget null synchronized link map for map entry string string entry link map entry set string key entry get key if path starts with key foundkey key foundtarget entry get value todo redirect to errorpage if foundtarget null foundkey null write text reply ctx 404 not found l10n get string static toadlet path not found return path foundtarget path substring foundkey length uri outuri null try outuri new uri null null path uri get query uri get fragment catch uri syntax exception e todo handle error somehow writehtml reply ctx 200 ok e get message return uri get raw query throw new redirect exception outuri handleget httprequest toadletcontext toadletcontextclosedexception ioexception redirectexception getpath linkmap linkmap entryset getkey startswith getvalue writetextreply getstring statictoadlet pathnotfound getquery getfragment urisyntaxexception writehtmlreply getmessage getrawquery redirectexception private static final long serial versionuid 1 public key encode exception string string super string serialversionuid keyencodeexception public key encode exception super keyencodeexception public key encode exception string message throwable cause super message cause keyencodeexception public key encode exception throwable cause super cause keyencodeexception transient field fld btree multi field index btreemultifieldindex btree multi field index class cls string field name boolean unique this cls cls this unique unique this field name field name this class name class descriptor get class name cls locate fields type class descriptor tp array of byte types new int field name length for int i 0 i types length i types i check type fld i get type btreemultifieldindex fieldname fieldname fieldname classname classdescriptor getclassname locatefields classdescriptor tparrayofbyte fieldname checktype gettype private final void locate fields fld new field field name length for int i 0 i field name length i fld i class descriptor locate field cls field name i if fld i null throw new storage error storage error indexed field not found class name field name i locatefields fieldname fieldname classdescriptor locatefield fieldname storageerror storageerror indexed_field_not_found classname fieldname public class get indexed class return cls getindexedclass public field get key fields return fld getkeyfields public void on load cls class descriptor load class get storage class name locate fields onload classdescriptor loadclass getstorage classname locatefields int compare byte arrays byte key byte item int offs int lengtn int o1 0 int o2 offs byte a1 key byte a2 item for int i 0 i fld length o1 key length i int diff 0 switch types i case class descriptor tp boolean case class descriptor tp byte diff a1 o1 a2 o2 break case class descriptor tp short diff bytes unpack2 a1 o1 bytes unpack2 a2 o2 o1 2 o2 2 break case class descriptor tp char diff char bytes unpack2 a1 o1 char bytes unpack2 a2 o2 o1 2 o2 2 break case class descriptor tp int case class descriptor tp object case class descriptor tp enum int i1 bytes unpack4 a1 o1 int i2 bytes unpack4 a2 o2 diff i1 i2 1 i1 i2 0 1 o1 4 o2 4 break case class descriptor tp long case class descriptor tp date long l1 bytes unpack8 a1 o1 long l2 bytes unpack8 a2 o2 diff l1 l2 1 l1 l2 0 1 o1 8 o2 8 break case class descriptor tp float float f1 float int bits to float bytes unpack4 a1 o1 float f2 float int bits to float bytes unpack4 a2 o2 diff f1 f2 1 f1 f2 0 1 o1 4 o2 4 break case class descriptor tp double double d1 double long bits to double bytes unpack8 a1 o1 double d2 double long bits to double bytes unpack8 a2 o2 diff d1 d2 1 d1 d2 0 1 o1 8 o2 8 break case class descriptor tp string int len1 bytes unpack4 a1 o1 int len2 bytes unpack4 a2 o2 o1 4 o2 4 int len len1 len2 len1 len2 while len 0 diff char bytes unpack2 a1 o1 char bytes unpack2 a2 o2 if diff 0 return diff o1 2 o2 2 diff len1 len2 break case class descriptor tp array of byte int len1 bytes unpack4 a1 o1 int len2 bytes unpack4 a2 o2 o1 4 o2 4 int len len1 len2 len1 len2 while len 0 diff a1 o1 a2 o2 if diff 0 return diff diff len1 len2 break default assert failed invalid type if diff 0 return diff return 0 comparebytearrays classdescriptor tpboolean classdescriptor tpbyte classdescriptor tpshort classdescriptor tpchar classdescriptor tpint classdescriptor tpobject classdescriptor tpenum classdescriptor tplong classdescriptor tpdate classdescriptor tpfloat intbitstofloat intbitstofloat classdescriptor tpdouble longbitstodouble longbitstodouble classdescriptor tpstring classdescriptor tparrayofbyte string convert string object s return string s convertstring object unpack byte array key page pg int pos int offs btree page first key offs btree page get key str offs pg pos byte data pg data object values new object fld length for int i 0 i fld length i object v null switch types i case class descriptor tp boolean v boolean value of data offs 0 break case class descriptor tp byte v new byte data offs break case class descriptor tp short v short value of bytes unpack2 data offs offs 2 break case class descriptor tp char v new character char bytes unpack2 data offs offs 2 break case class descriptor tp int v new integer bytes unpack4 data offs offs 4 break case class descriptor tp object int oid bytes unpack4 data offs v oid 0 null storage impl get storage lookup object oid null offs 4 break case class descriptor tp long v new long bytes unpack8 data offs offs 8 break case class descriptor tp enum v fld i get type get enum constants bytes unpack4 data offs offs 4 break case class descriptor tp date long msec bytes unpack8 data offs v msec 1 null new date msec offs 8 break case class descriptor tp float v new float float int bits to float bytes unpack4 data offs offs 4 break case class descriptor tp double v new double double long bits to double bytes unpack8 data offs offs 8 break case class descriptor tp string int len bytes unpack4 data offs offs 4 char sval new char len for int j 0 j len j sval j char bytes unpack2 data offs offs 2 v new string sval break case class descriptor tp array of byte int len bytes unpack4 data offs offs 4 byte bval new byte len system arraycopy data offs bval 0 len offs len break default assert failed invalid type values i v return values unpackbytearraykey btreepage firstkeyoffs btreepage getkeystroffs classdescriptor tpboolean valueof classdescriptor tpbyte classdescriptor tpshort valueof classdescriptor tpchar classdescriptor tpint classdescriptor tpobject storageimpl getstorage lookupobject classdescriptor tplong classdescriptor tpenum gettype getenumconstants classdescriptor tpdate classdescriptor tpfloat intbitstofloat classdescriptor tpdouble longbitstodouble classdescriptor tpstring classdescriptor tparrayofbyte private key extract key i persistent obj try byte buffer buf new byte buffer int dst 0 for int i 0 i fld length i field f field fld i switch types i case class descriptor tp boolean buf extend dst 1 buf arr dst byte f get boolean obj 1 0 break case class descriptor tp byte buf extend dst 1 buf arr dst f get byte obj break case class descriptor tp short buf extend dst 2 bytes pack2 buf arr dst f get short obj dst 2 break case class descriptor tp char buf extend dst 2 bytes pack2 buf arr dst short f get char obj dst 2 break case class descriptor tp int buf extend dst 4 bytes pack4 buf arr dst f get int obj dst 4 break case class descriptor tp object i persistent p i persistent f get obj buf extend dst 4 if p null if p is persistent get storage make persistent p bytes pack4 buf arr dst p get oid else bytes pack4 buf arr dst 0 dst 4 break case class descriptor tp long buf extend dst 8 bytes pack8 buf arr dst f get long obj dst 8 break case class descriptor tp date date d date f get obj buf extend dst 8 bytes pack8 buf arr dst d null 1 d get time dst 8 break case class descriptor tp float buf extend dst 4 bytes pack4 buf arr dst float float to int bits f get float obj dst 4 break case class descriptor tp double buf extend dst 8 bytes pack8 buf arr dst double double to long bits f get double obj dst 8 break case class descriptor tp enum buf extend dst 4 bytes pack4 buf arr dst enum f get obj ordinal dst 4 break case class descriptor tp string buf extend dst 4 string str convert string f get obj if str null int len str length bytes pack4 buf arr dst len dst 4 buf extend dst len 2 for int j 0 j len j bytes pack2 buf arr dst short str char at j dst 2 else bytes pack4 buf arr dst 0 dst 4 break case class descriptor tp array of byte buf extend dst 4 byte arr byte f get obj if arr null int len arr length bytes pack4 buf arr dst len dst 4 buf extend dst len system arraycopy arr 0 buf arr dst len dst len else bytes pack4 buf arr dst 0 dst 4 break default assert failed invalid type return new key buf to array catch exception x throw new storage error storage error access violation x extractkey ipersistent bytebuffer bytebuffer classdescriptor tpboolean getboolean classdescriptor tpbyte getbyte classdescriptor tpshort getshort classdescriptor tpchar getchar classdescriptor tpint getint classdescriptor tpobject ipersistent ipersistent ispersistent getstorage makepersistent getoid classdescriptor tplong getlong classdescriptor tpdate gettime classdescriptor tpfloat floattointbits getfloat classdescriptor tpdouble doubletolongbits getdouble classdescriptor tpenum classdescriptor tpstring convertstring charat classdescriptor tparrayofbyte toarray storageerror storageerror access_violation private key convert key key key if key null return null if key type class descriptor tp array of object throw new storage error storage error incompatible key type object values object key oval byte buffer buf new byte buffer int dst 0 for int i 0 i values length i object v values i switch types i case class descriptor tp boolean buf extend dst 1 buf arr dst byte boolean v boolean value 1 0 break case class descriptor tp byte buf extend dst 1 buf arr dst number v byte value break case class descriptor tp short buf extend dst 2 bytes pack2 buf arr dst number v short value dst 2 break case class descriptor tp char buf extend dst 2 bytes pack2 buf arr dst v instanceof number number v short value short character v char value dst 2 break case class descriptor tp int buf extend dst 4 bytes pack4 buf arr dst number v int value dst 4 break case class descriptor tp object buf extend dst 4 bytes pack4 buf arr dst v null 0 i persistent v get oid dst 4 break case class descriptor tp long buf extend dst 8 bytes pack8 buf arr dst number v long value dst 8 break case class descriptor tp date buf extend dst 8 bytes pack8 buf arr dst v null 1 date v get time dst 8 break case class descriptor tp float buf extend dst 4 bytes pack4 buf arr dst float float to int bits number v float value dst 4 break case class descriptor tp double buf extend dst 8 bytes pack8 buf arr dst double double to long bits number v double value dst 8 break case class descriptor tp enum buf extend dst 4 bytes pack4 buf arr dst enum v ordinal dst 4 break case class descriptor tp string buf extend dst 4 if v null string str convert string v int len str length bytes pack4 buf arr dst len dst 4 buf extend dst len 2 for int j 0 j len j bytes pack2 buf arr dst short str char at j dst 2 else bytes pack4 buf arr dst 0 dst 4 break case class descriptor tp array of byte buf extend dst 4 if v null byte arr byte v int len arr length bytes pack4 buf arr dst len dst 4 buf extend dst len system arraycopy arr 0 buf arr dst len dst len else bytes pack4 buf arr dst 0 dst 4 break default assert failed invalid type return new key buf to array key inclusion 0 convertkey classdescriptor tparrayofobject storageerror storageerror incompatible_key_type bytebuffer bytebuffer classdescriptor tpboolean booleanvalue classdescriptor tpbyte bytevalue classdescriptor tpshort shortvalue classdescriptor tpchar shortvalue charvalue classdescriptor tpint intvalue classdescriptor tpobject ipersistent getoid classdescriptor tplong longvalue classdescriptor tpdate gettime classdescriptor tpfloat floattointbits floatvalue classdescriptor tpdouble doubletolongbits doublevalue classdescriptor tpenum classdescriptor tpstring convertstring charat classdescriptor tparrayofbyte toarray public boolean put t obj return super put extract key obj obj extractkey public t set t obj return super set extract key obj obj extractkey public void remove t obj super remove extract key obj obj extractkey public t remove key key return super remove convert key key convertkey public boolean contains object t obj key key extract key obj if unique return super get key null else i persistent mbrs get key key for int i 0 i mbrs length i if mbrs i obj return true return false containsobject extractkey ipersistent public boolean contains t obj key key extract key obj if unique return super get key null else i persistent mbrs get key key for int i 0 i mbrs length i if mbrs i equals obj return true return false extractkey ipersistent public void append t obj throw new storage error storage error unsupported index type storageerror storageerror unsupported_index_type public t get key from key till array list list new array list if root 0 btree page find storage impl get storage root convert key from convert key till this height list return t list to array t array new instance cls list size arraylist arraylist btreepage storageimpl getstorage convertkey convertkey toarray newinstance public t get prefix string prefix throw new storage error storage error incompatible key type getprefix storageerror storageerror incompatible_key_type public t prefix search string key throw new storage error storage error incompatible key type prefixsearch storageerror storageerror incompatible_key_type public t to persistent array t arr t array new instance cls n elems if root 0 btree page traverse forward storage impl get storage root type height arr 0 return arr topersistentarray newinstance nelems btreepage traverseforward storageimpl getstorage public t get key key return super get convert key key convertkey public iterable iterator t iterator key from key till int order return super iterator convert key from convert key till order iterableiterator convertkey convertkey public iterable iterator map entry object t entry iterator key from key till int order return super entry iterator convert key from convert key till order iterableiterator entryiterator entryiterator convertkey convertkey public iterable iterator t query by example t obj key key extract key obj return iterator key key ascent order iterableiterator querybyexample extractkey ascent_order public iterable iterator t select string predicate query t query new query impl t get storage return query select cls iterator predicate iterableiterator queryimpl getstorage public boolean is case insensitive return false iscaseinsensitive class btree case insensitive multi field index t extends i persistent extends btree multi field index t btree case insensitive multi field index btreecaseinsensitivemultifieldindex ipersistent btreemultifieldindex btreecaseinsensitivemultifieldindex btree case insensitive multi field index btree case insensitive multi field index class cls string field names boolean unique super cls field names unique btreecaseinsensitivemultifieldindex btreecaseinsensitivemultifieldindex fieldnames fieldnames string convert string object s return string s to lower case convertstring tolowercase public boolean is case insensitive return true iscaseinsensitive mime type type public known unsafe content type exception mime type type this type type mimetype knownunsafecontenttypeexception mimetype override public string get explanation string builder sb new string builder sb append p b sb append type read description sb append b p n p l10n known unsafe ul if type dangerous inlines sb append li font color red b l10n dangerous inlines label b font l10n dangerous inline li if type dangerous links sb append li font color red b l10n dangerous links label b font l10n dangerous links li if type dangerous scripting sb append li font color red b l10n dangerous scripts label b font l10n dangerous scripts li if type dangerous read metadata sb append li font color red b l10n dangerous metadata label b font l10n dangerous metadata li sb append ul l10n no filter return sb to string getexplanation stringbuilder stringbuilder readdescription knownunsafe dangerousinlines dangerousinlineslabel dangerousinline dangerouslinks dangerouslinkslabel dangerouslinks dangerousscripting dangerousscriptslabel dangerousscripts dangerousreadmetadata dangerousmetadatalabel dangerousmetadata nofilter tostring override public html node gethtml explanation html node explanation new html node div explanation add child p add child b type read description explanation add child p l10n known unsafe html node list explanation add child ul html node reason list add child li reason add child span class warning l10n dangerous inlines label reason add child l10n dangerous inlines reason list add child li reason add child span class warning l10n dangerous links label reason add child l10n dangerous links reason list add child li reason add child span class warning l10n dangerous scripts label reason add child l10n dangerous scripts reason list add child li reason add child span class warning l10n dangerous metadata label reason add child l10n dangerous metadata explanation add child p l10n no filter return explanation htmlnode gethtmlexplanation htmlnode htmlnode addchild addchild readdescription addchild knownunsafe htmlnode addchild htmlnode addchild addchild dangerousinlineslabel addchild dangerousinlines addchild addchild dangerouslinkslabel addchild dangerouslinks addchild addchild dangerousscriptslabel addchild dangerousscripts addchild addchild dangerousmetadatalabel addchild dangerousmetadata addchild nofilter override public string gethtml encoded title return l10n title type html encoder encode type primary mime type gethtmlencodedtitle htmlencoder primarymimetype override public string get raw title return l10n title type type primary mime type getrawtitle primarymimetype private static string l10n string key return l10n get string known unsafe content type exception key getstring knownunsafecontenttypeexception private static string l10n string key string pattern string value return l10n get string known unsafe content type exception key pattern value getstring knownunsafecontenttypeexception private function2d y map function public map filter ymapfunction mapfilter public void setx map function function2d x map function this x map function x map function setxmapfunction xmapfunction xmapfunction xmapfunction public function2d getx map function return x map function getxmapfunction xmapfunction public void sety map function function2d y map function this y map function y map function setymapfunction ymapfunction ymapfunction ymapfunction public function2d gety map function return y map function getymapfunction ymapfunction override protected void transform inverse int x int y float out float x map y map x map x map function evaluate x y y map y map function evaluate x y out 0 x map transformed space width out 1 y map transformed space height transforminverse xmap ymap xmap xmapfunction ymap ymapfunction xmap transformedspace ymap transformedspace override public string to string return distort map coordinates tostring logger register log threshold callback new log threshold callback override public void should update logminor logger should log logger minor this logdebug logger should log logger debug this registerlogthresholdcallback logthresholdcallback shouldupdate shouldlog shouldlog private long started time public synchronized long get started time return started time startedtime getstartedtime startedtime public message core timedoutfilters new vector message filter 32 messagecore _timedoutfilters messagefilter decode a packet from data and a peer can be called by incoming packet filter s param data param offset param length param peer public message decode single message byte data int offset int length peer context peer int overhead try return message decode message from packet data offset length peer overhead catch throwable t logger error this could not decode packet t t return null incomingpacketfilter decodesinglemessage peercontext decodemessagefrompacket public void start final ticker ticker synchronized this started time system current time millis ticker queue timed job new runnable public void run try remove timed out filters catch throwable t logger error this failed to remove timed out filters t t finally ticker queue timed job this filter remove time filter remove time startedtime currenttimemillis queuetimedjob removetimedoutfilters queuetimedjob filter_remove_time filter_remove_time public void run try remove timed out filters catch throwable t logger error this failed to remove timed out filters t t finally ticker queue timed job this filter remove time removetimedoutfilters queuetimedjob filter_remove_time remove timed out filters void remove timed out filters long t start system current time millis 1 extra millisecond to give wait for a chance to remove the filter avoids exhaustive and unsuccessful search in wait for removal of a timed out filter if logminor logger minor this removing timed out filters synchronized filters for list iterator message filter i filters list iterator i has next message filter f i next if f timed out t start if logminor logger minor this removing f i remove timedoutfilters add f do not break after finding a non timed out filter because some filters may be timed out because their client callbacks say they should be also simplifies the logic significantly we ve had some major bugs here see also the end of wait for for another weird case for message filter f timedoutfilters f set message null f on timed out timedoutfilters clear long t end system current time millis if t end t start 50 if t end t start 3000 logger error this remove timed out filters took t end t start ms else if logminor logger minor this remove timed out filters took t end t start ms removetimedoutfilters tstart currenttimemillis waitfor waitfor _filters listiterator messagefilter _filters listiterator hasnext messagefilter timedout tstart _timedoutfilters waitfor messagefilter _timedoutfilters setmessage ontimedout _timedoutfilters tend currenttimemillis tend tstart tend tstart removetimedoutfilters tend tstart removetimedoutfilters tend tstart dispatch a message to a waiting filter or feed it to the dispatcher if none are found param m the message to dispatch public void check filters message m packet socket handler from long t start system current time millis if logminor logger minor this check filters m from m get source if m get source instanceof peer node peer node m get source add to local node received messages from statistic m boolean matched false if m get spec equals dmt packet transmit if logminor logger minor this system current time millis 60000 from m get source m message filter match null synchronized filters for list iterator message filter i filters list iterator i has next message filter f i next if f matched logger error this removed pre matched message filter found in filters f i remove continue if f match m matched true i remove match f if logminor logger minor this matched f break only one match permitted per message if match null match set message m match on matched feed unmatched messages to the dispatcher if matched dispatcher null try if logminor logger minor this feeding to dispatcher m matched dispatcher handle message m catch throwable t logger error this dispatcher threw t t keep the last few unclaimed messages around in case the intended receiver isn t receiving yet if matched if logminor logger minor this unclaimed m check filters and then add to unmatched is atomic it has to be atomic because otherwise we can get a race condition that results in timeouts on m fs specifically thread a receives packet thread a checks filters it doesn t match any thread a feeds to dispatcher thread b creates filter thread b checks unmatched thread b adds filter thread b sleeps thread a returns from dispatcher which didn t match thread a adds to unmatched oops the only way to fix this is to have checking the filters and unmatched be a single atomic operation another race is possible if we merely recheck the filters after we return from dispatcher for example synchronized filters if logminor logger minor this rechecking filters and adding message for list iterator message filter i filters list iterator i has next message filter f i next if f match m matched true match f i remove if logminor logger minor this matched f break only one match permitted per message if matched while unclaimed size max unmatched fifo size message removed unclaimed remove first long message life time system current time millis removed local instantiation time if removed get source instanceof peer node logger normal this dropping unclaimed from removed get source get peer lived time util format time message life time 2 true quantity removed else logger normal this dropping unclaimed lived time util format time message life time 2 true quantity removed unclaimed add last m if logminor logger minor this done if match null match set message m match on matched long t end system current time millis if t end t start 50 if t end t start 3000 logger error this check filters took t end t start ms with unclaimedfifo size of unclaimed size for matched matched else if logminor logger minor this check filters took t end t start ms with unclaimedfifo size of unclaimed size for matched matched checkfilters packetsockethandler tstart currenttimemillis checkfilters getsource getsource peernode peernode getsource addtolocalnodereceivedmessagesfromstatistic getspec packettransmit currenttimemillis getsource messagefilter _filters listiterator messagefilter _filters listiterator hasnext messagefilter _filters setmessage onmatched _dispatcher _dispatcher handlemessage _unclaimed _unmatched mfs _unmatched _unmatched _filters listiterator messagefilter _filters listiterator hasnext messagefilter _unclaimed max_unmatched_fifo_size _unclaimed removefirst messagelifetime currenttimemillis localinstantiationtime getsource peernode getsource getpeer timeutil formattime messagelifetime timeutil formattime messagelifetime _unclaimed addlast setmessage onmatched tend currenttimemillis tend tstart tend tstart checkfilters tend tstart unclaimedfifosize _unclaimed checkfilters tend tstart unclaimedfifosize _unclaimed incoming packet filter should call this when a node is disconnected public void on disconnect peer context ctx array list message filter dropped filters null rare operation we can waste objects for better locking synchronized filters list iterator message filter i filters list iterator while i has next message filter f i next if f matches dropped connection ctx if dropped filters null dropped filters new array list message filter dropped filters add f i remove if dropped filters null for message filter mf dropped filters mf on dropped connection ctx incomingpacketfilter ondisconnect peercontext arraylist messagefilter droppedfilters _filters listiterator messagefilter _filters listiterator hasnext messagefilter matchesdroppedconnection droppedfilters droppedfilters arraylist messagefilter droppedfilters droppedfilters messagefilter droppedfilters ondroppedconnection incoming packet filter should call this when a node connects with a new boot id public void on restart peer context ctx array list message filter dropped filters null rare operation we can waste objects for better locking synchronized filters list iterator message filter i filters list iterator while i has next message filter f i next if f matches restarted connection ctx if dropped filters null dropped filters new array list message filter dropped filters add f i remove if dropped filters null for message filter mf dropped filters mf on restarted connection ctx incomingpacketfilter onrestart peercontext arraylist messagefilter droppedfilters _filters listiterator messagefilter _filters listiterator hasnext messagefilter matchesrestartedconnection droppedfilters droppedfilters arraylist messagefilter droppedfilters droppedfilters messagefilter droppedfilters onrestartedconnection public void add async filter message filter filter async message filter callback callback throws disconnected exception filter set async callback callback if filter matched logger error this add async filter on a filter which is already matched filter new exception error filter clear matched filter on start waiting false if logminor logger minor this adding async filter filter for callback message ret null if filter any connections dropped throw new disconnected exception or filter on dropped connection filter dropped connection check to see whether the filter matches any of the recently unclaimed messages drop any unclaimed messages that the filter doesn t match that are also older than max unclaimed fifo item lifetime long now system current time millis long message drop time now max unclaimed fifo item lifetime long message life time 0 synchronized filters once in the list it is up to the callback system to trigger the disconnection however we may have disconnected between check above and locking so we must check again if filter any connections dropped throw new disconnected exception or filter on dropped connection filter dropped connection but we are holding the filters lock if logminor logger minor this checking unclaimed for list iterator message i unclaimed list iterator i has next message m i next if filter match m i remove ret m if logminor logger debug this matching from unclaimed break else if m local instantiation time message drop time i remove message life time now m local instantiation time if m get source instanceof peer node logger normal this dropping unclaimed from m get source get peer lived time util format time message life time 2 true age m else logger normal this dropping unclaimed lived time util format time message life time 2 true age m if ret null if logminor logger minor this not in unclaimed insert filter into filter list in order of timeout list iterator message filter i filters list iterator while true if i has next i add filter if logminor logger minor this added at end break message filter mf i next if mf get timeout filter get timeout i previous i add filter if logminor logger minor this added in middle mf timeout mf get timeout my timeout filter get timeout break if ret null filter set message ret filter on matched filter clear matched addasyncfilter messagefilter asyncmessagefiltercallback disconnectedexception setasynccallback addasyncfilter clearmatched onstartwaiting anyconnectionsdropped disconnectedexception ondroppedconnection droppedconnection _unclaimed _unclaimed max_unclaimed_fifo_item_lifetime currenttimemillis messagedroptime max_unclaimed_fifo_item_lifetime messagelifetime _filters anyconnectionsdropped disconnectedexception ondroppedconnection droppedconnection _filters _unclaimed listiterator _unclaimed listiterator hasnext _unclaimed localinstantiationtime messagedroptime messagelifetime localinstantiationtime getsource peernode getsource getpeer timeutil formattime messagelifetime timeutil formattime messagelifetime _unclaimed listiterator messagefilter _filters listiterator hasnext messagefilter gettimeout gettimeout gettimeout gettimeout setmessage onmatched clearmatched wait for a filter to trigger or timeout blocks until either the trigger is activated or it times out or the peer is disconnected param filter the filter to wait for param ctr byte counter to add bytes from the message to return either a message or null if the filter timed out throws disconnected exception if the single peer being waited for disconnects public message wait for message filter filter byte counter ctr throws disconnected exception if logdebug logger debug this waiting for filter long start time system current time millis if filter matched logger error this wait for on a filter which is already matched filter new exception error filter clear matched filter on start waiting true message ret null if filter any connections dropped filter on dropped connection filter dropped connection throw new disconnected exception check to see whether the filter matches any of the recently unclaimed messages drop any unclaimed messages that the filter doesn t match that are also older than max unclaimed fifo item lifetime long now system current time millis long message drop time now max unclaimed fifo item lifetime long message life time 0 synchronized filters if logminor logger minor this checking unclaimed for list iterator message i unclaimed list iterator i has next message m i next if filter match m i remove ret m if logminor logger minor this matching from unclaimed break else if m local instantiation time message drop time i remove message life time now m local instantiation time if m get source instanceof peer node logger normal this dropping unclaimed from m get source get peer lived time util format time message life time 2 true age m else logger normal this dropping unclaimed lived time util format time message life time 2 true age m if ret null if logminor logger minor this not in unclaimed insert filter into filter list in order of timeout list iterator message filter i filters list iterator while true if i has next i add filter if logminor logger minor this added at end break message filter mf i next if mf get timeout filter get timeout i previous i add filter if logminor logger minor this added in middle mf timeout mf get timeout my timeout filter get timeout break long t end system current time millis if t end now 50 if t end now 3000 logger error this wait for unclaimed iteration took t end now ms with unclaimedfifo size of unclaimed size for ret of ret else if logminor logger minor this wait for unclaimed iteration took t end now ms with unclaimedfifo size of unclaimed size for ret of ret unlock to wait on filter waiting on the filter won t release the outer lock so we have to release it here if ret null if logminor logger minor this waiting synchronized filter try precaution against filter getting matched between being added to filters and here bug discovered by mason check really timed out too a for paranoia b for filters with a callback we could conceivably wait for them while filter matched filter dropped connection null filter really timed out now system current time millis long wait filter get timeout now if wait 0 break filter wait wait if filter dropped connection null throw new disconnected exception catch interrupted exception e ret filter get message if logdebug logger debug this returning ret from filter if filter matched we must remove it from filters before we return or when it is re added it will be in the list twice and potentially many more times than twice synchronized filters fortunately it will be close to the beginning of the filters list having just timed out that is assuming it hasn t already been removed in that case this will be slower filters remove filter matched a packet unclaimed or after wait filter set message ret filter on matched filter clear matched probably get rid if dijjer get dijjer get dump message wait times null dijjer get dijjer get dump message wait times println filter to string t filter get initial timeout t system current time millis start time dijjer get dijjer get dump message wait times flush long end time system current time millis if logdebug logger debug this returning in end time start time ms if ctr null ret null ctr received bytes ret receivedbytecount return ret disconnectedexception waitfor messagefilter bytecounter disconnectedexception starttime currenttimemillis waitfor clearmatched onstartwaiting anyconnectionsdropped ondroppedconnection droppedconnection disconnectedexception _unclaimed _unclaimed max_unclaimed_fifo_item_lifetime currenttimemillis messagedroptime max_unclaimed_fifo_item_lifetime messagelifetime _filters _unclaimed listiterator _unclaimed listiterator hasnext _unclaimed localinstantiationtime messagedroptime messagelifetime localinstantiationtime getsource peernode getsource getpeer timeutil formattime messagelifetime timeutil formattime messagelifetime _unclaimed listiterator messagefilter _filters listiterator hasnext messagefilter gettimeout gettimeout gettimeout gettimeout tend currenttimemillis tend tend waitfor _unclaimed tend unclaimedfifosize _unclaimed waitfor _unclaimed tend unclaimedfifosize _unclaimed _filters reallytimedout waitfor droppedconnection reallytimedout currenttimemillis gettimeout droppedconnection disconnectedexception interruptedexception getmessage _filters _filters _filters setmessage onmatched clearmatched getdijjer getdumpmessagewaittimes getdijjer getdumpmessagewaittimes tostring getinitialtimeout currenttimemillis starttime getdijjer getdumpmessagewaittimes endtime currenttimemillis endtime starttime receivedbytes _receivedbytecount send a message to a peer context throws not connected exception if we are not currently connected to the node public void send peer context destination message m byte counter ctr throws not connected exception if m get spec is internal only logger error this trying to send internal only message m of spec m get spec new exception debug return destination send async m null ctr peercontext notconnectedexception peercontext bytecounter notconnectedexception getspec isinternalonly getspec sendasync public void set dispatcher dispatcher d dispatcher d setdispatcher _dispatcher return the number of received messages that are currently unclaimed public int get unclaimedfifo size synchronized filters return unclaimed size getunclaimedfifosize _filters _unclaimed public map string integer get unclaimedfifo message counts map string integer message counts new hash map string integer synchronized filters for list iterator message i unclaimed list iterator i has next message m i next string message name m get spec get name integer message count message counts get message name if message count null message counts put message name integer value of 1 else message count integer value of message count int value 1 message counts put message name message count return message counts getunclaimedfifomessagecounts messagecounts hashmap _filters listiterator _unclaimed listiterator hasnext messagename getspec getname messagecount messagecounts messagename messagecount messagecounts messagename valueof messagecount valueof messagecount intvalue messagecounts messagename messagecount messagecounts public class opennet connections toadlet extends connections toadlet implements link enabled callback protected opennet connections toadlet node n node client core core high level simple client client super n core client opennetconnectionstoadlet connectionstoadlet linkenabledcallback opennetconnectionstoadlet nodeclientcore highlevelsimpleclient override protected void draw name column html node peer row peer node status peer node status do nothing no names on opennet drawnamecolumn htmlnode peerrow peernodestatus peernodestatus override protected void draw private note column html node peer row peer node status peer node status boolean f proxy javascript enabled do nothing no private notes either no such thing as negative trust in cyberspace drawprivatenotecolumn htmlnode peerrow peernodestatus peernodestatus fproxyjavascriptenabled override protected boolean has name column return false hasnamecolumn override protected boolean has private note column return false hasprivatenotecolumn override protected simple field set get noderef return node export opennet public field set simplefieldset getnoderef exportopennetpublicfieldset override protected peer node status get peer node statuses boolean no heavy return node peers get opennet peer node statuses no heavy peernodestatus getpeernodestatuses noheavy getopennetpeernodestatuses noheavy public boolean is enabled toadlet context ctx return node is opennet enabled isenabled toadletcontext isopennetenabled override protected string get page title string title count string string my name return l10n get string opennet connections toadlet full title new string counts name new string title count string node get my name getpagetitle titlecountstring myname getstring opennetconnectionstoadlet fulltitle titlecountstring getmyname override protected boolean should draw noderef box boolean advanced mode enabled return advanced mode enabled shoulddrawnoderefbox advancedmodeenabled advancedmodeenabled override protected boolean show peer actions box no per peer actions supported on opennet there s no point they ll only reconnect possibly as a different identity and we don t want to be able to send n2ntm spam either return false showpeeractionsbox override protected void draw peer action select box html node peer form boolean advanced mode enabled do nothing see show peer actions box drawpeeractionselectbox htmlnode peerform advancedmodeenabled showpeeractionsbox override protected string get peer list title return l10n get string opennet connections toadlet peers list title getpeerlisttitle getstring opennetconnectionstoadlet peerslisttitle override protected boolean accept ref posts return true acceptrefposts override protected string default redirect location return opennet defaultredirectlocation override protected boolean is opennet return true isopennet protected class opennet comparator extends comparator by status opennet comparator string sort by boolean reversed super sort by reversed opennetcomparator comparatorbystatus opennetcomparator sortby sortby override protected int custom compare peer node status first node peer node status second node string sort by if sort by equals success time long t1 opennet peer node status first node time last success long t2 opennet peer node status second node time last success if t1 t2 return reversed 1 1 else if t2 t1 return reversed 1 1 return super custom compare first node second node sort by customcompare peernodestatus firstnode peernodestatus secondnode sortby sortby successtime opennetpeernodestatus firstnode timelastsuccess opennetpeernodestatus secondnode timelastsuccess customcompare firstnode secondnode sortby override protected comparator peer node status comparator string sort by boolean reversed return new opennet comparator sort by reversed peernodestatus sortby opennetcomparator sortby override simple column end column headers boolean advanced mode if advanced mode return null return new simple column new simple column override protected void draw column html node peer row peer node status peer node status opennet peer node status status opennet peer node status peer node status long t last success status time last success peer row add child td class peer last success t last success 0 time util format time system current time millis t last success never override public string get explanation key return opennet connections toadlet success time override public string get sort string return success time override public string get title key return opennet connections toadlet success time title simplecolumn endcolumnheaders advancedmode advancedmode simplecolumn simplecolumn drawcolumn htmlnode peerrow peernodestatus peernodestatus opennetpeernodestatus opennetpeernodestatus peernodestatus tlastsuccess timelastsuccess peerrow addchild tlastsuccess timeutil formattime currenttimemillis tlastsuccess getexplanationkey opennetconnectionstoadlet successtime getsortstring successtime gettitlekey opennetconnectionstoadlet successtimetitle override protected void draw column html node peer row peer node status peer node status opennet peer node status status opennet peer node status peer node status long t last success status time last success peer row add child td class peer last success t last success 0 time util format time system current time millis t last success never drawcolumn htmlnode peerrow peernodestatus peernodestatus opennetpeernodestatus opennetpeernodestatus peernodestatus tlastsuccess timelastsuccess peerrow addchild tlastsuccess timeutil formattime currenttimemillis tlastsuccess peer row add child td class peer last success t last success 0 time util format time system current time millis t last success never override public string get explanation key return opennet connections toadlet success time peerrow addchild tlastsuccess timeutil formattime currenttimemillis tlastsuccess getexplanationkey opennetconnectionstoadlet successtime return opennet connections toadlet success time override public string get sort string return success time opennetconnectionstoadlet successtime getsortstring successtime return success time override public string get title key return opennet connections toadlet success time title successtime gettitlekey opennetconnectionstoadlet successtimetitle creates a new web page impl it is abstract because only a subclass can run the desired make method to generate the content param my web interface a reference to the web interface which created the page used to get resources the page needs param my request the request sent by the user public web page impl web interface my web interface http request my request wot my web interface get wot uri my web interface geturi pr wot get plugin respirator this pm my web interface get page maker this page node pm get page node web of trust null this request my request this content boxes new array list html node webpageimpl mywebinterface webinterface myrequest webpageimpl webinterface mywebinterface httprequest myrequest mywebinterface getwot mywebinterface getpluginrespirator mywebinterface getpagemaker pagenode getpagenode myrequest contentboxes arraylist htmlnode generates the html code that will be sent to the browser return html code of the page public string tohtml html node content node pm get content node page node we add every content boxes iterator html node content box content boxes iterator while content box has next content node add child content box next fixme this code does seem to get executed but the test box is invisible why html node test pm get infobox infobox alert test test add child test page node add child test generate the html output return page node generate htmlnode contentnode getcontentnode pagenode contentboxes htmlnode contentbox contentboxes contentbox hasnext contentnode addchild contentbox htmlnode getinfobox addchild pagenode addchild pagenode adds an error box to the web page param title the title of the desired error box public html node add error box string title html node error box pm get infobox infobox alert title content boxes add error box return pm get content node error box errorbox webpage errorbox htmlnode adderrorbox htmlnode errorbox getinfobox contentboxes errorbox getcontentnode errorbox adds an error box to the web page param title the title of the desired error box param message the error message that will be displayed public html node add error box string title string message html node error box pm get infobox infobox alert title error box add child p message content boxes add error box return pm get content node error box errorbox webpage errorbox htmlnode adderrorbox htmlnode errorbox getinfobox errorbox addchild contentboxes errorbox getcontentnode errorbox adds a new info box to the web page param title the title of the desired info box return the content node of the newly created info box protected html node add content box string title html node box pm get infobox title content boxes add box return pm get content node box infobox webpage infobox contentnode infobox htmlnode addcontentbox htmlnode getinfobox contentboxes getcontentnode public class opennet peer node status extends peer node status opennet peer node status peer node peer node boolean no heavy super peer node no heavy time last success opennet peer node peer node time last success opennetpeernodestatus peernodestatus opennetpeernodestatus peernode peernode noheavy peernode noheavy timelastsuccess opennetpeernode peernode timelastsuccess private static final long serial versionuid 1 public duplicate trust exception string message super message serialversionuid duplicatetrustexception creates a new known identities page param my web interface a reference to the web interface which created the page used to get resources the page needs param my request the request sent by the user public known identities page web interface my web interface http request my request super my web interface my request knownidentitiespage mywebinterface webinterface myrequest knownidentitiespage webinterface mywebinterface httprequest myrequest mywebinterface myrequest public void make if request is part set add identity try wot add identity request get part as string identityuri 1024 html node success box add content box success success box add child the identity was added and is now being downloaded catch exception e add error box adding the identity failed e get message if request is part set set trust string trusterid request get part as string ownerid 128 string trusteeid request is part set trustee request get part as string trustee 128 null string value request get part as string value 4 string comment request get part as string comment 256 fixme store max length as a constant in class identity try if trusteeid null for add identity trusteeid identity getid fromuri new freeneturi request get part as string identityuri 1024 if value trim equals wot remove trust trusterid trusteeid else wot set trust trusterid trusteeid byte parse byte value comment catch exception e add error box setting trust failed e get message own identity tree owner null object container db wot getdb plugin respirator pr wot get plugin respirator int nb own identities 1 string ownerid request get part as string ownerid 128 if ownerid equals try tree owner wot get own identity byid ownerid catch exception e logger error this error while selecting the own identity e add error box error while selecting the own identity e get message else synchronized wot object set own identity all own identities wot get all own identities nb own identities all own identities size if nb own identities 1 tree owner all own identities next make add identity form pr tree owner if tree owner null try make known identities list tree owner db pr catch exception e logger error this e get message add error box error e get class e get message else if nb own identities 1 make select tree owner form db pr else make no own identity warning ispartset addidentity addidentity getpartasstring htmlnode successbox addcontentbox successbox addchild adderrorbox getmessage ispartset settrust getpartasstring ispartset getpartasstring getpartasstring getpartasstring addidentity getidfromuri getpartasstring removetrust settrust parsebyte adderrorbox getmessage ownidentity treeowner objectcontainer pluginrespirator getpluginrespirator nbownidentities getpartasstring treeowner getownidentitybyid ownidentity adderrorbox ownidentity getmessage objectset ownidentity allownidentities getallownidentities nbownidentities allownidentities nbownidentities treeowner allownidentities makeaddidentityform treeowner treeowner makeknownidentitieslist treeowner getmessage adderrorbox getclass getmessage nbownidentities makeselecttreeownerform makenoownidentitywarning makes a form where the user can enter the requesturi of an identity he knows param pr a reference to the link plugin respirator param tree owner the owner of the known identity list not used for adding the identity but for showing the known identity list properly after adding private void make add identity form plugin respirator pr own identity tree owner todo add trust value and comment fields and make them mandatory the user should only add an identity he trusts html node add box content add content box add an identity html node create form pr add form child add box content uri add identity if tree owner null create form add child input new string type name value new string hidden ownerid tree owner getid create form add child input new string type name value new string hidden page add identity create form add child span new string title style new string this must be a valid freenet uri border bottom 1px dotted cursor help identity uri create form add child input new string type name size new string text identityuri 70 create form add child br if tree owner null create form add child input new string type name value new string hidden set trust true create form add child span trust add child input new string type name size value new string text value 4 create form add child span comment add child input new string type name size value new string text comment 20 create form add child br create form add child input new string type name value new string submit add identity add pluginrespirator treeowner makeaddidentityform pluginrespirator ownidentity treeowner htmlnode addboxcontent addcontentbox htmlnode createform addformchild addboxcontent addidentity treeowner createform addchild treeowner createform addchild addidentity createform addchild createform addchild createform addchild treeowner createform addchild settrust createform addchild addchild createform addchild addchild createform addchild createform addchild addidentity private void make no own identity warning add error box no own identity found you should create an identity first makenoownidentitywarning adderrorbox private void make select tree owner form object container db plugin respirator pr html node list box content add content box select the trust tree owner html node select form pr add form child list box content uri view tree select form add child input new string type name value new string hidden page view tree html node select box select form add child select name ownerid synchronized wot for own identity own identity wot get all own identities select box add child option value own identity getid own identity get nickname select form add child input new string type name value new string submit select view this identity s web of trust makeselecttreeownerform objectcontainer pluginrespirator htmlnode listboxcontent addcontentbox htmlnode selectform addformchild listboxcontent viewtree selectform addchild viewtree htmlnode selectbox selectform addchild ownidentity ownidentity getallownidentities selectbox addchild ownidentity ownidentity getnickname selectform addchild makes the list of identities known by the tree owner param db a reference to the database param pr a reference to the link plugin respirator param tree owner owner of the trust tree we want to display private void make known identities list own identity tree owner object container db plugin respirator pr throws duplicate score exception duplicate trust exception html node list box content add content box known identities display the list of known identities html node identities table list box content add child table border 0 html node row identities table add child tr row add child th nickname row add child th fetched row add child th trustlist row add child th score rank row add child th trust comment row add child th trusters row add child th trustees synchronized wot for identity id wot get all identities if id tree owner continue row identities table add child tr nick name row add child td new string title style new string id get requesturi to string cursor help add child a href show identity id id getid id get nickname date last fetched id get last fetched date if last fetched equals new date 0 synchronized m date format m date format set time zone time zone get default simple date format format date in utc does convert to the configured time zone interesting eh row add child td m date format format last fetched else row add child td never publish trust list row add child td new string align new string center id does publish trust list yes no score try row add child td new string align new string center integer to string wot get score own identity tree owner id get score wot get score own identity tree owner id get rank catch not in trust tree exception e this only happen with identities added manually by the user todo maybe we should give the opportunity to trust it at creation time row add child td null own trust row add child get received trust form tree owner id nb trusters html node trusters cell row add child td new string align new string center trusters cell add child new html node a href uri show identity id id getid long to string wot get received trusts id size nb trustees html node trustees cell row add child td new string align new string center trustees cell add child new html node a href uri show identity id id getid long to string wot get given trusts id size pluginrespirator treeowner makeknownidentitieslist ownidentity treeowner objectcontainer pluginrespirator duplicatescoreexception duplicatetrustexception htmlnode listboxcontent addcontentbox htmlnode identitiestable listboxcontent addchild htmlnode identitiestable addchild addchild addchild addchild addchild addchild addchild addchild getallidentities treeowner identitiestable addchild nickname addchild getrequesturi tostring addchild showidentity getnickname lastfetched getlastfetcheddate lastfetched mdateformat mdateformat settimezone timezone getdefault simpledateformat timezone addchild mdateformat lastfetched addchild trustlist addchild doespublishtrustlist addchild tostring getscore ownidentity treeowner getscore getscore ownidentity treeowner getrank notintrusttreeexception addchild addchild getreceivedtrustform treeowner htmlnode trusterscell addchild trusterscell addchild htmlnode showidentity tostring getreceivedtrusts htmlnode trusteescell addchild trusteescell addchild htmlnode showidentity tostring getgiventrusts private html node get received trust form own identity truster identity trustee throws duplicate trust exception string trust value string trust comment trust trust try trust wot get trust truster trustee trust value string value of trust get value trust comment trust get comment catch not trusted exception e logger debug this truster get nickname does not trust trustee get nickname html node cell new html node td html node trust form pr add form child cell uri set trust trust form add child input new string type name value new string hidden page set trust trust form add child input new string type name value new string hidden ownerid truster getid trust form add child input new string type name value new string hidden trustee trustee getid trust form add child input new string type name size value new string text value 2 trust value trust form add child input new string type name size value new string text comment 50 trust comment trust form add child input new string type name value new string submit set trust update return cell htmlnode getreceivedtrustform ownidentity duplicatetrustexception trustvalue trustcomment gettrust trustvalue valueof getvalue trustcomment getcomment nottrustedexception getnickname getnickname htmlnode htmlnode htmlnode trustform addformchild settrust trustform addchild settrust trustform addchild trustform addchild trustform addchild trustvalue trustform addchild trustcomment trustform addchild settrust creates a new file bucket param file the file to read and write to param create file only if true create the file if it doesn t exist but if it does exist throw a file exists exception on any write operation this is safe against symlink attacks because we write to a temp file and then rename it is technically possible that the rename will clobber an existing file if there is a race condition but since it will not write over a symlink this is probably not dangerous user supplied filenames should in any case be restricted by higher levels param read only if true any attempt to write to the bucket will result in an io exception can be set later irreversible see is read only set read only param delete on finalize if true delete the file on finalization reversible param delete on exit if true delete the file on a clean exit of the jvm irreversible use with care public file bucket file file boolean read only boolean create file only boolean delete on finalize boolean delete on exit boolean delete on free super file delete on exit if file null throw new null pointer exception file orig file file file file get absolute file copy it so we can safely delete it if orig file file file new file file get path this read only read only this create file only create file only this file file this delete on finalize delete on finalize this delete on free delete on free this delete on exit delete on exit useful for finding temp file leaks system err println file bucket ctr 0 file get absolute path new exception get stack print stack trace file restart counter 0 filebucket createfileonly fileexistsexception readonly ioexception isreadonly setreadonly deleteonfinalize deleteonexit filebucket readonly createfileonly deleteonfinalize deleteonexit deleteonfree deleteonexit nullpointerexception origfile getabsolutefile origfile getpath readonly readonly createfileonly createfileonly deleteonfinalize deleteonfinalize deleteonfree deleteonfree deleteonexit deleteonexit filebucket getabsolutepath printstacktrace filerestartcounter returns the file object this buckets data is kept in override public synchronized file get file return file getfile public synchronized boolean is read only return read only isreadonly readonly public synchronized void set read only read only true setreadonly readonly turn off delete file on finalize flag note that if you have already set delete file on exit there is little that you can do to recover it delete file on finalize on the other hand is reversible public synchronized void dont delete on finalize delete on finalize false dontdeleteonfinalize deleteonfinalize override protected boolean create file only return create file only createfileonly createfileonly override protected boolean delete on exit return delete on exit deleteonexit deleteonexit override protected boolean delete on finalize return delete on finalize deleteonfinalize deleteonfinalize override protected boolean delete on free return delete on free deleteonfree deleteonfree public void store to object container container container store this storeto objectcontainer public void remove from object container container logger minor this removing this container activate file 5 container delete file container delete this removefrom objectcontainer public void object on activate object container container container activate file 5 objectonactivate objectcontainer public bucket create shadow throws io exception string fnam file get path file new file new file fnam return new file bucket new file true false false false false createshadow ioexception getpath newfile filebucket newfile public nodechk byte routing key2 byte crypto algorithm super routing key2 if routing key2 length key length throw new illegal argument exception wrong length routing key2 length should be key length this crypto algorithm crypto algorithm routingkey2 cryptoalgorithm routingkey2 routingkey2 key_length illegalargumentexception routingkey2 key_length cryptoalgorithm cryptoalgorithm private nodechk nodechk key super key this crypto algorithm key crypto algorithm cryptoalgorithm cryptoalgorithm override public key clone key return new nodechk this clonekey public static final byte base type 1 public final void write to data output stream data output stream stream throws io exception write stream base_type writetodataoutputstream dataoutputstream ioexception override public string to string return super to string base64 encode routing key integer to hex string hash tostring tostring routingkey tohexstring override public final void write data output index throws io exception index write short get type index write routing key dataoutput _index ioexception _index writeshort gettype _index routingkey public static key readchk data input raf byte algo throws io exception byte buf new byte key length raf read fully buf return new nodechk buf algo datainput ioexception key_length readfully override public boolean equals object key if key this return true if key instanceof nodechk nodechk chk nodechk key return java util arrays equals chk routing key routing key crypto algorithm chk crypto algorithm return false routingkey routingkey cryptoalgorithm cryptoalgorithm override public int hash code return super hash code hashcode hashcode override public short get type return short 0x100 crypto algorithm 0xff gettype cryptoalgorithm override public byte get routing key return routing key getroutingkey routingkey override public byte get full key byte buf new byte full key length short type get type buf 0 byte type 8 buf 1 byte type 0xff system arraycopy routing key 0 buf 2 routing key length return buf getfullkey full_key_length gettype routingkey routingkey public static byte routing key from full key byte key buf if key buf length key length return key buf if key buf length full key length logger error nodechk class routing key from full key on key buf length bytes return null if key buf 0 1 key buf 1 key algo aes pcfb 256 sha256 if key buf key buf length 1 0 key buf key buf length 2 0 we are certain it s a routing key logger minor nodechk class recovering routing key stored wrong as full key two nulls at end else it might be a routing key or it might be random data logger error nodechk class maybe recovering routing key stored wrong as full key byte out new byte key length system arraycopy key buf 0 out 0 key length return out byte out new byte key length system arraycopy key buf 2 out 0 key length return out routingkeyfromfullkey keybuf keybuf key_length keybuf keybuf full_key_length routingkeyfromfullkey keybuf keybuf keybuf algo_aes_pcfb_256_sha256 keybuf keybuf keybuf keybuf key_length keybuf key_length key_length keybuf key_length public int compare to object arg0 if arg0 instanceof nodessk return 1 nodechk key nodechk arg0 return fields compare bytes routing key key routing key compareto comparebytes routingkey routingkey override public void remove from object container container container delete this removefrom objectcontainer public class java lnf filter extends point filter public java lnf filter javalnffilter pointfilter javalnffilter override public int filterrgb int x int y int rgb if x 1 y 1 return rgb return image math mix colors 0 25f 0xff999999 rgb imagemath mixcolors override public string to string return stylize java l f stipple tostring public list peers message simple field set fs with metadata fields string to bool fs get with metadata false with volatile fields string to bool fs get with volatile false this identifier fs get identifier fs remove value identifier listpeersmessage simplefieldset withmetadata stringtobool withmetadata withvolatile stringtobool withvolatile removevalue override public simple field set get field set return new simple field set true simplefieldset getfieldset simplefieldset override public string get name return name getname override public void run fcp connection handler handler node node throws message invalid exception if handler has full access throw new message invalid exception protocol error message access denied list peers requires full access identifier false peer node nodes node get peer nodes for int i 0 i nodes length i peer node pn nodes i handler output handler queue new peer message pn with metadata with volatile identifier handler output handler queue new end list peers message identifier fcpconnectionhandler messageinvalidexception hasfullaccess messageinvalidexception protocolerrormessage access_denied listpeers peernode getpeernodes peernode outputhandler peermessage withmetadata withvolatile outputhandler endlistpeersmessage override public void remove from object container container container delete this removefrom objectcontainer public service event object source super source todo auto generated constructor stub serviceevent returns the jmdns instance which originated the event public abstract jmdns getdns public abstract jmdns getdns returns the fully qualified type of the service public abstract string get type gettype returns the instance name of the service always returns null if the event is sent to a service type listener always returns null if the event is sent to a service type listener see plugins mdns discovery javax jmdns service event get info public abstract service info get info mdnsdiscovery serviceevent getinfo serviceinfo getinfo public parser public abstract node parse input stream in stream throws parser exception inputstream instream parserexception public node parse url locationurl throws parser exception try httpurl connection url con httpurl connection locationurl open connection url con set request method get input stream url in url con get input stream node root elem parse url in url in close url con disconnect return root elem catch exception e throw new parser exception e string host locationurl get host int port locationurl get port string uri locationurl get path http request http req new http request http req set method http get http req seturi uri http response http res http req post host port if http res is successful false throw new parser exception locationurl to string string content new string http res get content string buffer input stream str buf new string buffer input stream content return parse str buf parserexception httpurlconnection urlcon httpurlconnection openconnection urlcon setrequestmethod inputstream urlin urlcon getinputstream rootelem urlin urlin urlcon rootelem parserexception gethost getport getpath httprequest httpreq httprequest httpreq setmethod httpreq httpresponse httpres httpreq httpres issuccessful parserexception tostring httpres getcontent stringbufferinputstream strbuf stringbufferinputstream strbuf public node parse file description file throws parser exception try input stream file in new file input stream description file node root parse file in file in close return root catch exception e throw new parser exception e descriptionfile parserexception inputstream filein fileinputstream descriptionfile filein filein parserexception public node parse string descr throws parser exception try string buffer input stream decr in new string buffer input stream descr node root parse decr in return root catch exception e throw new parser exception e parserexception stringbufferinputstream decrin stringbufferinputstream decrin parserexception public fft int logn prepare the weighting factors w1 new float logn w2 new float logn w3 new float logn int n 1 for int k 0 k logn k n 1 double angle 2 0 math pi n w1 k float math sin 0 5 angle w2 k 2 0f w1 k w1 k w3 k float math sin angle private void scramble int n float real float imag int j 0 for int i 0 i n i if i j float t t real j real j real i real i t t imag j imag j imag i imag i t int m n 1 while j m m 2 j m m 1 j m private void butterflies int n int logn int direction float real float imag int n 1 for int k 0 k logn k float w re w im wp re wp im temp re temp im wt int half n n n 1 wt direction w1 k wp re w2 k wp im direction w3 k w re 1 0f w im 0 0f for int offset 0 offset half n offset for int i offset i n i n int j i half n float re real j float im imag j temp re w re re w im im temp im w im re w re im real j real i temp re real i temp re imag j imag i temp im imag i temp im wt w re w re wt wp re w im wp im w re w im w im wp re wt wp im w im if direction 1 float nr 1 0f n for int i 0 i n i real i nr imag i nr w_re w_im wp_re wp_im temp_re temp_im half_n wp_re wp_im w_re w_im half_n half_n temp_re w_re w_im temp_im w_im w_re temp_re temp_re temp_im temp_im w_re w_re wp_re w_im wp_im w_re w_im w_im wp_re wp_im w_im public void transform1d float real float imag int logn int n boolean forward scramble n real imag butterflies n logn forward 1 1 real imag public void transform2d float real float imag int cols int rows boolean forward int log2cols log2 cols int log2rows log2 rows int n math max rows cols float rtemp new float n float itemp new float n fft the rows for int y 0 y rows y int offset y cols system arraycopy real offset rtemp 0 cols system arraycopy imag offset itemp 0 cols transform1d rtemp itemp log2cols cols forward system arraycopy rtemp 0 real offset cols system arraycopy itemp 0 imag offset cols fft the columns for int x 0 x cols x int index x for int y 0 y rows y rtemp y real index itemp y imag index index cols transform1d rtemp itemp log2rows rows forward index x for int y 0 y rows y real index rtemp y imag index itemp y index cols private int log2 int n int m 1 int log2n 0 while m n m 2 log2n return m n log2n 1 parse a message from a datagram packet dns incoming datagram packet packet throws io exception this packet packet inet address source packet get address this data packet get data this len packet get length this off packet get offset this questions collections empty list this answers collections empty list this received time system current time millis try id read unsigned short flags read unsigned short num questions read unsigned short num answers read unsigned short num authorities read unsigned short num additionals read unsigned short parse questions if num questions 0 questions collections synchronized list new array list num questions for int i 0 i num questions i dns question question new dns question read name read unsigned short read unsigned short questions add question parse answers int n num answers num authorities num additionals if n 0 answers collections synchronized list new array list n for int i 0 i n i string domain read name int type read unsigned short int clazz read unsigned short int ttl read int int len read unsigned short int end off len dns record rec null switch type case dns constants type a i pv4 case dns constants type aaaa i pv6 fixme pjyf oct 14 2004 this has not been tested rec new dns record address domain type clazz ttl read bytes off len break case dns constants type cname case dns constants type ptr string service try service read name catch io exception e there was a problem reading the service name e print stack trace rec new dns record pointer domain type clazz ttl service break case dns constants type txt rec new dns record text domain type clazz ttl read bytes off len break case dns constants type srv int priority read unsigned short int weight read unsigned short int port read unsigned short string target try this is a hack to handle a bug in the bonjour conformance test it is sending out target strings that don t follow the domain name format if use domain name format for srv target target read name else target read non name string catch io exception e this can happen if the type of the label cannot be handled down below the offset gets advanced to the end of the record e print stack trace rec new dns record service domain type clazz ttl priority weight port target break case dns constants type hinfo maybe we should do something with those break default logger finer dns incoming unknown type type break if rec null rec set record source source add a record if we were able to create one answers add rec else addjust the numbers for the skipped record if answers size num answers num answers else if answers size num answers num authorities num authorities else if answers size num answers num authorities num additionals num additionals off end catch io exception e logger log level warning dns incoming dump print true n exception e throw e dnsincoming datagrampacket ioexception inetaddress getaddress getdata getlength getoffset empty_list empty_list receivedtime currenttimemillis readunsignedshort readunsignedshort numquestions readunsignedshort numanswers readunsignedshort numauthorities readunsignedshort numadditionals readunsignedshort numquestions synchronizedlist arraylist numquestions numquestions dnsquestion dnsquestion readname readunsignedshort readunsignedshort numanswers numauthorities numadditionals synchronizedlist arraylist readname readunsignedshort readunsignedshort readint readunsignedshort dnsrecord dnsconstants type_a ipv4 dnsconstants type_aaaa ipv6 dnsrecord readbytes dnsconstants type_cname dnsconstants type_ptr readname ioexception printstacktrace dnsrecord dnsconstants type_txt dnsrecord readbytes dnsconstants type_srv readunsignedshort readunsignedshort readunsignedshort bonjourconformancetest use_domain_name_format_for_srv_target readname readnonnamestring ioexception printstacktrace dnsrecord dnsconstants type_hinfo dnsincoming setrecordsource numanswers numanswers numanswers numauthorities numauthorities numanswers numauthorities numadditionals numadditionals ioexception dnsincoming check if the message is a query boolean is query return flags dns constants flags qr mask dns constants flags qr query isquery dnsconstants flags_qr_mask dnsconstants flags_qr_query check if the message is truncated public boolean is truncated return flags dns constants flags tc 0 istruncated dnsconstants flags_tc check if the message is a response boolean is response return flags dns constants flags qr mask dns constants flags qr response isresponse dnsconstants flags_qr_mask dnsconstants flags_qr_response private int get int off throws io exception if off 0 off len throw new io exception parser error offset off return data off 0xff ioexception ioexception private int read unsigned short throws io exception return get off 8 get off readunsignedshort ioexception private int read int throws io exception return read unsigned short 16 read unsigned short readint ioexception readunsignedshort readunsignedshort private byte read bytes int off int len throws io exception byte bytes new byte len system arraycopy data off bytes 0 len return bytes readbytes ioexception private void readutf string buffer buf int off int len throws io exception for int end off len off end int ch get off switch ch 4 case 0 case 1 case 2 case 3 case 4 case 5 case 6 case 7 0xxxxxxx break case 12 case 13 110x xxxx 10xx xxxx ch ch 0x1f 6 get off 0x3f break case 14 1110 xxxx 10xx xxxx 10xx xxxx ch ch 0x0f 12 get off 0x3f 6 get off 0x3f break default 10xx xxxx 1111 xxxx ch ch 0x3f 4 get off 0x0f break buf append char ch stringbuffer ioexception private string read non name string throws io exception string buffer buf new string buffer int off this off int len get off readutf buf off len return buf to string readnonnamestring ioexception stringbuffer stringbuffer tostring private string read name throws io exception string buffer buf new string buffer int off this off int next 1 int first off while true int len get off if len 0 break switch len 0xc0 case 0x00 buf append off readutf buf off len off len buf append break case 0xc0 buf append off 1 if next 0 next off 1 off len 0x3f 8 get off if off first throw new io exception bad domain name possible circular name detected name start first bad offset 0x integer to hex string off first off break default throw new io exception unsupported dns label type integer to hex string len 0xc0 at off 1 this off next 0 next off return buf to string readname ioexception stringbuffer stringbuffer ioexception tohexstring ioexception tohexstring tostring debugging string print boolean dump string buffer buf new string buffer buf append to string n for iterator iterator questions iterator iterator has next buf append ques iterator next n int count 0 for iterator iterator answers iterator iterator has next count if count num answers buf append answ else if count num answers num authorities buf append auth else buf append addi buf append iterator next n if dump for int off 0 len packet get length off len off 32 int n math min 32 len off if off 10 buf append if off 100 buf append buf append off buf append for int i 0 i n i if i 8 0 buf append buf append integer to hex string data off i 0xf0 4 buf append integer to hex string data off i 0x0f 0 buf append n buf append for int i 0 i n i if i 8 0 buf append buf append int ch data off i 0xff buf append ch ch 127 char ch buf append n limit message size if off 32 256 buf append n break return buf to string stringbuffer stringbuffer tostring hasnext hasnext numanswers numanswers numauthorities getlength tohexstring tohexstring tostring public string to string string buffer buf new string buffer buf append is query dns query dns response if packet get address null buf append packet get address get host address buf append buf append packet get port buf append len buf append packet get length buf append id 0x buf append integer to hex string id if flags 0 buf append flags 0x buf append integer to hex string flags if flags dns constants flags qr response 0 buf append r if flags dns constants flags aa 0 buf append aa if flags dns constants flags tc 0 buf append tc if num questions 0 buf append questions buf append num questions if num answers 0 buf append answers buf append num answers if num authorities 0 buf append authorities buf append num authorities if num additionals 0 buf append additionals buf append num additionals buf append return buf to string tostring stringbuffer stringbuffer isquery getaddress getaddress gethostaddress getport getlength tohexstring tohexstring dnsconstants flags_qr_response dnsconstants flags_aa dnsconstants flags_tc numquestions numquestions numanswers numanswers numauthorities numauthorities numadditionals numadditionals tostring appends answers to this incoming throws illegal argument exception if not a query or if truncated void append dns incoming that if this is query this is truncated that is query if that num questions 0 if collections empty list equals this questions this questions collections synchronized list new array list that num questions this questions add all that questions this num questions that num questions if collections empty list equals answers answers collections synchronized list new array list if that num answers 0 this answers add all this num answers that answers sub list 0 that num answers this num answers that num answers if that num authorities 0 this answers add all this num answers this num authorities that answers sub list that num answers that num answers that num authorities this num authorities that num authorities if that num additionals 0 this answers add all that answers sub list that num answers that num authorities that num answers that num authorities that num additionals this num additionals that num additionals else throw new illegal argument exception illegalargumentexception dnsincoming isquery istruncated isquery numquestions empty_list synchronizedlist arraylist numquestions addall numquestions numquestions empty_list synchronizedlist arraylist numanswers addall numanswers sublist numanswers numanswers numanswers numauthorities addall numanswers numauthorities sublist numanswers numanswers numauthorities numauthorities numauthorities numadditionals addall sublist numanswers numauthorities numanswers numauthorities numadditionals numadditionals numadditionals illegalargumentexception public int elapse since arrival return int system current time millis received time elapsesincearrival currenttimemillis receivedtime public list get questions return questions getquestions public list get answers return answers getanswers creates an identity inserter param db a reference to the database param client a reference to an link high level simple client to perform inserts param tbf needed to create buckets from identities before insert public identity inserter wot my wot super my wot get plugin respirator get node my wot get plugin respirator gethl simple client wot identity inserter m wot my wot m random m wot get plugin respirator get node fast weak random start identityinserter highlevelsimpleclient identityinserter mywot mywot getpluginrespirator getnode mywot getpluginrespirator gethlsimpleclient mwot mywot mrandom mwot getpluginrespirator getnode fastweakrandom override protected collection client getter create fetch storage return null clientgetter createfetchstorage override protected collection base client putter create insert storage return new array list base client putter 10 10 identities should be much baseclientputter createinsertstorage arraylist baseclientputter override public int get priority return native thread low priority getpriority nativethread low_priority override protected long get startup delay return startup delay 2 m random next int startup delay getstartupdelay startup_delay mrandom nextint startup_delay override protected long get sleep time return thread period 2 m random next int thread period getsleeptime thread_period mrandom nextint thread_period override protected void iterate abort inserts synchronized m wot for own identity identity m wot get all own identities if identity needs insert try long min delayed insert time identity get last change date get time min delay before insert long max delayed insert time identity get last insert date get time max delay before insert if current timeutc get in millis math min min delayed insert time max delayed insert time logger debug this starting insert of identity get nickname identity get inserturi insert identity else long last change before current timeutc get in millis identity get last change date get time 60 1000 long last insert before current timeutc get in millis identity get last insert date get time 60 1000 logger debug this delaying insert of identity get nickname identity get inserturi last change last change before min ago last insert last insert before min ago catch exception e logger error this identity insert failed e get message e abortinserts mwot ownidentity mwot getallownidentities needsinsert mindelayedinserttime getlastchangedate gettime min_delay_before_insert maxdelayedinserttime getlastinsertdate gettime max_delay_before_insert currenttimeutc getinmillis mindelayedinserttime maxdelayedinserttime getnickname getinserturi lastchangebefore currenttimeutc getinmillis getlastchangedate gettime lastinsertbefore currenttimeutc getinmillis getlastinsertdate gettime getnickname getinserturi lastchangebefore lastinsertbefore getmessage inserts an own identity throws io exception private void insert own identity identity throws io exception bucket tempb mtbf make bucket 64 1024 fixme tweak output stream os null try os tempb get output stream m wot getxml transformer export own identity identity os os close os null tempb set read only long edition identity get edition if identity get last insert date after new date 0 edition fixme toad are these parameters correct insert block ib new insert block tempb null identity get inserturi set suggested edition edition insert context ictx m client get insert context true fixme are these parameters correct client putter pu m client insert ib false null false ictx this fixme set to a reasonable value before release plugin manager default is interactive priority pu set priority class request starter update priority class add insert pu tempb null logger debug this started insert of identity identity get nickname catch exception e logger error this error during insert of identity identity get nickname e finally if tempb null tempb free closer close os ownidentity ioexception ownidentity ioexception makebucket outputstream getoutputstream mwot getxmltransformer exportownidentity setreadonly getedition getlastinsertdate insertblock insertblock getinserturi setsuggestededition insertcontext mclient getinsertcontext clientputter mclient pluginmanager setpriorityclass requeststarter update_priority_class addinsert getnickname getnickname public void on success base client putter state object container container logger debug this successful insert of identity state geturi try synchronized m wot own identity identity m wot get own identity byuri state geturi identity set edition state geturi get edition identity update last insert date m wot store and commit identity catch exception e logger error this error e finally remove insert state onsuccess baseclientputter objectcontainer mwot ownidentity mwot getownidentitybyuri setedition getedition updatelastinsertdate mwot storeandcommit removeinsert public void on failure insert exception e base client putter state object container container if e get mode insert exception cancelled logger debug this insert cancelled state geturi return try logger error this error during insert of identity state geturi e we do not increase the edition of the identity if there is a collision because the fetcher will fetch the new edition and the inserter will insert it with that edition in the next run finally remove insert state onfailure insertexception baseclientputter objectcontainer getmode insertexception removeinsert not needed functions from the client callback interface public void on failure fetch exception e client getter state object container container todo auto generated method stub clientcallback onfailure fetchexception clientgetter objectcontainer public void on fetchable base client putter state object container container todo auto generated method stub onfetchable baseclientputter objectcontainer public void on generateduri freeneturi uri base client putter state object container container todo auto generated method stub ongenerateduri baseclientputter objectcontainer public void on major progress object container container todo auto generated method stub onmajorprogress objectcontainer public void on success fetch result result client getter state object container container todo auto generated method stub onsuccess fetchresult clientgetter objectcontainer final string identifier generatessk message simple field set fs identifier fs get identifier generatesskmessage simplefieldset override public simple field set get field set simple field set fs new simple field set true if identifier null fs put single identifier identifier return fs simplefieldset getfieldset simplefieldset simplefieldset putsingle override public string get name return name getname override public void run fcp connection handler handler node node throws message invalid exception insertable clientssk key insertable clientssk create random node random freeneturi inserturi key get inserturi freeneturi requesturi key geturi ssk keypair message msg new ssk keypair message inserturi requesturi identifier handler output handler queue msg fcpconnectionhandler messageinvalidexception insertableclientssk insertableclientssk createrandom getinserturi sskkeypairmessage sskkeypairmessage outputhandler override public void remove from object container container container delete this removefrom objectcontainer called upon plugin unloading we unregister advertised services public synchronized void terminate jmdns close goon false notify all notifyall public void run plugin plugin respirator pr this pr pr wait until the node is initialised while pr get node null pr get node is has started try thread sleep 1000 catch interrupted exception e node config pr get node config our advertised services new linked list our disabled services new linked list found nodes new linked list final service info fproxy info tmci info fcp info node info try create the multicast listener jmdns jmdns create final string address server pr get node get my name watch out for other nodes jmdns add service listener mdns discovery freenet service type new nodemdns listener this advertise fproxy fproxy info service info create http tcp local truncate and sanitize freenet 0 7 fproxy address node config get fproxy get int port 0 0 path if node config get fproxy get boolean enabled node config get fproxy get option bind to is default jmdns register service fproxy info our advertised services add fproxy info else our disabled services add fproxy info advertise fcp fcp info service info create fcp tcp local truncate and sanitize freenet 0 7 fcp address node config get fcp get int port 0 0 if node config get fcp get boolean enabled node config get fcp get option bind to is default jmdns register service fcp info our advertised services add fcp info else our disabled services add fcp info advertise tmci tmci info service info create telnet tcp local truncate and sanitize freenet 0 7 tmci address node config get console get int port 0 0 if node config get console get boolean enabled node config get console get option bind to is default jmdns register service tmci info our advertised services add tmci info else our disabled services add tmci info advertise the node node info service info create mdns discovery freenet service type truncate and sanitize freenet 0 7 node address node config get node get int listen port 0 0 jmdns register service node info our advertised services add node info catch io exception e e print stack trace while goon synchronized this try wait long max value catch interrupted exception e runplugin pluginrespirator getnode getnode ishasstarted interruptedexception nodeconfig getnode ouradvertisedservices linkedlist ourdisabledservices linkedlist foundnodes linkedlist serviceinfo fproxyinfo tmciinfo fcpinfo nodeinfo getnode getmyname addservicelistener mdnsdiscovery freenetservicetype nodemdnslistener fproxyinfo serviceinfo _http _tcp truncateandsanitize nodeconfig getint nodeconfig getboolean nodeconfig getoption bindto isdefault registerservice fproxyinfo ouradvertisedservices fproxyinfo ourdisabledservices fproxyinfo fcpinfo serviceinfo _fcp _tcp truncateandsanitize nodeconfig getint nodeconfig getboolean nodeconfig getoption bindto isdefault registerservice fcpinfo ouradvertisedservices fcpinfo ourdisabledservices fcpinfo tmciinfo serviceinfo _telnet _tcp truncateandsanitize nodeconfig getint nodeconfig getboolean nodeconfig getoption bindto isdefault registerservice tmciinfo ouradvertisedservices tmciinfo ourdisabledservices tmciinfo nodeinfo serviceinfo mdnsdiscovery freenetservicetype truncateandsanitize nodeconfig getint listenport registerservice nodeinfo ouradvertisedservices nodeinfo ioexception printstacktrace max_value interruptedexception final mdns discovery plugin public nodemdns listener mdns discovery plugin this plugin plugin mdnsdiscovery nodemdnslistener mdnsdiscovery public void service added service event event system out println service added event get name event get type force the gathering of informations jmdns get service info mdns discovery freenet service type event get name synchronized plugin plugin notify serviceadded serviceevent getname gettype getserviceinfo mdnsdiscovery freenetservicetype getname public void service removed service event event system out println service removed event get name event get type if mdns discovery freenet service type equals event get type synchronized found nodes iterator it found nodes iterator service info to remove event get info while it has next service info si service info it next if to remove equals si found nodes remove si synchronized plugin plugin notify serviceremoved serviceevent getname gettype mdnsdiscovery freenetservicetype gettype foundnodes foundnodes serviceinfo toremove getinfo hasnext serviceinfo serviceinfo toremove foundnodes public void service resolved service event event system out println service resolved event get info if mdns discovery freenet service type equals event get type synchronized found nodes found nodes add event get info synchronized plugin plugin notify serviceresolved serviceevent getinfo mdnsdiscovery freenetservicetype gettype foundnodes foundnodes getinfo private void print services html node content node string description service info services html node peer table infobox content node add child div class infobox infobox services length 0 normal warning html node peer table infobox header peer table infobox add child div class infobox header html node peer table infobox content peer table infobox add child div class infobox content if services null services length 0 peer table infobox header add child description html node peer table peer table infobox content add child table class darknet connections html node peer table header row peer table add child tr peer table header row add child th add child span new string title style new string the name or the service border bottom 1px dotted cursor help service name peer table header row add child th add child span new string title style new string the name of the machine hosting the service border bottom 1px dotted cursor help machine peer table header row add child th add child span new string title style new string the node s network address as ip port border bottom 1px dotted cursor help address peer table header row add child th add child span new string title style new string service parameters border bottom 1px dotted cursor help parameters html node peer row string mdns service mdns server mdns host mdns port mdns description for int i 0 i services length i peer row peer table add child tr service info info services i mdns service info get name mdns server info get server mdns host info get host address mdns port integer to string info get port mdns description info get text string peer row add child td class peer name add child mdns service null null mdns service peer row add child td class peer machine add child mdns server null null mdns server peer row add child td class peer address add child mdns host null null mdns host mdns port null null mdns port peer row add child td class peer private darknet comment note add child mdns description null mdns description else peer table infobox header add child description peer table infobox content add child no freenet resources found on the local subnet sorry printservices htmlnode contentnode serviceinfo htmlnode peertableinfobox contentnode addchild htmlnode peertableinfoboxheader peertableinfobox addchild htmlnode peertableinfoboxcontent peertableinfobox addchild peertableinfoboxheader addchild htmlnode peertable peertableinfoboxcontent addchild darknet_connections htmlnode peertableheaderrow peertable addchild peertableheaderrow addchild addchild peertableheaderrow addchild addchild peertableheaderrow addchild addchild peertableheaderrow addchild addchild htmlnode peerrow mdnsservice mdnsserver mdnshost mdnsport mdnsdescription peerrow peertable addchild serviceinfo mdnsservice getname mdnsserver getserver mdnshost gethostaddress mdnsport tostring getport mdnsdescription gettextstring peerrow addchild addchild mdnsservice mdnsservice peerrow addchild addchild mdnsserver mdnsserver peerrow addchild addchild mdnshost mdnshost mdnsport mdnsport peerrow addchild addchild mdnsdescription mdnsdescription peertableinfoboxheader addchild peertableinfoboxcontent addchild public string handlehttp get http request request throws pluginhttp exception html node page node pr get page maker get page node mdns discovery plugin configuration page false null html node content node pr get page maker get content node page node print services content node the following services are being broadcast from this node service info our advertised services to array new service info our advertised services size synchronized found nodes if found nodes size 0 print services content node the following nodes have been found on the local subnet service info found nodes to array new service info found nodes size if our advertised services size 3 html node disabled services infobox content node add child div class infobox infobox normal html node disabled services infobox header disabled services infobox add child div class infobox header html node disabled services infobox content disabled services infobox add child div class infobox content disabled services infobox header add child disabled services disabled services infobox content add child the following services won t be advertised on the local network because they are either disabled ot bound to the local interface html node disabled services list disabled services infobox content add child ul id disabled service list for int i 0 i our disabled services size i disabled services list add child li add child service info our disabled services get i get name return page node generate handlehttpget httprequest pluginhttpexception htmlnode pagenode getpagemaker getpagenode mdnsdiscovery htmlnode contentnode getpagemaker getcontentnode pagenode printservices contentnode serviceinfo ouradvertisedservices toarray serviceinfo ouradvertisedservices foundnodes foundnodes printservices contentnode serviceinfo foundnodes toarray serviceinfo foundnodes ouradvertisedservices htmlnode disabledservicesinfobox contentnode addchild htmlnode disabledservicesinfoboxheader disabledservicesinfobox addchild htmlnode disabledservicesinfoboxcontent disabledservicesinfobox addchild disabledservicesinfoboxheader addchild disabledservicesinfoboxcontent addchild htmlnode disabledserviceslist disabledservicesinfoboxcontent addchild ourdisabledservices disabledserviceslist addchild addchild serviceinfo ourdisabledservices getname pagenode public string handlehttp post http request request throws pluginhttp exception return null handlehttppost httprequest pluginhttpexception function used to sanitize a service name it ought to be less than 63 char long and shouldn t contain param the string to sanitize return a sanitized string private string truncate and sanitize string str int index of dot do index of dot str index of if index of dot 1 break str str substring 0 index of dot str substring index of dot 1 while true if str length 62 str str substring 0 62 return str truncateandsanitize indexofdot indexofdot indexof indexofdot indexofdot indexofdot public long get real version return version getrealversion public list peer notes message simple field set fs this fs fs this identifier fs get identifier fs remove value identifier listpeernotesmessage simplefieldset removevalue override public simple field set get field set return new simple field set true simplefieldset getfieldset simplefieldset override public string get name return name getname override public void run fcp connection handler handler node node throws message invalid exception if handler has full access throw new message invalid exception protocol error message access denied list peer notes requires full access identifier false string node identifier fs get node identifier if node identifier null throw new message invalid exception protocol error message missing field error node identifier field missing identifier false peer node pn node get peer node node identifier if pn null fcp message msg new unknown node identifier message node identifier identifier handler output handler queue msg return if pn instanceof darknet peer node throw new message invalid exception protocol error message darknet only modify peer only available for darknet peers identifier false darknet peer node dpn darknet peer node pn fixme this should be generalized for multiple peer notes per peer after peer node is similarly generalized string note text dpn get private darknet comment note handler output handler queue new peer note node identifier note text node peer note type private darknet comment identifier handler output handler queue new end list peer notes message node identifier identifier fcpconnectionhandler messageinvalidexception hasfullaccess messageinvalidexception protocolerrormessage access_denied listpeernotes nodeidentifier nodeidentifier nodeidentifier messageinvalidexception protocolerrormessage missing_field nodeidentifier peernode getpeernode nodeidentifier fcpmessage unknownnodeidentifiermessage nodeidentifier outputhandler darknetpeernode messageinvalidexception protocolerrormessage darknet_only modifypeer darknetpeernode darknetpeernode peernode notetext getprivatedarknetcommentnote outputhandler peernote nodeidentifier notetext peer_note_type_private_darknet_comment outputhandler endlistpeernotesmessage nodeidentifier override public void remove from object container container throw new unsupported operation exception removefrom objectcontainer unsupportedoperationexception private node service node public node get service node return service node servicenode getservicenode servicenode public service get service node service node get service node if service node null return null return new service service node getservice servicenode getservicenode servicenode servicenode public node get state variable node return state variable node getstatevariablenode statevariablenode public state variable this service node null this state variable node new node statevariable servicenode statevariablenode public state variable node service node node state var node this service node service node this state variable node state var node statevariable servicenode statevarnode servicenode servicenode statevariablenode statevarnode public static boolean is state variable node node node return state variable elem name equals node get name isstatevariablenode statevariable elem_name getname private final static string name name public void set name string value get state variable node set node name value setname getstatevariablenode setnode public string get name return get state variable node get node value name getname getstatevariablenode getnodevalue private final static string datatype data type public void set data type string value get state variable node set node datatype value datatype setdatatype getstatevariablenode setnode public string get data type return get state variable node get node value datatype getdatatype getstatevariablenode getnodevalue private final static string sendevents no no public void set send events boolean state get state variable node set attribute sendevents state true sendevents yes sendevents no sendevents_no setsendevents getstatevariablenode setattribute sendevents_yes sendevents_no public boolean is send events string state get state variable node get attribute value sendevents if state null return false if state equals ignore case sendevents yes true return true return false issendevents getstatevariablenode getattributevalue equalsignorecase sendevents_yes public void set state variable state var set name state var get name set value state var get value set data type state var get data type set send events state var is send events statevariable statevar setname statevar getname setvalue statevar getvalue setdatatype statevar getdatatype setsendevents statevar issendevents public state variable data get state variable data node node get state variable node state variable data user data state variable data node get user data if user data null user data new state variable data node set user data user data user data set node node return user data statevariabledata getstatevariabledata getstatevariablenode statevariabledata userdata statevariabledata getuserdata userdata userdata statevariabledata setuserdata userdata userdata setnode userdata public void set value string value thnaks for tho beisch 11 09 04 string curr value get state variable data get value thnaks for tho rick keiner 11 18 04 if curr value null curr value equals value true return get state variable data set value value notify event service service get service if service null return if is send events false return service notify this setvalue currvalue getstatevariabledata getvalue currvalue currvalue getstatevariabledata setvalue getservice issendevents public void set value int value set value integer to string value setvalue setvalue tostring public void set value long value set value long to string value setvalue setvalue tostring public string get value return get state variable data get value getvalue getstatevariabledata getvalue public allowed value list get allowed value list allowed value list value list new allowed value list node value list node get state variable node get node allowed value list elem name if value list node null return value list int n node value list node getn nodes for int n 0 n n node n node node value list node get node n if allowed value is allowed value node node false continue allowed value allowed val new allowed value node value list add allowed val return value list allowedvaluelist getallowedvaluelist allowedvaluelist valuelist allowedvaluelist valuelistnode getstatevariablenode getnode allowedvaluelist elem_name valuelistnode valuelist nnode valuelistnode getnnodes nnode valuelistnode getnode allowedvalue isallowedvaluenode allowedvalue allowedval allowedvalue valuelist allowedval valuelist public boolean has allowed value list allowed value list value list get allowed value list return 0 value list size true false hasallowedvaluelist allowedvaluelist valuelist getallowedvaluelist valuelist public allowed value range get allowed value range node value range node get state variable node get node allowed value range elem name if value range node null return null return new allowed value range value range node allowedvaluerange getallowedvaluerange valuerangenode getstatevariablenode getnode allowedvaluerange elem_name valuerangenode allowedvaluerange valuerangenode public boolean has allowed value range return get allowed value range null true false hasallowedvaluerange getallowedvaluerange public query listener get query listener return get state variable data get query listener querylistener getquerylistener getstatevariabledata getquerylistener public void set query listener query listener listener get state variable data set query listener listener setquerylistener querylistener getstatevariabledata setquerylistener public boolean perform query listener query request query req query listener listener get query listener if listener null return false query response query res new query response state variable ret var new state variable ret var set this ret var set value ret var set status u pnp status invalid var if listener query control received ret var true query res set response ret var else u pnp status upnp status ret var get status query res set fault response upnp status get code upnp status get description query req post query res return true performquerylistener queryrequest queryreq querylistener getquerylistener queryresponse queryres queryresponse statevariable retvar statevariable retvar retvar setvalue retvar setstatus upnpstatus invalid_var querycontrolreceived retvar queryres setresponse retvar upnpstatus upnpstatus retvar getstatus queryres setfaultresponse upnpstatus getcode upnpstatus getdescription queryreq queryres public query response get query response return get state variable data get query response queryresponse getqueryresponse getstatevariabledata getqueryresponse private void set query response query response res get state variable data set query response res setqueryresponse queryresponse getstatevariabledata setqueryresponse public u pnp status get query status return get query response getu pnp error upnpstatus getquerystatus getqueryresponse getupnperror public boolean post queryl action query request query req new query request query req set request this if debug is on true query req print query response query res query req post if debug is on true query res print set query response query res thanks for dimas cyberrate users sourceforge net and stefano lenzi kismet sl users sourceforge net 07 09 04 if query res is successful false set value query res get return value return false set value query res get return value return true postquerylaction queryrequest queryreq queryrequest queryreq setrequest ison queryreq queryresponse queryres queryreq ison queryres setqueryresponse queryres queryres issuccessful setvalue queryres getreturnvalue setvalue queryres getreturnvalue public void set status int code string descr upnp status set code code upnp status set description descr setstatus upnpstatus setcode upnpstatus setdescription public void set status int code set status code u pnp status code2 string code setstatus setstatus upnpstatus code2string public u pnp status get status return upnp status upnpstatus getstatus upnpstatus private final byte bits public bit array byte data bits data size data length 8 _bits bitarray _bits _size this constructor does not check for unacceptable sizes and should only be used on trusted data public bit array data input dis throws io exception size dis read int bits new byte size 8 size 8 0 0 1 dis read fully bits bitarray datainput ioexception _size readint _bits _size _size readfully _bits public bit array data input dis int max size throws io exception size dis read int if size 0 size max size throw new io exception unacceptable bitarray size size bits new byte size 8 size 8 0 0 1 dis read fully bits bitarray datainput maxsize ioexception _size readint _size _size maxsize ioexception _size _bits _size _size readfully _bits public bit array int size size size bits new byte size 8 size 8 0 0 1 bitarray _size _bits public bit array bit array src this size src size this bits new byte src bits length system arraycopy src bits 0 bits 0 src bits length bitarray bitarray _size _size _bits _bits _bits _bits _bits public void set bit int pos boolean f int b unsigned byte to int bits pos 8 int mask 1 pos 8 if f bits pos 8 byte b mask else bits pos 8 byte b mask setbit unsignedbytetoint _bits _bits _bits public boolean bit at int pos int b unsigned byte to int bits pos 8 int mask 1 pos 8 return b mask 0 bitat unsignedbytetoint _bits public static int unsigned byte to int byte b return b 0xff unsignedbytetoint override public string to string string builder sb new string builder this size for int x 0 x size x if bit at x sb append 1 else sb append 0 return sb to string tostring stringbuilder stringbuilder _size _size bitat tostring public void write to data output stream data output stream dos throws io exception dos write int size dos write bits writetodataoutputstream dataoutputstream ioexception writeint _size _bits public static int serialized length int size return size 8 size 8 0 0 1 4 serializedlength public int get size return size getsize _size override public boolean equals object o if o instanceof bit array return false bit array ba bit array o if ba get size get size return false for int x 0 x get size x if ba bit at x bit at x return false return true bitarray bitarray bitarray getsize getsize getsize bitat bitat override public int hash code return fields hash code bits hashcode hashcode _bits public void set all ones for int i 0 i bits length i bits i byte 0xff setallones _bits _bits public int first one for int i 0 i bits length i byte b bits i if b 0 continue for int j 0 j 8 j int mask 1 j if b mask 0 int x i 8 j if x size return 1 return x return 1 firstone _bits _bits _size public int compare to object o long po page o offs return offs po 1 offs po 0 1 compareto page data new byte page size pagesize public void run plugin plugin respirator pr2 logger error this start pr pr2 pm pr get page maker pm add navigation link fproxy back to fpoxy false null client pr gethl simple client fcp pr get node client core getfcp server runplugin pluginrespirator getpagemaker addnavigationlink gethlsimpleclient getnode clientcore getfcpserver public void terminate private html node create error box string title string errmsg html node error box pm get infobox infobox alert title error box add child errmsg return error box htmlnode createerrorbox htmlnode errorbox getinfobox errorbox addchild errorbox public string handlehttp get http request request throws pluginhttp exception string uri request get param key if uri trim length 0 return make uri page return make index page uri false handlehttpget httprequest pluginhttpexception getparam makeuripage makeindexpage public string handlehttp post http request request throws pluginhttp exception string pass request get part as string form password 32 if pass length 0 pass equals pr get node client core form password return make error page buh invalid form password string uri request get part as string key 1024 if uri trim length 0 return make uri page if request get part as string add 128 length 0 string downloadkey request get part as string uri 1024 try try add to queue new freeneturi downloadkey catch malformedurl exception e logger error this todo e todo better handling an error page return make index page uri false else return make index page uri request get part as string addall 128 length 0 handlehttppost httprequest pluginhttpexception getpartasstring formpassword getnode clientcore formpassword makeerrorpage getpartasstring makeuripage getpartasstring getpartasstring tryaddtoqueue malformedurlexception makeindexpage makeindexpage getpartasstring pages private string make uri page html node page node get page node html node content node pm get content node page node content node add child create uri box return page node generate makeuripage htmlnode pagenode getpagenode htmlnode contentnode getcontentnode pagenode contentnode addchild createuribox pagenode private string make error page string error return make error page error error makeerrorpage makeerrorpage private string make error page string title string error html node page node get page node html node content node pm get content node page node content node add child create error box title error content node add child create uri box return page node generate makeerrorpage htmlnode pagenode getpagenode htmlnode contentnode getcontentnode pagenode contentnode addchild createerrorbox contentnode addchild createuribox pagenode private string make error page string title string error string new uri html node page node get page node html node content node pm get content node page node html node error box create error box title error error box add child br error box add child new html node a href self uri key new uri new uri content node add child error box content node add child create uri box return page node generate makeerrorpage newuri htmlnode pagenode getpagenode htmlnode contentnode getcontentnode pagenode htmlnode errorbox createerrorbox errorbox addchild errorbox addchild htmlnode self_uri newuri newuri contentnode addchild errorbox contentnode addchild createuribox pagenode private html node get page node return pm get page node thaw index browser null htmlnode getpagenode getpagenode private string make index page string index boolean add try freeneturi uri new freeneturi index fetch result content client fetch uri 90000 string mime content get mime type if application x freenet index equals mime return make error page wrong mime type mime expected mime type application x freenet index but found mime data here parse xml xml element xmldoc new xml element xmldoc parse from reader new input stream reader content as bucket get input stream now print the result return print index page uri xmldoc add catch malformedurl exception e logger error this invalid uri index e return make error page invalid uri index the given freenet key is invalid catch fetch exception e logger error this fetch failed for index e switch e mode case fetch exception permanent redirect case fetch exception too many path components return make error page fetch failed for index code e mode e get localized message e newuri to string case fetch exception data not found case fetch exception route not found case fetch exception rejected overload case fetch exception all data not found return make error page fetch failed for index code e mode e get localized message index default return make error page fetch failed for index code e mode e get localized message catch io exception e logger error this io error e return make error page io error io error while processing index e get localized message catch xml parse exception e logger error this debug e return make error page parser error error while processing index e get localized message catch exception e logger error this debug e return make error page error while processing index e get localized message makeindexpage fetchresult getmimetype makeerrorpage xmlelement xmlelement parsefromreader inputstreamreader asbucket getinputstream printindexpage malformedurlexception makeerrorpage fetchexception fetchexception permanent_redirect fetchexception too_many_path_components makeerrorpage getlocalizedmessage tostring fetchexception data_not_found fetchexception route_not_found fetchexception rejected_overload fetchexception all_data_not_found makeerrorpage getlocalizedmessage makeerrorpage getlocalizedmessage ioexception ioerror makeerrorpage ioerror ioerror getlocalizedmessage xmlparseexception makeerrorpage getlocalizedmessage makeerrorpage getlocalizedmessage page utils private html node create uri box html node browse box pm get infobox open an index html node browse content pm get content node browse box browse content add child display the top level chunk as hexprint html node browse form pr add form child browse content self uri uri form browse form add child index to explore u00a0 browse form add child input new string type name size new string text key 70 browse form add child u00a0 browse form add child input new string type name value new string submit debug explore return browse box htmlnode createuribox htmlnode browsebox getinfobox htmlnode browsecontent getcontentnode browsebox browsecontent addchild htmlnode browseform addformchild browsecontent self_uri uriform browseform addchild browseform addchild browseform addchild browseform addchild browsebox private string print index page freeneturi uri xml element doc boolean add html node page node get page node html node content node pm get content node page node xml element root doc html node title box pm get infobox index uri html node index box pm get infobox links html node file box pm get infobox files html node table new html node table class requests html node header row table add child tr class table header header row add child th header row add child th key name header row add child th mimetype header row add child th size boolean hasfiles false enumeration rootchilds root enumerate children while rootchilds has more elements xml element rc xml element rootchilds next element string name rc get name if header equals name enumeration headerchilds rc enumerate children string titel null string clientname null string date null string category null while headerchilds has more elements xml element he xml element headerchilds next element string hename he get name if title equals hename titel he get content else if client equals hename clientname he get content else if date equals hename date he get content else if category equals hename category he get content else logger error this unexpected xml element hename at line rc get line nr new error debug if titel null title box add child titel u00a0 titel title box add child br if clientname null title box add child client u00a0 clientname title box add child br if date null title box add child date u00a0 date title box add child br if category null title box add child category u00a0 category title box add child br else if indexes equals name enumeration indexchilds rc enumerate children while indexchilds has more elements xml element ie xml element indexchilds next element index box add child new html node a href self uri key ie get string attribute key ie get string attribute key index box add child br else if files equals name enumeration filechilds rc enumerate children hasfiles rc count children 0 while filechilds has more elements xml element fe xml element filechilds next element html node file row table add child tr string s fe get string attribute key string s1 try freeneturi u new freeneturi s if add try add to queue u if s length 100 s1 s substring 0 12 s1 s1 s substring 85 s s1 else s1 s file row add child create add cell s uri to string file row add child create cell new html node a href key s s1 catch malformedurl exception e1 file row add child new html node td file row add child create cell new html node s file row add child create cell new html node fe get string attribute mime file row add child create cell new html node fe get string attribute size html node all row table add child tr all row add child create add all cell uri to string file box add child table else if comments equals name else logger error this unexpected xml element name at line rc get line nr new error debug content node add child title box content node add child index box if hasfiles content node add child file box content node add child create uri box return page node generate printindexpage xmlelement htmlnode pagenode getpagenode htmlnode contentnode getcontentnode pagenode xmlelement htmlnode titlebox getinfobox htmlnode indexbox getinfobox htmlnode filebox getinfobox htmlnode htmlnode htmlnode headerrow addchild headerrow addchild headerrow addchild headerrow addchild headerrow addchild enumeratechildren hasmoreelements xmlelement xmlelement nextelement getname enumeratechildren hasmoreelements xmlelement xmlelement nextelement getname getcontent getcontent getcontent getcontent getlinenr titlebox addchild titlebox addchild titlebox addchild titlebox addchild titlebox addchild titlebox addchild titlebox addchild titlebox addchild enumeratechildren hasmoreelements xmlelement xmlelement nextelement indexbox addchild htmlnode self_uri getstringattribute getstringattribute indexbox addchild enumeratechildren countchildren hasmoreelements xmlelement xmlelement nextelement htmlnode filerow addchild getstringattribute tryaddtoqueue filerow addchild createaddcell tostring filerow addchild createcell htmlnode malformedurlexception filerow addchild htmlnode filerow addchild createcell htmlnode filerow addchild createcell htmlnode getstringattribute filerow addchild createcell htmlnode getstringattribute htmlnode allrow addchild allrow addchild createaddallcell tostring filebox addchild getlinenr contentnode addchild titlebox contentnode addchild indexbox contentnode addchild filebox contentnode addchild createuribox pagenode private void try add to queue final freeneturi fetchuri pr get node client core client context job runner queue new db job public void run object container container client context context try fcp make persistent global request fetchuri null forever disk container catch not allowed exception e logger normal this failed to make persistent request e e catch io exception e logger normal this failed to make persistent request e e catch throwable t unexpected and severe might even be oom just log it logger error this failed to make persistent request t t native thread high priority false tryaddtoqueue getnode clientcore clientcontext jobrunner dbjob objectcontainer clientcontext makepersistentglobalrequest notallowedexception ioexception nativethread high_priority public void run object container container client context context try fcp make persistent global request fetchuri null forever disk container catch not allowed exception e logger normal this failed to make persistent request e e catch io exception e logger normal this failed to make persistent request e e catch throwable t unexpected and severe might even be oom just log it logger error this failed to make persistent request t t objectcontainer clientcontext makepersistentglobalrequest notallowedexception ioexception private html node create add cell string key string uri html node delete node new html node td html node delete form pr add form child delete node self uri add form key hash code delete form add child input new string type name value new string hidden uri key delete form add child input new string type name value new string hidden key uri delete form add child input new string type name value new string submit add download return delete node htmlnode createaddcell htmlnode deletenode htmlnode htmlnode deleteform addformchild deletenode self_uri addform hashcode deleteform addchild deleteform addchild deleteform addchild deletenode private html node create add all cell string uri html node delete node new html node td html node delete form pr add form child delete node self uri add form all delete form add child input new string type name value new string hidden key uri delete form add child input new string type name value new string submit addall download all return delete node htmlnode createaddallcell htmlnode deletenode htmlnode htmlnode deleteform addformchild deletenode self_uri addform deleteform addchild deleteform addchild deletenode private html node create cell html node node html node cell new html node td cell add child node return cell htmlnode createcell htmlnode htmlnode htmlnode addchild public string get version return 0 1 r version get svn revision getversion getsvnrevision public long get real version return version get version getrealversion getversion public static void main string args thaw index browser tib new thaw index browser system out println system out println tib get version system out println thawindexbrowser thawindexbrowser getversion public string get string string key todo return key getstring public void set language language new language todo setlanguage newlanguage create a buffer by reading a data input stream param dis throws io exception public short buffer data input dis throws io exception data new byte dis read short length short data length start 0 dis read fully data datainputstream ioexception shortbuffer datainput ioexception _data readshort _length _data _start readfully _data create a buffer from a byte array param data public short buffer byte data start 0 if data length short max value throw new illegal argument exception too big data length length short data length data data shortbuffer _start max_value illegalargumentexception _length _data public short buffer byte data int start int length start start data data if length short max value throw new illegal argument exception length short length shortbuffer _start _data max_value illegalargumentexception _length retrieve a byte array containing the data in this buffer may be copied so don t rely on it being the internal buffer return the byte array public byte get data if start 0 length data length return data else byte r new byte length system arraycopy data start r 0 length return r getdata _start _length _data _data _length _data _start _length copy the data to a byte array param array param position public void copy to byte array int position system arraycopy data start array position length copyto _data _start _length public byte byte at int pos if pos length throw new array index out of bounds exception return data pos start byteat _length arrayindexoutofboundsexception _data _start public void write to data output stream data output stream stream throws io exception stream write short length stream write data start length writetodataoutputstream dataoutputstream ioexception writeshort _length _data _start _length override public string to string if this length 50 return buffer this length else string builder b new string builder this length 3 b append append this length append for int x 0 x this length x b append byte at x b append return b to string tostring _length _length stringbuilder stringbuilder _length _length _length byteat tostring override public boolean equals object o if this o return true if o instanceof short buffer return false final short buffer buffer short buffer o if length buffer length return false if start buffer start return false if arrays equals data buffer data return false return true shortbuffer shortbuffer shortbuffer _length _length _start _start _data _data override public int hash code return fields hash code data start length 16 hashcode hashcode _data _start _length public int get length return length getlength _length private theme string code string name string description this code code this name name this description description public static theme theme from name string css name for theme t theme values if t code equals ignore case css name t name equals ignore case css name return t return get default themefromname cssname equalsignorecase cssname equalsignorecase cssname getdefault public static theme get default return theme clean getdefault public page maker fred pluginl10n plug theme t set theme t plugin plug plugin mode true pagemaker fredpluginl10n settheme pluginmode protected page maker theme t set theme t plugin null plugin mode false pagemaker settheme pluginmode void set override file f this override f setoverride public void set theme theme theme2 if theme2 null this theme theme get default else url themeurl get class get resource staticfiles themes theme2 code theme css if themeurl null this theme theme get default else this theme theme2 settheme getdefault getclass getresource getdefault public void add navigation link string path string name string title boolean full only link enabled callback cb if plugin mode plugin null fixme invent a check on compile time log only logger error this deprecated way to use pagemaker from plugin your plugin need to implement fred pluginl10n to do so new error fixme navigation link texts add name if full only navigation link texts non full add name navigation link titles put name title navigation links put name path if cb null navigation link callbacks put name cb addnavigationlink fullonly linkenabledcallback pluginmode fredpluginl10n navigationlinktexts fullonly navigationlinktextsnonfull navigationlinktitles navigationlinks navigationlinkcallbacks fixme implement a proper way for chosing what the menu looks like upon handlehttp get post deprecated public void remove navigation link string name navigation link texts remove name navigation link texts non full remove name navigation link titles remove name navigation links remove name handlehttpget removenavigationlink navigationlinktexts navigationlinktextsnonfull navigationlinktitles navigationlinks public html node create back link toadlet context toadlet context string name string referer toadlet context get headers get referer if referer null return new html node a new string href title new string referer name name return new html node a new string href title new string javascript back name name htmlnode createbacklink toadletcontext toadletcontext toadletcontext getheaders htmlnode htmlnode public html node get page node string title toadlet context ctx return get page node title true ctx htmlnode getpagenode toadletcontext getpagenode public html node get page node string title boolean render navigation links toadlet context ctx boolean full access ctx null false ctx is allowed full access html node page node new html node html doctype html w3c dtd xhtml 1 1 en html node html node page node add child html xml lang l10n get selected language iso code html node head node html node add child head head node add child meta new string http equiv content new string content type text html charset utf 8 head node add child title title freenet if override null head node add child link new string rel href type title new string stylesheet static themes theme code theme css text css theme code else head node add child get override content for theme t theme values string theme name t code head node add child link new string rel href type media title new string alternate stylesheet static themes theme name theme css text css screen theme name html node body node html node add child body html node page div body node add child div id page html node top bar div page div add child div id topbar top bar div add child h1 title if render navigation links html node navbar div page div add child div id navbar html node navbar ul navbar div add child ul id navlist for string navigation link full access navigation link texts navigation link texts non full link enabled callback cb navigation link callbacks get navigation link if cb null cb is enabled ctx continue string navigation title navigation link titles get navigation link string navigation path navigation links get navigation link html node list item navbar ul add child li if plugin null list item add child a new string href title new string navigation path plugin get string navigation title plugin get string navigation link else list item add child a new string href title new string navigation path l10n get string navigation title l10n get string navigation link html node content div page div add child div id content head nodes put page node head node content nodes put page node content div return page node htmlnode getpagenode rendernavigationlinks toadletcontext fullaccess isallowedfullaccess htmlnode pagenode htmlnode htmldoctype htmlnode htmlnode pagenode addchild getselectedlanguage isocode htmlnode headnode htmlnode addchild headnode addchild headnode addchild headnode addchild headnode addchild getoverridecontent themename headnode addchild themename themename htmlnode bodynode htmlnode addchild htmlnode pagediv bodynode addchild htmlnode topbardiv pagediv addchild topbardiv addchild rendernavigationlinks htmlnode navbardiv pagediv addchild htmlnode navbarul navbardiv addchild navigationlink fullaccess navigationlinktexts navigationlinktextsnonfull linkenabledcallback navigationlinkcallbacks navigationlink isenabled navigationtitle navigationlinktitles navigationlink navigationpath navigationlinks navigationlink htmlnode listitem navbarul addchild listitem addchild navigationpath getstring navigationtitle getstring navigationlink listitem addchild navigationpath getstring navigationtitle getstring navigationlink htmlnode contentdiv pagediv addchild headnodes pagenode headnode contentnodes pagenode contentdiv pagenode returns the head node belonging to the given page node this method has to be called before link get content node html node param page node the page node to retrieve the head node for return the head node or code null code if code page node code is not a valid page node or link get content node html node has already been called public html node get head node html node page node return head nodes remove page node getcontentnode htmlnode pagenode pagenode getcontentnode htmlnode htmlnode getheadnode htmlnode pagenode headnodes pagenode returns the content node that belongs to the specified node the node has to be a node that was earlier retrieved by a call to one of the link get page node string toadlet context or link get infobox string string methods p strong warning strong this method can only be called once param node the page node to get the content node for return the content node for the specified page node public html node get content node html node node head nodes remove node return content nodes remove node getpagenode toadletcontext getinfobox htmlnode getcontentnode htmlnode headnodes contentnodes public html node get infobox string header if header null throw new null pointer exception return get infobox new html node header htmlnode getinfobox nullpointerexception getinfobox htmlnode public html node get infobox html node header if header null throw new null pointer exception return get infobox null header htmlnode getinfobox htmlnode nullpointerexception getinfobox public html node get infobox string category string header if header null throw new null pointer exception return get infobox category new html node header htmlnode getinfobox nullpointerexception getinfobox htmlnode returns an infobox with the given style and header if you retrieve an infobox from this method be sure to retrieve the matching content node with link get content node html node otherwise your layout will be destroyed and you will get memory leaks param category the css styles separated by a space param header the header html node return the infobox public html node get infobox string category html node header if header null throw new null pointer exception html node infobox new html node div class infobox category null category infobox add child div class infobox header add child header content nodes put infobox infobox add child div class infobox content return infobox getcontentnode htmlnode htmlnode getinfobox htmlnode nullpointerexception htmlnode htmlnode addchild addchild contentnodes addchild private html node get override content html node result new html node style type text css try result add child file util readutf override catch io exception e logger error this got an ioe e get message e return result htmlnode getoverridecontent htmlnode htmlnode addchild fileutil ioexception getmessage protected int draw mode selection array node client core core http request req html node content node return draw mode selection array core req content node 1 null null drawmodeselectionarray nodeclientcore httprequest htmlnode contentnode drawmodeselectionarray contentnode protected int draw mode selection array node client core core http request req html node content node int alternate mode string alternate mode title key string alternate mode tooltip key mode can be changed by a link not just by the default int mode core is advanced mode enabled mode advanced mode simple if req is parameter set mode mode req get int param mode mode fixme style this properly html node table content node add child table border 1 html node row table add child tr html node cell row add child td if alternate mode 1 if mode alternate mode cell add child a new string href title new string mode alternate mode l10n get string alternate mode tooltip key l10n get string alternate mode title key else cell add child b title l10n get string alternate mode tooltip key l10n get string alternate mode title key cell row add child td if mode mode simple cell add child a new string href title new string mode 1 l10n mode simple tooltip l10n mode simple else cell add child b title l10n mode simple tooltip l10n mode simple cell row add child td if mode mode advanced cell add child a new string href title new string mode 2 l10n mode advanced tooltip l10n mode advanced else cell add child b title l10n mode advanced tooltip l10n mode advanced return mode drawmodeselectionarray nodeclientcore httprequest htmlnode contentnode alternatemode alternatemodetitlekey alternatemodetooltipkey isadvancedmodeenabled mode_advanced mode_simple isparameterset getintparam htmlnode contentnode addchild htmlnode addchild htmlnode addchild alternatemode alternatemode addchild alternatemode getstring alternatemodetooltipkey getstring alternatemodetitlekey addchild getstring alternatemodetooltipkey getstring alternatemodetitlekey addchild mode_simple addchild modesimpletooltip modesimple addchild modesimpletooltip modesimple addchild mode_advanced addchild modeadvancedtooltip modeadvanced addchild modeadvancedtooltip modeadvanced private static final string l10n string string return l10n get string page maker string getstring pagemaker create a new puzzle for curren timeutc get with an index set to a free index of the given inserter the free index shall be queried from the given introduction puzzle store store it in the puzzle store and return it param store the introduction puzzle store where the puzzle shall be stored param inserter the inserter of the puzzle return the new puzzle throws io exception currentimeutc introductionpuzzlestore introductionpuzzlestore ioexception protected boolean initialized false public transfer filter can filter index color model true transferfilter canfilterindexcolormodel override public int filterrgb int x int y int rgb int a rgb 0xff000000 int r rgb 16 0xff int g rgb 8 0xff int b rgb 0xff r r table r g g table g b b table b return a r 16 g 8 b rtable gtable btable override public buffered image filter buffered image src buffered image dst if initialized initialize return super filter src dst bufferedimage bufferedimage bufferedimage protected void initialize initialized true r table g table b table make table rtable gtable btable maketable protected int make table int table new int 256 for int i 0 i 256 i table i pixel utils clamp int 255 transfer function i 255 0f return table maketable pixelutils transferfunction protected float transfer function float v return 0 transferfunction public int getlut if initialized initialize int lut new int 256 for int i 0 i 256 i lut i filterrgb 0 0 i 24 i 16 i 8 i return lut public detectedip inet address addr short type this public address addr this nat type type this mtu 1500 inetaddress publicaddress nattype override public boolean equals object o if o instanceof detectedip return false detectedip d detectedip o return d nat type nat type d public address equals public address nattype nattype publicaddress publicaddress override public int hash code return public address hash code nat type hashcode publicaddress hashcode nattype override public string to string return public address to string nat type mtu tostring publicaddress tostring nattype public class not connected exception extends exception private static final long serial versionuid 1 public not connected exception string string super string notconnectedexception serialversionuid notconnectedexception public not connected exception super notconnectedexception public not connected exception disconnected exception e super e to string init cause e notconnectedexception disconnectedexception tostring initcause override public final synchronized throwable fill in stack trace return null fillinstacktrace public simple healing queue insert context context short prio int max running super prio new request client public boolean persistent return false public void remove from object container container throw new unsupported operation exception this ctx context this running inserters new hash map this max running max running simplehealingqueue insertcontext maxrunning requestclient removefrom objectcontainer unsupportedoperationexception runninginserters hashmap maxrunning maxrunning public simple healing queue insert context context short prio int max running super prio new request client public boolean persistent return false simplehealingqueue insertcontext maxrunning requestclient return false public void remove from object container container throw new unsupported operation exception removefrom objectcontainer unsupportedoperationexception public boolean inner queue bucket data client context context single block inserter sbi int ctr synchronized this ctr counter if running inserters size max running return false try sbi new single block inserter this data short 1 freeneturi empty chk uri ctx this false chk block data length ctr false false false data null context false true catch throwable e logger error this caught trying to insert healing block e e return false running inserters put data sbi try sbi schedule null context if logger should log logger minor this logger minor this started healing insert ctr for data return true catch throwable e logger error this caught trying to insert healing block e e return false innerqueue clientcontext singleblockinserter runninginserters maxrunning singleblockinserter empty_chk_uri chkblock data_length runninginserters shouldlog public void queue bucket data client context context if inner queue data context data free clientcontext innerqueue override public void on major progress object container container ignore onmajorprogress objectcontainer override public freeneturi geturi return freeneturi empty chk uri empty_chk_uri override public boolean is finished return false isfinished override public void notify clients object container container client context context do nothing notifyclients objectcontainer clientcontext public void on success client put state state object container container client context context single block inserter sbi single block inserter state bucket data bucket sbi get token synchronized this running inserters remove data if logger should log logger minor this logger minor this successfully inserted healing block sbi geturi no encode for data sbi token data free onsuccess clientputstate objectcontainer clientcontext singleblockinserter singleblockinserter gettoken runninginserters shouldlog geturinoencode public void on failure insert exception e client put state state object container container client context context single block inserter sbi single block inserter state bucket data bucket sbi get token synchronized this running inserters remove data if logger should log logger minor this logger minor this failed to insert healing block sbi geturi no encode e for data sbi token e data free onfailure insertexception clientputstate objectcontainer clientcontext singleblockinserter singleblockinserter gettoken runninginserters shouldlog geturinoencode public void on encode base client key usk client put state state object container container client context context ignore onencode baseclientkey clientputstate objectcontainer clientcontext public void on transition client put state old state client put state new state object container container should never happen logger error this impossible on transition on simple healing queue from old state to new state new exception debug ontransition clientputstate oldstate clientputstate newstate objectcontainer ontransition simplehealingqueue oldstate newstate public void on metadata metadata m client put state state object container container client context context should never happen logger error this got metadata on simple healing queue from state m new exception debug onmetadata clientputstate objectcontainer clientcontext simplehealingqueue public void on block set finished client put state state object container container client context context ignore onblocksetfinished clientputstate objectcontainer clientcontext public void on fetchable client put state state object container container ignore onfetchable clientputstate objectcontainer override public void on transition client get state old state client get state new state object container container ignore ontransition clientgetstate oldstate clientgetstate newstate objectcontainer override protected void inner to network object container container client context context ignore innertonetwork objectcontainer clientcontext override public void cancel object container container client context context super cancel objectcontainer clientcontext public class null string callback extends string callback override public string get return nullstringcallback stringcallback override public void set string val throws invalid config value exception ignore invalidconfigvalueexception creates a new identity fetcher param db a reference to the database param client a reference to a link high level simple client protected identity fetcher wot my wot m wot my wot client context m wot get plugin respirator get node client core client context client m wot get plugin respirator gethl simple client request client m wot get request client identityfetcher highlevelsimpleclient identityfetcher mywot mwot mywot clientcontext mwot getpluginrespirator getnode clientcore clientcontext mwot getpluginrespirator gethlsimpleclient requestclient mwot getrequestclient fetches an identity from freenet sets next edition to false by default if not specified param identity the identity to fetch public void fetch identity identity fetch identity false nextedition fetches an identity from freenet sets next edition to false by default if not specified param identity the identity to fetch param next edition whether we want to check current edition or the next one public synchronized void fetch identity identity boolean next edition todo check whether we should increase the edition in the associated client getter and restart the request or rather wait for it to finish if identities contains identity return try if next edition identity get first fetched date equals new date 0 fetch identity get requesturi set suggested edition identity get requesturi get suggested edition 1 else fetch identity get requesturi identities add identity catch fetch exception e logger error this request restart failed e e nextedition nextedition nextedition clientgetter nextedition getfirstfetcheddate getrequesturi setsuggestededition getrequesturi getsuggestededition getrequesturi fetchexception fetches a file from freenet by its uri param uri the link freeneturi we want to fetch throws fetch exception if the node encounters a problem public synchronized void fetch freeneturi uri throws fetch exception todo check whether we are downloading the uri already probably only as debug code to see if it actually happens fetch context fetch context client get fetch context fetch context max splitfile block retries 1 retry forever fetch context max non splitfile retries 1 retry forever logger debug this trying to start fetching uri uri to string client getter g client fetch uri 1 request client this fetch context fixme set to a reasonable value before release plugin manager default is interactive priority g set priority class request starter update priority class client context null requests add g fetchexception fetchexception fetchcontext fetchcontext getfetchcontext fetchcontext maxsplitfileblockretries fetchcontext maxnonsplitfileretries tostring clientgetter requestclient fetchcontext pluginmanager setpriorityclass requeststarter update_priority_class clientcontext stops all running requests protected synchronized void stop logger debug this trying to stop all requests iterator client getter i requests iterator int counter 0 while i has next i next cancel i remove counter logger debug this stopped counter current requests clientgetter hasnext private synchronized void remove request client getter g requests remove g logger debug this removed request for g geturi removerequest clientgetter private synchronized void remove identity client getter state try identities remove m wot get identity byuri state geturi catch unknown identity exception ex assert false removeidentity clientgetter mwot getidentitybyuri unknownidentityexception called when the node can t fetch a file or when there is a newer edition if this is the later we restart the request public synchronized void on failure fetch exception e client getter state object container container if e get mode fetch exception cancelled logger debug this fetch cancelled state geturi return if e mode fetch exception permanent redirect e mode fetch exception too many path components try state restart e newuri null client context catch fetch exception e1 logger error this request restart failed e1 e1 else errors we can t want deal with logger error this fetch failed for state geturi e remove request state remove identity state onfailure fetchexception clientgetter objectcontainer getmode fetchexception fetchexception permanent_redirect fetchexception too_many_path_components clientcontext fetchexception removerequest removeidentity called when a file is successfully fetched we then create an link identity parser and give it the file content public synchronized void on success fetch result result client getter state object container container logger debug this fetched identity state geturi try m wot getxml transformer import identity state geturi result as bucket get input stream catch exception e logger error this parsing failed for state geturi e try state restart state geturi set suggested edition state geturi get edition 1 null client context catch exception e logger error this error fetching next edition for state geturi identityparser onsuccess fetchresult clientgetter objectcontainer mwot getxmltransformer importidentity asbucket getinputstream setsuggestededition getedition clientcontext only called by inserts public void on success base client putter state object container container onsuccess baseclientputter objectcontainer only called by inserts public void on failure insert exception e base client putter state object container container onfailure insertexception baseclientputter objectcontainer only called by inserts public void on fetchable base client putter state object container container onfetchable baseclientputter objectcontainer only called by inserts public void on generateduri freeneturi uri base client putter state object container container ongenerateduri baseclientputter objectcontainer called when freenet async thinks that the request should be serialized to disk if it is a persistent request public void on major progress object container container onmajorprogress objectcontainer construct a lookup filter public lookup filter can filter index color model true lookupfilter lookupfilter canfilterindexcolormodel construct a lookup filter param colormap the color map public lookup filter colormap colormap can filter index color model true this colormap colormap lookupfilter lookupfilter canfilterindexcolormodel set the colormap to be used for the filter param colormap the colormap see get colormap public void set colormap colormap colormap this colormap colormap getcolormap setcolormap get the colormap to be used for the filter return the colormap see set colormap public colormap get colormap return colormap setcolormap getcolormap override public int filterrgb int x int y int rgb int a rgb 0xff000000 int r rgb 16 0xff int g rgb 8 0xff int b rgb 0xff rgb r g b 3 return colormap get color rgb 255 0f getcolor override public string to string return colors lookup tostring logger register log threshold callback new log threshold callback override public void should update logminor logger should log logger minor this logdebug logger should log logger debug this registerlogthresholdcallback logthresholdcallback shouldupdate shouldlog shouldlog final fcp connection handler handler fcp connection input handler fcp connection handler handler this handler handler fcpconnectionhandler fcpconnectioninputhandler fcpconnectionhandler void start handler server node executor execute this fcp input handler for handler sock get remote socket address getremotesocketaddress public void run freenet support logger os thread logpid this try real run catch too long exception e logger normal this caught e get message e catch io exception e if logminor logger minor this caught e e catch out of memory error e oom handler handleoom e catch throwable t logger error this caught t t t print stack trace handler close handler closed input osthread realrun toolongexception getmessage ioexception outofmemoryerror oomhandler printstacktrace closedinput public void real run throws io exception input stream is new buffered input stream handler sock get input stream 4096 line reading input stream lis new line reading input stream is boolean first message true while true simple field set fs if wrapper manager has shutdown hook been triggered fcp message msg new protocol error message protocol error message shutting down true the node is shutting down node false handler output handler queue msg closer close is return read a message string message type lis read line 128 128 true if message type null closer close is return if message type equals continue fs new simple field set lis 4096 128 true true true true check for valid endmarker if first message fs get end marker null fs get end marker starts with end data equals fs get end marker fcp message err new protocol error message protocol error message message parse error false invalid end marker fs get end marker fs get identifer fs get boolean global false handler output handler queue err continue fcp message msg try if logdebug logger debug this incoming fcp message n message type n fs to string msg fcp message create message type fs handler bf handler server core persistent temp bucket factory if msg null continue catch message invalid exception e if first message fcp message err new protocol error message protocol error message client hello must be first message true null null false handler output handler queue err handler close closer close is return else fcp message err new protocol error message e protocol code false e get message e ident e global handler output handler queue err continue if first message msg instanceof client hello message fcp message err new protocol error message protocol error message client hello must be first message true null null false handler output handler queue err handler close closer close is return if msg instanceof base data carrying message fixme tidy up coalesce with above and below try catch mie s try base data carrying message msg read from lis handler bf handler server catch message invalid exception e fcp message err new protocol error message e protocol code false e get message e ident e global handler output handler queue err continue if first message msg instanceof client hello message fcp message err new protocol error message protocol error message no late client hellos false null null false handler output handler queue err continue try if logdebug logger debug this parsed message msg for handler msg run handler handler server node catch message invalid exception e fcp message err new protocol error message e protocol code false e get message e ident e global handler output handler queue err continue first message false if handler is closed closer close is return realrun ioexception inputstream bufferedinputstream getinputstream linereadinginputstream linereadinginputstream firstmessage simplefieldset wrappermanager hasshutdownhookbeentriggered fcpmessage protocolerrormessage protocolerrormessage shutting_down outputhandler messagetype readline messagetype messagetype simplefieldset firstmessage getendmarker getendmarker startswith getendmarker fcpmessage protocolerrormessage protocolerrormessage message_parse_error getendmarker getboolean outputhandler fcpmessage messagetype tostring fcpmessage messagetype persistenttempbucketfactory messageinvalidexception firstmessage fcpmessage protocolerrormessage protocolerrormessage client_hello_must_be_first_message outputhandler fcpmessage protocolerrormessage protocolcode getmessage outputhandler firstmessage clienthellomessage fcpmessage protocolerrormessage protocolerrormessage client_hello_must_be_first_message outputhandler basedatacarryingmessage basedatacarryingmessage readfrom messageinvalidexception fcpmessage protocolerrormessage protocolcode getmessage outputhandler firstmessage clienthellomessage fcpmessage protocolerrormessage protocolerrormessage no_late_client_hellos outputhandler messageinvalidexception fcpmessage protocolerrormessage protocolcode getmessage outputhandler firstmessage isclosed public boolean object can new object container container throw new unsupported operation exception fcp connection input handler storage in database not supported objectcannew objectcontainer unsupportedoperationexception fcpconnectioninputhandler public message reference string new messageid freeneturi newuri board my board if new messageid null newuri null my board null this instanceof own message list own message reference throw new illegal argument exception todo be more verbose m messageid new messageid muri newuri m board my board messagereference newmessageid myboard newmessageid myboard ownmessagelist ownmessagereference illegalargumentexception mmessageid newmessageid mboard myboard private transient ext object container db public void initialize transient ext object container mydb db mydb extobjectcontainer initializetransient extobjectcontainer public synchronized void store synchronized db lock if db ext is stored this db ext is active this throw new runtime exception trying to store a non active message list object db store muri db store this db commit isstored isactive runtimeexception messagelist returns null implemented only in own message list own message reference public string get messageid return m messageid ownmessagelist ownmessagereference getmessageid mmessageid public freeneturi geturi return muri public board get board return m board getboard mboard public synchronized boolean was message downloaded return i was downloaded wasmessagedownloaded iwasdownloaded marks the message reference as downloaded and stores the change in the database public synchronized void set message was downloaded flag assert i was downloaded false i was downloaded true store messagereference setmessagewasdownloadedflag iwasdownloaded iwasdownloaded public message list get message list db activate this 3 return m message list messagelist getmessagelist mmessagelist called by it s parent code message list code to store the reference to it does not call store protected void set message list message list my message list m message list my message list messagelist setmessagelist messagelist mymessagelist mmessagelist mymessagelist public message list fetch failed reference message list my message list reason my reason if my message list null my reason null throw new illegal argument exception m message list my message list m reason my reason messagelistfetchfailedreference messagelist mymessagelist myreason mymessagelist myreason illegalargumentexception mmessagelist mymessagelist mreason myreason private transient ext object container db public void initialize transient ext object container mydb db mydb extobjectcontainer initializetransient extobjectcontainer not synchronized because this class only has final members public void store db store this public message list get message list return m message list messagelist getmessagelist mmessagelist public reason get reason return m reason getreason mreason public message fetch failed reference message reference my message reference reason my reason if my message reference null my reason null throw new illegal argument exception m message reference my message reference m reason my reason messagefetchfailedreference messagereference mymessagereference myreason mymessagereference myreason illegalargumentexception mmessagereference mymessagereference mreason myreason private transient ext object container db public void initialize transient ext object container mydb db mydb extobjectcontainer initializetransient extobjectcontainer not synchronized because this class only has final members public void store db store this public message reference get message reference return m message reference messagereference getmessagereference mmessagereference public reason get reason return m reason getreason mreason param identity manager param myuri param new messages a list of the messages if a message is posted to multiple boards the list should contain one code message reference code object for each board throws invalid parameter exception throws no such identity exception public message list ft identity my author freeneturi myuri list message reference new messages throws invalid parameter exception no such identity exception this my author myuri new array list message reference new messages if m messages size 1 throw new illegal argument exception trying to construct a message list with no messages hashtable string freeneturi messageur is new hashtable string freeneturi new messages size fixme 1 limit the amount of message references 2 limit the amount of boards a single message can be posted to by counting the number of occurrences of a single freeneturi in the message reference list 3 ensure that no freeneturi board pair is twice or more in the list this would be a dos attempt see also the constraints list at the top of this file note currently wot message listxml ensures 3 by using a hash set board for message reference ref m messages ref set message list this try message verifyid m author ref get messageid catch invalid parameter exception e throw new illegal argument exception trying to create a message list which contains a message with an id which does not belong to the author of the message list freeneturi previousuri messageur is put ref get messageid ref geturi if previousuri null previousuri equals ref geturi false throw new illegal argument exception trying to create a message list which maps one message id to multiple ur is identitymanager newmessages messagereference invalidparameterexception nosuchidentityexception messagelist ftidentity myauthor messagereference newmessages invalidparameterexception nosuchidentityexception myauthor arraylist messagereference newmessages mmessages illegalargumentexception messageuris newmessages messagereferences messagereference wotmessagelistxml hashset messagereference mmessages setmessagelist mauthor getmessageid invalidparameterexception illegalargumentexception messagelist messagelist messageuris getmessageid illegalargumentexception messagelist uris for constructing an empty dummy message list when the download of message list failed param my author param myuri public message list ft identity my author freeneturi myuri this my author myuri new array list message reference 0 myauthor messagelist ftidentity myauthor myauthor arraylist messagereference general constructor for being used by public constructors protected message list ft identity my author freeneturi myuri array list message reference new messages if myuri null throw new illegal argument exception trying to construct a message list with null uri m index int myuri get edition if m index 0 throw new illegal argument exception trying to construct a message list with invalid index m index if my author null arrays equals my author get requesturi get routing key myuri get routing key false throw new illegal argument exception trying to construct a message list with a wrong author my author m author my author mid calculateid m messages new messages m message count m messages size messagelist ftidentity myauthor arraylist messagereference newmessages illegalargumentexception messagelist mindex getedition mindex illegalargumentexception mindex myauthor myauthor getrequesturi getroutingkey getroutingkey illegalargumentexception myauthor mauthor myauthor mmessages newmessages mmessagecount mmessages protected message list ft own identity my author int new index if my author null throw new illegal argument exception trying to construct a message list with no author if new index 0 throw new illegal argument exception trying to construct a message list with invalid index new index m author my author m index new index mid calculateid m messages new array list message reference 16 todo find a reasonable value messagelist ftownidentity myauthor newindex myauthor illegalargumentexception messagelist newindex illegalargumentexception newindex mauthor myauthor mindex newindex mmessages arraylist messagereference protected transient message manager m message manager public void initialize transient ext object container mydb message manager my message manager db mydb m message manager my message manager messagemanager mmessagemanager initializetransient extobjectcontainer messagemanager mymessagemanager mmessagemanager mymessagemanager public synchronized void store fixme check for duplicates synchronized db lock for message reference ref m messages ref initialize transient db ref store db store this db commit messagereference mmessages initializetransient protected string calculateid return calculateid m author m index mauthor mindex public static string calculateid ft identity author int index return index base64 encode author get requesturi get routing key ftidentity getrequesturi getroutingkey public static string getid fromuri freeneturi uri return uri get edition base64 encode uri get routing key getidfromuri getedition getroutingkey public string getid return mid get the ssk uri of this message list return public freeneturi geturi return generateuri m author get requesturi m index ssk forusk mauthor getrequesturi mindex sskforusk get the usk uri of a message list with the given base uri and index param baseuri param index return protected abstract freeneturi generateuri freeneturi baseuri int index public ft identity get author return m author ftidentity getauthor mauthor public int get index return m index getindex mindex you have to synchronize on the code message list code when using this method public iterator message reference iterator return m messages iterator messagelist messagereference mmessages public synchronized message reference get reference freeneturi messageuri throws no such message exception for message reference ref this if ref geturi equals messageuri return ref throw new no such message exception messagereference getreference nosuchmessageexception messagereference nosuchmessageexception private static final long serial versionuid 1 public unknown identity exception string message super message serialversionuid unknownidentityexception private int intor intog intob public channel mix filter can filter index color model true channelmixfilter canfilterindexcolormodel public void set blue green int blue green this blue green blue green setbluegreen bluegreen bluegreen bluegreen public int get blue green return blue green getbluegreen bluegreen public void set red blue int red blue this red blue red blue setredblue redblue redblue redblue public int get red blue return red blue getredblue redblue public void set green red int green red this green red green red setgreenred greenred greenred greenred public int get green red return green red getgreenred greenred public void set intor int intor this intor intor setintor public int get intor return intor getintor public void set intog int intog this intog intog setintog public int get intog return intog getintog public void set intob int intob this intob intob setintob public int get intob return intob getintob override public int filterrgb int x int y int rgb int a rgb 0xff000000 int r rgb 16 0xff int g rgb 8 0xff int b rgb 0xff int nr pixel utils clamp intor blue green g 255 blue green b 255 255 intor r 255 int ng pixel utils clamp intog red blue b 255 red blue r 255 255 intog g 255 int nb pixel utils clamp intob green red r 255 green red g 255 255 intob b 255 return a nr 16 ng 8 nb pixelutils bluegreen bluegreen pixelutils redblue redblue pixelutils greenred greenred override public string to string return colors mix channels tostring public responder jmdns impl jmdns impl dns incoming in inet address addr int port this jmdns impl jmdns impl this in in this addr addr this port port jmdnsimpl jmdnsimpl dnsincoming inetaddress jmdnsimpl jmdnsimpl public void start according to draft cheshire dnsext multicastdns txt chapter 8 responding we respond immediately if we know for sure that we are the only one who can respond to the query in all other cases we respond within 20 120 ms according to draft cheshire dnsext multicastdns txt chapter 7 2 multi packet known answer suppression we respond after 20 120 ms if the query is truncated boolean i am the only one true for iterator i in get questions iterator i has next dns entry entry dns entry i next if entry instanceof dns question dns question q dns question entry logger finest start question q i am the only one q get type dns constants type srv q get type dns constants type txt q get type dns constants type a q get type dns constants type aaaa this jmdns impl get local host get name equals ignore case q get name this jmdns impl get services contains key q get name to lower case if i am the only one break int delay i am the only one in is truncated 0 dns constants response min wait interval jmdns impl get random next int dns constants response max wait interval dns constants response min wait interval 1 in elapse since arrival if delay 0 delay 0 logger finest start responder chosen delay delay this jmdns impl schedule this delay iamtheonlyone getquestions hasnext dnsentry dnsentry dnsquestion dnsquestion dnsquestion iamtheonlyone gettype dnsconstants type_srv gettype dnsconstants type_txt gettype dnsconstants type_a gettype dnsconstants type_aaaa jmdnsimpl getlocalhost getname equalsignorecase getname jmdnsimpl getservices containskey getname tolowercase iamtheonlyone iamtheonlyone istruncated dnsconstants response_min_wait_interval jmdnsimpl getrandom nextint dnsconstants response_max_wait_interval dnsconstants response_min_wait_interval elapsesincearrival jmdnsimpl public void run synchronized this jmdns impl get io lock if this jmdns impl get planned answer in this jmdns impl set planned answer null we use these sets to prevent duplicate records fixme this should be moved into dns outgoing hash set questions new hash set hash set answers new hash set if this jmdns impl get state dns state announced try boolean is unicast port dns constants mdns port answer questions for iterator iterator in get questions iterator iterator has next dns entry entry dns entry iterator next if entry instanceof dns question dns question q dns question entry for unicast responses the question must be included if is unicast out add question q questions add q int type q get type if type dns constants type any type dns constants type srv i ama not sure of why there is a special case here pjyf oct 15 2004 if this jmdns impl get local host get name equals ignore case q get name type dns constants type a dns record answer this jmdns impl get local host getdns4 address record if answer null answers add answer answer this jmdns impl get local host getdns6 address record if answer null answers add answer type dns constants type ignore else if this jmdns impl get service types contains key q get name to lower case type dns constants type ptr switch type case dns constants type a answer a query for a domain name out add answer in addr port out host dns record answer this jmdns impl get local host getdns4 address record if answer null answers add answer break case dns constants type aaaa answer a query for a domain name dns record answer this jmdns impl get local host getdns6 address record if answer null answers add answer break case dns constants type ptr answer a query for services of a given type find matching services for iterator service iterator this jmdns impl get services values iterator service iterator has next service info impl info service info impl service iterator next if info get state dns state announced if q get name equals ignore case info get type dns record answer this jmdns impl get local host getdns4 address record if answer null answers add answer answer this jmdns impl get local host getdns6 address record if answer null answers add answer answers add new dns record pointer info get type dns constants type ptr dns constants class in dns constants dns ttl info get qualified name answers add new dns record service info get qualified name dns constants type srv dns constants class in dns constants class unique dns constants dns ttl info get priority info get weight info get port this jmdns impl get local host get name answers add new dns record text info get qualified name dns constants type txt dns constants class in dns constants class unique dns constants dns ttl info get text if q get name equals ignore case services dns sd udp local for iterator service type iterator this jmdns impl get service types values iterator service type iterator has next answers add new dns record pointer services dns sd udp local dns constants type ptr dns constants class in dns constants dns ttl string service type iterator next break case dns constants type srv case dns constants type any case dns constants type txt service info impl info service info impl this jmdns impl get services get q get name to lower case if info null info get state dns state announced dns record answer this jmdns impl get local host getdns4 address record if answer null answers add answer answer this jmdns impl get local host getdns6 address record if answer null answers add answer answers add new dns record pointer info get type dns constants type ptr dns constants class in dns constants dns ttl info get qualified name answers add new dns record service info get qualified name dns constants type srv dns constants class in dns constants class unique dns constants dns ttl info get priority info get weight info get port this jmdns impl get local host get name answers add new dns record text info get qualified name dns constants type txt dns constants class in dns constants class unique dns constants dns ttl info get text break default system out println jmdns responder unhandled query q break remove known answers if the ttl is at least half of jmdnsimpl getiolock jmdnsimpl getplannedanswer jmdnsimpl setplannedanswer dnsoutgoing hashset hashset hashset hashset jmdnsimpl getstate dnsstate isunicast dnsconstants mdns_port getquestions hasnext dnsentry dnsentry dnsquestion dnsquestion dnsquestion isunicast addquestion gettype dnsconstants type_any dnsconstants type_srv jmdnsimpl getlocalhost getname equalsignorecase getname dnsconstants type_a dnsrecord jmdnsimpl getlocalhost getdns4addressrecord jmdnsimpl getlocalhost getdns6addressrecord dnsconstants type_ignore jmdnsimpl getservicetypes containskey getname tolowercase dnsconstants type_ptr dnsconstants type_a addanswer dnsrecord jmdnsimpl getlocalhost getdns4addressrecord dnsconstants type_aaaa dnsrecord jmdnsimpl getlocalhost getdns6addressrecord dnsconstants type_ptr serviceiterator jmdnsimpl getservices serviceiterator hasnext serviceinfoimpl serviceinfoimpl serviceiterator getstate dnsstate getname equalsignorecase gettype dnsrecord jmdnsimpl getlocalhost getdns4addressrecord jmdnsimpl getlocalhost getdns6addressrecord dnsrecord gettype dnsconstants type_ptr dnsconstants class_in dnsconstants dns_ttl getqualifiedname dnsrecord getqualifiedname dnsconstants type_srv dnsconstants class_in dnsconstants class_unique dnsconstants dns_ttl getpriority getweight getport jmdnsimpl getlocalhost getname dnsrecord getqualifiedname dnsconstants type_txt dnsconstants class_in dnsconstants class_unique dnsconstants dns_ttl gettext getname equalsignorecase _services _dns _udp servicetypeiterator jmdnsimpl getservicetypes servicetypeiterator hasnext dnsrecord _services _dns _udp dnsconstants type_ptr dnsconstants class_in dnsconstants dns_ttl servicetypeiterator dnsconstants type_srv dnsconstants type_any dnsconstants type_txt serviceinfoimpl serviceinfoimpl jmdnsimpl getservices getname tolowercase getstate dnsstate dnsrecord jmdnsimpl getlocalhost getdns4addressrecord jmdnsimpl getlocalhost getdns6addressrecord dnsrecord gettype dnsconstants type_ptr dnsconstants class_in dnsconstants dns_ttl getqualifiedname dnsrecord getqualifiedname dnsconstants type_srv dnsconstants class_in dnsconstants class_unique dnsconstants dns_ttl getpriority getweight getport jmdnsimpl getlocalhost getname dnsrecord getqualifiedname dnsconstants type_txt dnsconstants class_in dnsconstants class_unique dnsconstants dns_ttl gettext jmdnsresponder public class null bucket factory implements bucket factory public bucket make bucket long size throws io exception return new null bucket nullbucketfactory bucketfactory makebucket ioexception nullbucket public class null short callback extends short callback override public short get return 0 nullshortcallback shortcallback override public void set short val throws invalid config value exception ignore invalidconfigvalueexception private function1d f1 f2 public composite function1d function1d f1 function1d f2 this f1 f1 this f2 f2 compositefunction1d public float evaluate float v return f1 evaluate f2 evaluate v public wot message inserter node my node high level simple client my client string my name wot identity manager my identity manager wot message manager my message manager super my node my client my name my identity manager my message manager m message manager my message manager m random m node fast weak random m request client m message manager request client start wotmessageinserter mynode highlevelsimpleclient myclient myname wotidentitymanager myidentitymanager wotmessagemanager mymessagemanager mynode myclient myname myidentitymanager mymessagemanager mmessagemanager mymessagemanager mrandom mnode fastweakrandom mrequestclient mmessagemanager requestclient override protected collection client getter create fetch storage return null clientgetter createfetchstorage override protected collection base client putter create insert storage return new array list base client putter estimated parallel message insert count baseclientputter createinsertstorage arraylist baseclientputter estimated_parallel_message_insert_count override public int get priority return native thread norm priority getpriority nativethread norm_priority override protected long get startup delay return startup delay 2 m random next int startup delay getstartupdelay startup_delay mrandom nextint startup_delay override protected long get sleep time return thread period 2 m random next int thread period getsleeptime thread_period mrandom nextint thread_period override protected synchronized void iterate abort all transfers synchronized m message manager for wot own message message m message manager get not inserted own messages try fixme delay the messages and set their date to reflect the delay insert message message catch exception e logger error this insert of message failed e abortalltransfers mmessagemanager wotownmessage mmessagemanager getnotinsertedownmessages insertmessage you have to synchronize on this code wot message inserter code when using this function protected void insert message own message m throws insert exception io exception transformer exception parser configuration exception bucket tempb mtbf make bucket 2048 m get text length todo set to a reasonable value output stream os null try os tempb get output stream wot messagexml encode m os os close os null tempb set read only we do not specifiy a client meta data with mimetype because that would result in the insertion of an additional chk insert block ib new insert block tempb null m get inserturi insert context ictx m client get insert context true client putter pu m client insert ib false null false ictx this pu set priority class request starter update priority class pluginmanager defaults to interactive priority add insert pu m messagei ds put pu m getid tempb null logger debug this started insert of message from m get author get nickname finally if tempb null tempb free closer close os wotmessageinserter insertmessage ownmessage insertexception ioexception transformerexception parserconfigurationexception makebucket gettext outputstream getoutputstream wotmessagexml setreadonly clientmetadata insertblock insertblock getinserturi insertcontext mclient getinsertcontext clientputter mclient setpriorityclass requeststarter update_priority_class addinsert mmessageids getauthor getnickname override public synchronized void on success base client putter state object container container try wot own message m wot own message m message manager get own message m messagei ds get state m mark as inserted state geturi m message manager add message to message list m logger debug this successful insert of m get realuri catch exception e logger error this message insert finished but on success failed e finally remove insert state onsuccess baseclientputter objectcontainer wotownmessage wotownmessage mmessagemanager getownmessage mmessageids markasinserted mmessagemanager addmessagetomessagelist getrealuri onsuccess removeinsert override public synchronized void on failure insert exception e base client putter state object container container try logger error this message insert failed e finally remove insert state onfailure insertexception baseclientputter objectcontainer removeinsert you have to synchronize on this code wot message inserter code when using this function override protected void abort all transfers super abort all transfers m messagei ds clear wotmessageinserter abortalltransfers abortalltransfers mmessageids you have to synchronize on this code wot message inserter code when using this function override protected void remove insert base client putter p super remove insert p m messagei ds remove p wotmessageinserter removeinsert baseclientputter removeinsert mmessageids not needed functions override public void on success fetch result result client getter state object container container onsuccess fetchresult clientgetter objectcontainer public void on success fetch result result client getter state object container container override public void on failure fetch exception e client getter state object container container onsuccess fetchresult clientgetter objectcontainer onfailure fetchexception clientgetter objectcontainer public void on failure fetch exception e client getter state object container container override public void on generateduri freeneturi uri base client putter state object container container onfailure fetchexception clientgetter objectcontainer ongenerateduri baseclientputter objectcontainer public void on generateduri freeneturi uri base client putter state object container container override public void on fetchable base client putter state object container container ongenerateduri baseclientputter objectcontainer onfetchable baseclientputter objectcontainer public void on fetchable base client putter state object container container override public void on major progress object container container onfetchable baseclientputter objectcontainer onmajorprogress objectcontainer public weave filter weavefilter public void setx gap float x gap this x gap x gap setxgap xgap xgap xgap public void setx width float x width this x width x width setxwidth xwidth xwidth xwidth public float getx width return x width getxwidth xwidth public void sety width float y width this y width y width setywidth ywidth ywidth ywidth public float gety width return y width getywidth ywidth public float getx gap return x gap getxgap xgap public void sety gap float y gap this y gap y gap setygap ygap ygap ygap public float gety gap return y gap getygap ygap public void set crossings int matrix this matrix matrix setcrossings public int get crossings return matrix getcrossings public void set use image colors boolean use image colors this use image colors use image colors setuseimagecolors useimagecolors useimagecolors useimagecolors public boolean get use image colors return use image colors getuseimagecolors useimagecolors public void set round threads boolean round threads this round threads round threads setroundthreads roundthreads roundthreads roundthreads public boolean get round threads return round threads getroundthreads roundthreads public void set shade crossings boolean shade crossings this shade crossings shade crossings setshadecrossings shadecrossings shadecrossings shadecrossings public boolean get shade crossings return shade crossings getshadecrossings shadecrossings override public int filterrgb int x int y int rgb x x width x gap 2 y y width y gap 2 float nx image math mod x x width x gap float ny image math mod y y width y gap int ix int x x width x gap int iy int y y width y gap boolean inx nx x width boolean iny ny y width float dx dy float cx cy int lrgbx lrgby if round threads dx math abs x width 2 nx x width 2 dy math abs y width 2 ny y width 2 else dx dy 0 if shade crossings cx image math smooth step x width 2 x width 2 x gap math abs x width 2 nx cy image math smooth step y width 2 y width 2 y gap math abs y width 2 ny else cx cy 0 if use image colors lrgbx lrgby rgb else lrgbx rgbx lrgby rgby int v int ixc ix cols int iyr iy rows int m matrix iyr ixc if inx if iny v m 1 lrgbx lrgby v image math mix colors 2 m 1 dx dy v 0xff000000 else if shade crossings if m matrix iy 1 rows ixc if m 0 cy 1 cy cy 0 5f lrgbx image math mix colors cy lrgbx 0xff000000 else if m 0 lrgbx image math mix colors 0 5f lrgbx 0xff000000 v image math mix colors 2 dx lrgbx 0xff000000 else if iny if shade crossings if m matrix iyr ix 1 cols if m 1 cx 1 cx cx 0 5f lrgby image math mix colors cx lrgby 0xff000000 else if m 1 lrgby image math mix colors 0 5f lrgby 0xff000000 v image math mix colors 2 dy lrgby 0xff000000 else v 0x00000000 return v xwidth xgap ywidth ygap imagemath xwidth xgap imagemath ywidth ygap xwidth xgap ywidth ygap xwidth ywidth roundthreads xwidth xwidth ywidth ywidth shadecrossings imagemath smoothstep xwidth xwidth xgap xwidth imagemath smoothstep ywidth ywidth ygap ywidth useimagecolors imagemath mixcolors shadecrossings imagemath mixcolors imagemath mixcolors imagemath mixcolors shadecrossings imagemath mixcolors imagemath mixcolors imagemath mixcolors override public string to string return texture weave tostring private final node update manager updater public updated version available user alert node update manager updater super false null null null null short 0 false l10n get string user alert hide false null this updater updater nodeupdatemanager updatedversionavailableuseralert nodeupdatemanager getstring useralert override public string get title return l10n title gettitle private string l10n string key return l10n get string updated version available user alert key getstring updatedversionavailableuseralert private string l10n string key string pattern string value return l10n get string updated version available user alert key pattern value getstring updatedversionavailableuseralert private string l10n string key string patterns string values return l10n get string updated version available user alert key patterns values getstring updatedversionavailableuseralert override public string get text update thingy ut create update thingy string builder sb new string builder sb append ut first bit if ut form text null sb append form action method post input type submit name update value sb append ut form text sb append form return sb to string gettext updatethingy createupdatethingy stringbuilder stringbuilder firstbit formtext formtext tostring override public string get short text if updater is armed if updater can update now return l10n short ready not armed else return l10n short not ready not armed else return l10n short armed getshorttext isarmed canupdatenow shortreadynotarmed shortnotreadynotarmed shortarmed private static class update thingy public update thingy string first string form this first bit first this form text form updatethingy updatethingy firstbit formtext override public html node gethtml text update thingy ut create update thingy html node alert node new html node div alert node add child ut first bit if ut form text null alert node add child form new string action method new string post add child input new string type name value new string submit update ut form text return alert node htmlnode gethtmltext updatethingy createupdatethingy htmlnode alertnode htmlnode alertnode addchild firstbit formtext alertnode addchild addchild formtext alertnode private update thingy create update thingy string builder sb new string builder sb append l10n not latest sb append if updater is armed updater in final check sb append l10n final check new string count max time new string integer to string updater get revocationdnf counter integer to string revocation checker revocation dnf min time util format time updater time remaining on check sb append else if updater is armed sb append l10n armed else string form text if updater can update now boolean b false if updater has new main jar sb append l10n downloaded new jar version integer to string updater new main jar version sb append b true if updater has new ext jar sb append l10n b also downloaded new ext jar downloaded new ext jar version integer to string updater new ext jar version sb append if updater can update immediately sb append l10n click to update now form text l10n update now button else sb append l10n click to updateasap form text l10n updateasap button else boolean fetching new updater fetching new main jar boolean fetching new ext updater fetching new ext jar if fetching new if fetching new ext sb append l10n fetching new both new string node version ext version new string integer to string updater fetching new main jar version integer to string updater fetching new ext jar version else sb append l10n fetching new node node version integer to string updater fetching new main jar version else if fetching new ext sb append l10n fetching new ext ext version integer to string updater fetching new ext jar version sb append l10n updateasap question form text l10n updateasap button return new update thingy sb to string form text return new update thingy sb to string null updatethingy createupdatethingy stringbuilder stringbuilder notlatest isarmed infinalcheck finalcheck tostring getrevocationdnfcounter tostring revocationchecker revocation_dnf_min timeutil formattime timeremainingoncheck isarmed formtext canupdatenow hasnewmainjar downloadednewjar tostring newmainjarversion hasnewextjar alsodownloadednewextjar downloadednewextjar tostring newextjarversion canupdateimmediately clicktoupdatenow formtext updatenowbutton clicktoupdateasap formtext updateasapbutton fetchingnew fetchingnewmainjar fetchingnewext fetchingnewextjar fetchingnew fetchingnewext fetchingnewboth nodeversion extversion tostring fetchingnewmainjarversion tostring fetchingnewextjarversion fetchingnewnode nodeversion tostring fetchingnewmainjarversion fetchingnewext fetchingnewext extversion tostring fetchingnewextjarversion updateasapquestion formtext updateasapbutton updatethingy tostring formtext updatethingy tostring override public short get priority class if updater in final check return user alert warning else return user alert minor getpriorityclass infinalcheck useralert useralert override public boolean is valid return updater is enabled updater is blown updater fetching new ext jar updater fetching new main jar updater has new ext jar updater has new main jar isvalid isenabled isblown fetchingnewextjar fetchingnewmainjar hasnewextjar hasnewmainjar override public void is valid boolean b ignore isvalid create a logger threshhold set to normal public logger hook chain this normal loggerhookchain create a logger param threshold suppress all log calls with lower priority then this public logger hook chain int threshold super threshold hooks new logger hook 0 loggerhookchain loggerhook hooks new logger hook 0 public logger hook chain string threshold throws invalid threshold exception super threshold hooks new logger hook 0 loggerhook loggerhookchain invalidthresholdexception loggerhook this is the implementation of logger hook method which allows one logger receive events from another implements logger hook log override public synchronized void log object o class c string msg throwable e int priority logger hook my hooks hooks for int i 0 i my hooks length i my hooks i log o c msg e priority loggerhook loggerhook loggerhook myhooks myhooks myhooks add a hook which will be called every time a message is logged public synchronized void add hook logger hook lh logger hook new hooks new logger hook hooks length 1 system arraycopy new hooks 0 hooks 0 hooks length new hooks hooks length lh hooks new hooks addhook loggerhook loggerhook newhooks loggerhook newhooks newhooks newhooks remove a hook from the logger public synchronized void remove hook logger hook lh final int hooks length hooks length logger hook new hooks new logger hook hooks length 1 hooks length 1 0 int x 0 boolean removed false for int i 0 i hooks length i if hooks i lh removed true else new hooks x hooks i if removed return if x new hooks length hooks new hooks else logger hook final hooks new logger hook x system arraycopy new hooks 0 final hooks 0 x hooks final hooks removehook loggerhook hookslength loggerhook newhooks loggerhook hookslength hookslength hookslength newhooks newhooks newhooks loggerhook finalhooks loggerhook newhooks finalhooks finalhooks returns all the current hooks public synchronized logger hook get hooks return hooks loggerhook gethooks override public long min flags return 0 minflags override public long not flags return 0 notflags override public long any flags return 2 error 1 threshold 1 anyflags override public void set detailed thresholds string details throws invalid threshold exception super set detailed thresholds details no need to tell subordinates we will do the filtering logger hook h get hooks for int i 0 i h length i h i set detailed thresholds details setdetailedthresholds invalidthresholdexception setdetailedthresholds loggerhook gethooks setdetailedthresholds override public void set threshold int thresh super set threshold thresh logger hook h get hooks for int i 0 i h length i h i set threshold thresh setthreshold setthreshold loggerhook gethooks setthreshold public class reduce noise filter extends whole image filter public reduce noise filter reducenoisefilter wholeimagefilter reducenoisefilter private int smooth int v int minindex 0 maxindex 0 min integer max value max integer min value for int i 0 i 9 i if i 4 if v i min min v i minindex i if v i max max v i maxindex i if v 4 min return v minindex if v 4 max return v maxindex return v 4 max_value min_value override protected int filter pixels int width int height int in pixels rectangle transformed space int index 0 int r new int 9 int g new int 9 int b new int 9 int out pixels new int width height for int y 0 y height y for int x 0 x width x int k 0 int irgb in pixels index int ir irgb 16 0xff int ig irgb 8 0xff int ib irgb 0xff for int dy 1 dy 1 dy int iy y dy if 0 iy iy height int ioffset iy width for int dx 1 dx 1 dx int ix x dx if 0 ix ix width int rgb in pixels ioffset ix r k rgb 16 0xff g k rgb 8 0xff b k rgb 0xff else r k ir g k ig b k ib k else for int dx 1 dx 1 dx r k ir g k ig b k ib k out pixels index in pixels index 0xff000000 smooth r 16 smooth g 8 smooth b index return out pixels filterpixels inpixels transformedspace outpixels inpixels inpixels outpixels inpixels outpixels override public string to string return blur smooth tostring public class minimum filter extends whole image filter public minimum filter minimumfilter wholeimagefilter minimumfilter override protected int filter pixels int width int height int in pixels rectangle transformed space int index 0 int out pixels new int width height for int y 0 y height y for int x 0 x width x int pixel 0xffffffff for int dy 1 dy 1 dy int iy y dy int ioffset if 0 iy iy height ioffset iy width for int dx 1 dx 1 dx int ix x dx if 0 ix ix width pixel pixel utils combine pixels pixel in pixels ioffset ix pixel utils min out pixels index pixel return out pixels filterpixels inpixels transformedspace outpixels pixelutils combinepixels inpixels pixelutils outpixels outpixels override public string to string return blur minimum tostring private final hash map key key block blocks by key new hash map key key block public synchronized void add key block block blocks by key put block get key block hashmap keyblock blocksbykey hashmap keyblock keyblock blocksbykey getkey public synchronized key block get key key return blocks by key get key keyblock blocksbykey public synchronized set keys return blocks by key key set blocksbykey keyset public client key block get client key key key block block get key get node key if block null return null try return key create key block key block catch key verify exception e logger error this caught decoding block with key e e return null clientkeyblock clientkey keyblock getnodekey createkeyblock keyverifyexception public boolean object can new object container container storing a block set is not supported there are some complications so lets not implement this until fcp supports it currently we can t do fetch from blob we can only do fetch to blob and insert blob the major problems are in both chk block and ssk block who is responsible for deleting the node keys we have to have them in the objects in ssk block who is responsible for deleting the dsa public key and the dsa group a group might be unique or might be shared between very many ss ks especially in the second case we don t want to just copy every time even for transient uses the best solution may be to copy in object can new but even then callers to the relevant getter methods may be a worry throw new unsupported operation exception block set storage in database not supported objectcannew objectcontainer blockset chkblock sskblock sskblock dsapublickey dsagroup ssks objectcannew unsupportedoperationexception string cause public retrieval exception int reason reason reason cause get err string reason _cause retrievalexception _reason _cause geterrstring public retrieval exception int reason string cause reason reason cause cause if cause null cause length 0 cause equals null cause get err string reason retrievalexception _reason _cause _cause geterrstring public int get reason return reason getreason _reason override public string to string return get err string reason cause tostring geterrstring _reason _cause guaranteed not to have any spaces in it public string get err string return get err string reason geterrstring geterrstring _reason public static string get err string int reason switch reason case premature eof return premature eof case io error return io error case sender died return sender died case timed out return timed out case already cached return already cached case sender disconnected return sender disconnected case no datainsert return no datainsert case cancelled by receiver return cancelled by receiver case unknown return unknown case unable to send block within timeout return unable to send block within timeout case gone to turtle mode return gone to turtle mode case turtle killed return turtle killed default return unknown reason geterrstring premature_eof premature_eof io_error io_error sender_died sender_died timed_out timed_out already_cached already_cached sender_disconnected sender_disconnected no_datainsert no_datainsert cancelled_by_receiver cancelled_by_receiver unable_to_send_block_within_timeout unable_to_send_block_within_timeout gone_to_turtle_mode gone_to_turtle_mode turtle_killed turtle_killed override public string get message return to string getmessage tostring override public final synchronized throwable fill in stack trace return null fillinstacktrace public class grayscale filter extends point filter public grayscale filter can filter index color model true grayscalefilter pointfilter grayscalefilter canfilterindexcolormodel override public int filterrgb int x int y int rgb int a rgb 0xff000000 int r rgb 16 0xff int g rgb 8 0xff int b rgb 0xff rgb r g b 3 simple average rgb r 77 g 151 b 28 8 ntsc luma return a rgb 16 rgb 8 rgb override public string to string return colors grayscale tostring static logger register log threshold callback new log threshold callback override public void should update logminor logger should log logger minor this registerlogthresholdcallback logthresholdcallback shouldupdate shouldlog push ing an object that is already in the queue moves that object to the most recently used position but doesn t add a duplicate entry in the queue public final synchronized void push k key v value q item k v insert hash get key if insert null insert new q item k v key value hash put key insert else insert value value list remove insert if logminor logger minor this pushed insert key value list unshift insert qitem qitem return least recently pushed key public final synchronized k pop key if list size 0 return hash remove list pop obj obj else return null popkey return least recently pushed value public final synchronized v pop value if list size 0 return hash remove list pop obj value else return null popvalue public final synchronized v peek value if list size 0 return hash get list tail obj value else return null peekvalue public final int size return list size public final synchronized boolean remove key k key q item k v i hash remove key if i null list remove i return true else return false removekey qitem check if this queue contains obj param obj object to match return true if this queue contains obj public final synchronized boolean contains key k key return hash contains key key containskey containskey note that this does not automatically promote the key you have to do that by hand with push key value public final synchronized v get k key q item k v q hash get key if q null return null return q value qitem public enumeration k keys return new item enumeration itemenumeration public enumeration v values return new values enumeration valuesenumeration private enumeration q item k v source list reverse elements public boolean has more elements return source has more elements qitem reverseelements hasmoreelements hasmoreelements public k next element return source next element obj nextelement nextelement private enumeration q item k v source list reverse elements public boolean has more elements return source has more elements qitem reverseelements hasmoreelements hasmoreelements public v next element return source next element value nextelement nextelement public v value public q item k key v val this obj key this value val qitem override public string to string return super to string obj value tostring tostring public boolean is empty return list is empty isempty isempty note that unlike the java util versions this will not reallocate hence it doesn t return so pass in an appropriately big array and make sure you hold the lock param entries return public synchronized void values to array v entries enumeration v values values int i 0 while values has more elements entries i values next element valuestoarray hasmoreelements nextelement public synchronized void clear list clear hash clear private static final long serial versionuid 1l public pubkey verify exception crypt format exception e super e serialversionuid pubkeyverifyexception cryptformatexception public pubkey verify exception string msg super msg pubkeyverifyexception override public void should update logminor logger should log logger minor this logdebug logger should log logger debug this shouldupdate shouldlog shouldlog private final int hash code override public int hash code return hash code hashcode hashcode hashcode public split file inserter base client putter put put completion callback cb bucket data compressor type best codec long decompressed length client metadata client metadata insert context ctx boolean getchk only boolean is metadata object token archive type archive type boolean free data boolean persistent object container container client context context throws insert exception hash code super hash code this parent put this archive type archive type this compression codec best codec this token token this finished false this is metadata is metadata this cm client metadata this getchk only getchk only this cb cb this ctx ctx this decompressed length decompressed length this data length data size bucket data buckets try data buckets bucket tools split data chk block data length persistent ctx persistent bucket factory context temp bucket factory free data persistent container if data buckets data buckets length 1 size chk block data length bucket old data data buckets data buckets length 1 data buckets data buckets length 1 bucket tools pad old data chk block data length context persistent bucket factory int old data size if persistent data buckets data buckets length 1 store to container old data free if persistent old data remove from container if logminor logger minor this data size data size buckets data buckets length catch io exception e throw new insert exception insert exception bucket error e null count data blocks data buckets length encoding is done by segments this splitfile algorithm ctx splitfile algorithm segment size ctx splitfile segment data blocks check segment size splitfile algorithm metadata splitfile nonredundant 0 ctx splitfile segment check blocks this persistent persistent if persistent container activate parent 1 create segments segments split into segments segment size data buckets context main executor container context persistent put if persistent deactivate all buckets and let data buckets be gc ed for int i 0 i data buckets length i if we don t set them now they will be set when the segment is set which means they will be set deactivated and cause np es data buckets i store to container container deactivate data buckets i 1 if data buckets length segment size otherwise we are nulling out within the segment data buckets i null data buckets null int count 0 for int i 0 i segments length i count segments i count check blocks count check blocks count save progress to disk don t want to do all that again probably includes compression in caller parent on major progress container if persistent for int i 0 i segments length i container store segments i container deactivate segments i 1 splitfileinserter baseclientputter putcompletioncallback compressor_type bestcodec decompressedlength clientmetadata clientmetadata insertcontext getchkonly ismetadata archive_type archivetype freedata objectcontainer clientcontext insertexception hashcode hashcode archivetype archivetype compressioncodec bestcodec ismetadata ismetadata clientmetadata getchkonly getchkonly decompressedlength decompressedlength datalength databuckets databuckets buckettools chkblock data_length persistentbucketfactory tempbucketfactory freedata databuckets databuckets chkblock data_length olddata databuckets databuckets databuckets databuckets buckettools olddata chkblock data_length persistentbucketfactory olddata databuckets databuckets storeto olddata olddata removefrom databuckets ioexception insertexception insertexception bucket_error countdatablocks databuckets splitfilealgorithm splitfilealgorithm segmentsize splitfilesegmentdatablocks checksegmentsize splitfilealgorithm splitfile_nonredundant splitfilesegmentcheckblocks splitintosegments segmentsize databuckets mainexecutor databuckets databuckets npes databuckets storeto databuckets databuckets segmentsize databuckets databuckets countcheckblocks countcheckblocks onmajorprogress public split file inserter base client putter parent put completion callback cb client metadata client metadata insert context ctx boolean getchk only boolean metadata object token archive type archive type simple field set fs object container container client context context throws resume exception hash code super hash code this parent parent this archive type archive type this token token this finished false this is metadata metadata this cm client metadata this getchk only getchk only this cb cb this ctx ctx this persistent parent persistent don t read finished wait for the segment finished s string length fs get data length if length null throw new resume exception no data length try data length long parse long length catch number format exception e throw new resume exception corrupt data length e length length fs get decompressed length long dl 0 back compat if length null try dl long parse long length catch number format exception e dl 1 decompressed length dl string tmp fs get segment size if length null throw new resume exception no segment size try segment size integer parse int tmp catch number format exception e throw new resume exception corrupt segment size e length tmp fs get check segment size if length null throw new resume exception no check segment size try check segment size integer parse int tmp catch number format exception e throw new resume exception corrupt check segment size e length string ccodec fs get compression codec compressor type compressor null if ccodec null try compressor compressor type value of ccodec catch throwable t try short codec no short parse short ccodec compressor compressor type get compressor by metadataid codec no catch number format exception nfe throw new resume exception invalid compression codec ccodec compression codec compressor string scodec fs get splitfile codec if scodec null throw new resume exception no splitfile codec try splitfile algorithm short parse short scodec catch number format exception e throw new resume exception corrupt splitfile codec e scodec simple field set segfs fs subset segments if segfs null throw new resume exception no segments string segc segfs get count if segc null throw new resume exception no segment count int segment count try segment count integer parse int segc catch number format exception e throw new resume exception corrupt segment count e segc segments new split file inserter segment segment count int data blocks 0 int check blocks 0 for int i 0 i segments length i string index integer to string i simple field set segment segfs subset index segfs remove subset index if segment null throw new resume exception no segment i segments i new split file inserter segment this persistent parent segment splitfile algorithm ctx getchk only i context container data blocks segments i count data blocks check blocks segments i count check blocks this count data blocks data blocks this count check blocks check blocks splitfileinserter baseclientputter putcompletioncallback clientmetadata clientmetadata insertcontext getchkonly archive_type archivetype simplefieldset objectcontainer clientcontext resumeexception hashcode hashcode archivetype archivetype ismetadata clientmetadata getchkonly getchkonly segmentfinished datalength resumeexception datalength datalength parselong numberformatexception resumeexception datalength decompressedlength parselong numberformatexception decompressedlength segmentsize resumeexception segmentsize segmentsize parseint numberformatexception resumeexception segmentsize checksegmentsize resumeexception checksegmentsize checksegmentsize parseint numberformatexception resumeexception checksegmentsize compressioncodec compressor_type compressor_type valueof codecno parseshort compressor_type getcompressorbymetadataid codecno numberformatexception resumeexception compressioncodec splitfilecodec resumeexception splitfilealgorithm parseshort numberformatexception resumeexception splitfilecodec simplefieldset resumeexception resumeexception segmentcount segmentcount parseint numberformatexception resumeexception splitfileinsertersegment segmentcount datablocks checkblocks tostring simplefieldset removesubset resumeexception splitfileinsertersegment splitfilealgorithm getchkonly datablocks countdatablocks checkblocks countcheckblocks countdatablocks datablocks countcheckblocks checkblocks group the blocks into segments private split file inserter segment split into segments int segment size bucket orig data blocks executor executor object container container client context context boolean persistent base client putter putter int data blocks orig data blocks length vector segs new vector first split the data up if data blocks segment size segment size 1 single segment split file inserter segment only seg new split file inserter segment this persistent putter splitfile algorithm fec codec get check blocks splitfile algorithm orig data blocks length orig data blocks ctx getchk only 0 container segs add only seg else int j 0 int seg no 0 for int i segment size i segment size if i data blocks i data blocks bucket seg new bucket i j system arraycopy orig data blocks j seg 0 i j j i for int x 0 x seg length x if seg x null throw new null pointer exception in split into segs x is null of seg length of seg no split file inserter segment s new split file inserter segment this persistent putter splitfile algorithm fec codec get check blocks splitfile algorithm seg length seg ctx getchk only seg no container segs add s if i data blocks break seg no if persistent container activate parent 1 parent notify clients container context return split file inserter segment segs to array new split file inserter segment segs size splitfileinsertersegment splitintosegments segmentsize origdatablocks objectcontainer clientcontext baseclientputter datablocks origdatablocks datablocks segmentsize segmentsize splitfileinsertersegment onlyseg splitfileinsertersegment splitfilealgorithm feccodec getcheckblocks splitfilealgorithm origdatablocks origdatablocks getchkonly onlyseg segno segmentsize segmentsize datablocks datablocks origdatablocks nullpointerexception splitintosegs segno splitfileinsertersegment splitfileinsertersegment splitfilealgorithm feccodec getcheckblocks splitfilealgorithm getchkonly segno datablocks segno notifyclients splitfileinsertersegment toarray splitfileinsertersegment public void start object container container final client context context throws insert exception for int i 0 i segments length i if persistent container activate segments i 1 segments i start container context if persistent container deactivate segments i 1 if persistent container activate parent 1 if count data blocks 32 parent on major progress container parent notify clients container context objectcontainer clientcontext insertexception countdatablocks onmajorprogress notifyclients public void encoded segment split file inserter segment segment object container container client context context if logminor logger minor this encoded segment segment seg no of this boolean ret false boolean encode synchronized this encode force encode for int i 0 i segments length i if segments i segment if persistent container activate segments i 1 if segments i null segments i is encoded ret true if segments i segment persistent container deactivate segments i 1 break if segments i segment persistent container deactivate segments i 1 if encode segment force encode container context if ret return if persistent container activate cb 1 cb on block set finished this container context if persistent container deactivate cb 1 if count data blocks 32 if persistent container activate parent 1 parent on major progress container encodedsegment splitfileinsertersegment objectcontainer clientcontext segno forceencode isencoded forceencode onblocksetfinished countdatablocks onmajorprogress public void segment hasur is split file inserter segment segment object container container client context context if logminor logger minor this segment has ur is segment synchronized this if have sent metadata return for int i 0 i segments length i if persistent container activate segments i 1 boolean hasur is segments i hasur is if persistent segments i segment container deactivate segments i 1 if hasur is if logminor logger minor this segment does not have ur is segments i return if logminor logger minor this have ur is from all segments encode metadata container context segment segmenthasuris splitfileinsertersegment objectcontainer clientcontext uris havesentmetadata hasuris hasuris hasuris uris uris encodemetadata private void encode metadata object container container client context context split file inserter segment dont deactivate segment boolean missingur is metadata m null clientchk dataur is new clientchk count data blocks clientchk checkur is new clientchk count check blocks synchronized this int dpos 0 int cpos 0 for int i 0 i segments length i if persistent container activate segments i 1 clientchk data segments i get datach ks system arraycopy data 0 dataur is dpos data length dpos data length clientchk check segments i get checkch ks system arraycopy check 0 checkur is cpos check length cpos check length if persistent segments i dont deactivate segment container deactivate segments i 1 create metadata if logminor logger minor this data ur is dataur is length check ur is checkur is length missingur is any nulls dataur is any nulls checkur is if persistent copy the ur is we don t know what the callee wants the metadata for he might well ignore it as in simple manifest putter on metadata this way he doesn t need to worry about removing them for int i 0 i dataur is length i container activate dataur is i 5 dataur is i dataur is i clone key for int i 0 i checkur is length i container activate checkur is i 5 checkur is i checkur is i clone key if missingur is create metadata if persistent container activate cm 5 client metadata meta cm if persistent meta meta null null meta clone m new metadata splitfile algorithm dataur is checkur is segment size check segment size meta data length archive type compression codec decompressed length is metadata have sent metadata true if missingur is if logminor logger minor this missing ur is error fail new insert exception insert exception internal error missing ur is after encoding null container context return else if persistent container activate cb 1 cb on metadata m this container context if persistent container deactivate cb 1 encodemetadata objectcontainer clientcontext splitfileinsertersegment dontdeactivatesegment missinguris datauris countdatablocks checkuris countcheckblocks getdatachks datauris getcheckchks checkuris dontdeactivatesegment uris datauris uris checkuris missinguris anynulls datauris anynulls checkuris uris simplemanifestputter onmetadata datauris datauris datauris datauris clonekey checkuris checkuris checkuris checkuris clonekey missinguris clientmetadata splitfilealgorithm datauris checkuris segmentsize checksegmentsize datalength archivetype compressioncodec decompressedlength ismetadata havesentmetadata missinguris uris insertexception insertexception internal_error uris onmetadata private void fail insert exception e object container container client context context synchronized this if finished return finished true if persistent container store this container activate cb 1 cb on failure e this container context if persistent container deactivate cb 1 insertexception objectcontainer clientcontext onfailure fixme move this to somewhere private static boolean any nulls object array for int i 0 i array length i if array i null return true return false anynulls public base client putter get parent return parent baseclientputter getparent public void segment finished split file inserter segment segment object container container client context context if logminor logger minor this segment finished segment new exception debug boolean all gone true if count data blocks 32 if persistent container activate parent 1 parent on major progress container synchronized this if finished if logminor logger minor this finished already return for int i 0 i segments length i if persistent segments i segment container activate segments i 1 if segments i is finished if logminor logger minor this segment not finished i segments i all gone false if persistent segments i segment container deactivate segments i 1 break if persistent segments i segment container deactivate segments i 1 insert exception e segment get exception if e null e is fatal cancel container context else if all gone return finished true if persistent container store this on all finished container context segmentfinished splitfileinsertersegment objectcontainer clientcontext allgone countdatablocks onmajorprogress isfinished allgone insertexception getexception isfatal allgone onallfinished public void segment fetchable split file inserter segment segment object container container if logminor logger minor this segment fetchable segment synchronized this if finished return if fetchable return for int i 0 i segments length i if persistent segments i segment container activate segments i 1 if segments i is fetchable if logminor logger minor this segment not fetchable i segments i if persistent segments i segment container deactivate segments i 1 return if persistent segments i segment container deactivate segments i 1 fetchable true if persistent container activate cb 1 container store this cb on fetchable this container segmentfetchable splitfileinsertersegment objectcontainer isfetchable onfetchable private void on all finished object container container client context context if logminor logger minor this all finished try finished failure code tracker tracker new failure code tracker true boolean all succeeded true for int i 0 i segments length i if persistent container activate segments i 1 insert exception e segments i get exception if e null continue if logminor logger minor this failure on segment i segments i e e all succeeded false if e error codes null tracker merge e error codes tracker inc e get mode if persistent container activate cb 1 if all succeeded cb on success this container context else cb on failure insert exception construct tracker this container context catch throwable t we must tell the parent something logger error this caught t t cb on failure new insert exception insert exception internal error this container context onallfinished objectcontainer clientcontext failurecodetracker failurecodetracker allsucceeded insertexception getexception allsucceeded errorcodes errorcodes getmode allsucceeded onsuccess onfailure insertexception onfailure insertexception insertexception internal_error public void cancel object container container client context context if logminor logger minor this cancelling this synchronized this if finished return finished true if persistent container store this for int i 0 i segments length i if persistent container activate segments i 1 segments i cancel container context the segments will call segment finished but it will ignore them because finished true hence we need to call the callback here since the caller expects us to if persistent container activate cb 1 cb on failure new insert exception insert exception cancelled this container context objectcontainer clientcontext segmentfinished onfailure insertexception insertexception public void schedule object container container client context context throws insert exception start container context objectcontainer clientcontext insertexception public object get token return token gettoken public long get length return data length getlength datalength force the remaining blocks which haven t been encoded so far to be encoded asap public void force encode object container container client context context if persistent container activate this 1 logger minor this forcing encode on this synchronized this force encode true for int i 0 i segments length i if persistent container activate segments i 1 segments i force encode container context if persistent container deactivate segments i 1 forceencode objectcontainer clientcontext forceencode forceencode public void remove from object container container client context context parent can remove itself ctx will be removed by parent cb will remove itself cm will be removed by parent token setter can remove token for split file inserter segment segment segments container activate segment 1 segment remove from container context container delete this removefrom objectcontainer clientcontext splitfileinsertersegment removefrom public boolean object can update object container container if logdebug logger debug this object can update on this new exception debug return true objectcanupdate objectcontainer objectcanupdate public boolean object can new object container container if finished logger error this object can new but finished on this new exception error else if logdebug logger debug this object can new on this new exception debug return true objectcannew objectcontainer objectcannew objectcannew public insertable clientssk string doc name byte pub key hash dsa public key pub key dsa private key priv key byte crypto key byte crypto algorithm throws malformedurl exception super doc name pub key hash get extra bytes crypto algorithm pub key crypto key if pub key null throw new null pointer exception this priv key priv key insertableclientssk docname pubkeyhash dsapublickey pubkey dsaprivatekey privkey cryptokey cryptoalgorithm malformedurlexception docname pubkeyhash getextrabytes cryptoalgorithm pubkey cryptokey pubkey nullpointerexception privkey privkey public static insertable clientssk create freeneturi uri throws malformedurl exception if uri get key type equals ignore case ksk return clientksk create uri if uri get routing key null throw new malformedurl exception insertable ssk ur is must have a private key uri if uri get crypto key null throw new malformedurl exception insertable ssk ur is must have a private key uri byte key type byte extra uri get extra if uri get key type equals ssk if extra null throw new malformedurl exception inserting pre 1010 keys not supported formatted exactly as extra on fetching if extra length 5 throw new malformedurl exception ssk private key extra too short if extra 1 1 throw new malformedurl exception ssk not a private key key type extra 2 if key type key algo aes pcfb 256 sha256 throw new malformedurl exception unrecognized crypto type in ssk private key else throw new malformedurl exception not a valid ssk insert uri type uri get key type if uri get doc name null uri get doc name length 0 throw new malformedurl exception ssk ur is must have a document name to avoid ambiguity dsa group g global ds agroup biga dsa private key priv key new dsa private key new native big integer 1 uri get routing key g dsa public key pub key new dsa public key g priv key byte pk hash pub key as bytes hash return new insertable clientssk uri get doc name pk hash pub key priv key uri get crypto key key type insertableclientssk malformedurlexception getkeytype equalsignorecase getroutingkey malformedurlexception uris getcryptokey malformedurlexception uris keytype getextra getkeytype malformedurlexception malformedurlexception malformedurlexception keytype keytype algo_aes_pcfb_256_sha256 malformedurlexception malformedurlexception getkeytype getdocname getdocname malformedurlexception uris dsagroup dsagroupbiga dsaprivatekey privkey dsaprivatekey nativebiginteger getroutingkey dsapublickey pubkey dsapublickey privkey pkhash pubkey asbyteshash insertableclientssk getdocname pkhash pubkey privkey getcryptokey keytype public clientssk block encode bucket source data boolean as metadata boolean dont compress short already compressed codec long source length random source r throws ssk encode exception io exception byte compressed data short compression algo try compressed comp key compress source data dont compress already compressed codec source length clientssk block max decompressed data length ssk block data length true compressed data comp compressed data compression algo comp compression algorithm catch key encode exception e throw new ssk encode exception e get message e pad it message digest md256 sha256 get message digest try byte data first pad it if compressed data length ssk block data length hash the data if compressed data length 0 md256 update compressed data byte digest md256 digest mersenne twister mt new mersenne twister digest data new byte ssk block data length if compressed data length data length throw new runtime exception compressed data length compressed data length but data length data length system arraycopy compressed data 0 data 0 compressed data length byte random bytes new byte ssk block data length compressed data length mt next bytes random bytes system arraycopy random bytes 0 data compressed data length ssk block data length compressed data length else data compressed data implicit hash of data byte orig data hash md256 digest data rijndael aes try aes new rijndael 256 256 catch unsupported cipher exception e throw new error 256 256 rijndael not supported encrypt data data encryption key h plaintext data aes initialize orig data hash pcfb mode pcfb pcfb mode create aes pcfb reset orig data hash pcfb block encipher data 0 data length byte encrypted data hash md256 digest data create headers byte headers new byte ssk block total headers length first two bytes hash id int x 0 headers x byte key block hash sha256 8 headers x byte key block hash sha256 then crypto id headers x byte key algo aes pcfb 256 sha256 8 headers x key algo aes pcfb 256 sha256 then e h docname copy to headers system arraycopy eh docname 0 headers x eh docname length x eh docname length now the encrypted headers byte encrypted headers new byte ssk block encrypted headers length system arraycopy orig data hash 0 encrypted headers 0 orig data hash length int y orig data hash length short len short compressed data length if as metadata len 32768 encrypted headers y byte len 8 encrypted headers y byte len encrypted headers y byte compression algo 8 encrypted headers y byte compression algo if encrypted headers length y throw new illegal state exception have more bytes to generate encoding ssk aes initialize crypto key pcfb reset eh docname pcfb block encipher encrypted headers 0 encrypted headers length system arraycopy encrypted headers 0 headers x encrypted headers length x encrypted headers length generate implicit overall hash md256 update headers 0 x md256 update encrypted data hash byte overall hash md256 digest now sign it dsa signature sig dsa sign pub key get group priv key new native big integer 1 overall hash r pack r and s into 32 bytes each and copy to headers then create and return the clientssk block byte r buf truncate sig getr to byte array ssk block sig r length byte s buf truncate sig gets to byte array ssk block sig s length system arraycopy r buf 0 headers x r buf length x r buf length system arraycopy s buf 0 headers x s buf length x s buf length if x ssk block total headers length throw new illegal state exception too long try return new clientssk block data headers this false fixme set last arg to true to not verify catch ssk verify exception e illegal state exception exception new illegal state exception impossible encoding error e get message exception init cause e throw exception finally sha256 return message digest md256 clientsskblock sourcedata asmetadata dontcompress alreadycompressedcodec sourcelength randomsource sskencodeexception ioexception compresseddata compressionalgo sourcedata dontcompress alreadycompressedcodec sourcelength clientsskblock max_decompressed_data_length sskblock data_length compresseddata compresseddata compressionalgo compressionalgorithm keyencodeexception sskencodeexception getmessage messagedigest getmessagedigest compresseddata sskblock data_length compresseddata compresseddata mersennetwister mersennetwister sskblock data_length compresseddata runtimeexception compresseddata compresseddata compresseddata compresseddata randombytes sskblock data_length compresseddata nextbytes randombytes randombytes compresseddata sskblock data_length compresseddata compresseddata origdatahash unsupportedcipherexception origdatahash pcfbmode pcfbmode origdatahash blockencipher encrypteddatahash sskblock total_headers_length keyblock hash_sha256 keyblock hash_sha256 algo_aes_pcfb_256_sha256 algo_aes_pcfb_256_sha256 ehdocname ehdocname ehdocname encryptedheaders sskblock encrypted_headers_length origdatahash encryptedheaders origdatahash origdatahash compresseddata asmetadata encryptedheaders encryptedheaders encryptedheaders compressionalgo encryptedheaders compressionalgo encryptedheaders illegalstateexception cryptokey ehdocname blockencipher encryptedheaders encryptedheaders encryptedheaders encryptedheaders encryptedheaders encrypteddatahash overallhash dsasignature pubkey getgroup privkey nativebiginteger overallhash clientsskblock rbuf tobytearray sskblock sig_r_length sbuf tobytearray sskblock sig_s_length rbuf rbuf rbuf sbuf sbuf sbuf sskblock total_headers_length illegalstateexception clientsskblock sskverifyexception illegalstateexception illegalstateexception getmessage initcause returnmessagedigest private byte truncate byte bs int len if bs length len return bs else if bs length len byte buf new byte len system arraycopy bs 0 buf len bs length bs length return buf else if bs length len for int i 0 i bs length len i if bs i 0 throw new illegal state exception cannot truncate byte buf new byte len system arraycopy bs bs length len buf 0 len return buf illegalstateexception public static insertable clientssk create random random source r string doc name byte ckey new byte crypto key length r next bytes ckey dsa group g global ds agroup biga dsa private key priv key new dsa private key g r dsa public key pub key new dsa public key g priv key try byte pk hash sha256 digest pub key as bytes return new insertable clientssk doc name pk hash pub key priv key ckey key algo aes pcfb 256 sha256 catch malformedurl exception e throw new error e insertableclientssk createrandom randomsource docname crypto_key_length nextbytes dsagroup dsagroupbiga dsaprivatekey privkey dsaprivatekey dsapublickey pubkey dsapublickey privkey pkhash pubkey asbytes insertableclientssk docname pkhash pubkey privkey algo_aes_pcfb_256_sha256 malformedurlexception public freeneturi get inserturi return new freeneturi ssk doc name priv key getx to byte array crypto key get insert extra bytes getinserturi docname privkey tobytearray cryptokey getinsertextrabytes private byte get insert extra bytes byte extra get extra bytes extra 1 1 insert return extra getinsertextrabytes getextrabytes public dsa group get crypto group return global ds agroup biga dsagroup getcryptogroup dsagroupbiga override public void remove from object container container container activate priv key 5 priv key remove from container super remove from container removefrom objectcontainer privkey privkey removefrom removefrom public class not enough nice levels user alert extends abstract user alert public not enough nice levels user alert super true null null null null user alert warning true l10n get string user alert hide true null notenoughnicelevelsuseralert abstractuseralert notenoughnicelevelsuseralert useralert getstring useralert override public string get title return l10n get string not enough nice levels user alert title gettitle getstring notenoughnicelevelsuseralert override public string get text return l10n get string not enough nice levels user alert content new string available required new string string value of native thread native priority range string value of native thread enough nice levels gettext getstring notenoughnicelevelsuseralert valueof nativethread native_priority_range valueof nativethread enough_nice_levels override public string get short text return l10n get string not enough nice levels user alert short getshorttext getstring notenoughnicelevelsuseralert override public html node gethtml text return new html node div get text htmlnode gethtmltext htmlnode gettext public forward port string name boolean isip6 int protocol int port number this name name this isip6 isip6 this protocol protocol this port number port number hash code name hash code isip6 1 0 protocol port number forwardport portnumber portnumber portnumber hashcode hashcode portnumber override public int hash code return hash code hashcode hashcode override public boolean equals object o if o this return true if o instanceof forward port return false forward port f forward port o return f name equals name f isip6 isip6 f protocol protocol f port number port number forwardport forwardport forwardport portnumber portnumber create an instance of jmdns public static jmdns create throws io exception return new jmdns impl ioexception jmdnsimpl create an instance of jmdns and bind it to a specific network interface given its ip address public static jmdns create inet address addr throws io exception return new jmdns impl addr inetaddress ioexception jmdnsimpl return the host name associated with this jmdns instance note may not be the same as what started the host name is subject to negotiation hostname return the address of the interface to which this instance of jmdns is bound get service information if the information is not cached the method will block until updated information is received p usage note do not call this method from the awt event dispatcher thread you will make the user interface unresponsive param type fully qualified service type such as code http tcp local code param name unqualified service name such as code foobar code return null if the service information cannot be obtained _http _tcp get service information if the information is not cached the method will block for the given timeout until updated information is received p usage note if you call this method from the awt event dispatcher thread use a small timeout or you will make the user interface unresponsive param type full qualified service type such as code http tcp local code param name unqualified service name such as code foobar code param timeout timeout in milliseconds return null if the service information cannot be obtained _http _tcp request service information the information about the service is requested and the service listener resolve service method is called as soon as it is available p usage note do not call this method from the awt event dispatcher thread you will make the user interface unresponsive param type full qualified service type such as code http tcp local code param name unqualified service name such as code foobar code servicelistener resolveservice _http _tcp request service information the information about the service is requested and the service listener resolve service method is called as soon as it is available param type full qualified service type such as code http tcp local code param name unqualified service name such as code foobar code param timeout timeout in milliseconds servicelistener resolveservice _http _tcp listen for service types param listener listener for service types remove listener for service types param listener listener for service types listen for services of a given type the type has to be a fully qualified type name such as code http tcp local code param type full qualified service type such as code http tcp local code param listener listener for service updates _http _tcp _http _tcp remove listener for services of a given type param listener listener for service updates register a service the service is registered for access by other jmdns clients the name of the service may be changed to make it unique public abstract void register service service info info throws io exception unregister a service the service should have been registered public abstract void unregister service service info info registerservice serviceinfo ioexception unregisterservice serviceinfo public abstract void unregister service service info info unregister all services public abstract void unregister all services unregisterservice serviceinfo unregisterallservices register a service type if this service type was not already known all service listeners will be notified of the new service type service types are automatically registered as they are discovered public abstract void register service type string type close down jmdns release all resources and unregister all services public abstract void close registerservicetype list services and service types debugging only servicetypes returns a list of service infos of the specified type param type service type name such as code http tcp local code return an array of service instance names _http _tcp construct a bicubic scale filter which resizes to 32x32 pixels public bicubic scale filter this 32 32 bicubicscalefilter bicubicscalefilter constructor for a filter which scales the input image to the given width and height using bicubic interpolation unfortunately it appears that bicubic actually looks worse than bilinear interpolation on most java implementations but you can be the judge param width the width of the output image param height the height of the output image public bicubic scale filter int width int height this width width this height height bicubicscalefilter public buffered image filter buffered image src buffered image dst int w src get width int h src get height if dst null color model dstcm src get color model dst new buffered image dstcm dstcm create compatible writable raster width height dstcm is alpha premultiplied null graphics2d g dst create graphics g set rendering hint rendering hints key interpolation rendering hints value interpolation bicubic g draw image src 0 0 width height null g dispose return dst bufferedimage bufferedimage bufferedimage getwidth getheight colormodel getcolormodel bufferedimage createcompatiblewritableraster isalphapremultiplied creategraphics setrenderinghint renderinghints key_interpolation renderinghints value_interpolation_bicubic drawimage override public string to string return distort bicubic scale tostring private final wot m wot public fcp interface final wot my wot m wot my wot mwot fcpinterface mywot mwot mywot public void handle final plugin reply sender replysender final simple field set params final bucket data final int accesstype try final string message params get message if message equals create identity replysender send handle create identity params data else if message equals set trust replysender send handle set trust params data else if message equals add identity replysender send handle add identity params data else if message equals get identity replysender send handle get identity params data else if message equals get own identities replysender send handle get own identities params data else if message equals get identities by score replysender send handle get identities by score params data else if message equals get trusters replysender send handle get trusters params data else if message equals get trustees replysender send handle get trustees params data else if message equals add context replysender send handle add context params data else if message equals remove context replysender send handle remove context params data else if message equals set property replysender send handle set property params data else if message equals get property replysender send handle get property params data else if message equals remove property replysender send handle remove property params data else throw new exception unknown message message catch final exception e logger error this e to string try replysender send error messagefcp params get message e data catch final plugin not found exception e1 logger normal this connection to request sender lost e1 pluginreplysender simplefieldset createidentity handlecreateidentity settrust handlesettrust addidentity handleaddidentity getidentity handlegetidentity getownidentities handlegetownidentities getidentitiesbyscore handlegetidentitiesbyscore gettrusters handlegettrusters gettrustees handlegettrustees addcontext handleaddcontext removecontext handleremovecontext setproperty handlesetproperty getproperty handlegetproperty removeproperty handleremoveproperty tostring errormessagefcp pluginnotfoundexception private string get mandatory parameter final simple field set sfs final string name throws invalid parameter exception final string result sfs get name if result null throw new illegal argument exception missing mandatory parameter name return result getmandatoryparameter simplefieldset invalidparameterexception illegalargumentexception private simple field set handle create identity final simple field set params throws invalid parameter exception fs parse exception malformedurl exception own identity identity final string identity nickname get mandatory parameter params nickname final string identity context get mandatory parameter params context final string identity publishes trust list str get mandatory parameter params publish trust list final boolean identity publishes trust list identity publishes trust list str equals true identity publishes trust list str equals yes final string identity requesturi params get requesturi final string identity inserturi params get inserturi the constructor will throw for us if one is missing do not use because that would lead to creation of a new uri if the user forgot one of the ur is and the user would not get notified about that synchronized m wot preserve the locking order to prevent future deadlocks if identity requesturi null identity inserturi null identity m wot create own identity identity nickname identity publishes trust list identity context else identity m wot create own identity identity inserturi identity requesturi identity nickname identity publishes trust list identity context if params get publish introduction puzzles null params get boolean publish introduction puzzles if identity publishes trust list throw new invalid parameter exception an identity cannot publish introduction puzzles if it does not publish its trust list synchronized identity todo create a function for those try identity add context introduction puzzle introduction context identity set property introduction server puzzle count property integer to string introduction server default puzzle count m wot store and commit identity catch runtime exception e m wot delete identity identity throw e final simple field set sfs new simple field set true sfs put overwrite message identity created sfs put overwrite id identity getid sfs put overwrite inserturi identity get inserturi to string sfs put overwrite requesturi identity get requesturi to string return sfs simplefieldset handlecreateidentity simplefieldset invalidparameterexception fsparseexception malformedurlexception ownidentity identitynickname getmandatoryparameter identitycontext getmandatoryparameter identitypublishestrustliststr getmandatoryparameter publishtrustlist identitypublishestrustlist identitypublishestrustliststr identitypublishestrustliststr identityrequesturi identityinserturi uris mwot identityrequesturi identityinserturi mwot createownidentity identitynickname identitypublishestrustlist identitycontext mwot createownidentity identityinserturi identityrequesturi identitynickname identitypublishestrustlist identitycontext publishintroductionpuzzles getboolean publishintroductionpuzzles identitypublishestrustlist invalidparameterexception addcontext introductionpuzzle introduction_context setproperty introductionserver puzzle_count_property tostring introductionserver default_puzzle_count mwot storeandcommit runtimeexception mwot deleteidentity simplefieldset simplefieldset putoverwrite identitycreated putoverwrite putoverwrite getinserturi tostring putoverwrite getrequesturi tostring private simple field set handle set trust final simple field set params throws invalid parameter exception number format exception unknown identity exception final string trusterid get mandatory parameter params truster final string trusteeid get mandatory parameter params trustee final string trust value get mandatory parameter params value final string trust comment get mandatory parameter params comment m wot set trust trusterid trusteeid byte parse byte trust value trust comment final simple field set sfs new simple field set true sfs put overwrite message trust set return sfs simplefieldset handlesettrust simplefieldset invalidparameterexception numberformatexception unknownidentityexception getmandatoryparameter getmandatoryparameter trustvalue getmandatoryparameter trustcomment getmandatoryparameter mwot settrust parsebyte trustvalue trustcomment simplefieldset simplefieldset putoverwrite trustset private simple field set handle add identity final simple field set params throws invalid parameter exception malformedurl exception final string requesturi get mandatory parameter params requesturi final identity identity m wot add identity requesturi final simple field set sfs new simple field set true sfs put overwrite message identity added sfs put overwrite id identity getid return sfs simplefieldset handleaddidentity simplefieldset invalidparameterexception malformedurlexception getmandatoryparameter mwot addidentity simplefieldset simplefieldset putoverwrite identityadded putoverwrite private simple field set handle get identity final simple field set params throws invalid parameter exception unknown identity exception final string tree ownerid get mandatory parameter params tree owner final string identityid get mandatory parameter params identity final simple field set sfs new simple field set true sfs put overwrite message identity synchronized m wot final own identity tree owner m wot get own identity byid tree ownerid final identity identity m wot get identity byid identityid try final trust trust m wot get trust tree owner identity sfs put overwrite trust byte to string trust get value catch final not trusted exception e1 sfs put overwrite trust null try final score score m wot get score tree owner identity sfs put overwrite score integer to string score get score sfs put overwrite rank integer to string score get rank catch final not in trust tree exception e sfs put overwrite score null sfs put overwrite rank null final iterator string contexts identity get contexts iterator for int i 1 contexts has next i sfs put overwrite context i contexts next return sfs simplefieldset handlegetidentity simplefieldset invalidparameterexception unknownidentityexception treeownerid getmandatoryparameter treeowner getmandatoryparameter simplefieldset simplefieldset putoverwrite mwot ownidentity treeowner mwot getownidentitybyid treeownerid mwot getidentitybyid mwot gettrust treeowner putoverwrite tostring getvalue nottrustedexception putoverwrite mwot getscore treeowner putoverwrite tostring getscore putoverwrite tostring getrank notintrusttreeexception putoverwrite putoverwrite getcontexts hasnext putoverwrite private simple field set handle get own identities final simple field set params final simple field set sfs new simple field set true sfs put overwrite message own identities synchronized m wot final object set own identity result m wot get all own identities for int i 1 result has next final own identity oid result next sfs put overwrite identity i oid getid sfs put overwrite requesturi i oid get requesturi to string sfs put overwrite inserturi i oid get inserturi to string sfs put overwrite nickname i oid get nickname todo allow the client to select what data he wants this is here so you do not forget to do it in the if if you add an if around the put statements to allow selection i return sfs simplefieldset handlegetownidentities simplefieldset simplefieldset simplefieldset putoverwrite ownidentities mwot objectset ownidentity mwot getallownidentities hasnext ownidentity putoverwrite putoverwrite getrequesturi tostring putoverwrite getinserturi tostring putoverwrite getnickname private simple field set handle get identities by score final simple field set params throws invalid parameter exception unknown identity exception final string tree ownerid params get tree owner final string selection get mandatory parameter params selection final string context get mandatory parameter params context final string select string selection trim int select 0 todo decide about the default value if select string equals select 1 else if select string equals select 1 else if select string equals 0 select 0 else throw new invalid parameter exception unhandled selection value select final simple field set sfs new simple field set true sfs put overwrite message identities synchronized m wot final own identity tree owner tree ownerid null m wot get own identity byid tree ownerid null final object set score result m wot get identities by score tree owner select final boolean get all context equals for int i 1 result has next final score score result next if get all score get target has context context final identity identity score get target sfs put overwrite identity i identity getid sfs put overwrite requesturi i identity get requesturi to string sfs put overwrite nickname i identity get nickname null identity get nickname i todo allow the client to select what data he wants return sfs simplefieldset handlegetidentitiesbyscore simplefieldset invalidparameterexception unknownidentityexception treeownerid treeowner getmandatoryparameter getmandatoryparameter selectstring selectstring selectstring selectstring invalidparameterexception simplefieldset simplefieldset putoverwrite mwot ownidentity treeowner treeownerid mwot getownidentitybyid treeownerid objectset mwot getidentitiesbyscore treeowner getall hasnext getall gettarget hascontext gettarget putoverwrite putoverwrite getrequesturi tostring putoverwrite getnickname getnickname private simple field set handle get trusters final simple field set params throws invalid parameter exception unknown identity exception final string identityid get mandatory parameter params identity final string context get mandatory parameter params context final simple field set sfs new simple field set true sfs put overwrite message identities final boolean get all context equals synchronized m wot final object set trust received trusts m wot get received trusts m wot get identity byid identityid for int i 1 received trusts has next final trust trust received trusts next if get all trust get truster has context params get context sfs put overwrite identity i trust get truster getid sfs put overwrite value i byte to string trust get value sfs put overwrite comment i trust get comment todo allow the client to select what data he wants i return sfs simplefieldset handlegettrusters simplefieldset invalidparameterexception unknownidentityexception getmandatoryparameter getmandatoryparameter simplefieldset simplefieldset putoverwrite getall mwot objectset receivedtrusts mwot getreceivedtrusts mwot getidentitybyid receivedtrusts hasnext receivedtrusts getall gettruster hascontext putoverwrite gettruster putoverwrite tostring getvalue putoverwrite getcomment private simple field set handle get trustees final simple field set params throws invalid parameter exception unknown identity exception final string identityid get mandatory parameter params identity final string context get mandatory parameter params context final simple field set sfs new simple field set true sfs put overwrite message identities final boolean get all context equals synchronized m wot final object set trust given trusts m wot get given trusts m wot get identity byid identityid for int i 1 given trusts has next final trust trust given trusts next if get all trust get truster has context params get context sfs put overwrite identity i trust get truster getid sfs put overwrite value i byte to string trust get value sfs put overwrite comment i trust get comment todo allow the client to select what data he wants i return sfs simplefieldset handlegettrustees simplefieldset invalidparameterexception unknownidentityexception getmandatoryparameter getmandatoryparameter simplefieldset simplefieldset putoverwrite getall mwot objectset giventrusts mwot getgiventrusts mwot getidentitybyid giventrusts hasnext giventrusts getall gettruster hascontext putoverwrite gettruster putoverwrite tostring getvalue putoverwrite getcomment private simple field set handle add context final simple field set params throws invalid parameter exception unknown identity exception final string identityid get mandatory parameter params identity final string context get mandatory parameter params context m wot add context identityid context final simple field set sfs new simple field set true sfs put overwrite message context added return sfs simplefieldset handleaddcontext simplefieldset invalidparameterexception unknownidentityexception getmandatoryparameter getmandatoryparameter mwot addcontext simplefieldset simplefieldset putoverwrite contextadded private simple field set handle remove context final simple field set params throws invalid parameter exception unknown identity exception final string identityid get mandatory parameter params identity final string context get mandatory parameter params context m wot remove context identityid context final simple field set sfs new simple field set true sfs put overwrite message context removed return sfs simplefieldset handleremovecontext simplefieldset invalidparameterexception unknownidentityexception getmandatoryparameter getmandatoryparameter mwot removecontext simplefieldset simplefieldset putoverwrite contextremoved private simple field set handle set property final simple field set params throws invalid parameter exception unknown identity exception final string identityid get mandatory parameter params identity final string property name get mandatory parameter params property final string property value get mandatory parameter params value m wot set property identityid property name property value final simple field set sfs new simple field set true sfs put overwrite message property added return sfs simplefieldset handlesetproperty simplefieldset invalidparameterexception unknownidentityexception getmandatoryparameter propertyname getmandatoryparameter propertyvalue getmandatoryparameter mwot setproperty propertyname propertyvalue simplefieldset simplefieldset putoverwrite propertyadded private simple field set handle get property final simple field set params throws invalid parameter exception unknown identity exception final string identityid get mandatory parameter params identity final string property name get mandatory parameter params property final simple field set sfs new simple field set true sfs put overwrite message property value sfs put overwrite property m wot get property identityid property name return sfs simplefieldset handlegetproperty simplefieldset invalidparameterexception unknownidentityexception getmandatoryparameter propertyname getmandatoryparameter simplefieldset simplefieldset putoverwrite propertyvalue putoverwrite mwot getproperty propertyname private simple field set handle remove property final simple field set params throws invalid parameter exception unknown identity exception final string identityid get mandatory parameter params identity final string property name get mandatory parameter params property m wot remove property identityid property name final simple field set sfs new simple field set true sfs put overwrite message property removed return sfs simplefieldset handleremoveproperty simplefieldset invalidparameterexception unknownidentityexception getmandatoryparameter propertyname getmandatoryparameter mwot removeproperty propertyname simplefieldset simplefieldset putoverwrite propertyremoved private simple field set error messagefcp final string original message final exception e final simple field set sfs new simple field set true sfs put overwrite message error sfs put overwrite original message original message sfs put overwrite description e to string return sfs simplefieldset errormessagefcp originalmessage simplefieldset simplefieldset putoverwrite putoverwrite originalmessage originalmessage putoverwrite tostring private static final long serial versionuid 3144583349586910509l public invalid description exception super serialversionuid invaliddescriptionexception public invalid description exception string s super s invaliddescriptionexception public invalid description exception string s file file super s file to string invaliddescriptionexception tostring public invalid description exception exception e super e get message invaliddescriptionexception getmessage protected static final digest shactx sha1 get instance crypto key getinstance cryptokey public static crypto key read input stream i throws io exception crypt format exception data input stream dis new data input stream i string type dis readutf try class key class class for name type method m key class get method read new class input stream class return crypto key m invoke null new object dis catch exception e e print stack trace if e instanceof crypt format exception throw crypt format exception e if e instanceof io exception throw io exception e logger error crypto key class unknown exception while reading crypto key e return null cryptokey inputstream ioexception cryptformatexception datainputstream datainputstream keyclass forname keyclass getmethod inputstream cryptokey printstacktrace cryptformatexception cryptformatexception ioexception ioexception cryptokey cryptokey public abstract void write output stream o throws io exception public abstract string key type outputstream ioexception keytype public abstract string key type public abstract byte fingerprint keytype public abstract string key type public abstract byte fingerprint public abstract byte as bytes keytype asbytes protected byte fingerprint big integer quantities synchronized shactx for int i 0 i quantities length i byte mpi util mp ibytes quantities i shactx update mpi 0 mpi length return shactx digest biginteger mpibytes public string verbose to string string builder b new string builder b append to string append t append fingerprint to string return b to string verbosetostring stringbuilder stringbuilder tostring fingerprinttostring tostring override public string to string string builder b new string builder key type length 1 4 b append key type append hex util bytes to hex append fingerprint 16 4 b return b to string tostring stringbuilder stringbuilder keytype keytype hexutil bytestohexappend tostring public string fingerprint to string string fphex hex util bytes to hex fingerprint string builder b new string builder 40 10 b append fphex substring 0 4 append append fphex substring 4 8 append append fphex substring 8 12 append append fphex substring 12 16 append append fphex substring 16 20 append append fphex substring 20 24 append append fphex substring 24 28 append append fphex substring 28 32 append append fphex substring 32 36 append append fphex substring 36 40 return b to string fingerprinttostring hexutil bytestohex stringbuilder stringbuilder tostring public static void main string args throws exception for crypto key kp crypto key read system in system err println kp verbose to string cryptokey cryptokey verbosetostring public host info inet address address string name super this address address this name name if address null try interfaze network interface get by inet address address catch exception exception fixme shouldn t we take an action here logger log level warning local host info exception exception hostinfo inetaddress networkinterface getbyinetaddress localhostinfo public string get name return name getname public inet address get address return address inetaddress getaddress public network interface get interface return interfaze networkinterface getinterface synchronized string increment host name host name count int plocal name index of local int punder name last index of name name substring 0 punder 1 plocal punder host name count local return name incrementhostname hostnamecount indexof lastindexof hostnamecount boolean should ignore packet datagram packet packet boolean result false if get address null inet address from packet get address if from null if from is link local address get address is link local address ignore linklocal packets on regular interfaces unless this is also a linklocal interface this is to avoid duplicates this is a terrible hack caused by the lack of an api to get the address of the interface on which the packet was received result true if from is loopback address get address is loopback address ignore loopback packets on a regular interface unless this is also a loopback interface result true return result shouldignorepacket datagrampacket getaddress inetaddress getaddress islinklocaladdress getaddress islinklocaladdress isloopbackaddress getaddress isloopbackaddress dns record address getdns address record dns record address address return dns constants type aaaa address type getdns6 address record getdns4 address record dnsrecord getdnsaddressrecord dnsrecord dnsconstants type_aaaa getdns6addressrecord getdns4addressrecord public dns record address getdns4 address record if get address null get address instanceof inet4 address get address instanceof inet6 address inet6 address get address isi pv4 compatible address return new dns record address get name dns constants type a dns constants class in dns constants dns ttl get address return null dnsrecord getdns4addressrecord getaddress getaddress inet4address getaddress inet6address inet6address getaddress isipv4compatibleaddress dnsrecord getname dnsconstants type_a dnsconstants class_in dnsconstants dns_ttl getaddress public dns record address getdns6 address record if get address null get address instanceof inet6 address return new dns record address get name dns constants type aaaa dns constants class in dns constants dns ttl get address return null dnsrecord getdns6addressrecord getaddress getaddress inet6address dnsrecord getname dnsconstants type_aaaa dnsconstants class_in dnsconstants dns_ttl getaddress public string to string string buffer buf new string buffer buf append local host info buf append get name null get name no name buf append buf append get interface null get interface get display name buf append buf append get address null get address get host address no address buf append return buf to string tostring stringbuffer stringbuffer getname getname getinterface getinterface getdisplayname getaddress getaddress gethostaddress tostring public void add address records dns outgoing out boolean authoritative throws io exception dns record answer getdns4 address record if answer null if authoritative out add authorative answer answer else out add answer answer 0 answer getdns6 address record if answer null if authoritative out add authorative answer answer else out add answer answer 0 addaddressrecords dnsoutgoing ioexception dnsrecord getdns4addressrecord addauthorativeanswer addanswer getdns6addressrecord addauthorativeanswer addanswer private random random numbers new random public sparkle filter randomnumbers sparklefilter public void set color int color this color color setcolor public int get color return color getcolor public void set randomness int randomness this randomness randomness setrandomness public int get randomness return randomness getrandomness set the amount of sparkle param amount the amount min value 0 max value 1 see get amount public void set amount int amount this amount amount getamount setamount get the amount of sparkle return the amount see set amount public int get amount return amount setamount getamount public void set rays int rays this rays rays setrays public int get rays return rays getrays set the radius of the effect param radius the radius min value 0 see get radius public void set radius int radius this radius radius getradius setradius get the radius of the effect return the radius see set radius public int get radius return radius setradius getradius override public void set dimensions int width int height this width width this height height centrex width 2 centrey height 2 super set dimensions width height random numbers set seed seed ray lengths new float rays for int i 0 i rays i ray lengths i radius randomness 100 0f radius float random numbers next gaussian setdimensions setdimensions randomnumbers setseed raylengths raylengths randomnumbers nextgaussian override public int filterrgb int x int y int rgb float dx x centrex float dy y centrey float distance dx dx dy dy float angle float math atan2 dy dx float d angle image math pi image math two pi rays int i int d float f d i if radius 0 float length image math lerp f ray lengths i rays ray lengths i 1 rays float g length length distance 0 0001f g float math pow g 100 amount 50 0 f 0 5f f amount 50 0f f 1 f f f g f image math clamp f 0 1 return image math mix colors f rgb color imagemath imagemath two_pi imagemath raylengths raylengths imagemath imagemath mixcolors override public string to string return stylize sparkle tostring persistent cooldown queue item sendable get client key key long time persistent cooldown queue parent this client client this key key this key as bytes hex util bytes to hex key get full key this time time this parent parent persistentcooldownqueueitem sendableget persistentcooldownqueue keyasbytes hexutil bytestohex getfullkey public void delete object container container client not our problem parent not our problem key remove from container container delete this objectcontainer removefrom public wot message list ft identity my author freeneturi myuri list message reference new messages throws invalid parameter exception no such identity exception super my author myuri new messages todo auto generated constructor stub wotmessagelist ftidentity myauthor messagereference newmessages invalidparameterexception nosuchidentityexception myauthor newmessages public wot message list ft identity my author freeneturi myuri super my author myuri wotmessagelist ftidentity myauthor myauthor public wot identity get author return wot identity m author wotidentity getauthor wotidentity mauthor public freeneturi geturi return assembleuri m author get requesturi m index ssk forusk mauthor getrequesturi mindex sskforusk protected freeneturi generateuri freeneturi baseuri int index return assembleuri baseuri index get the usk uri of a message list with the given identity and index param identity param index return public static freeneturi generateuri wot identity identity int index return assembleuri identity get requesturi index wotidentity getrequesturi public static freeneturi assembleuri freeneturi baseuri int index baseuri baseuri set key type usk baseuri baseuri set doc name freetalk plugin title message list baseuri baseuri set suggested edition index baseuri baseuri set meta string null return baseuri setkeytype setdocname plugin_title messagelist setsuggestededition setmetastring creates a new redirect exception param message the message to put in the reply param new location the location to redirect to public redirect pluginhttp exception string message string new location super message null this new location new location newlocation redirectpluginhttpexception newlocation newlocation newlocation creates a new redirect exception param message the message to put in the reply param location unsued param new location the location to redirect to deprecated use link redirect pluginhttp exception string string instead deprecated public redirect pluginhttp exception string message string location string new location super message location this new location new location newlocation redirectpluginhttpexception redirectpluginhttpexception newlocation newlocation newlocation public client put complex dir message simple field set fs bucket factory bf temp persistent temp bucket factory bf persistent throws message invalid exception parse the standard client put dir headers uri etc super fs files by name new hash map string object files to read new linked list dir put file long total bytes 0 now parse the meat simple field set files fs subset files if files null throw new message invalid exception protocol error message missing field missing files section identifier global boolean logminor logger should log logger minor this for int i 0 i simple field set subset files subset integer to string i if subset null break dir put file f dir put file create subset identifier global persistence type client request persist forever bf persistent bf temp add file f if logminor logger minor this adding f if f instanceof direct dir put file total bytes direct dir put file f bytes to read files to read add last f if logminor logger minor this total bytes now total bytes attached bytes total bytes clientputcomplexdirmessage simplefieldset bucketfactory bftemp persistenttempbucketfactory bfpersistent messageinvalidexception clientputdir filesbyname hashmap filestoread linkedlist dirputfile totalbytes simplefieldset messageinvalidexception protocolerrormessage missing_field shouldlog simplefieldset tostring dirputfile dirputfile persistencetype clientrequest persist_forever bfpersistent bftemp addfile directdirputfile totalbytes directdirputfile bytestoread filestoread addlast totalbytes totalbytes attachedbytes totalbytes add a file to the files by name throws message invalid exception private void add file dir put file f throws message invalid exception add file files by name f get name f filesbyname messageinvalidexception addfile dirputfile messageinvalidexception addfile filesbyname getname suppress warnings unchecked private void add file hash map string object by name string name dir put file f throws message invalid exception int idx name index of if idx 1 by name put name f else string before name substring 0 idx string after name substring idx 1 object o by name get before if o null if o instanceof hash map add file hash map string object o after f return else throw new message invalid exception protocol error message invalid message cannot be both a file and a directory before identifier global else o new hash map object object by name put before o add file hash map string object o after f suppresswarnings addfile hashmap byname dirputfile messageinvalidexception indexof byname byname hashmap addfile hashmap messageinvalidexception protocolerrormessage invalid_message hashmap byname addfile hashmap static final string name client put complex dir override public string get name return name clientputcomplexdir getname override long data length return attached bytes datalength attachedbytes string get identifier return identifier getidentifier override public void read from input stream is bucket factory bf fcp server server throws io exception message invalid exception iterator dir put file i files to read iterator while i has next direct dir put file f direct dir put file i next f read is readfrom inputstream bucketfactory fcpserver ioexception messageinvalidexception dirputfile filestoread hasnext directdirputfile directdirputfile override protected void write data output stream os throws io exception iterator dir put file i files to read iterator while i has next direct dir put file f direct dir put file i next f write os writedata outputstream ioexception dirputfile filestoread hasnext directdirputfile directdirputfile override public void run fcp connection handler handler node node throws message invalid exception convert the hierarchical hashmap s of dir put file s to hierarchical hashmap s of manifest element s then simply create the client put dir hash map string object manifest elements new hash map string object convert files by name to manifest elements files by name manifest elements node handler start client put dir this manifest elements false fcpconnectionhandler messageinvalidexception dirputfile manifestelement clientputdir hashmap manifestelements hashmap convertfilesbynametomanifestelements filesbyname manifestelements startclientputdir manifestelements convert a hierarchy of hash map s containing dir put file s into a hierarchy of hash map s containing manifest element s suppress warnings unchecked private void convert files by name to manifest elements hash map string object files by name hash map string object manifest elements node node throws message invalid exception for map entry string object entry files by name entry set string temp name entry get key object val entry get value if val instanceof hash map hash map string object h hash map string object val hash map string object manifests new hash map string object manifest elements put temp name manifests convert files by name to manifest elements h manifests node else dir put file f dir put file val if f instanceof disk dir put file node client core allow upload from disk dir put file f get file throw new message invalid exception protocol error message access denied not allowed to upload disk dir put file f get file identifier global manifest element e f get element manifest elements put temp name e hashmap dirputfile hashmap manifestelement suppresswarnings convertfilesbynametomanifestelements hashmap filesbyname hashmap manifestelements messageinvalidexception filesbyname entryset tempname getkey getvalue hashmap hashmap hashmap hashmap hashmap manifestelements tempname convertfilesbynametomanifestelements dirputfile dirputfile diskdirputfile clientcore allowuploadfrom diskdirputfile getfile messageinvalidexception protocolerrormessage access_denied diskdirputfile getfile manifestelement getelement manifestelements tempname override public void remove from object container container files to read clear container activate files by name integer max value remove from container files by name container delete this removefrom objectcontainer filestoread filesbyname max_value removefrom filesbyname private void remove from object container container hash map files by name iterator i files by name values iterator while i has next object val i next if val instanceof hash map remove from container hash map val else dir put file val remove from container container delete files by name removefrom objectcontainer hashmap filesbyname filesbyname hasnext hashmap removefrom hashmap dirputfile removefrom filesbyname public final runnable thread new runnable public void run synchronized this while has node started try wait 1000 catch interrupted exception e try inner store catch io exception e string err cannot store config e logger error this err e system err println err e print stack trace synchronized store sync is writing config false hasnodestarted interruptedexception innerstore ioexception printstacktrace storesync iswritingconfig public freenet file persistent config simple field set set file filename file temp filename throws io exception super set filename temp filename freenetfilepersistentconfig simplefieldset tempfilename ioexception tempfilename public static freenet file persistent config construct freenet file persistent config file f throws io exception file filename f file temp filename new file f get path tmp return new freenet file persistent config load filename temp filename filename temp filename freenetfilepersistentconfig constructfreenetfilepersistentconfig ioexception tempfilename getpath freenetfilepersistentconfig tempfilename tempfilename override public void store synchronized this if finished init logger minor this initialization not finished refusing to write config new exception error return synchronized store sync if is writing config ticker null logger normal this already writing the config file to disk or the node object hasn t been set refusing to proceed return is writing config true ticker queue timed job thread 0 finishedinit storesync iswritingconfig iswritingconfig queuetimedjob public void finished init ticker ticker super finished init this ticker ticker finishedinit finishedinit public void set has node started synchronized this if has node started logger error this it has already been called that shouldn t happen this has node started true notify all sethasnodestarted hasnodestarted hasnodestarted notifyall public service resolver jmdns impl jmdns impl string type this jmdns impl jmdns impl this type type serviceresolver jmdnsimpl jmdnsimpl jmdnsimpl jmdnsimpl public void start timer timer timer schedule this dns constants query wait interval dns constants query wait interval dnsconstants query_wait_interval dnsconstants query_wait_interval public void run try if this jmdns impl get state dns state announced if count 3 logger finer run jmdns querying service long now system current time millis dns outgoing out new dns outgoing dns constants flags qr query out add question new dns question type dns constants type ptr dns constants class in for iterator s this jmdns impl get services values iterator s has next final service info impl info service info impl s next try out add answer new dns record pointer info get type dns constants type ptr dns constants class in dns constants dns ttl info get qualified name now catch io exception ee break this jmdns impl send out else after three queries we can quit this cancel else if this jmdns impl get state dns state canceled this cancel catch throwable e logger log level warning run exception e this jmdns impl recover jmdnsimpl getstate dnsstate currenttimemillis dnsoutgoing dnsoutgoing dnsconstants flags_qr_query addquestion dnsquestion dnsconstants type_ptr dnsconstants class_in jmdnsimpl getservices hasnext serviceinfoimpl serviceinfoimpl addanswer dnsrecord gettype dnsconstants type_ptr dnsconstants class_in dnsconstants dns_ttl getqualifiedname ioexception jmdnsimpl jmdnsimpl getstate dnsstate jmdnsimpl private final int hash code sendable request boolean persistent this persistent persistent this hash code super hash code hashcode sendablerequest hashcode hashcode override public final int hash code return hash code hashcode hashcode protected final boolean persistent get the priority class of the request public abstract short get priority class object container container getpriorityclass objectcontainer public abstract short get priority class object container container public abstract int get retry count getpriorityclass objectcontainer getretrycount choose a key to fetch removes the block number from any internal queues but not the key itself implementors must have a separate queue of block numbers and mapping of block numbers to keys return an object identifying a specific key null indicates no keys available public abstract sendable request item choose key keys fetching locally keys object container container client context context all key identifiers including those not currently eligible to be sent because they are on a cooldown queue requests for them are in progress etc public abstract long count all keys object container container client context context sendablerequestitem choosekey keysfetchinglocally objectcontainer clientcontext countallkeys objectcontainer clientcontext public abstract long count all keys object container container client context context all key identifiers currently eligible to be sent does not include those currently running on the cooldown queue etc public abstract long count sendable keys object container container client context context countallkeys objectcontainer clientcontext countsendablekeys objectcontainer clientcontext get or create a sendable request sender for this object this is a non persistent object used to send the requests see sendable get get sender param container a database handle may be necessary for creating it param context a client context may also be necessary return sendablerequestsender sendableget getsender public abstract sendable request sender get sender object container container client context context if true the request has been cancelled or has completed either way it need not be registered any more is empty on the other hand means there are no queued blocks public abstract boolean is cancelled object container container sendablerequestsender getsender objectcontainer clientcontext isempty iscancelled objectcontainer public abstract boolean is cancelled object container container get client context object this isn t called as frequently as you might expect once on registration and then when there is an error so it doesn t need to be stored on the request itself hence we pass in a container public abstract request client get client object container container iscancelled objectcontainer requestclient getclient objectcontainer public abstract request client get client object container container is this request persistent must not change public final boolean persistent return persistent requestclient getclient objectcontainer get the client request this does need to be cached on the request itself public abstract client requester get client request clientrequest clientrequester getclientrequest public abstract client requester get client request public synchronized random grab array get parent grab array return parent grab array clientrequester getclientrequest randomgrabarray getparentgrabarray parentgrabarray public boolean knows parent grab array return true knowsparentgrabarray public synchronized void set parent grab array random grab array parent object container container parent grab array parent if persistent container store this setparentgrabarray randomgrabarray objectcontainer parentgrabarray public void unregister object container container client context context random grab array arr get parent grab array if arr null if persistent container activate arr 1 arr remove this container else should this be a higher priority if logger should log logger minor this logger minor this cannot unregister this not registered new exception debug client requester cr get client request if persistent container activate cr 1 get scheduler context remove from all requests by client request cr this true container fixme should we deactivate if persistent container deactivate cr 1 objectcontainer clientcontext randomgrabarray getparentgrabarray shouldlog clientrequester getclientrequest getscheduler removefromallrequestsbyclientrequest public abstract client request scheduler get scheduler client context context clientrequestscheduler getscheduler clientcontext public abstract client request scheduler get scheduler client context context is this an ssk for purposes of determining which scheduler to use public abstract boolean isssk clientrequestscheduler getscheduler clientcontext public abstract boolean isssk is this an insert for purposes of determining which scheduler to use public abstract boolean is insert isinsert public abstract boolean is insert requeue after an internal error public abstract void internal error throwable t request scheduler sched object container container client context context boolean persistent isinsert internalerror requestscheduler objectcontainer clientcontext public abstract void internal error throwable t request scheduler sched object container container client context context boolean persistent construct a full set of chosen block s for a persistent request these are transient so we will need to clone keys etc public abstract list persistent chosen block make blocks persistent chosen request request request scheduler sched object container container client context context internalerror requestscheduler objectcontainer clientcontext chosenblock persistentchosenblock makeblocks persistentchosenrequest requestscheduler objectcontainer clientcontext public class darknet connections toadlet extends connections toadlet darknet connections toadlet node n node client core core high level simple client client super n core client darknetconnectionstoadlet connectionstoadlet darknetconnectionstoadlet nodeclientcore highlevelsimpleclient override public string supported methods return get post supportedmethods private static string l10n string string return l10n get string darknet connections toadlet string getstring darknetconnectionstoadlet protected class darknet comparator extends comparator by status darknet comparator string sort by boolean reversed super sort by reversed darknetcomparator comparatorbystatus darknetcomparator sortby sortby override protected int custom compare peer node status first node peer node status second node string sort by if sort by equals name return darknet peer node status first node get name compare to ignore case darknet peer node status second node get name else if sort by equals privnote return darknet peer node status first node get private darknet comment note compare to ignore case darknet peer node status second node get private darknet comment note else return super custom compare first node second node sort by customcompare peernodestatus firstnode peernodestatus secondnode sortby sortby darknetpeernodestatus firstnode getname comparetoignorecase darknetpeernodestatus secondnode getname sortby darknetpeernodestatus firstnode getprivatedarknetcommentnote comparetoignorecase darknetpeernodestatus secondnode getprivatedarknetcommentnote customcompare firstnode secondnode sortby default comparison after taking into account status override protected int last resort compare peer node status first node peer node status second node return darknet peer node status first node get name compare to ignore case darknet peer node status second node get name lastresortcompare peernodestatus firstnode peernodestatus secondnode darknetpeernodestatus firstnode getname comparetoignorecase darknetpeernodestatus secondnode getname override protected comparator peer node status comparator string sort by boolean reversed return new darknet comparator sort by reversed peernodestatus sortby darknetcomparator sortby override protected boolean has name column return true hasnamecolumn override protected void draw name column html node peer row peer node status peer node status name column peer row add child td class peer name add child a href send n2ntm peernode hashcode peer node status hash code darknet peer node status peer node status get name drawnamecolumn htmlnode peerrow peernodestatus peernodestatus peerrow addchild addchild send_n2ntm peernode_hashcode peernodestatus hashcode darknetpeernodestatus peernodestatus getname override protected boolean has private note column return true hasprivatenotecolumn override protected void draw private note column html node peer row peer node status peer node status boolean f proxy javascript enabled private darknet node comment note column darknet peer node status status darknet peer node status peer node status if f proxy javascript enabled peer row add child td class peer private darknet comment note add child input new string type name size maxlength on blur on change value new string text peerprivatenote peer node status hash code 16 250 peer note blur peer note change status get private darknet comment note else peer row add child td class peer private darknet comment note add child input new string type name size maxlength value new string text peerprivatenote peer node status hash code 16 250 status get private darknet comment note drawprivatenotecolumn htmlnode peerrow peernodestatus peernodestatus fproxyjavascriptenabled darknetpeernodestatus darknetpeernodestatus peernodestatus fproxyjavascriptenabled peerrow addchild addchild onblur onchange peerprivatenote_ peernodestatus hashcode peernoteblur peernotechange getprivatedarknetcommentnote peerrow addchild addchild peerprivatenote_ peernodestatus hashcode getprivatedarknetcommentnote override protected simple field set get noderef return node export darknet public field set simplefieldset getnoderef exportdarknetpublicfieldset override protected peer node status get peer node statuses boolean no heavy return node peers get darknet peer node statuses no heavy peernodestatus getpeernodestatuses noheavy getdarknetpeernodestatuses noheavy override protected string get page title string title count string string my name return l10n get string darknet connections toadlet full title new string counts name new string title count string node get my name getpagetitle titlecountstring myname getstring darknetconnectionstoadlet fulltitle titlecountstring getmyname override protected boolean should draw noderef box boolean advanced mode enabled return true shoulddrawnoderefbox advancedmodeenabled override protected boolean show peer actions box return true showpeeractionsbox override protected void draw peer action select box html node peer form boolean advanced mode enabled html node action select peer form add child select new string id name new string action action action select add child option value l10n select action action select add child option value send n2ntm l10n send message to peers action select add child option value update notes l10n update changed privnotes if advanced mode enabled action select add child option value enable enable selected peers action select add child option value disable disable selected peers action select add child option value set burst only on selected peers set burst only only set this if you have a static ip and are not na ted and neither is the peer action select add child option value clear burst only on selected peers clear burst only action select add child option value set listen only on selected peers set listen only not recommended action select add child option value clear listen only on selected peers clear listen only action select add child option value set allow local on selected peers set allow local addresses useful if you are connecting to another node on the same lan action select add child option value clear allow local on selected peers clear allow local addresses action select add child option value set ignore source port on selected peers set ignore source port try this if behind an evil corporate firewall otherwise not recommended action select add child option value clear ignore source port on selected peers clear ignore source port action select add child option value set dont route on selected peers set dont route you shouldn t use that unless you know what you re doing really action select add child option value clear dont route on selected peers clear dont route action select add child option value l10n separator action select add child option value remove l10n remove peers peer form add child input new string type name value new string submit do action l10n go drawpeeractionselectbox htmlnode peerform advancedmodeenabled htmlnode actionselect peerform addchild actionselect addchild selectaction actionselect addchild send_n2ntm sendmessagetopeers actionselect addchild update_notes updatechangedprivnotes advancedmodeenabled actionselect addchild actionselect addchild actionselect addchild set_burst_only burstonly nated actionselect addchild clear_burst_only burstonly actionselect addchild set_listen_only listenonly actionselect addchild clear_listen_only listenonly actionselect addchild set_allow_local allowlocaladdresses actionselect addchild clear_allow_local allowlocaladdresses actionselect addchild set_ignore_source_port ignoresourceport actionselect addchild clear_ignore_source_port ignoresourceport actionselect addchild set_dont_route dontroute actionselect addchild clear_dont_route dontroute actionselect addchild actionselect addchild removepeers peerform addchild doaction override protected string get peer list title return l10n my friends getpeerlisttitle myfriends override protected boolean accept ref posts return true acceptrefposts override protected string default redirect location return friends fixme defaultredirectlocation implement other post actions than adding nodes throws io exception throws toadlet context closed exception throws redirect exception override protected void handle alt post uri uri http request request toadlet context ctx boolean logminor throws toadlet context closed exception io exception redirect exception if request is part set do action request get part as string action 25 equals send n2ntm html node page node ctx get page maker get page node l10n send message title ctx html node content node ctx get page maker get content node page node darknet peer node peer nodes node get darknet connections hash map string string peers new hash map string string for darknet peer node pn peer nodes if request is part set node pn hash code string peer name pn get name string peer hash pn hash code if peers contains key peer hash peers put peer hash peer name n2ntm toadlet createn2ntm send form page node content node ctx peers writehtml reply ctx 200 ok page node generate return else if request is part set do action request get part as string action 25 equals update notes int hashcode integer decode request get param node int value darknet peer node peer nodes node get darknet connections for int i 0 i peer nodes length i if request is part set peerprivatenote peer nodes i hash code if request get part as string peerprivatenote peer nodes i hash code 250 equals peer nodes i get private darknet comment note peer nodes i set private darknet comment note request get part as string peerprivatenote peer nodes i hash code 250 redirect here ctx return else if request is part set do action request get part as string action 25 equals enable int hashcode integer decode request get param node int value darknet peer node peer nodes node get darknet connections for int i 0 i peer nodes length i if request is part set node peer nodes i hash code peer nodes i enable peer redirect here ctx return else if request is part set do action request get part as string action 25 equals disable int hashcode integer decode request get param node int value darknet peer node peer nodes node get darknet connections for int i 0 i peer nodes length i if request is part set node peer nodes i hash code peer nodes i disable peer redirect here ctx return else if request is part set do action request get part as string action 25 equals set burst only int hashcode integer decode request get param node int value darknet peer node peer nodes node get darknet connections for int i 0 i peer nodes length i if request is part set node peer nodes i hash code peer nodes i set burst only true redirect here ctx return else if request is part set do action request get part as string action 25 equals clear burst only int hashcode integer decode request get param node int value darknet peer node peer nodes node get darknet connections for int i 0 i peer nodes length i if request is part set node peer nodes i hash code peer nodes i set burst only false redirect here ctx return else if request is part set do action request get part as string action 25 equals set ignore source port int hashcode integer decode request get param node int value darknet peer node peer nodes node get darknet connections for int i 0 i peer nodes length i if request is part set node peer nodes i hash code peer nodes i set ignore source port true redirect here ctx return else if request is part set do action request get part as string action 25 equals clear ignore source port int hashcode integer decode request get param node int value darknet peer node peer nodes node get darknet connections for int i 0 i peer nodes length i if request is part set node peer nodes i hash code peer nodes i set ignore source port false redirect here ctx return else if request is part set do action request get part as string action 25 equals clear dont route darknet peer node peer nodes node get darknet connections for int i 0 i peer nodes length i if request is part set node peer nodes i hash code peer nodes i set routing status true true redirect here ctx return else if request is part set do action request get part as string action 25 equals set dont route darknet peer node peer nodes node get darknet connections for int i 0 i peer nodes length i if request is part set node peer nodes i hash code peer nodes i set routing status false true redirect here ctx return else if request is part set do action request get part as string action 25 equals set listen only int hashcode integer decode request get param node int value darknet peer node peer nodes node get darknet connections for int i 0 i peer nodes length i if request is part set node peer nodes i hash code peer nodes i set listen only true redirect here ctx return else if request is part set do action request get part as string action 25 equals clear listen only int hashcode integer decode request get param node int value darknet peer node peer nodes node get darknet connections for int i 0 i peer nodes length i if request is part set node peer nodes i hash code peer nodes i set listen only false redirect here ctx return else if request is part set do action request get part as string action 25 equals set allow local int hashcode integer decode request get param node int value darknet peer node peer nodes node get darknet connections for int i 0 i peer nodes length i if request is part set node peer nodes i hash code peer nodes i set allow local addresses true redirect here ctx return else if request is part set do action request get part as string action 25 equals clear allow local int hashcode integer decode request get param node int value darknet peer node peer nodes node get darknet connections for int i 0 i peer nodes length i if request is part set node peer nodes i hash code peer nodes i set allow local addresses false redirect here ctx return else if request is part set remove request is part set do action request get part as string action 25 equals remove if logminor logger minor this remove node darknet peer node peer nodes node get darknet connections for int i 0 i peer nodes length i if request is part set node peer nodes i hash code if peer nodes i time last connection completed system current time millis 1000 60 60 24 7 one week peer nodes i peer node status peer manager peer node status never connected request is part set forceit this node remove peer connection peer nodes i if logminor logger minor this removed node node peer nodes i hash code else if logminor logger minor this refusing to remove node peer nodes i hash code trying to prevent network churn let s display the warning message html node page node ctx get page maker get page node l10n confirm remove node title ctx html node content node ctx get page maker get content node page node html node infobox content node add child ctx get page maker get infobox infobox warning l10n confirm remove node warning title html node content ctx get page maker get content node infobox content add child p add child l10n get string darknet connections toadlet confirm remove node new string name new string peer nodes i get name html node remove form ctx add form child content friends remove confirm form remove form add child input new string type name value new string hidden node peer nodes i hash code remove remove form add child input new string type name value new string submit cancel l10n get string toadlet cancel remove form add child input new string type name value new string submit remove l10n remove remove form add child input new string type name value new string hidden forceit l10n force remove writehtml reply ctx 200 ok page node generate return fixme maybe it breaks multi node removing else if logminor logger minor this part not set node peer nodes i hash code redirect here ctx return else if request is part set accept transfer fixme this is ugly should probably move both this code and the peer node code somewhere darknet peer node peer nodes node get darknet connections for int i 0 i peer nodes length i if request is part set node peer nodes i hash code long id long parse long request get part as string id 32 fixme handle number format exception peer nodes i accept transfer id break redirect here ctx return else if request is part set reject transfer ioexception toadletcontextclosedexception redirectexception handlealtpost httprequest toadletcontext toadletcontextclosedexception ioexception redirectexception ispartset doaction getpartasstring send_n2ntm htmlnode pagenode getpagemaker getpagenode sendmessagetitle htmlnode contentnode getpagemaker getcontentnode pagenode darknetpeernode peernodes getdarknetconnections hashmap hashmap darknetpeernode peernodes ispartset node_ hashcode peer_name getname peer_hash hashcode containskey peer_hash peer_hash peer_name n2ntmtoadlet createn2ntmsendform pagenode contentnode writehtmlreply pagenode ispartset doaction getpartasstring update_notes getparam intvalue darknetpeernode peernodes getdarknetconnections peernodes ispartset peerprivatenote_ peernodes hashcode getpartasstring peerprivatenote_ peernodes hashcode peernodes getprivatedarknetcommentnote peernodes setprivatedarknetcommentnote getpartasstring peerprivatenote_ peernodes hashcode redirecthere ispartset doaction getpartasstring getparam intvalue darknetpeernode peernodes getdarknetconnections peernodes ispartset node_ peernodes hashcode peernodes enablepeer redirecthere ispartset doaction getpartasstring getparam intvalue darknetpeernode peernodes getdarknetconnections peernodes ispartset node_ peernodes hashcode peernodes disablepeer redirecthere ispartset doaction getpartasstring set_burst_only getparam intvalue darknetpeernode peernodes getdarknetconnections peernodes ispartset node_ peernodes hashcode peernodes setburstonly redirecthere ispartset doaction getpartasstring clear_burst_only getparam intvalue darknetpeernode peernodes getdarknetconnections peernodes ispartset node_ peernodes hashcode peernodes setburstonly redirecthere ispartset doaction getpartasstring set_ignore_source_port getparam intvalue darknetpeernode peernodes getdarknetconnections peernodes ispartset node_ peernodes hashcode peernodes setignoresourceport redirecthere ispartset doaction getpartasstring clear_ignore_source_port getparam intvalue darknetpeernode peernodes getdarknetconnections peernodes ispartset node_ peernodes hashcode peernodes setignoresourceport redirecthere ispartset doaction getpartasstring clear_dont_route darknetpeernode peernodes getdarknetconnections peernodes ispartset node_ peernodes hashcode peernodes setroutingstatus redirecthere ispartset doaction getpartasstring set_dont_route darknetpeernode peernodes getdarknetconnections peernodes ispartset node_ peernodes hashcode peernodes setroutingstatus redirecthere ispartset doaction getpartasstring set_listen_only getparam intvalue darknetpeernode peernodes getdarknetconnections peernodes ispartset node_ peernodes hashcode peernodes setlistenonly redirecthere ispartset doaction getpartasstring clear_listen_only getparam intvalue darknetpeernode peernodes getdarknetconnections peernodes ispartset node_ peernodes hashcode peernodes setlistenonly redirecthere ispartset doaction getpartasstring set_allow_local getparam intvalue darknetpeernode peernodes getdarknetconnections peernodes ispartset node_ peernodes hashcode peernodes setallowlocaladdresses redirecthere ispartset doaction getpartasstring clear_allow_local getparam intvalue darknetpeernode peernodes getdarknetconnections peernodes ispartset node_ peernodes hashcode peernodes setallowlocaladdresses redirecthere ispartset ispartset doaction getpartasstring darknetpeernode peernodes getdarknetconnections peernodes ispartset node_ peernodes hashcode peernodes timelastconnectioncompleted currenttimemillis peernodes peernodestatus peermanager peer_node_status_never_connected ispartset removepeerconnection peernodes node_ peernodes hashcode node_ peernodes hashcode htmlnode pagenode getpagemaker getpagenode confirmremovenodetitle htmlnode contentnode getpagemaker getcontentnode pagenode htmlnode contentnode addchild getpagemaker getinfobox confirmremovenodewarningtitle htmlnode getpagemaker getcontentnode addchild addchild getstring darknetconnectionstoadlet confirmremovenode peernodes getname htmlnode removeform addformchild removeconfirmform removeform addchild node_ peernodes hashcode removeform addchild getstring removeform addchild removeform addchild forceremove writehtmlreply pagenode node_ peernodes hashcode redirecthere ispartset accepttransfer peernode darknetpeernode peernodes getdarknetconnections peernodes ispartset node_ peernodes hashcode parselong getpartasstring numberformatexception peernodes accepttransfer redirecthere ispartset rejecttransfer private void redirect here toadlet context ctx throws toadlet context closed exception io exception multi value table string string headers new multi value table string string headers put location friends ctx send reply headers 302 found headers null 0 redirecthere toadletcontext toadletcontextclosedexception ioexception multivaluetable multivaluetable sendreplyheaders override protected boolean is opennet return false isopennet override simple column end column headers boolean advanced mode return null simplecolumn endcolumnheaders advancedmode private int threshold 2 public erode filter new color 0xffffffff erodefilter newcolor set the threshold the number of neighbouring pixels for dilation to occur param threshold the new threshold see get threshold public void set threshold int threshold this threshold threshold getthreshold setthreshold return the threshold the number of neighbouring pixels for dilation to occur return the current threshold see set threshold public int get threshold return threshold setthreshold getthreshold override protected int filter pixels int width int height int in pixels rectangle transformed space int out pixels new int width height for int i 0 i iterations i int index 0 if i 0 int t in pixels in pixels out pixels out pixels t for int y 0 y height y for int x 0 x width x int pixel in pixels y width x if black function is black pixel int neighbours 0 for int dy 1 dy 1 dy int iy y dy int ioffset if 0 iy iy height ioffset iy width for int dx 1 dx 1 dx int ix x dx if dy 0 dx 0 0 ix ix width int rgb in pixels ioffset ix if black function is black rgb neighbours if neighbours threshold if colormap null pixel colormap get color float i iterations else pixel new color out pixels index pixel return out pixels filterpixels inpixels transformedspace outpixels inpixels inpixels outpixels outpixels inpixels blackfunction isblack inpixels blackfunction isblack getcolor newcolor outpixels outpixels override public string to string return binary erode tostring public static final int max compressed data length data length 4 override public string to string return super to string chk chk max_compressed_data_length data_length tostring tostring return the header for this key do not modify this data public byte get headers return headers getheaders return the actual data for this key do not modify this data public byte get data return data getdata public static chk block construct byte data byte header throws chk verify exception return new chk block data header null true key algo aes pcfb 256 sha256 chkblock chkverifyexception chkblock algo_aes_pcfb_256_sha256 public chk block byte data2 byte header2 nodechk key throws chk verify exception this data2 header2 key key crypto algorithm chkblock chkverifyexception cryptoalgorithm public chk block byte data2 byte header2 nodechk key byte crypto algorithm throws chk verify exception this data2 header2 key true crypto algorithm chkblock cryptoalgorithm chkverifyexception cryptoalgorithm public chk block byte data2 byte header2 nodechk key boolean verify byte crypto algorithm throws chk verify exception data data2 headers header2 if headers length total headers length throw new illegal argument exception wrong length headers length should be total headers length hash identifier short headers 0 0xff 8 headers 1 0xff logger debug chk block class data length data length header length header length if key null verify this chk key hash code key hash code fields hash code data fields hash code headers crypto algorithm return minimal verification check the hash if hash identifier hash sha256 throw new chk verify exception hash not sha 256 message digest md sha256 get message digest md update headers md update data byte hash md digest sha256 return message digest md if key null chk new nodechk hash crypto algorithm else chk key byte check chk routing key if java util arrays equals hash check throw new chk verify exception hash does not verify otherwise it checks out hash code chk hash code fields hash code data fields hash code headers crypto algorithm chkblock cryptoalgorithm chkverifyexception total_headers_length illegalargumentexception total_headers_length hashidentifier chkblock hashcode hashcode hashcode hashcode cryptoalgorithm hashidentifier hash_sha256 chkverifyexception messagedigest getmessagedigest returnmessagedigest cryptoalgorithm routingkey chkverifyexception hashcode hashcode hashcode hashcode cryptoalgorithm public key get key return chk getkey public byte get raw headers return headers getrawheaders public byte get raw data return data getrawdata public byte get pubkey bytes return null getpubkeybytes public byte get full key return get key get full key getfullkey getkey getfullkey public byte get routing key return get key get routing key getroutingkey getkey getroutingkey override public int hash code return hash code hashcode hashcode override public boolean equals object o if o instanceof chk block return false chk block block chk block o if chk equals block chk return false if arrays equals data block data return false if arrays equals headers block headers return false if hash identifier block hash identifier return false return true chkblock chkblock chkblock hashidentifier hashidentifier public boolean object can new object container container storing an ssk block is not supported there are some complications so lets not implement this since we don t actually use the functionality atm the major problems are in both chk block and ssk block who is responsible for deleting the node keys we have to have them in the objects in ssk block who is responsible for deleting the dsa public key and the dsa group a group might be unique or might be shared between very many ss ks especially in the second case we don t want to just copy every time even for transient uses the best solution may be to copy in object can new but even then callers to the relevant getter methods may be a worry throw new unsupported operation exception block set storage in database not supported objectcannew objectcontainer sskblock chkblock sskblock sskblock dsapublickey dsagroup ssks objectcannew unsupportedoperationexception final random access file raf public random access file wrapper random access file raf this raf raf randomaccessfile randomaccessfilewrapper randomaccessfile public random access file wrapper file filename string mode throws file not found exception raf new random access file filename mode randomaccessfilewrapper filenotfoundexception randomaccessfile public void pread long file offset byte buf int buf offset int length throws io exception synchronized this raf seek file offset raf read fully buf buf offset length fileoffset bufoffset ioexception fileoffset readfully bufoffset public void pwrite long file offset byte buf int buf offset int length throws io exception synchronized this raf seek file offset raf write buf buf offset length fileoffset bufoffset ioexception fileoffset bufoffset public long size throws io exception return raf length ioexception public void close try raf close catch io exception e logger error this could not close raf e for this e ioexception public bookmark item freeneturi k string n string d boolean has an activelink user alert manager uam throws malformedurl exception this key k this name n this desc d this has an activelink has an activelink this alerts uam alert new bookmark updated user alert assert name null assert key null bookmarkitem hasanactivelink useralertmanager malformedurlexception hasanactivelink hasanactivelink bookmarkupdateduseralert public bookmark item string line user alert manager uam throws malformedurl exception string result line split this name result 0 this desc result 1 this has an activelink fields string to bool result 2 false this key new freeneturi result 3 this alerts uam this alert new bookmark updated user alert assert name null assert key null bookmarkitem useralertmanager malformedurlexception hasanactivelink stringtobool bookmarkupdateduseralert public bookmark item simple field set sfs user alert manager uam throws fs parse exception malformedurl exception this name sfs get name if name null name this desc sfs get description if desc null desc this has an activelink sfs get boolean has an activelink this key new freeneturi sfs get uri this alerts uam this alert new bookmark updated user alert bookmarkitem simplefieldset useralertmanager fsparseexception malformedurlexception hasanactivelink getboolean hasanactivelink bookmarkupdateduseralert private class bookmark updated user alert extends abstract user alert public bookmark updated user alert super true null null null null user alert minor false null true null bookmarkupdateduseralert abstractuseralert bookmarkupdateduseralert useralert override public string get title return l10n bookmark updated title name name gettitle bookmarkupdatedtitle override public string get text return l10n bookmark updated new string name edition new string name long to string key get suggested edition gettext bookmarkupdated tostring getsuggestededition override public html node gethtml text html node n new html node div l10n addl10n substitution n bookmark item bookmark updated with link new string link link name edition new string a href key to string a html encoder encode name long to string key get suggested edition return n htmlnode gethtmltext htmlnode htmlnode addl10nsubstitution bookmarkitem bookmarkupdatedwithlink tostring htmlencoder tostring getsuggestededition override public boolean is valid synchronized bookmark item this return updated isvalid bookmarkitem override public void is valid boolean validity if validity return disable bookmark isvalid disablebookmark override public string dismiss button text return l10n delete bookmark update notification dismissbuttontext deletebookmarkupdatenotification override public void on dismiss disable bookmark ondismiss disablebookmark override public string get short text return l10n bookmark updated short name name getshorttext bookmarkupdatedshort override public boolean is event notification return true iseventnotification private synchronized void disable bookmark updated false alerts unregister alert disablebookmark private string l10n string key return l10n get string bookmark item key getstring bookmarkitem private string l10n string key string pattern string value return l10n get string bookmark item key new string pattern new string value getstring bookmarkitem private string l10n string key string patterns string values return l10n get string bookmark item key patterns values getstring bookmarkitem private synchronized void enable bookmark if updated return updated true alerts register alert enablebookmark public string get key return key to string getkey tostring public synchronized freeneturi geturi return key public synchronized void update freeneturi uri boolean has an activelink string description this key uri this desc description this has an activelink has an activelink hasanactivelink hasanactivelink hasanactivelink public synchronized string get key type return key get key type getkeytype getkeytype override public string get name return equals name l10n unnamed bookmark name getname unnamedbookmark override public string to string return this name this desc null this desc this has an activelink this key to string tostring hasanactivelink tostring public synchronized void set edition long ed node client core node if key get suggested edition ed return key key set suggested edition ed enable bookmark setedition nodeclientcore getsuggestededition setsuggestededition enablebookmark public usk getusk throws malformedurl exception return usk create key malformedurlexception override public int hash code int hash super hash code hash 31 hash this key set suggested edition 0 hash code hash 31 hash this has an activelink 1 0 hash 31 hash this desc null this desc hash code 0 return hash hashcode hashcode setsuggestededition hashcode hasanactivelink hashcode override public boolean equals object o if o this return true if o instanceof bookmark item bookmark item b bookmark item o if super equals o return false if b key equals key if b key get key type equals usk if b key set suggested edition key get suggested edition equals key return false else return false if b alerts alerts return false belongs to a different node if b has an activelink has an activelink return false if b desc desc return true if b desc null desc null return false if b desc equals desc return false return true else return false bookmarkitem bookmarkitem bookmarkitem getkeytype setsuggestededition getsuggestededition hasanactivelink hasanactivelink public boolean has an activelink return has an activelink hasanactivelink hasanactivelink public string get description return desc null desc getdescription override public simple field set get simple field set simple field set sfs new simple field set true sfs put single name name sfs put single description desc sfs put has an activelink has an activelink sfs put single uri key to string return sfs simplefieldset getsimplefieldset simplefieldset simplefieldset putsingle putsingle hasanactivelink hasanactivelink putsingle tostring split file fetcher sub segment split file fetcher segment segment client requester parent int retry count super parent this segment segment this retry count retry count if parent null throw new null pointer exception ctx segment block fetch context block nums new vector integer logminor logger should log logger minor this splitfilefetchersubsegment splitfilefetchersegment clientrequester retrycount retrycount retrycount nullpointerexception blockfetchcontext blocknums shouldlog override public boolean dont cache object container container if persistent container activate ctx 1 if ctx null if segment null logger error this ctx null but segment null else logger error this ctx null and segment null on this return ctx cache local requests dontcache objectcontainer cachelocalrequests override public fetch context get context return ctx fetchcontext getcontext override public sendable request item choose key keys fetching locally keys object container container client context context if cancelled return null return get random block num keys context container sendablerequestitem choosekey keysfetchinglocally objectcontainer clientcontext getrandomblocknum override public client key get key object token object container container if persistent container activate this 1 container activate segment 1 synchronized segment if cancelled if logminor logger minor this segment is finishing when getting key token on this return null client key key segment get block key my sendable request item token x container if key null if segment is finished container logger error this segment finished but didn t tell us this else if segment is finishing container logger error this segment finishing but didn t tell us this else logger error this segment not finishing yet still returns null for get key token for this new exception debug return key clientkey getkey objectcontainer clientkey getblockkey mysendablerequestitem isfinished isfinishing getkey fetch the array from the segment because we need to include all keys especially those on cooldown queues this is important when unregistering override public long count all keys object container container client context context if persistent container activate this 1 container activate segment 1 j16sdiz 22 dec 2008 client request schedular remove pending keys call this to get a list of request to be removed fixme client request schedular remove pending keys is leaking what s missing here return segment get key numbers at retry level retry count length countallkeys objectcontainer clientcontext clientrequestschedular removependingkeys clientrequestschedular removependingkeys getkeynumbersatretrylevel retrycount just those keys which are eligible to be started now override public long count sendable keys object container container client context context if persistent container activate this 1 container activate block nums 1 clean block nums container return block nums size countsendablekeys objectcontainer clientcontext blocknums cleanblocknums blocknums private void clean block nums object container container synchronized segment int init size block nums size integer prev null for int i 0 i block nums size i integer x block nums get i if x prev x equals prev block nums remove i i if persistent container delete x else prev x if block nums size init size logger error this cleaned block number list duplicates was init size now block nums size cleanblocknums objectcontainer initsize blocknums blocknums blocknums blocknums blocknums initsize initsize blocknums private sendable request item get random block num keys fetching locally keys client context context object container container if persistent container activate this 1 container activate block nums 1 container activate segment 1 logminor logger should log logger minor this synchronized segment if block nums is empty if logminor logger minor this no blocks to remove return null for int i 0 i 10 i integer ret int x if block nums size 0 return null x context random next int block nums size ret block nums get x int num ret key key segment get block node key num container if key null if segment is finishing container segment is finished container return null if segment have block num container logger error this already have block ret but was in block nums on this else logger error this key is null for block ret for this continue if keys has key key continue if logminor logger minor this removing block x of block nums size 1 ret on this return new my sendable request item num return null sendablerequestitem getrandomblocknum keysfetchinglocally clientcontext objectcontainer blocknums shouldlog blocknums isempty blocknums nextint blocknums blocknums getblocknodekey isfinishing isfinished haveblock blocknums haskey blocknums mysendablerequestitem private static class my sendable request item implements sendable request item final int x my sendable request item int x this x x mysendablerequestitem sendablerequestitem mysendablerequestitem this x x public void dump ignore we will be gc ed override public boolean has valid keys keys fetching locally keys object container container client context context if persistent container activate this 1 container activate block nums 1 container activate segment 1 boolean has set false boolean retval false synchronized segment for int i 0 i 10 i integer ret int x if block nums is empty break x context random next int block nums size ret block nums get x int block ret key key segment get block node key block container if key null if segment is finishing container segment is finished container return false if segment have block block container logger error this already have block ret but was in block nums on this in has valid keys else logger error this key is null for block ret for this in has valid keys block nums remove x if persistent container delete ret if has set has set true container store block nums continue if keys has key key continue retval true break if persistent container deactivate block nums 5 container deactivate segment 1 return retval hasvalidkeys keysfetchinglocally objectcontainer clientcontext blocknums hasset blocknums isempty nextint blocknums blocknums getblocknodekey isfinishing isfinished haveblock blocknums hasvalidkeys hasvalidkeys blocknums hasset hasset blocknums haskey blocknums override public boolean ignore store return ctx ignore store ignorestore ignorestore public void on failure bulk call failure item items object container container client context context fetch exception fetch exceptions new fetch exception items length int count fatal 0 if persistent container activate block nums 2 for int i 0 i items length i fetch exceptions i translate exception items i e if fetch exceptions i is fatal count fatal remove block num my sendable request item items i token x container true if persistent container store block nums container deactivate block nums 2 container activate segment 1 container activate parent 1 container activate segment errors 1 if parent is cancelled if logger should log logger minor this logger minor this failing cancelled fail the segment segment fail new fetch exception fetch exception cancelled container context false fixme do we need to free the key num s or will that happen later anyway return for int i 0 i fetch exceptions length i segment errors inc fetch exceptions i get mode int non fatal exceptions items length count fatal int block numbers new int non fatal exceptions if count fatal 0 fetch exception new fetch exceptions new fetch exception items length count fatal call the fatal callbacks directly int x 0 for int i 0 i items length i int block num my sendable request item items i token x if fetch exceptions i is fatal segment on fatal failure fetch exceptions i block num this container context else block numbers x block num new fetch exceptions x fetch exceptions i x fetch exceptions new fetch exceptions else for int i 0 i block numbers length i block numbers i my sendable request item items i token x segment on non fatal failure fetch exceptions block numbers this container context if persistent container deactivate segment 1 container deactivate parent 1 container deactivate segment errors 1 onfailure bulkcallfailureitem objectcontainer clientcontext fetchexception fetchexceptions fetchexception countfatal blocknums fetchexceptions translateexception fetchexceptions isfatal countfatal removeblocknum mysendablerequestitem blocknums blocknums iscancelled shouldlog fetchexception fetchexception keynum fetchexceptions fetchexceptions getmode nonfatalexceptions countfatal blocknumbers nonfatalexceptions countfatal fetchexception newfetchexceptions fetchexception countfatal blocknum mysendablerequestitem fetchexceptions isfatal onfatalfailure fetchexceptions blocknum blocknumbers blocknum newfetchexceptions fetchexceptions fetchexceptions newfetchexceptions blocknumbers blocknumbers mysendablerequestitem onnonfatalfailure fetchexceptions blocknumbers fixme refactor this out to a common method see simple single file fetcher private fetch exception translate exception low level get exception e switch e code case low level get exception data not found case low level get exception data not found in store return new fetch exception fetch exception data not found case low level get exception recently failed return new fetch exception fetch exception recently failed case low level get exception decode failed return new fetch exception fetch exception block decode error case low level get exception internal error return new fetch exception fetch exception internal error case low level get exception rejected overload return new fetch exception fetch exception rejected overload case low level get exception route not found return new fetch exception fetch exception route not found case low level get exception transfer failed return new fetch exception fetch exception transfer failed case low level get exception verify failed return new fetch exception fetch exception block decode error case low level get exception cancelled return new fetch exception fetch exception cancelled default logger error this unknown low level get exception code e code return new fetch exception fetch exception internal error unknown error code e code simplesinglefilefetcher fetchexception translateexception lowlevelgetexception lowlevelgetexception data_not_found lowlevelgetexception data_not_found_in_store fetchexception fetchexception data_not_found lowlevelgetexception recently_failed fetchexception fetchexception recently_failed lowlevelgetexception decode_failed fetchexception fetchexception block_decode_error lowlevelgetexception internal_error fetchexception fetchexception internal_error lowlevelgetexception rejected_overload fetchexception fetchexception rejected_overload lowlevelgetexception route_not_found fetchexception fetchexception route_not_found lowlevelgetexception transfer_failed fetchexception fetchexception transfer_failed lowlevelgetexception verify_failed fetchexception fetchexception block_decode_error lowlevelgetexception fetchexception fetchexception lowlevelgetexception fetchexception fetchexception internal_error translate it then call the real on failure override public void on failure low level get exception e object token object container container client context context if logminor logger minor this on failure e token on this on failure translate exception e token container context onfailure onfailure lowlevelgetexception objectcontainer clientcontext onfailure onfailure translateexception real on failure protected void on failure fetch exception e object token object container container client context context if persistent container activate segment 1 container activate parent 1 container activate segment errors 1 boolean force fatal false if parent is cancelled if logger should log logger minor this logger minor this failing cancelled e new fetch exception fetch exception cancelled force fatal true segment errors inc e get mode if e is fatal token null segment fail e container context false else if e is fatal force fatal segment on fatal failure e my sendable request item token x this container context else segment on non fatal failure e my sendable request item token x this container context remove block num my sendable request item token x container false if persistent container deactivate segment 1 container deactivate parent 1 container deactivate segment errors 1 onfailure onfailure fetchexception objectcontainer clientcontext forcefatal iscancelled shouldlog fetchexception fetchexception forcefatal getmode isfatal isfatal forcefatal onfatalfailure mysendablerequestitem onnonfatalfailure mysendablerequestitem removeblocknum mysendablerequestitem protected void on success bucket data boolean from store integer token int block no client key block block object container container client context context if persistent container activate this 1 container activate segment 1 container activate parent 1 if parent is cancelled data free if persistent data remove from container on failure new fetch exception fetch exception cancelled token container context return segment on success data block no block container context this onsuccess fromstore blockno clientkeyblock objectcontainer clientcontext iscancelled removefrom onfailure fetchexception fetchexception onsuccess blockno convert a client key block to a bucket if an error occurs report it via on failure and return null protected bucket extract client key block block object token object container container client context context bucket data try data block decode context get bucket factory persistent int math min ctx max output length integer max value false catch key decode exception e1 if logger should log logger minor this logger minor this decode failure e1 e1 on failure new fetch exception fetch exception block decode error e1 get message token container context return null catch too big exception e on failure new fetch exception fetch exception too big e get message token container context return null catch io exception e logger error this could not capture data disk full e e on failure new fetch exception fetch exception bucket error e token container context return null if logger should log logger minor this logger minor this data null could not decode null decoded data size bytes return data clientkeyblock onfailure clientkeyblock objectcontainer clientcontext getbucketfactory maxoutputlength max_value keydecodeexception shouldlog onfailure fetchexception fetchexception block_decode_error getmessage toobigexception onfailure fetchexception fetchexception too_big getmessage ioexception onfailure fetchexception fetchexception bucket_error shouldlog override public request client get client object container container if persistent container activate parent 1 return parent get client requestclient getclient objectcontainer getclient override public client requester get client request return parent clientrequester getclientrequest override public short get priority class object container container if persistent container activate parent 1 return parent priority class getpriorityclass objectcontainer priorityclass override public int get retry count return retry count getretrycount retrycount override public boolean is cancelled object container container if persistent container activate parent 1 container activate segment 1 synchronized segment return parent cancelled iscancelled objectcontainer public boolean is empty object container container if persistent container activate this 1 container activate block nums 1 synchronized segment return cancelled block nums is empty isempty objectcontainer blocknums blocknums isempty override public boolean isssk not allowed in splitfiles return false public void add all int blocks object container container client context context boolean dont complain on dupes int list new int blocks for int i 0 i blocks i list i i add all list container context dont complain on dupes addall objectcontainer clientcontext dontcomplainondupes addall dontcomplainondupes public void add all int blocks object container container client context context boolean dont complain on dupes if persistent container activate segment 1 container activate block nums 1 boolean logminor logger should log logger minor this if logminor logger minor this adding blocks blocks to this synchronized segment if cancelled throw new illegal state exception adding blocks to already cancelled this for int x 0 x blocks length x int i blocks x integer ii integer value of i if block nums contains ii if dont complain on dupes logger error this block numbers already contain block i else if logminor logger minor this block numbers already contain block i else block nums add ii if persistent container store block nums addall objectcontainer clientcontext dontcomplainondupes blocknums shouldlog illegalstateexception valueof blocknums dontcomplainondupes blocknums blocknums return true if the caller should schedule public boolean add int block no object container container client context context boolean dont complain on dupes if persistent container activate segment 1 container activate block nums 1 boolean logminor logger should log logger minor this if logminor logger minor this adding block block no to this if block no 0 throw new illegal argument exception integer i integer value of block no boolean schedule true synchronized segment if cancelled throw new illegal state exception adding block block no to already cancelled this if block nums contains i if dont complain on dupes logger error this block numbers already contain block block no else if logminor logger minor this block numbers already contain block block no else block nums add i race condition starter thread sees there is only one block on us so removes us another thread adds a block we don t schedule as we now have two blocks starter thread removes us other blocks may be added later but we are never rescheduled fixing this by only removing the sendable request after we ve removed the block is nontrivial with the current code so what we do here is simply check whether we are registered instead of checking whether block nums size 1 as we used to if schedule get parent grab array null if logminor logger minor this already registered not scheduling block nums size block nums schedule false if persistent container store block nums return schedule blockno objectcontainer clientcontext dontcomplainondupes blocknums shouldlog blockno blockno illegalargumentexception valueof blockno illegalstateexception blockno blocknums dontcomplainondupes blockno blockno blocknums sendablerequest blocknums getparentgrabarray blocknums blocknums blocknums override public string to string return super to string retry count segment block nums null null string value of block nums size tempid object hash tostring tostring retrycount blocknums valueof blocknums objecthash if there are no more blocks cancel the sub segment remove it from the segment and return true the caller must call kill true true else return false param container param context return public boolean possibly remove from parent object container container client context context if persistent container activate this 1 container activate segment 1 container activate block nums 1 if logminor logger minor this possibly removing from parent this synchronized segment if block nums is empty if persistent container deactivate block nums 1 return false if logminor logger minor this definitely removing from parent this if segment maybe remove seg this container if persistent container deactivate block nums 1 return false cancelled true return true subsegment possiblyremovefromparent objectcontainer clientcontext blocknums blocknums isempty blocknums mayberemoveseg blocknums public void on got key key key key block block object container container client context context if persistent container activate this 1 container activate segment 1 container activate block nums 1 if logminor logger minor this on got key key find and remove block if it is on this subsegment however it may have been removed already int block no synchronized segment for int i 0 i block nums size i integer token block nums get i int num token key k segment get block node key num container if k null k equals key block nums remove i if persistent container delete token break block no segment get block number key container if block no 1 logger minor this no block found for key key on this return integer token integer value of block no clientchk ckey segment get block key block no container clientchk block cb try cb new clientchk block chk block block ckey catch chk verify exception e on failure new fetch exception fetch exception block decode error e token container context return bucket data extract cb token container context if data null return if cb is metadata on success data false token token int value cb container context else on failure new fetch exception fetch exception invalid metadata metadata where expected data token container context ongotkey keyblock objectcontainer clientcontext blocknums ongotkey blockno blocknums blocknums getblocknodekey blocknums blockno getblocknumber blockno valueof blockno getblockkey blockno clientchkblock clientchkblock chkblock chkverifyexception onfailure fetchexception fetchexception block_decode_error ismetadata onsuccess intvalue onfailure fetchexception fetchexception invalid_metadata terminate a subsegment called by the segment which will have already removed the subsegment from the list will delete the object from the database if persistent public void kill object container container client context context boolean dont deactivate seg boolean cancelled already if persistent container activate segment 1 container activate block nums 1 if logminor logger minor this killing this do unregister first so can get and unregister each key and avoid a memory leak unregister container context integer old nums null synchronized segment if cancelled already if cancelled logger error this should be cancelled already this new exception error cancelled true if block nums is empty logger error this block nums not empty on this block nums new exception error else if cancelled return cancelled true if persistent old nums block nums to array new integer block nums size block nums clear if persistent old nums null old nums length 0 for integer i old nums container delete i if persistent remove from container context dont deactivate seg objectcontainer clientcontext dontdeactivateseg cancelledalready blocknums oldnums cancelledalready blocknums isempty blocknums oldnums blocknums toarray blocknums blocknums oldnums oldnums oldnums removefrom dontdeactivateseg public void remove from object container container client context context boolean dont deactivate seg container activate segment 1 container activate block nums 1 synchronized segment if cancelled logger error this removing when not cancelled on this new exception error cancelled true if block nums is empty logger error this removing when block nums not empty on this new exception error for integer i block nums container delete i block nums clear container delete block nums container delete this if dont deactivate seg container deactivate segment 1 we do not need to call sendable get as it has no internal data structures that need deleting removefrom objectcontainer clientcontext dontdeactivateseg blocknums blocknums isempty blocknums blocknums blocknums blocknums dontdeactivateseg sendableget override public long get cooldown wakeup object token object container container if persistent container activate this 1 container activate segment 1 long ret segment get cooldown wakeup my sendable request item token x return ret getcooldownwakeup objectcontainer getcooldownwakeup mysendablerequestitem override public void requeue after cooldown key key long time object container container client context context if persistent container activate segment 1 if logger should log logger minor this logger minor this requeueing after cooldown key for this if segment requeue after cooldown key time container context this logger error this key was not wanted after cooldown key for this in requeue after cooldown if persistent container deactivate segment 1 requeueaftercooldown objectcontainer clientcontext shouldlog requeueaftercooldown requeueaftercooldown override public long get cooldown wakeup by key key key object container container only deactivate if was deactivated in the first place see the remove pending key stack trace segment is the listener getter boolean activated false if persistent activated container ext is active segment if activated container activate segment 1 long ret segment get cooldown wakeup by key key container if persistent if activated container deactivate segment 1 return ret getcooldownwakeupbykey objectcontainer removependingkey isactive getcooldownwakeupbykey override public void reset cooldown times object container container if persistent container activate this 1 container activate segment 1 synchronized segment segment reset cooldown times block nums to array new integer block nums size resetcooldowntimes objectcontainer resetcooldowntimes blocknums toarray blocknums public void reschedule object container container client context context try get scheduler context register null new sendable get this persistent true container segment block fetch context blocks true catch key listener construction exception e logger error this impossible e on this e objectcontainer clientcontext getscheduler sendableget blockfetchcontext keylistenerconstructionexception public boolean remove block num int block num object container container boolean caller activates and sets if logminor logger minor this removing block block num from this if persistent caller activates and sets container activate block nums 2 boolean found false synchronized segment for int i 0 i block nums size i integer token block nums get i int num token if num block num block nums remove i if persistent container delete token if logminor logger minor this removed block block num from this found true break if persistent caller activates and sets container store block nums container deactivate block nums 2 return found removeblocknum blocknum objectcontainer calleractivatesandsets blocknum calleractivatesandsets blocknums blocknums blocknums blocknum blocknums blocknum calleractivatesandsets blocknums blocknums public void remove block nums int block nos object container container if persistent container activate block nums 2 boolean store false for int i 0 i block nos length i store remove block num block nos i container true if persistent if store container store block nums container deactivate block nums 2 removeblocknums blocknos objectcontainer blocknums blocknos removeblocknum blocknos blocknums blocknums override public list persistent chosen block make blocks persistent chosen request request request scheduler sched object container container client context context if persistent container activate segment 1 container activate block nums 1 integer block numbers synchronized this block numbers block nums to array new integer block nums size array list persistent chosen block blocks new array list persistent chosen block arrays sort block numbers int prev block number 1 for int i 0 i block numbers length i int block number block numbers i if block number prev block number logger error this duplicate block number in make blocks in this two copies of block number continue prev block number block number client key key segment get block key block number container if key null if logminor logger minor this block block number is null maybe race condition continue key key clone key key k key get node key persistent chosen block block new persistent chosen block false request new my sendable request item block number k key sched if logminor logger minor this created block block for block number block number on this blocks add block blocks trim to size if persistent container deactivate segment 1 container deactivate block nums 1 return blocks persistentchosenblock makeblocks persistentchosenrequest requestscheduler objectcontainer clientcontext blocknums blocknumbers blocknumbers blocknums toarray blocknums arraylist persistentchosenblock arraylist persistentchosenblock blocknumbers prevblocknumber blocknumbers blocknumber blocknumbers blocknumber prevblocknumber makeblocks blocknumber prevblocknumber blocknumber clientkey getblockkey blocknumber blocknumber clonekey getnodekey persistentchosenblock persistentchosenblock mysendablerequestitem blocknumber blocknumber trimtosize blocknums override public key list keys object container container boolean activated false if persistent activated container ext is active segment if activated container activate segment 1 key keys segment list keys container if persistent activated container deactivate segment 1 return keys listkeys objectcontainer isactive listkeys public int object hash return super hash code objecthash hashcode public boolean object can store object container container if block nums null throw new null pointer exception storing this but block nums null return true objectcanstore objectcontainer blocknums nullpointerexception blocknums override public void pre register object container container client context context boolean to network if to network return boolean deactivate false if persistent deactivate container ext is active parent container activate parent 1 parent to network container context if deactivate container deactivate parent 1 preregister objectcontainer clientcontext tonetwork tonetwork isactive tonetwork static boolean disable false dns requester node node this node node dnsrequester void start logger normal this starting dns requester system out println starting dns requester node executor execute this dns requester thread for node get darknet port number dnsrequester dnsrequester dnsrequester getdarknetportnumber public void run freenet support logger os thread logpid this while true try real run catch out of memory error e oom handler handleoom e system err println will retry above failed operation catch throwable t logger error this caught in dns requester t t osthread realrun outofmemoryerror oomhandler dnsrequester private void real run peer node nodes node peers my peers long now system current time millis if now last log time 1000 if logger should log logger minor this logger minor this processing dns requests log rate limited last log time now for int i 0 i nodes length i logger minor this node nodes i if nodes i is connected not connected try new dns lookup logger minor this doing lookup on nodes i of nodes length nodes i maybe update handshakei ps false try synchronized this wait 10000 sleep 10s catch interrupted exception e ignore just wake up just sleeping to not busy wait anyway realrun peernode mypeers currenttimemillis lastlogtime shouldlog lastlogtime isconnected maybeupdatehandshakeips interruptedexception public void force run synchronized this notify all forcerun notifyall public void run if should write peers should write peers false write peers inner node ps queue timed job write peers runnable min writepeers delay shouldwritepeers shouldwritepeers writepeersinner queuetimedjob writepeersrunnable min_writepeers_delay create a peer manager by reading a list of peers from a file param node param filename public peer manager node node logger normal this creating peer manager logminor logger should log logger minor this peer node statuses new hash map integer hash set peer node peer node statuses darknet new hash map integer hash set peer node peer node routing backoff reasons new hash map string hash set peer node system out println creating peer manager my peers new peer node 0 connected peers new peer node 0 this node node peermanager peermanager peermanager shouldlog peernodestatuses hashmap hashset peernode peernodestatusesdarknet hashmap hashset peernode peernoderoutingbackoffreasons hashmap hashset peernode peermanager mypeers peernode connectedpeers peernode attempt to read a file full of noderefs try the file as named first then the bak if it is empty or otherwise doesn t work param filename the filename to read from if this doesn t work we try the bak file param crypto the cryptographic identity which these nodes are connected to param opennet the opennet manager for the nodes only needed for constructing the nodes if is opennet param is opennet whether the file contains opennet peers param old opennet peers if true don t add the nodes to the routing table pass them to the opennet manager as old peers i e inactive nodes which may try to reconnect void try read peers string filename node crypto crypto opennet manager opennet boolean is opennet boolean old opennet peers synchronized write peers sync if old opennet peers if is opennet open filename filename else dark filename filename outgoing packet mangler mangler crypto packet mangler file peers file new file filename file backup file new file filename bak try to read the node list from disk if peers file exists if read peers peers file mangler crypto opennet old opennet peers string msg if old opennet peers msg read opennet count old opennet peers old opennet peers from peers file else if is opennet msg read get opennet peers length opennet peers from peers file else msg read get darknet peers length darknet peers from peers file logger normal this msg system out println msg return try the backup if backup file exists if read peers backup file mangler crypto opennet old opennet peers string msg if old opennet peers msg read opennet count old opennet peers old opennet peers from peers file else if is opennet msg read get opennet peers length opennet peers from peers file else msg read get darknet peers length darknet peers from peers file logger normal this msg system out println msg else logger error this no readable peers file with peers in it found system err println no readable peers file with peers in it found isopennet isopennet oldopennetpeers tryreadpeers nodecrypto opennetmanager isopennet oldopennetpeers writepeerssync oldopennetpeers isopennet openfilename darkfilename outgoingpacketmangler packetmangler peersfile backupfile peersfile readpeers peersfile oldopennetpeers oldopennetpeers countoldopennetpeers peersfile isopennet getopennetpeers peersfile getdarknetpeers peersfile backupfile readpeers backupfile oldopennetpeers oldopennetpeers countoldopennetpeers peersfile isopennet getopennetpeers peersfile getdarknetpeers peersfile private boolean read peers file peers file outgoing packet mangler mangler node crypto crypto opennet manager opennet boolean old opennet peers boolean got some false file input stream fis try fis new file input stream peers file catch file not found exception e4 logger normal this peers file not found peers file return false input stream reader ris try ris new input stream reader fis utf 8 catch unsupported encoding exception e4 throw new error impossible jvm doesn t support utf 8 e4 e4 buffered reader br new buffered reader ris try fixme no better way while true read a single node peer simple field set fs fs new simple field set br false true peer node pn try pn peer node create fs node crypto opennet this true mangler catch fs parse exception e2 logger error this could not parse peer e2 n fs to string e2 continue catch peer parse exception e2 logger error this could not parse peer e2 n fs to string e2 continue catch reference signature verification exception e2 logger error this could not parse peer e2 n fs to string e2 continue if old opennet peers opennet add old opennet node pn else add peer pn true false got some true catch eof exception e end of file fine catch io exception e1 logger error this could not read peers file e1 e1 try br close catch io exception e3 logger error this ignoring e3 caught reading peers file e3 return got some readpeers peersfile outgoingpacketmangler nodecrypto opennetmanager oldopennetpeers gotsome fileinputstream fileinputstream peersfile filenotfoundexception peersfile inputstreamreader inputstreamreader unsupportedencodingexception bufferedreader bufferedreader nodepeer simplefieldset simplefieldset peernode peernode fsparseexception tostring peerparseexception tostring referencesignatureverificationexception tostring oldopennetpeers addoldopennetnode addpeer gotsome eofexception ioexception ioexception peersfile gotsome public boolean add peer peer node pn return add peer pn false false addpeer peernode addpeer add a peer param pn the node to add to the routing table param ignore opennet if true don t check for opennet peers if false check for opennet peers and if so if opennet is enabled auto add them to the opennet lru otherwise fail param reactivate if true re enable the peer if it is in state disconnecting before re adding it return true if the node was successfully added false if it was already present or if we tried to add an opennet peer when opennet was disabled boolean add peer peer node pn boolean ignore opennet boolean reactivate assert pn null if reactivate pn force cancel disconnecting synchronized this for int i 0 i my peers length i if my peers i equals pn if logminor logger minor this can t add peer pn because already have my peers i new exception debug return false peer node new my peers new peer node my peers length 1 system arraycopy my peers 0 new my peers 0 my peers length new my peers my peers length pn my peers new my peers logger normal this added pn if pn record status add peer node status pn get peer node status pn false pn set peer node status system current time millis updatepm user alert if ignore opennet pn instanceof opennet peer node opennet manager opennet node get opennet if opennet null opennet force add peer pn true else logger error this adding opennet peer when no opennet enabled pn removing remove peer pn return false return true ignoreopennet addpeer peernode ignoreopennet forcecanceldisconnecting mypeers mypeers mypeers peernode newmypeers peernode mypeers mypeers newmypeers mypeers newmypeers mypeers mypeers newmypeers recordstatus addpeernodestatus getpeernodestatus setpeernodestatus currenttimemillis updatepmuseralert ignoreopennet opennetpeernode opennetmanager getopennet forceaddpeer removepeer synchronized boolean have peer peer node pn for int i 0 i my peers length i if my peers i pn return true return false havepeer peernode mypeers mypeers private boolean remove peer peer node pn if logminor logger minor this removing pn boolean is in peers false synchronized this for int i 0 i my peers length i if my peers i pn is in peers true if pn instanceof darknet peer node darknet peer node pn remove extra peer data dir if is in peers int peer node status pn get peer node status if pn record status remove peer node status peer node status pn is in peers string peer node previous routing backoff reason pn get previous backoff reason if peer node previous routing backoff reason null remove peer node routing backoff reason peer node previous routing backoff reason pn removing from connected peers array list peer node a new array list peer node for peer node mp my peers if mp pn mp is connected mp is real connection a add mp peer node new connected peers new peer node a size new connected peers a to array new connected peers connected peers new connected peers removing from my peers peer node new my peers new peer node my peers length 1 int position in new array 0 for peer node mp my peers if mp pn new my peers position in new array mp position in new array my peers new my peers logger normal this removed pn pn on remove if is in peers updatepm user alert return true removepeer peernode isinpeers mypeers mypeers isinpeers darknetpeernode darknetpeernode removeextrapeerdatadir isinpeers peernodestatus getpeernodestatus recordstatus removepeernodestatus peernodestatus isinpeers peernodepreviousroutingbackoffreason getpreviousbackoffreason peernodepreviousroutingbackoffreason removepeernoderoutingbackoffreason peernodepreviousroutingbackoffreason connectedpeers arraylist peernode arraylist peernode peernode mypeers isconnected isrealconnection peernode newconnectedpeers peernode newconnectedpeers toarray newconnectedpeers connectedpeers newconnectedpeers mypeers peernode newmypeers peernode mypeers positioninnewarray peernode mypeers newmypeers positioninnewarray positioninnewarray mypeers newmypeers onremove isinpeers updatepmuseralert public boolean remove all peers logger normal this remove all peers peer node old peers synchronized this old peers my peers my peers new peer node 0 connected peers new peer node 0 for int i 0 i old peers length i old peers i on remove return true removeallpeers removeallpeers peernode oldpeers oldpeers mypeers mypeers peernode connectedpeers peernode oldpeers oldpeers onremove public boolean disconnected peer node pn synchronized this boolean is in peers false for int i 0 i connected peers length i if connected peers i pn is in peers true if is in peers return false removing from connected peers array list peer node a new array list peer node for peer node mp my peers if mp pn mp is routable a add mp peer node new connected peers new peer node a size new connected peers a to array new connected peers connected peers new connected peers updatepm user alert node lm announce loc change return true peernode isinpeers connectedpeers connectedpeers isinpeers isinpeers connectedpeers arraylist peernode arraylist peernode peernode mypeers isroutable peernode newconnectedpeers peernode newconnectedpeers toarray newconnectedpeers connectedpeers newconnectedpeers updatepmuseralert announcelocchange long time first any connections 0 public long get time first any connections return time first any connections timefirstanyconnections gettimefirstanyconnections timefirstanyconnections public void add connected peer peer node pn logminor logger should log logger minor this if pn is real connection if logminor logger minor this not a real connection pn return if pn is connected if logminor logger minor this not connected pn return long now system current time millis synchronized this if time first any connections 0 time first any connections now for int i 0 i connected peers length i if connected peers i pn if logminor logger minor this already connected pn return boolean in my peers false for int i 0 i my peers length i if my peers i pn in my peers true break if in my peers logger error this connecting to pn but not in peers add peer pn if logminor logger minor this connecting pn peer node new connected peers new peer node connected peers length 1 system arraycopy connected peers 0 new connected peers 0 connected peers length new connected peers connected peers length pn connected peers new connected peers if logminor logger minor this connected peers connected peers length updatepm user alert node lm announce loc change addconnectedpeer peernode shouldlog isrealconnection isconnected currenttimemillis timefirstanyconnections timefirstanyconnections connectedpeers connectedpeers inmypeers mypeers mypeers inmypeers inmypeers addpeer peernode newconnectedpeers peernode connectedpeers connectedpeers newconnectedpeers connectedpeers newconnectedpeers connectedpeers connectedpeers newconnectedpeers connectedpeers updatepmuseralert announcelocchange find the node with the given peer address public peer node get by peer peer peer for int i 0 i my peers length i if my peers i is real connection continue if peer equals my peers i get peer return my peers i return null peernode getbypeer mypeers mypeers isrealconnection mypeers getpeer mypeers connect to a node provided the fieldset representing it public void connect simple field set noderef outgoing packet mangler mangler throws fs parse exception peer parse exception reference signature verification exception peer node pn node create new darknet node noderef for int i 0 i my peers length i if arrays equals my peers i identity pn identity return add peer pn simplefieldset outgoingpacketmangler fsparseexception peerparseexception referencesignatureverificationexception peernode createnewdarknetnode mypeers mypeers addpeer disconnect from a specified node public void disconnect final peer node pn boolean send disconnect message final boolean wait for ack boolean purge if logminor logger minor this disconnecting pn short to string synchronized this if have peer pn return pn notify disconnecting if send disconnect message message msg dmt createfnp disconnect true purge 1 new short buffer new byte 0 try pn send async msg new async message callback boolean done false public void acknowledged done public void disconnected done public void fatal error done public void sent if wait for ack done void done synchronized this if done return done true if remove peer pn write peers ctr disconn catch not connected exception e if pn is disconnecting remove peer pn write peers return node get ticker queue timed job new runnable public void run if pn is disconnecting remove peer pn write peers node max peer inactivity else if remove peer pn write peers peernode senddisconnectmessage waitforack shorttostring havepeer notifydisconnecting senddisconnectmessage createfnpdisconnect shortbuffer sendasync asyncmessagecallback fatalerror waitforack removepeer writepeers ctrdisconn notconnectedexception isdisconnecting removepeer writepeers getticker queuetimedjob isdisconnecting removepeer writepeers max_peer_inactivity removepeer writepeers boolean done false public void acknowledged done public void disconnected done public void fatal error done fatalerror public void sent if wait for ack done waitforack void done synchronized this if done return done true if remove peer pn write peers removepeer writepeers node get ticker queue timed job new runnable public void run if pn is disconnecting remove peer pn write peers getticker queuetimedjob isdisconnecting removepeer writepeers final byte counter ctr disconn new byte counter public void received bytes int x node node stats disconn bytes received x bytecounter ctrdisconn bytecounter receivedbytes nodestats disconnbytesreceived public void sent bytes int x node node stats disconn bytes sent x sentbytes nodestats disconnbytessent public void sent payload int x ignore sentpayload long uid locationuid pair peer node pn location pn get location uid pn swap identifier locationuidpair peernode getlocation swapidentifier public int compare to locationuid pair p compare purely on location so result is the same as get peer location doubles if p location location return 1 if p location location return 1 return 0 compareto locationuidpair getpeerlocationdoubles return an array of the current locations as doubles of all our connected peers or double 0 if node shall we publish our peers location is false public double get peer location doubles boolean prune backed off peers double locs if node shall we publish our peers location return new double 0 peer node conns synchronized this conns connected peers locs new double conns length int x 0 for int i 0 i conns length i if conns i is routable if prune backed off peers conns i should be excluded from peer list locs x conns i get location wipe out any information contained in the order java util arrays sort locs 0 x if x locs length double new locs new double x system arraycopy locs 0 new locs 0 x return new locs else return locs shallwepublishourpeerslocation getpeerlocationdoubles prunebackedoffpeers shallwepublishourpeerslocation peernode connectedpeers isroutable prunebackedoffpeers shouldbeexcludedfrompeerlist getlocation newlocs newlocs newlocs just like get peer location doubles except it also returns the uid for each node public locationuid pair get peer locations andui ds peer node conns locationuid pair loc pairs synchronized this conns my peers loc pairs new locationuid pair conns length int x 0 for int i 0 i conns length i if conns i is routable loc pairs x new locationuid pair conns i sort it arrays sort loc pairs 0 x if x loc pairs length locationuid pair new locs new locationuid pair x system arraycopy loc pairs 0 new locs 0 x return new locs else return loc pairs getpeerlocationdoubles locationuidpair getpeerlocationsanduids peernode locationuidpair locpairs mypeers locpairs locationuidpair isroutable locpairs locationuidpair locpairs locpairs locationuidpair newlocs locationuidpair locpairs newlocs newlocs locpairs return a random routable connected peer fixme should this take performance into account do not remove the synchronized see below for why public synchronized peer node get random peer peer node exclude if connected peers length 0 return null for int i 0 i 5 i peer node pn connected peers node random next int connected peers length if pn exclude continue if pn is routable return pn none of them worked move the un connected ones out this is safe as they will add themselves when they reconnect and they can t do it yet as we are synchronized array list peer node v new array list peer node connected peers length logminor logger should log logger minor this for peer node pn my peers if pn exclude continue if pn is routable v add pn else if logminor logger minor this excluding pn because is disconnected int length without excluded v size if exclude null exclude is routable v add exclude peer node new connected peers new peer node v size new connected peers v to array new connected peers if logminor logger minor this connected peers in get random peer new connected peers length was connected peers length connected peers new connected peers if length without excluded 0 return null return connected peers node random next int length without excluded peernode getrandompeer peernode connectedpeers peernode connectedpeers nextint connectedpeers isroutable arraylist peernode arraylist peernode connectedpeers shouldlog peernode mypeers isroutable lengthwithoutexcluded isroutable peernode newconnectedpeers peernode newconnectedpeers toarray newconnectedpeers getrandompeer newconnectedpeers connectedpeers connectedpeers newconnectedpeers lengthwithoutexcluded connectedpeers nextint lengthwithoutexcluded asynchronously send this message to every connected peer public void local broadcast message msg boolean ignore routability boolean only real connections byte counter ctr peer node peers synchronized this my peers not connected peers as connected peers only contains routable peers and we may want to send to non routable peers peers my peers for int i 0 i peers length i if ignore routability if peers i is connected continue else if peers i is routable continue if only real connections peers i is real connection continue try peers i send async msg null ctr catch not connected exception e ignore localbroadcast ignoreroutability onlyrealconnections bytecounter peernode mypeers connectedpeers connectedpeers mypeers ignoreroutability isconnected isroutable onlyrealconnections isrealconnection sendasync notconnectedexception asynchronously send a differential node reference to every is connected peer public void locally broadcast diff node ref simple field set fs boolean to darknet only boolean to opennet only peer node peers synchronized this my peers not connected peers as connected peers only contains routable peers and we want to also send to non routable peers peers my peers for int i 0 i peers length i if peers i is connected continue if to darknet only peers i is darknet continue if to opennet only peers i is opennet continue peers i send node to node message fs node n2n message type diffnoderef false 0 false isconnected locallybroadcastdiffnoderef simplefieldset todarknetonly toopennetonly peernode mypeers connectedpeers connectedpeers mypeers isconnected todarknetonly isdarknet toopennetonly isopennet sendnodetonodemessage n2n_message_type_diffnoderef public peer node get random peer return get random peer null peernode getrandompeer getrandompeer public double closest peer location double loc double ignore loc int min uptime percent peer node peers synchronized this peers connected peers double best diff 1 0 double best loc double max value boolean found one false for int i 0 i peers length i peer node p peers i if p is routable continue if p is routing backed off continue if p get uptime min uptime percent continue double peerloc p get location if math abs peerloc ignore loc double min value 2 continue double diff location distance peerloc loc if diff best diff found one true best diff diff best loc peerloc if found one for int i 0 i peers length i peer node p peers i if p is routable continue if p get uptime min uptime percent continue ignore backoff state double peerloc p get location if math abs peerloc ignore loc double min value 2 continue double diff location distance peerloc loc if diff best diff found one true best diff diff best loc peerloc return best loc closestpeerlocation ignoreloc minuptimepercent peernode connectedpeers bestdiff bestloc max_value foundone peernode isroutable isroutingbackedoff getuptime minuptimepercent getlocation ignoreloc min_value bestdiff foundone bestdiff bestloc foundone peernode isroutable getuptime minuptimepercent getlocation ignoreloc min_value bestdiff foundone bestdiff bestloc bestloc public boolean is closer location double loc int min uptime percent double node loc node lm get location double node dist location distance node loc loc double closest closest peer location loc node loc min uptime percent if closest 1 0 no peers found return false double closest dist location distance closest loc return closest dist node dist iscloserlocation minuptimepercent nodeloc getlocation nodedist nodeloc closestpeerlocation nodeloc minuptimepercent closestdist closestdist nodedist public peer node closer peer peer node pn set peer node routed to double loc boolean ignore self boolean calculate misrouting int min version list double add unpicked locs to key key return closer peer pn routed to loc ignore self calculate misrouting min version add unpicked locs to 2 0 key peernode closerpeer peernode peernode routedto ignoreself calculatemisrouting minversion addunpickedlocsto closerpeer routedto ignoreself calculatemisrouting minversion addunpickedlocsto find the peer if any which is closer to the target location than we are and is not included in the provided set if ignore self false and we are closer to the target than any peers this function returns null this function returns two values the closest such peer which is backed off and the same which is not backed off it is possible for either to be null independent of the other closest is the closer of the two in either case and will not be null if any of the other two return values is not null param add unpicked locs to add all locations we didn t choose which we could have routed to to this array remove the location of the peer we pick from it param max distance if a node is further away from the target than this distance ignore it param key the original key if we have it and if we want to consult with the failure table to avoid routing to nodes which have recently failed for the same key public peer node closer peer peer node pn set peer node routed to double target boolean ignore self boolean calculate misrouting int min version list double add unpicked locs to double max distance key key peer node peers synchronized this peers connected peers if node enable per node failure tables key null if logminor logger minor this choosing closest peer connected peers peers length double max diff double max value if ignore self max diff location distance node lm get location target routing order non timed out non backed off peers in order of closeness to the target timed out non backed off peers least recently timed out first non timed out backed off peers in order of closeness to the target timed out backed off peers least recently timed out first peer node closest null double closest distance double max value peer node closest backed off null double closest backed off distance double max value peer node closest not backed off null double closest not backed off distance double max value peer node least recently timed out null long time least recently timed out long max value peer node least recently timed out backed off null long time least recently timed out backed off long max value timed out nodes list entry null if key null entry node failure table get timed out nodes list key long now system current time millis int count 0 double selection rates new double peers length double total selection rate 0 0 for int i 0 i peers length i selection rates i peers i selection rate total selection rate selection rates i boolean enablefoaf mitigation hack peers length peer node selection min peers total selection rate 0 0 for int i 0 i peers length i peer node p peers i if routed to contains p if logminor logger minor this skipping already routed to p get peer continue if p pn if logminor logger minor this skipping req came from p get peer continue if p is routable if logminor logger minor this skipping not connected p get peer continue if key null p is turtling key if logminor logger minor this skipping already turtling key p get peer if min version 0 version get arbitrary build number p get version 1 min version if logminor logger minor this skipping old version p get peer continue if enablefoaf mitigation hack double selection rate selection rates i double selection samples percentage selection rate total selection rate if peer node selection percentage warning selection samples percentage if logminor logger minor this skipping over selectionned peer selection samples percentage p get peer continue long timeout 1 if entry null timeout entry get timeout time p boolean timed out timeout now to help avoid odd race conditions get the location only once and use it for all calculations double loc p get location double diff location distance loc target double peers location p get peers location if peers location null node shall we route according to our peers location for double l peers location double new diff location distance l target if new diff diff loc l diff new diff if logminor logger minor this the peer p has published his peer s locations and the closest we have found to the target is diff away if diff max distance continue if ignore self diff max diff if logminor logger minor this ignoring further than self max diff max diff continue count if logminor logger minor this p loc loc target target d location distance loc target usedd diff timed out timed out for p get peer boolean chosen false if diff closest distance closest distance diff closest p chosen true if logminor logger minor this new best diff loc for p get peer boolean backed off p is routing backed off if backed off diff closest backed off distance timed out closest backed off distance diff closest backed off p chosen true if logminor logger minor this new best backed off diff loc for p get peer if backed off diff closest not backed off distance timed out closest not backed off distance diff closest not backed off p chosen true if logminor logger minor this new best not backed off diff loc for p get peer if timed out if backed off if timeout time least recently timed out time least recently timed out timeout least recently timed out p else if timeout time least recently timed out backed off time least recently timed out backed off timeout least recently timed out backed off p if add unpicked locs to null chosen double d new double loc here we can directly compare double s because they aren t processed in any way and are finite and probably nonzero if add unpicked locs to contains d add unpicked locs to add d peer node best closest not backed off various things are advisory i e they are taken into account but do not cause a request not to be routed at all backoff a node is backed off for a period after it rejects a request this is randomised and increases exponentially if no requests are accepted a longer period is imposed for timeouts after a request has been accepted and transfer failures recent failures after various kinds of failures we impose a timeout until when we will try to avoid sending the same key to that node this is part of per node failure tables combining these if there are nodes which are both not backed off and not timed out we route to whichever of those nodes is closest to the target location if we are still here all nodes are either backed off or timed out if there are nodes which are timed out but not backed off choose the node whose timeout expires soonest hence if a single key is requested continually we round robin between nodes if we still don t have a winner we know all nodes are backed off if there are nodes which are backed off but not timed out choose the node which is closest to the target but is not backed off if we still don t have a winner all nodes are backed off and timed out choose the backed off node whose timeout expires soonest if best null if least recently timed out null fixme downgrade to debug best least recently timed out if logminor logger minor this using least recently failed in timeout period peer for key best short to string for key else if closest backed off null best closest backed off if logminor logger minor this using best backed off peer for key best short to string else if least recently timed out backed off null best least recently timed out backed off if logminor logger minor this using least recently failed in timeout period backed off peer for key best short to string for key do not put a else here we need to re check the value if best null racy get location could have changed if calculate misrouting node node stats routing miss distance report location distance best closest get location int number of connected get peer node status size peer node status connected false int number of routing backed off get peer node status size peer node status routing backed off false if number of routing backed off number of connected 0 node node stats backed off percent report double number of routing backed off double number of routing backed off number of connected racy get location could have changed if add unpicked locs to null add the location which we did not pick if it exists if closest not backed off null closest backed off null add unpicked locs to add new double closest backed off get location increment selection samples now best return best ignoreself addunpickedlocsto maxdistance failuretable peernode closerpeer peernode peernode routedto ignoreself calculatemisrouting minversion addunpickedlocsto maxdistance peernode connectedpeers enablepernodefailuretables connectedpeers maxdiff max_value ignoreself maxdiff getlocation peernode closestdistance max_value peernode closestbackedoff closestbackedoffdistance max_value peernode closestnotbackedoff closestnotbackedoffdistance max_value peernode leastrecentlytimedout timeleastrecentlytimedout max_value peernode leastrecentlytimedoutbackedoff timeleastrecentlytimedoutbackedoff max_value timedoutnodeslist failuretable gettimedoutnodeslist currenttimemillis selectionrates totalselectionrate selectionrates selectionrate totalselectionrate selectionrates enablefoafmitigationhack peernode selection_min_peers totalselectionrate peernode routedto getpeer getpeer isroutable getpeer isturtling getpeer minversion getarbitrarybuildnumber getversion minversion getpeer enablefoafmitigationhack selectionrate selectionrates selectionsamplespercentage selectionrate totalselectionrate peernode selection_percentage_warning selectionsamplespercentage selectionsamplespercentage getpeer gettimeouttime timedout getlocation peerslocation getpeerslocation peerslocation shallwerouteaccordingtoourpeerslocation peerslocation newdiff newdiff newdiff maxdistance ignoreself maxdiff maxdiff maxdiff timedout timedout getpeer closestdistance closestdistance getpeer backedoff isroutingbackedoff backedoff closestbackedoffdistance timedout closestbackedoffdistance closestbackedoff getpeer backedoff closestnotbackedoffdistance timedout closestnotbackedoffdistance closestnotbackedoff getpeer timedout backedoff timeleastrecentlytimedout timeleastrecentlytimedout leastrecentlytimedout timeleastrecentlytimedoutbackedoff timeleastrecentlytimedoutbackedoff leastrecentlytimedoutbackedoff addunpickedlocsto addunpickedlocsto addunpickedlocsto peernode closestnotbackedoff leastrecentlytimedout leastrecentlytimedout shorttostring closestbackedoff closestbackedoff shorttostring leastrecentlytimedoutbackedoff leastrecentlytimedoutbackedoff shorttostring getlocation calculatemisrouting nodestats routingmissdistance getlocation numberofconnected getpeernodestatussize peer_node_status_connected numberofroutingbackedoff getpeernodestatussize peer_node_status_routing_backed_off numberofroutingbackedoff numberofconnected nodestats backedoffpercent numberofroutingbackedoff numberofroutingbackedoff numberofconnected getlocation addunpickedlocsto closestnotbackedoff closestbackedoff addunpickedlocsto closestbackedoff getlocation incrementselectionsamples return some status information public string get status string builder sb new string builder peer node peers synchronized this peers my peers string status new string peers length for int i 0 i peers length i peer node pn peers i status i pn get status true to string arrays sort status for int i 0 i status length i sb append status i sb append n return sb to string getstatus stringbuilder stringbuilder peernode mypeers peernode getstatus tostring tostring return tmci peer list public string gettmci peer list string builder sb new string builder peer node peers synchronized this peers my peers string peer list new string peers length for int i 0 i peers length i peer node pn peers i peer list i pn gettmci peer info arrays sort peer list for int i 0 i peer list length i sb append peer list i sb append n return sb to string gettmcipeerlist stringbuilder stringbuilder peernode mypeers peerlist peernode peerlist gettmcipeerinfo peerlist peerlist peerlist tostring public string get freeviz output string builder sb new string builder peer node peers synchronized this peers my peers string identity new string peers length for int i 0 i peers length i peer node pn peers i identity i pn get freeviz output arrays sort identity for int i 0 i identity length i sb append identity i sb append n return sb to string getfreevizoutput stringbuilder stringbuilder peernode mypeers peernode getfreevizoutput tostring private final object write peer file sync new object void write peers should write peers true writepeerfilesync writepeers shouldwritepeers protected string get darknet peers string string builder sb new string builder peer node peers synchronized this peers my peers for peer node pn peers if pn instanceof darknet peer node sb append pn export disk field set return sb to string getdarknetpeersstring stringbuilder stringbuilder peernode mypeers peernode darknetpeernode exportdiskfieldset tostring protected string get opennet peers string string builder sb new string builder peer node peers synchronized this peers my peers for peer node pn peers if pn instanceof opennet peer node sb append pn export disk field set return sb to string getopennetpeersstring stringbuilder stringbuilder peernode mypeers peernode opennetpeernode exportdiskfieldset tostring protected string get old opennet peers string opennet manager om string builder sb new string builder for peer node pn om get old peers if pn instanceof opennet peer node sb append pn export disk field set return sb to string getoldopennetpeersstring opennetmanager stringbuilder stringbuilder peernode getoldpeers opennetpeernode exportdiskfieldset tostring private void write peers inner string darknet null string opennet null string old opennet peers null string old opennet peers filename null synchronized write peers sync if dark filename null darknet get darknet peers string opennet manager om node get opennet if om null if open filename null opennet get opennet peers string old opennet peers filename om get old peers filename old opennet peers get old opennet peers string om synchronized write peer file sync if darknet null write peers inner dark filename darknet if old opennet peers null if opennet null write peers inner open filename opennet write peers inner old opennet peers filename old opennet peers writepeersinner oldopennetpeers oldopennetpeersfilename writepeerssync darkfilename getdarknetpeersstring opennetmanager getopennet openfilename getopennetpeersstring oldopennetpeersfilename getoldpeersfilename oldopennetpeers getoldopennetpeersstring writepeerfilesync writepeersinner darkfilename oldopennetpeers writepeersinner openfilename writepeersinner oldopennetpeersfilename oldopennetpeers write the peers file to disk private void write peers inner string filename string sb synchronized write peer file sync file output stream fos null string f filename bak try fos new file output stream f catch file not found exception e2 logger error this cannot write peers to disk cannot create f e2 e2 closer close fos return output stream writer w null try w new output stream writer fos utf 8 catch unsupported encoding exception e2 closer close w throw new error impossible jvm doesn t support utf 8 e2 e2 try w write sb w flush w close w null file fnam new file filename file util rename to new file f fnam catch io exception e try fos close catch io exception e1 logger error this cannot close peers file e e logger error this cannot write file e e return don t overwrite old file finally closer close w closer close fos writepeersinner writepeerfilesync fileoutputstream fileoutputstream filenotfoundexception outputstreamwriter outputstreamwriter unsupportedencodingexception fileutil renameto ioexception ioexception update the numbers needed by our peer manager user alert on the uam also run the node s on connected peers method if applicable public void updatepm user alert if ua null return int peers darknet peers opennet peers synchronized this darknet peers this get darknet peers length opennet peers this get opennet peers length peers darknet peers opennet peers seednodes don t count opennet manager om node get opennet boolean opennet definitely port forwarded boolean opennet enabled boolean opennet assumenat if om null opennet enabled true opennet definitely port forwarded om crypto definitely port forwarded opennet assumenat om crypto config always handshake aggressively else opennet enabled false opennet definitely port forwarded false opennet assumenat false boolean darknet definitely port forwarded node darknet definitely port forwarded boolean darknet assumenat node darknet crypto config always handshake aggressively synchronized ua ua opennet definitely port forwarded opennet definitely port forwarded ua darknet definitely port forwarded darknet definitely port forwarded ua opennet assumenat opennet assumenat ua darknet assumenat darknet assumenat ua darknet conns get peer node status size peer node status connected true get peer node status size peer node status routing backed off true ua conns get peer node status size peer node status connected false get peer node status size peer node status routing backed off false ua darknet peers darknet peers ua disconn darknet peers darknet peers ua darknet conns ua peers peers ua never conn get peer node status size peer node status never connected true ua clock problem get peer node status size peer node status clock problem false ua conn error get peer node status size peer node status conn error true ua is opennet enabled opennet enabled if any connected peers node on connected peer peermanageruseralert onconnectedpeers updatepmuseralert darknetpeers opennetpeers darknetpeers getdarknetpeers opennetpeers getopennetpeers darknetpeers opennetpeers opennetmanager getopennet opennetdefinitelyportforwarded opennetenabled opennetassumenat opennetenabled opennetdefinitelyportforwarded definitelyportforwarded opennetassumenat alwayshandshakeaggressively opennetenabled opennetdefinitelyportforwarded opennetassumenat darknetdefinitelyportforwarded darknetdefinitelyportforwarded darknetassumenat darknetcrypto alwayshandshakeaggressively opennetdefinitelyportforwarded opennetdefinitelyportforwarded darknetdefinitelyportforwarded darknetdefinitelyportforwarded opennetassumenat opennetassumenat darknetassumenat darknetassumenat darknetconns getpeernodestatussize peer_node_status_connected getpeernodestatussize peer_node_status_routing_backed_off getpeernodestatussize peer_node_status_connected getpeernodestatussize peer_node_status_routing_backed_off darknetpeers darknetpeers disconndarknetpeers darknetpeers darknetconns neverconn getpeernodestatussize peer_node_status_never_connected clockproblem getpeernodestatussize peer_node_status_clock_problem connerror getpeernodestatussize peer_node_status_conn_error isopennetenabled opennetenabled anyconnectedpeers onconnectedpeer public boolean any connected peers peer node conns synchronized this conns connected peers for int i 0 i conns length i if conns i is routable return true return false anyconnectedpeers peernode connectedpeers isroutable public boolean any darknet peers peer node conns synchronized this conns connected peers for peer node p conns if p is darknet return true return false anydarknetpeers peernode connectedpeers peernode isdarknet ask each peer node to read in it s extra peer data public void read extra peer data darknet peer node peers get darknet peers for int i 0 i peers length i try peers i read extra peer data catch exception e logger error this got exception while reading extra peer data e string msg extra peer data reading and processing completed logger normal this msg system out println msg peernode readextrapeerdata darknetpeernode getdarknetpeers readextrapeerdata public void start ua new peer manager user alert node node stats updatepm user alert node client core alerts register ua node ps queue timed job write peers runnable 0 peermanageruseralert nodestats updatepmuseralert clientcore queuetimedjob writepeersrunnable public int count non backed off peers peer node peers synchronized this peers connected peers even if my peers peers are connected they won t be routed to int count no backoff 0 for int i 0 i peers length i if peers i is routable if peers i is routing backed off count no backoff return count no backoff countnonbackedoffpeers peernode connectedpeers mypeers countnobackoff isroutable isroutingbackedoff countnobackoff countnobackoff stats stuff update oldest never connected peer age if the timer has expired public void maybe update oldest never connected peer age long now synchronized this if now next oldest never connected peer age update time return next oldest never connected peer age update time now oldest never connected peer age update interval oldest never connected peer age 0 peer node peer list my peers for int i 0 i peer list length i peer node pn peer list i if pn get peer node status peer node status never connected if now pn get peer added time oldest never connected peer age oldest never connected peer age now pn get peer added time if oldest never connected peer age 0 logminor logger minor this oldest never connected peer is oldest never connected peer age ms old next oldest never connected peer age update time now oldest never connected peer age update interval oldestneverconnectedpeerage maybeupdateoldestneverconnectedpeerage nextoldestneverconnectedpeerageupdatetime nextoldestneverconnectedpeerageupdatetime oldestneverconnectedpeerageupdateinterval oldestneverconnectedpeerage peernode peerlist mypeers peerlist peernode peerlist getpeernodestatus peer_node_status_never_connected getpeeraddedtime oldestneverconnectedpeerage oldestneverconnectedpeerage getpeeraddedtime oldestneverconnectedpeerage oldestneverconnectedpeerage nextoldestneverconnectedpeerageupdatetime oldestneverconnectedpeerageupdateinterval public long get oldest never connected peer age return oldest never connected peer age getoldestneverconnectedpeerage oldestneverconnectedpeerage log the current peer node status summary if the timer has expired public void maybe log peer node status summary long now if now next peer node status log time if now next peer node status log time 10 1000 next peer node status log time 0 logger error this maybe log peer node status summary not called for more than 10 seconds now next peer node status log time packet sender getting bogged down or something int number of connected 0 int number of routing backed off 0 int number of too new 0 int number of too old 0 int number of disconnected 0 int number of never connected 0 int number of disabled 0 int number of listen only 0 int number of listening 0 int number of bursting 0 int number of clock problem 0 int number of conn error 0 int number of disconnecting 0 int number of routing disabled 0 peer node status pns get peer node statuses true for int i 0 i pns length i if pns i null logger error this get peer node statuses true i null continue switch pns i get status value case peer node status connected number of connected break case peer node status routing backed off number of routing backed off break case peer node status too new number of too new break case peer node status too old number of too old break case peer node status disconnected number of disconnected break case peer node status never connected number of never connected break case peer node status disabled number of disabled break case peer node status listen only number of listen only break case peer node status listening number of listening break case peer node status bursting number of bursting break case peer node status clock problem number of clock problem break case peer node status conn error number of conn error break case peer node status disconnecting number of disconnecting break case peer node status routing disabled number of routing disabled break default logger error this unknown peer status value pns i get status value break logger normal this connected number of connected routing backed off number of routing backed off too new number of too new too old number of too old disconnected number of disconnected never connected number of never connected disabled number of disabled bursting number of bursting listening number of listening listen only number of listen only clock problem number of clock problem connection problem number of conn error disconnecting number of disconnecting next peer node status log time now peer node status log interval node display clock problem user alert number of clock problem 2 peernode maybelogpeernodestatussummary nextpeernodestatuslogtime nextpeernodestatuslogtime nextpeernodestatuslogtime maybelogpeernodestatussummary nextpeernodestatuslogtime packetsender numberofconnected numberofroutingbackedoff numberoftoonew numberoftooold numberofdisconnected numberofneverconnected numberofdisabled numberoflistenonly numberoflistening numberofbursting numberofclockproblem numberofconnerror numberofdisconnecting numberofroutingdisabled peernodestatus getpeernodestatuses getpeernodestatuses getstatusvalue peer_node_status_connected numberofconnected peer_node_status_routing_backed_off numberofroutingbackedoff peer_node_status_too_new numberoftoonew peer_node_status_too_old numberoftooold peer_node_status_disconnected numberofdisconnected peer_node_status_never_connected numberofneverconnected peer_node_status_disabled numberofdisabled peer_node_status_listen_only numberoflistenonly peer_node_status_listening numberoflistening peer_node_status_bursting numberofbursting peer_node_status_clock_problem numberofclockproblem peer_node_status_conn_error numberofconnerror peer_node_status_disconnecting numberofdisconnecting peer_node_status_routing_disabled numberofroutingdisabled getstatusvalue numberofconnected numberofroutingbackedoff numberoftoonew numberoftooold numberofdisconnected numberofneverconnected numberofdisabled numberofbursting numberoflistening numberoflistenonly numberofclockproblem numberofconnerror numberofdisconnecting nextpeernodestatuslogtime peernodestatusloginterval displayclockproblemuseralert numberofclockproblem add a peer node status to the map public void add peer node status int pn status peer node peer node boolean no log integer peer node status integer value of pn status add peer node statuses pn status peer node peer node status peer node statuses no log if peer node is opennet add peer node statuses pn status peer node peer node status peer node statuses darknet no log peernode addpeernodestatus pnstatus peernode peernode nolog peernodestatus valueof pnstatus addpeernodestatuses pnstatus peernode peernodestatus peernodestatuses nolog peernode isopennet addpeernodestatuses pnstatus peernode peernodestatus peernodestatusesdarknet nolog private void add peer node statuses int pn status peer node peer node integer peer node status hash map integer hash set peer node statuses boolean no log hash set peer node status set null synchronized statuses if statuses contains key peer node status status set statuses get peer node status if status set contains peer node if no log logger error this add peer node status node already in peer node statuses peer node status peer node get peer node status string peer node status int value return statuses remove peer node status else status set new hash set peer node if logminor logger minor this add peer node status adding peer node for peer node get identity string with status peer node get peer node status string peer node status int value status set add peer node statuses put peer node status status set addpeernodestatuses pnstatus peernode peernode peernodestatus hashmap hashset peernode nolog hashset peernode statusset containskey peernodestatus statusset peernodestatus statusset peernode nolog addpeernodestatus peernodestatuses peernode peernode getpeernodestatusstring peernodestatus intvalue peernodestatus statusset hashset peernode addpeernodestatus peernode peernode getidentitystring peernode getpeernodestatusstring peernodestatus intvalue statusset peernode peernodestatus statusset how many peer nodes have a particular status param darknet if true only count darknet nodes if false count all nodes public int get peer node status size int pn status boolean darknet integer peer node status integer value of pn status hash set peer node status set null hash map integer hash set peer node statuses darknet peer node statuses darknet this peer node statuses synchronized statuses if statuses contains key peer node status status set statuses get peer node status else status set new hash set peer node return status set size peernodes getpeernodestatussize pnstatus peernodestatus valueof pnstatus hashset peernode statusset hashmap hashset peernode peernodestatusesdarknet peernodestatuses containskey peernodestatus statusset peernodestatus statusset hashset peernode statusset remove a peer node status from the map param is in peers if true complain if the node is not in the peers list if false complain if it is public void remove peer node status int pn status peer node peer node boolean no log integer peer node status integer value of pn status remove peer node status pn status peer node status peer node peer node statuses no log if peer node is opennet remove peer node status pn status peer node status peer node peer node statuses darknet no log peernode isinpeers removepeernodestatus pnstatus peernode peernode nolog peernodestatus valueof pnstatus removepeernodestatus pnstatus peernodestatus peernode peernodestatuses nolog peernode isopennet removepeernodestatus pnstatus peernodestatus peernode peernodestatusesdarknet nolog private void remove peer node status int pn status integer peer node status peer node peer node hash map integer hash set peer node statuses boolean no log hash set peer node status set null synchronized statuses if statuses contains key peer node status status set statuses get peer node status if status set contains peer node if no log logger error this remove peer node status identity peer node get identity string for peer node short to string not in peer node statuses with status peer node get peer node status string peer node status int value new exception debug return if statuses is empty statuses remove peer node status else status set new hash set peer node if logminor logger minor this remove peer node status removing peer node for peer node get identity string with status peer node get peer node status string peer node status int value if status set contains peer node status set remove peer node removepeernodestatus pnstatus peernodestatus peernode peernode hashmap hashset peernode nolog hashset peernode statusset containskey peernodestatus statusset peernodestatus statusset peernode nolog removepeernodestatus peernode getidentitystring peernode shorttostring peernodestatuses peernode getpeernodestatusstring peernodestatus intvalue isempty peernodestatus statusset hashset peernode removepeernodestatus peernode peernode getidentitystring peernode getpeernodestatusstring peernodestatus intvalue statusset peernode statusset peernode add a peer node routing backoff reason to the map public void add peer node routing backoff reason string peer node routing backoff reason peer node peer node synchronized peer node routing backoff reasons hash set peer node reason set null if peer node routing backoff reasons contains key peer node routing backoff reason reason set peer node routing backoff reasons get peer node routing backoff reason if reason set contains peer node logger error this add peer node routing backoff reason identity peer node get identity string already in peer node routing backoff reasons as peer node get peer with status code peer node routing backoff reason return peer node routing backoff reasons remove peer node routing backoff reason else reason set new hash set peer node if logminor logger minor this add peer node routing backoff reason adding peer node for peer node get identity string with status code peer node routing backoff reason reason set add peer node peer node routing backoff reasons put peer node routing backoff reason reason set peernode addpeernoderoutingbackoffreason peernoderoutingbackoffreason peernode peernode peernoderoutingbackoffreasons hashset peernode reasonset peernoderoutingbackoffreasons containskey peernoderoutingbackoffreason reasonset peernoderoutingbackoffreasons peernoderoutingbackoffreason reasonset peernode addpeernoderoutingbackoffreason peernode getidentitystring peernoderoutingbackoffreasons peernode getpeer peernoderoutingbackoffreason peernoderoutingbackoffreasons peernoderoutingbackoffreason reasonset hashset peernode addpeernoderoutingbackoffreason peernode peernode getidentitystring peernoderoutingbackoffreason reasonset peernode peernoderoutingbackoffreasons peernoderoutingbackoffreason reasonset what are the currently tracked peer node routing backoff reasons public string get peer node routing backoff reasons string reason strings synchronized peer node routing backoff reasons reason strings peer node routing backoff reasons key set to array new string peer node routing backoff reasons size arrays sort reason strings return reason strings peernode getpeernoderoutingbackoffreasons reasonstrings peernoderoutingbackoffreasons reasonstrings peernoderoutingbackoffreasons keyset toarray peernoderoutingbackoffreasons reasonstrings reasonstrings how many peer nodes have a particular routing backoff reason public int get peer node routing backoff reason size string peer node routing backoff reason hash set peer node reason set null synchronized peer node routing backoff reasons if peer node routing backoff reasons contains key peer node routing backoff reason reason set peer node routing backoff reasons get peer node routing backoff reason return reason set size else return 0 peernodes getpeernoderoutingbackoffreasonsize peernoderoutingbackoffreason hashset peernode reasonset peernoderoutingbackoffreasons peernoderoutingbackoffreasons containskey peernoderoutingbackoffreason reasonset peernoderoutingbackoffreasons peernoderoutingbackoffreason reasonset remove a peer node routing backoff reason from the map public void remove peer node routing backoff reason string peer node routing backoff reason peer node peer node hash set peer node reason set null synchronized peer node routing backoff reasons if peer node routing backoff reasons contains key peer node routing backoff reason reason set peer node routing backoff reasons get peer node routing backoff reason if reason set contains peer node logger error this remove peer node routing backoff reason identity peer node get identity string not in peer node routing backoff reasons with status code peer node routing backoff reason new exception debug return peer node routing backoff reasons remove peer node routing backoff reason else reason set new hash set peer node if logminor logger minor this remove peer node routing backoff reason removing peer node for peer node get identity string with status code peer node routing backoff reason if reason set contains peer node reason set remove peer node if reason set size 0 peer node routing backoff reasons put peer node routing backoff reason reason set peernode removepeernoderoutingbackoffreason peernoderoutingbackoffreason peernode peernode hashset peernode reasonset peernoderoutingbackoffreasons peernoderoutingbackoffreasons containskey peernoderoutingbackoffreason reasonset peernoderoutingbackoffreasons peernoderoutingbackoffreason reasonset peernode removepeernoderoutingbackoffreason peernode getidentitystring peernoderoutingbackoffreasons peernoderoutingbackoffreason peernoderoutingbackoffreasons peernoderoutingbackoffreason reasonset hashset peernode removepeernoderoutingbackoffreason peernode peernode getidentitystring peernoderoutingbackoffreason reasonset peernode reasonset peernode reasonset peernoderoutingbackoffreasons peernoderoutingbackoffreason reasonset public peer node status get peer node statuses boolean no heavy peer node peers synchronized this peers my peers peer node status peernodestatuses new peer node status peers length for int peer index 0 peer count peers length peer index peer count peer index peernodestatuses peer index peers peer index get status no heavy return peernodestatuses peernodestatus getpeernodestatuses noheavy peernode mypeers peernodestatus _peernodestatuses peernodestatus peerindex peercount peerindex peercount peerindex _peernodestatuses peerindex peerindex getstatus noheavy _peernodestatuses public darknet peer node status get darknet peer node statuses boolean no heavy darknet peer node peers get darknet peers darknet peer node status peernodestatuses new darknet peer node status peers length for int peer index 0 peer count peers length peer index peer count peer index peernodestatuses peer index darknet peer node status peers peer index get status no heavy return peernodestatuses darknetpeernodestatus getdarknetpeernodestatuses noheavy darknetpeernode getdarknetpeers darknetpeernodestatus _peernodestatuses darknetpeernodestatus peerindex peercount peerindex peercount peerindex _peernodestatuses peerindex darknetpeernodestatus peerindex getstatus noheavy _peernodestatuses public opennet peer node status get opennet peer node statuses boolean no heavy opennet peer node peers get opennet peers opennet peer node status peernodestatuses new opennet peer node status peers length for int peer index 0 peer count peers length peer index peer count peer index peernodestatuses peer index opennet peer node status peers peer index get status no heavy return peernodestatuses opennetpeernodestatus getopennetpeernodestatuses noheavy opennetpeernode getopennetpeers opennetpeernodestatus _peernodestatuses opennetpeernodestatus peerindex peercount peerindex peercount peerindex _peernodestatuses peerindex opennetpeernodestatus peerindex getstatus noheavy _peernodestatuses update had routable connection count routable connection check count on peers if the timer has expired public void maybe update peer node routable connection stats long now synchronized this if now next routable connection stats update time return next routable connection stats update time now routable connection stats update interval if 1 next routable connection stats update time peer node peer list my peers for int i 0 i peer list length i peer node pn peer list i pn check routable connection status hadroutableconnectioncount routableconnectioncheckcount maybeupdatepeernoderoutableconnectionstats nextroutableconnectionstatsupdatetime nextroutableconnectionstatsupdatetime routableconnectionstatsupdateinterval nextroutableconnectionstatsupdatetime peernode peerlist mypeers peerlist peernode peerlist checkroutableconnectionstatus get the darknet peers list fixme optimise public darknet peer node get darknet peers peer node peers synchronized this peers my peers fixme optimise maybe maintain as a separate list vector peer node v new vector peer node my peers length for int i 0 i peers length i if peers i instanceof darknet peer node v add peers i return v to array new darknet peer node v size darknetpeernode getdarknetpeers peernode mypeers peernode peernode mypeers darknetpeernode toarray darknetpeernode public vector seed server peer node get connected seed server peers vector hash set byte array wrapper exclude peer node peers synchronized this peers my peers fixme optimise maybe maintain as a separate list vector seed server peer node v new vector seed server peer node my peers length for peer node p peers if p instanceof seed server peer node seed server peer node sspn seed server peer node p if exclude null exclude contains new byte array wrapper sspn get identity if logminor logger minor this not including in get connected seed server peers vector as in exclude set sspn user to string continue if sspn is connected if logminor logger minor this not including in get connected seed server peers vector as disconnected sspn user to string continue v add sspn return v seedserverpeernode getconnectedseedserverpeersvector hashset bytearraywrapper peernode mypeers seedserverpeernode seedserverpeernode mypeers peernode seedserverpeernode seedserverpeernode seedserverpeernode bytearraywrapper getidentity getconnectedseedserverpeersvector usertostring isconnected getconnectedseedserverpeersvector usertostring public list seed server peer node get seed server peers vector peer node peers synchronized this peers my peers fixme optimise maybe maintain as a separate list list seed server peer node v new array list seed server peer node my peers length for peer node peer peers if peer instanceof seed server peer node v add seed server peer node peer return v seedserverpeernode getseedserverpeersvector peernode mypeers seedserverpeernode arraylist seedserverpeernode mypeers peernode seedserverpeernode seedserverpeernode get the opennet peers list public opennet peer node get opennet peers peer node peers synchronized this peers my peers fixme optimise maybe maintain as a separate list vector peer node v new vector peer node my peers length for int i 0 i peers length i if peers i instanceof opennet peer node v add peers i return v to array new opennet peer node v size opennetpeernode getopennetpeers peernode mypeers peernode peernode mypeers opennetpeernode toarray opennetpeernode public boolean any connected peer has address freenet inet address addr peer node pn peer node peers synchronized this peers my peers for int i 0 i peers length i if peers i pn continue if peers i is connected continue if peers i is real connection continue ignore non searchable peers i e bootstrapping peers if get peer is null then presumably is connected if peers i get peer get freenet address equals addr return true return false anyconnectedpeerhasaddress freenetinetaddress peernode peernode mypeers isconnected isrealconnection getpeer isconnected getpeer getfreenetaddress public void remove opennet peers synchronized this array list peer node keep new array list peer node array list peer node conn new array list peer node for peer node pn my peers if pn instanceof opennet peer node continue keep add pn if pn is connected conn add pn my peers keep to array new peer node keep size connected peers keep to array new peer node conn size updatepm user alert removeopennetpeers arraylist peernode arraylist peernode arraylist peernode arraylist peernode peernode mypeers opennetpeernode isconnected mypeers toarray peernode connectedpeers toarray peernode updatepmuseralert public peer node contains peer peer node pn peer node peers pn is opennet peer node get opennet peers peer node get darknet peers for int i 0 i peers length i if arrays equals pn get identity peers i get identity return peers i return null peernode containspeer peernode peernode isopennet peernode getopennetpeers peernode getdarknetpeers getidentity getidentity public int quick count connected peers peer node conns connected peers if conns null return 0 return connected peers length quickcountconnectedpeers peernode connectedpeers connectedpeers public int count connected darknet peers int count 0 peer node peers my peers for int i 0 i peers length i if peers i null continue if peers i instanceof darknet peer node continue if peers i is opennet continue if peers i is routable continue count if logminor logger minor this count connected darknet peers returning count return count countconnecteddarknetpeers peernode mypeers darknetpeernode isopennet isroutable countconnecteddarknetpeers public int count connected peers int count 0 peer node peers my peers for int i 0 i peers length i if peers i null continue if peers i is routable continue count return count countconnectedpeers peernode mypeers isroutable public int count almost connected darknet peers int count 0 peer node peers my peers for int i 0 i peers length i if peers i null continue if peers i instanceof darknet peer node continue if peers i is opennet continue if peers i is connected continue count return count countalmostconnecteddarknetpeers peernode mypeers darknetpeernode isopennet isconnected public int count compatible darknet peers int count 0 peer node peers my peers for int i 0 i peers length i if peers i null continue if peers i instanceof darknet peer node continue if peers i is opennet continue if peers i is connected continue if peers i is routing compatible continue count return count countcompatibledarknetpeers peernode mypeers darknetpeernode isopennet isconnected isroutingcompatible public int count connected opennet peers int count 0 peer node peers connected peers for int i 0 i peers length i if peers i null continue if peers i instanceof opennet peer node continue if peers i is routable continue count return count countconnectedopennetpeers peernode connectedpeers opennetpeernode isroutable how many peers do we have that actually may connect don t include seednodes disabled nodes etc public int count valid peers peer node peers my peers int count 0 for int i 0 i peers length i if peers i is real connection continue if peers i is disabled continue count return count countvalidpeers peernode mypeers isrealconnection isdisabled public int count seednodes int count 0 for peer node peer my peers if peer instanceof seed server peer node peer instanceof seed client peer node count return count countseednodes peernode mypeers seedserverpeernode seedclientpeernode public int count backed off peers peer node peers my peers int count 0 for int i 0 i peers length i if peers i is real connection continue if peers i is disabled continue if peers i is routing backed off count return count countbackedoffpeers peernode mypeers isrealconnection isdisabled isroutingbackedoff public peer node get by identity byte identity peer node peers my peers for int i 0 i peers length i if arrays equals peers i get identity identity return peers i return null peernode getbyidentity peernode mypeers getidentity private void increment selection samples long now peer node pn todo reimplement with a bit field to spare memory pn increment number of selections now incrementselectionsamples peernode incrementnumberofselections private static final long serial versionuid 5516389508555401104l public attribute list serialversionuid attributelist public attribute get attribute int n return attribute get n getattribute public attribute get attribute string name if name null return null int n lists size for int n 0 n n lists n attribute elem get attribute n if name compare to elem get name 0 return elem return null getattribute nlists nlists getattribute compareto getname public ssdp request set version http version 11 ssdprequest setversion version_11 public void setnt string value set header http nt value setheader public string getnt return get header value http nt getheadervalue public void setnts string value set header http nts value setheader public string getnts return get header value http nts getheadervalue public void set location string value set header http location value setlocation setheader public string get location return get header value http location getlocation getheadervalue public void setusn string value set header http usn value setheader public string getusn return get header value http usn getheadervalue public void set lease time int len set header http cache control max age integer to string len setleasetime setheader cache_control tostring public int get lease time string cache ctrl get header value http cache control return ssdp get lease time cache ctrl getleasetime cachectrl getheadervalue cache_control getleasetime cachectrl public class assertion failed extends error public assertion failed super assertion failed assertionfailed assertionfailed public assertion failed string description super assertion description failed assertionfailed private float m11 1 0f public marble tex filter marbletexfilter public void set scale float scale this scale scale setscale public float get scale return scale getscale public void set stretch float stretch this stretch stretch setstretch public float get stretch return stretch getstretch public void set angle float angle this angle angle float cos float math cos angle float sin float math sin angle m00 cos m01 sin m10 sin m11 cos setangle public float get angle return angle getangle public void set turbulence float turbulence this turbulence turbulence setturbulence public float get turbulence return turbulence getturbulence public void set turbulence factor float turbulence factor this turbulence factor turbulence factor setturbulencefactor turbulencefactor turbulencefactor turbulencefactor public float get turbulence factor return turbulence factor getturbulencefactor turbulencefactor public void set colormap colormap colormap this colormap colormap setcolormap public colormap get colormap return colormap getcolormap override public int filterrgb int x int y int rgb float nx m00 x m01 y float ny m10 x m11 y nx scale stretch ny scale int a rgb 0xff000000 if colormap null float f noise turbulence2 nx ny turbulence f 3 turbulence factor f ny f math sin f math pi float chaos turbulence factor noise turbulence2 nx ny turbulence float f math sin math sin 8 chaos 7 nx 3 ny float f 3 turbulence factor chaos ny f float math sin f math pi float perturb float math sin 40 chaos f 2 perturb return colormap get color f else float red grn blu float chaos brown layer green layer float perturb brown perturb green perturb grn perturb float t chaos turbulence factor noise turbulence2 nx ny turbulence t float math sin math sin 8 chaos 7 nx 3 ny green layer brown layer math abs t perturb float math sin 40 chaos perturb float math abs perturb brown perturb 6f perturb 0 3f green perturb 2f perturb 0 8f grn perturb 15f perturb 0 85f grn 0 5f float math pow math abs brown layer 0 3 brown layer float math pow 0 5 brown layer 1 0 0 6 brown perturb green layer float math pow 0 5 green layer 1 0 0 6 green perturb red 0 5f brown layer 0 35f green layer 2 0f grn blu 0 25f brown layer 0 35f green layer 2 0f grn grn math max brown layer green layer grn perturb int r rgb 16 0xff int g rgb 8 0xff int b rgb 0xff r pixel utils clamp int r red g pixel utils clamp int g grn b pixel utils clamp int b blu return rgb 0xff000000 r 16 g 8 b turbulencefactor turbulencefactor turbulencefactor getcolor brownlayer greenlayer brownperturb greenperturb grnperturb turbulencefactor greenlayer brownlayer brownperturb greenperturb grnperturb brownlayer brownlayer brownlayer brownperturb greenlayer greenlayer greenperturb brownlayer greenlayer brownlayer greenlayer brownlayer greenlayer grnperturb pixelutils pixelutils pixelutils override public string to string return texture marble texture tostring create a question public dns question string name int type int clazz super name type clazz dnsquestion check if this question is answered by a given dns record boolean answered by dns record rec return clazz rec clazz type rec type type dns constants type any name equals rec name answeredby dnsrecord dnsconstants type_any for debugging only public string to string return to string question null tostring tostring public line int x1 int y1 int x2 int y2 this x1 x1 this y1 y1 this x2 x2 this y2 y2 public void setup dx x2 x1 dy y2 y1 length squared dx dx dy dy length float math sqrt length squared lengthsquared lengthsquared private float width height public field warp filter fieldwarpfilter set the amount of warp param amount the amount min value 0 max value 1 see get amount public void set amount float amount this amount amount getamount setamount get the amount of warp return the amount see set amount public float get amount return amount setamount getamount public void set power float power this power power setpower public float get power return power getpower public void set strength float strength this strength strength setstrength public float get strength return strength getstrength public void set in lines line in lines this in lines in lines setinlines inlines inlines inlines public line get in lines return in lines getinlines inlines public void set out lines line out lines this out lines out lines setoutlines outlines outlines outlines public line get out lines return out lines getoutlines outlines protected void transform int x int y point out override protected void transform inverse int x int y float out float u 0 v 0 float fraction 0 float distance float fdist float weight float a 0 001f float b 1 5f strength 0 5f float p power float total weight 0 0f float sumx 0 0f float sumy 0 0f for int line 0 line in lines length line line l1 in lines line line l intermediate lines line float dx x l x1 float dy y l y1 fraction dx l dx dy l dy l length squared fdist dy l dx dx l dy l length if fraction 0 distance float math sqrt dx dx dy dy else if fraction 1 dx x l x2 dy y l y2 distance float math sqrt dx dx dy dy else if fdist 0 distance fdist else distance fdist u l1 x1 fraction l1 dx fdist l1 dy l1 length v l1 y1 fraction l1 dy fdist l1 dx l1 length weight float math pow math pow l length p a distance b sumx u x weight sumy v y weight if x 10 0 y 20 system out println distance distance weight weight sumx sumx sumy sumy u u v v total weight weight out 0 image math clamp x sumx total weight 0 5f 0 width 1 out 1 image math clamp y sumy total weight 0 5f 0 height 1 out 0 x sumx total weight 0 5f out 1 y sumy total weight 0 5f transforminverse totalweight inlines inlines intermediatelines lengthsquared totalweight imagemath totalweight imagemath totalweight totalweight totalweight override public buffered image filter buffered image src buffered image dst this width width this height height if in lines null out lines null intermediate lines new line in lines length for int line 0 line in lines length line line l intermediate lines line new line image math lerp amount in lines line x1 out lines line x1 image math lerp amount in lines line y1 out lines line y1 image math lerp amount in lines line x2 out lines line x2 image math lerp amount in lines line y2 out lines line y2 l setup in lines line setup dst super filter src dst intermediate lines null return dst return src bufferedimage bufferedimage bufferedimage inlines outlines intermediatelines inlines inlines intermediatelines imagemath inlines outlines imagemath inlines outlines imagemath inlines outlines imagemath inlines outlines inlines intermediatelines override public string to string return distort field warp tostring override public url check source string source throws plugin not found exception return super check source https checksums freenetproject org latest source jar checksource pluginnotfoundexception checksource override string get plugin name string source throws plugin not found exception return source jar getpluginname pluginnotfoundexception override string getsha1sum throws plugin not found exception try url sha1url new url get source to string sha1 url connection url connection sha1url open connection url connection set use caches false url connection set allow user interaction false input stream is open connection check redirects url connection byte array output stream bos new byte array output stream byte buffer new byte 1024 int read while read is read buffer 1 bos write buffer 0 read return new string bos to byte array split 0 catch malformedurl exception e throw new plugin not found exception impossible e e catch io exception e throw new plugin not found exception error while fetching sha1 for plugin e e pluginnotfoundexception getsource tostring urlconnection urlconnection openconnection urlconnection setusecaches urlconnection setallowuserinteraction inputstream openconnectioncheckredirects urlconnection bytearrayoutputstream bytearrayoutputstream tobytearray malformedurlexception pluginnotfoundexception ioexception pluginnotfoundexception override input stream get input stream throws io exception file tmp keystore null file input stream fis null input stream is null try tmp keystore file create temp file keystore tmp tmp keystore delete on exit key store ks key store get instance jks ks load null new char 0 is get cert certificate factory cf certificate factory get instance x 509 collection extends certificate c cf generate certificates is iterator extends certificate it c iterator while it has next certificate cert it next ks set certificate entry cert get public key to string cert file output stream tmpfos new file output stream tmp keystore try ks store tmpfos new char 0 finally closer close tmpfos system out println the ca has been imported into the trust store catch exception e system err println error while handling the ca e get message throw new io exception error while handling the ca e finally closer close fis system set property javax net ssl trust store tmp keystore to string return super get input stream inputstream getinputstream ioexception tmp_keystore fileinputstream inputstream tmp_keystore createtempfile tmp_keystore deleteonexit keystore keystore getinstance getcert certificatefactory certificatefactory getinstance generatecertificates hasnext setcertificateentry getpublickey tostring fileoutputstream fileoutputstream tmp_keystore truststore getmessage ioexception setproperty truststore tmp_keystore tostring getinputstream private input stream get cert throws io exception normal the file should be here left by installer or update script file cert file new file certfile get absolute file if cert file exists return new file input stream cert file try to create pem file class loader loader class loader get system class loader input stream in loader get resource as stream certurl if in null file util write to in cert file if cert file exists system err println nodes certfile created use it return new file input stream cert file system err println nodes certfile couldnt created try direct couldnt write the file maybe paranoid selinux or hardware node return in system err println certficate file certfile not found on disk nor buildin throw new io exception certficate file certfile not found on disk nor buildin inputstream getcert ioexception certfile getabsolutefile certfile fileinputstream certfile classloader classloader getsystemclassloader inputstream getresourceasstream fileutil writeto certfile certfile fileinputstream certfile ioexception public static void init register known mime types plain text register new mime type text plain txt new string 0 new string text pot true true null null false false false false false false l10n text plain read advice l10n text plain write advice true us ascii null gif has a filter register new mime type image gif gif new string 0 new string 0 true false new gif filter null false false false false false false l10n image gif read advice l10n image gif write advice false null null jpeg has a filter register new mime type image jpeg jpeg new string 0 new string jpg true false new jpeg filter true true null false false false false false false l10n image jpeg read advice l10n image jpeg write advice false null null png has a filter register new mime type image png png new string 0 new string 0 true false new png filter true true true null false false false false true false l10n image png read advice l10n image png write advice false null null ico probably safe fixme check this out write filters register new mime type image x icon ico new string image vnd microsoft icon image ico application ico new string 0 true false null null false false false false false false l10n image ico read advice l10n image ico write advice false null null pdf very dangerous fixme ideally we would have a filter this is such a common format register new mime type application pdf pdf new string application x pdf new string 0 false false null null true true true false true true l10n application pdf read advice l10n application pdf write advice false null null html dangerous if not filtered register new mime type text html html new string text xhtml text xml xhtml application xhtml xml new string htm false false maybe new html filter null fixme true true true true true true l10n text html read advice l10n text html write advice true iso 8859 1 new html filter css danagerous if not filtered not sure about the filter register new mime type text css css new string 0 new string 0 false false unknown new css read filter null true true true true true false l10n text css read advice l10n text css write advice true utf 8 new css read filter mimetype textplainreadadvice textplainwriteadvice mimetype giffilter imagegifreadadvice imagegifwriteadvice mimetype jpegfilter imagejpegreadadvice imagejpegwriteadvice mimetype pngfilter imagepngreadadvice imagepngwriteadvice mimetype imageicoreadadvice imageicowriteadvice mimetype applicationpdfreadadvice applicationpdfwriteadvice mimetype htmlfilter texthtmlreadadvice texthtmlwriteadvice htmlfilter mimetype cssreadfilter textcssreadadvice textcsswriteadvice cssreadfilter private static string l10n string key return l10n get string content filter key getstring contentfilter public static void register mime type mime type synchronized mime types by name mime types by name put mime type primary mime type mime type string alt mime type alternate mime types if alt null alt length 0 for int i 0 i alt length i mime types by name put alt i mime type mimetype mimetype mimetypesbyname mimetypesbyname mimetype primarymimetype mimetype mimetype alternatemimetypes mimetypesbyname mimetype public static mime type getmime type string mime type return mime types by name get mime type mimetype getmimetype mimetype mimetypesbyname mimetype public final string type filter output bucket data string type this data data this type type filteroutput filter some data param data input data param bf the bucket factory used to create the bucket to return the filtered data in param type name mime type for input data throws io exception if an internal error involving buckets occurred throws unsafe content type exception if the mime type is declared unsafe e g pdf files throws illegal state exception if data is invalid e g corrupted file and the filter have no way to recover public static filter output filter bucket data bucket factory bf string type name uri baseuri founduri callback cb throws unsafe content type exception io exception if logger should log logger minor content filter class logger minor content filter class filter data size data size type name type name string type type name string options string charset null hash map string string other params null first parse the mime type int idx type index of if idx 1 options type substring idx 1 type type substring 0 idx parse options format type subtype optional white space optional white space param value param2 value2 string raw opts options split for int i 0 i raw opts length i string raw raw opts i idx raw index of if idx 1 logger error content filter class idx 1 for on option raw from type name continue string before raw substring 0 idx trim string after raw substring idx 1 trim if before equals charset charset after else if other params null other params new hash map string string other params put before after now look for a mime type handler mime type handler getmime type type if handler null throw new unknown content type exception type name else run the read filter if there is one if handler read filter null if handler takesa charset charset null charset length 0 charset detect charset data handler bucket output data handler read filter read filter data bf charset other params new generic read filter callback baseuri cb if charset null type type charset charset return new filter output output data type if handler safe to read return new filter output data type name handler throw unsafe content type exception return null typename ioexception unsafecontenttypeexception illegalstateexception filteroutput bucketfactory typename founduricallback unsafecontenttypeexception ioexception shouldlog contentfilter contentfilter typename typename typename hashmap otherparams indexof rawopts rawopts rawopts indexof contentfilter typename otherparams otherparams hashmap otherparams mimetype mimetype getmimetype unknowncontenttypeexception typename readfilter takesacharset detectcharset outputdata readfilter readfilter otherparams genericreadfiltercallback filteroutput outputdata safetoread filteroutput typename throwunsafecontenttypeexception private static string detect charset bucket data mime type handler throws io exception detect charset string charset detectbom data if charset null handler charset extractor null obviously this is slow this is why we need to detect on insert if handler default charset null try if charset handler charset extractor get charset data handler default charset null if logger should log logger minor content filter class logger minor content filter class returning charset charset return charset catch data filter exception e ignore try if charset handler charset extractor get charset data iso 8859 1 null return charset catch data filter exception e ignore try if charset handler charset extractor get charset data utf 8 null return charset catch data filter exception e ignore try if charset handler charset extractor get charset data utf 16 null return charset catch data filter exception e ignore try if charset handler charset extractor get charset data utf 32 null return charset catch unsupported encoding exception e doesn t seem to be supported by prior to 1 6 if logger should log logger minor content filter class logger minor content filter class utf 32 not supported catch data filter exception e ignore if it doesn t have a bom then it s probably safe to use as default return handler default charset detectcharset mimetype ioexception charsetextractor defaultcharset charsetextractor getcharset defaultcharset shouldlog contentfilter contentfilter datafilterexception charsetextractor getcharset datafilterexception charsetextractor getcharset datafilterexception charsetextractor getcharset datafilterexception charsetextractor getcharset unsupportedencodingexception shouldlog contentfilter contentfilter datafilterexception defaultcharset detect a byte order mark a sequence of bytes which identifies a document as encoded with a specific charset throws io exception private static string detectbom bucket bucket throws io exception input stream is null try byte data new byte 5 is new buffered input stream bucket get input stream int read 0 while read data length int x try x is read data read data length read catch eof exception e x 1 if x 0 break if starts with data bom utf8 return utf 8 if starts with data bom utf16 be starts with data bom utf16 le return utf 16 if starts with data bom utf32 be starts with data bom utf32 le return utf 32 if starts with data bom scsu return scsu if starts with data bom utf7 1 starts with data bom utf7 2 starts with data bom utf7 3 starts with data bom utf7 4 starts with data bom utf7 5 return utf 7 if starts with data bom utf ebcdic return utf ebcdic if starts with data bom bocu 1 return bocu 1 is close return null finally closer close is ioexception ioexception inputstream bufferedinputstream getinputstream eofexception startswith bom_utf8 startswith bom_utf16_be startswith bom_utf16_le startswith bom_utf32_be startswith bom_utf32_le startswith bom_scsu startswith bom_utf7_1 startswith bom_utf7_2 startswith bom_utf7_3 startswith bom_utf7_4 startswith bom_utf7_5 startswith bom_utf_ebcdic startswith bom_bocu_1 private static boolean starts with byte data byte cmp for int i 0 i cmp length i if data i cmp i return false return true startswith public static final long max oldest never connected peer age alert threshold long 2 7 24 60 60 1000 2 weeks public peer manager user alert node stats n super false null null null null short 0 true l10n get string user alert hide false null this n n max_oldest_never_connected_peer_age_alert_threshold peermanageruseralert nodestats getstring useralert override public string get title if is opennet enabled if peers 0 return l10n no peers title if conns 0 return l10n no conns title if conns min conn alert threshold return l10n only few conns title count integer to string conns if n bwlimit delay alert relevant bwlimit delay time node stats max bwlimit delay time alert threshold return l10n too high bwlimit delay time title if n node average ping alert relevant node average ping time node stats max node average ping time alert threshold return l10n too high ping time title if clock problem min clock problem peer alert threshold return l10n clock problem title if never conn max never connected peer alert threshold return l10n too many never connected title if conn error min conn error alert threshold return l10n conn error title if disconn darknet peers max disconn peer alert threshold darknet definitely port forwarded darknet assumenat return l10n too many disconnected title if conns max conn alert threshold return l10n too many conns title if peers max peer alert threshold return l10n too many peers title if oldest never connected peer age max oldest never connected peer age alert threshold return l10n too old never connected peers title else throw new illegal argument exception not valid gettitle isopennetenabled nopeerstitle noconnstitle min_conn_alert_threshold onlyfewconnstitle tostring bwlimitdelayalertrelevant bwlimitdelaytime nodestats max_bwlimit_delay_time_alert_threshold toohighbwlimitdelaytimetitle nodeaveragepingalertrelevant nodeaveragepingtime nodestats max_node_average_ping_time_alert_threshold toohighpingtimetitle clockproblem min_clock_problem_peer_alert_threshold clockproblemtitle neverconn max_never_connected_peer_alert_threshold toomanyneverconnectedtitle connerror min_conn_error_alert_threshold connerrortitle disconndarknetpeers max_disconn_peer_alert_threshold darknetdefinitelyportforwarded darknetassumenat toomanydisconnectedtitle max_conn_alert_threshold toomanyconnstitle max_peer_alert_threshold toomanypeerstitle oldestneverconnectedpeerage max_oldest_never_connected_peer_age_alert_threshold toooldneverconnectedpeerstitle illegalargumentexception override public string get short text return get title getshorttext gettitle private string l10n string key string pattern string value return l10n get string peer manager user alert key pattern value getstring peermanageruseralert private string l10n string key string pattern string value return l10n get string peer manager user alert key pattern value getstring peermanageruseralert private string l10n string key return l10n get string peer manager user alert key getstring peermanageruseralert override public string get text string s if peers 0 is opennet enabled if n is testnet enabled return l10n no peers testnet else return l10n no peers darknet else if conns 3 clock problem min clock problem peer alert threshold s l10n clock problem count integer to string clock problem else if conns 3 conn error min conn error alert threshold is opennet enabled s l10n conn error count integer to string conn error else if conns 0 is opennet enabled return l10n no conns else if conns 1 is opennet enabled return l10n one conn else if conns 2 is opennet enabled return l10n two conns else if n bwlimit delay alert relevant bwlimit delay time node stats max bwlimit delay time alert threshold s l10n too high bwlimit delay time new string delay max new string integer to string bwlimit delay time long to string node stats max bwlimit delay time alert threshold fixme i m not convinced about the next one else if n node average ping alert relevant node average ping time node stats max node average ping time alert threshold s l10n too high ping time new string ping max new string integer to string node average ping time long to string node stats max node average ping time alert threshold else if clock problem min clock problem peer alert threshold s l10n clock problem count integer to string clock problem else if never conn max never connected peer alert threshold s l10n too many never connected count integer to string never conn else if conn error min conn error alert threshold s l10n conn error count integer to string conn error else if disconn darknet peers max disconn peer alert threshold darknet definitely port forwarded darknet assumenat s l10n too many disconnected new string count max new string integer to string disconn darknet peers integer to string max disconn peer alert threshold else if conns max conn alert threshold s l10n too many conns new string count max new string integer to string conns integer to string max conn alert threshold else if peers max peer alert threshold s l10n too many peers new string count max new string integer to string peers integer to string max peer alert threshold else if oldest never connected peer age max oldest never connected peer age alert threshold return l10n too old never connected peers else throw new illegal argument exception not valid return s gettext isopennetenabled istestnetenabled nopeerstestnet nopeersdarknet clockproblem min_clock_problem_peer_alert_threshold clockproblem tostring clockproblem connerror min_conn_error_alert_threshold isopennetenabled connerror tostring connerror isopennetenabled noconns isopennetenabled oneconn isopennetenabled twoconns bwlimitdelayalertrelevant bwlimitdelaytime nodestats max_bwlimit_delay_time_alert_threshold toohighbwlimitdelaytime tostring bwlimitdelaytime tostring nodestats max_bwlimit_delay_time_alert_threshold nodeaveragepingalertrelevant nodeaveragepingtime nodestats max_node_average_ping_time_alert_threshold toohighpingtime tostring nodeaveragepingtime tostring nodestats max_node_average_ping_time_alert_threshold clockproblem min_clock_problem_peer_alert_threshold clockproblem tostring clockproblem neverconn max_never_connected_peer_alert_threshold toomanyneverconnected tostring neverconn connerror min_conn_error_alert_threshold connerror tostring connerror disconndarknetpeers max_disconn_peer_alert_threshold darknetdefinitelyportforwarded darknetassumenat toomanydisconnected tostring disconndarknetpeers tostring max_disconn_peer_alert_threshold max_conn_alert_threshold toomanyconns tostring tostring max_conn_alert_threshold max_peer_alert_threshold toomanypeers tostring tostring max_peer_alert_threshold oldestneverconnectedpeerage max_oldest_never_connected_peer_age_alert_threshold toooldneverconnectedpeers illegalargumentexception static final public string replace string text string find string replace return replace careful text find replace replacecareful static public string replace all string text string find string replace int i while i text index of find 0 text text substring 0 i replace text substring i find length return text replaceall indexof static public string replace careful string text string find string replace string split text split find 1 string builder sb new string builder text length split length 1 replace length find length for int i 0 i split length i sb append split i if i split length 1 sb append replace return sb to string replacecareful stringbuilder stringbuilder tostring override public html node gethtml text html node alert node new html node div if peers 0 is opennet enabled if n is testnet enabled alert node add child l10n no peers testnet else alert node add child l10n no peers darknet else if conns 3 clock problem min clock problem peer alert threshold alert node add child l10n clock problem count integer to string clock problem else if conns 3 conn error min conn error alert threshold alert node add child l10n conn error count integer to string conn error else if conns 0 is opennet enabled alert node add child l10n no conns else if conns 1 is opennet enabled alert node add child l10n one conn else if conns 2 is opennet enabled alert node add child l10n two conns else if n bwlimit delay alert relevant bwlimit delay time node stats max bwlimit delay time alert threshold alert node add child l10n too high bwlimit delay time new string delay max new string integer to string bwlimit delay time long to string node stats max bwlimit delay time alert threshold else if n node average ping alert relevant node average ping time node stats max node average ping time alert threshold alert node add child l10n too high ping time new string ping max new string integer to string node average ping time long to string node stats max node average ping time alert threshold else if clock problem min clock problem peer alert threshold alert node add child l10n clock problem count integer to string clock problem else if never conn max never connected peer alert threshold l10n addl10n substitution alert node peer manager user alert too many never connected with link new string link link count new string a href friends myref fref a integer to string never conn else if conn error min conn error alert threshold alert node add child l10n conn error count integer to string conn error else if disconn darknet peers max disconn peer alert threshold darknet definitely port forwarded darknet assumenat alert node add child l10n too many disconnected new string count max new string integer to string disconn darknet peers integer to string max disconn peer alert threshold else if conns max conn alert threshold alert node add child l10n too many conns new string count max new string integer to string conns integer to string max conn alert threshold else if peers max peer alert threshold alert node add child l10n too many peers new string count max new string integer to string peers integer to string max peer alert threshold else if oldest never connected peer age max oldest never connected peer age alert threshold alert node add child l10n too old never connected peers else throw new illegal argument exception not valid return alert node htmlnode gethtmltext htmlnode alertnode htmlnode isopennetenabled istestnetenabled alertnode addchild nopeerstestnet alertnode addchild nopeersdarknet clockproblem min_clock_problem_peer_alert_threshold alertnode addchild clockproblem tostring clockproblem connerror min_conn_error_alert_threshold alertnode addchild connerror tostring connerror isopennetenabled alertnode addchild noconns isopennetenabled alertnode addchild oneconn isopennetenabled alertnode addchild twoconns bwlimitdelayalertrelevant bwlimitdelaytime nodestats max_bwlimit_delay_time_alert_threshold alertnode addchild toohighbwlimitdelaytime tostring bwlimitdelaytime tostring nodestats max_bwlimit_delay_time_alert_threshold nodeaveragepingalertrelevant nodeaveragepingtime nodestats max_node_average_ping_time_alert_threshold alertnode addchild toohighpingtime tostring nodeaveragepingtime tostring nodestats max_node_average_ping_time_alert_threshold clockproblem min_clock_problem_peer_alert_threshold alertnode addchild clockproblem tostring clockproblem neverconn max_never_connected_peer_alert_threshold addl10nsubstitution alertnode peermanageruseralert toomanyneverconnectedwithlink tostring neverconn connerror min_conn_error_alert_threshold alertnode addchild connerror tostring connerror disconndarknetpeers max_disconn_peer_alert_threshold darknetdefinitelyportforwarded darknetassumenat alertnode addchild toomanydisconnected tostring disconndarknetpeers tostring max_disconn_peer_alert_threshold max_conn_alert_threshold alertnode addchild toomanyconns tostring tostring max_conn_alert_threshold max_peer_alert_threshold alertnode addchild toomanypeers tostring tostring max_peer_alert_threshold oldestneverconnectedpeerage max_oldest_never_connected_peer_age_alert_threshold alertnode addchild toooldneverconnectedpeers illegalargumentexception alertnode override public short get priority class if peers 0 is opennet enabled return user alert critical error if conns 0 is opennet enabled return user alert error if conns 3 clock problem min clock problem peer alert threshold return error if conns 3 conn error min conn error alert threshold return error if conns 3 is opennet enabled return error if n bwlimit delay alert relevant bwlimit delay time node stats max bwlimit delay time alert threshold return error if n node average ping alert relevant node average ping time node stats max node average ping time alert threshold return error if clock problem min clock problem peer alert threshold return error if never conn max never connected peer alert threshold return warning if conn error min conn error alert threshold return warning if disconn darknet peers max disconn peer alert threshold darknet definitely port forwarded darknet assumenat return warning if conns max conn alert threshold return warning if peers max peer alert threshold return warning if oldest never connected peer age max oldest never connected peer age alert threshold return warning return error getpriorityclass isopennetenabled useralert critical_error isopennetenabled useralert clockproblem min_clock_problem_peer_alert_threshold connerror min_conn_error_alert_threshold isopennetenabled bwlimitdelayalertrelevant bwlimitdelaytime nodestats max_bwlimit_delay_time_alert_threshold nodeaveragepingalertrelevant nodeaveragepingtime nodestats max_node_average_ping_time_alert_threshold clockproblem min_clock_problem_peer_alert_threshold neverconn max_never_connected_peer_alert_threshold connerror min_conn_error_alert_threshold disconndarknetpeers max_disconn_peer_alert_threshold darknetdefinitelyportforwarded darknetassumenat max_conn_alert_threshold max_peer_alert_threshold oldestneverconnectedpeerage max_oldest_never_connected_peer_age_alert_threshold override public boolean is valid only update here so we don t get odd behavior with it fluctuating bwlimit delay time int n get bwlimit delay time node average ping time int n get node average ping time oldest never connected peer age int n peers get oldest never connected peer age return peers 0 is opennet enabled conns 3 is opennet enabled never conn max never connected peer alert threshold disconn darknet peers max disconn peer alert threshold darknet definitely port forwarded darknet assumenat conns max conn alert threshold peers max peer alert threshold clock problem min clock problem peer alert threshold conn error min conn error alert threshold n bwlimit delay alert relevant bwlimit delay time node stats max bwlimit delay time alert threshold n node average ping alert relevant node average ping time node stats max node average ping time alert threshold oldest never connected peer age max oldest never connected peer age alert threshold super is valid isvalid bwlimitdelaytime getbwlimitdelaytime nodeaveragepingtime getnodeaveragepingtime oldestneverconnectedpeerage getoldestneverconnectedpeerage isopennetenabled isopennetenabled neverconn max_never_connected_peer_alert_threshold disconndarknetpeers max_disconn_peer_alert_threshold darknetdefinitelyportforwarded darknetassumenat max_conn_alert_threshold max_peer_alert_threshold clockproblem min_clock_problem_peer_alert_threshold connerror min_conn_error_alert_threshold bwlimitdelayalertrelevant bwlimitdelaytime nodestats max_bwlimit_delay_time_alert_threshold nodeaveragepingalertrelevant nodeaveragepingtime nodestats max_node_average_ping_time_alert_threshold oldestneverconnectedpeerage max_oldest_never_connected_peer_age_alert_threshold isvalid logger register log threshold callback new log threshold callback override public void should update logminor logger should log logger minor this registerlogthresholdcallback logthresholdcallback shouldupdate shouldlog public static final double crazy max ping time 365 25 24 60 60 1000 node pinger node n this node n crazy_max_ping_time nodepinger void start run public void run try peer node peers null synchronized node peers if node peers connected peers null node peers connected peers length 0 return peers new peer node node peers connected peers length system arraycopy node peers connected peers 0 peers 0 node peers connected peers length now we don t have to care about synchronization anymore recalculate mean peers finally requeue after to avoid exacerbating overload node ps queue timed job this 200 peernode connectedpeers connectedpeers peernode connectedpeers connectedpeers connectedpeers recalculatemean queuetimedjob recalculate the mean ping time private void recalculate mean peer node peers if peers length 0 return mean ping calculate median ping peers if logminor logger minor this median ping mean ping recalculatemean peernode meanping calculatemedianping meanping private double calculate median ping peer node peers double all peers new double peers length for int i 0 i peers length i peer node peer peers i all peers i peer average ping time arrays sort all peers return all peers peers length 2 calculatemedianping peernode allpeers peernode allpeers averagepingtime allpeers allpeers public double average ping time return mean ping averagepingtime meanping private static final long serial versionuid 7443033796560597360l public parser exception exception e super e serialversionuid parserexception public parser exception string s super s parserexception consutrctor of perisstent string param str java string public persistent string string str this str str persistentstring private persistent string persistentstring get java string return java string public string to string return str tostring append string to the current string value of persistent string param tail appended string public void append string tail modify str str tail persistentstring assign new string value to the persistent string param str new string value public void set string str modify this str str persistentstring get current string value return java string public string get return str private class need restart user alert extends abstract user alert override public string get title return l10n need restart title needrestartuseralert abstractuseralert gettitle needrestarttitle override public string get text return gethtml text to string gettext gethtmltext tostring override public string get short text return l10n need restart short getshorttext needrestartshort override public html node gethtml text html node alert node new html node div alert node add child l10n need restart if node is using wrapper alert node add child br html node restart form alert node add child form new string action method enctype id accept charset new string post multipart form data restart form utf 8 add child div restart form add child input new string type name value new string hidden form password node client core form password restart form add child div restart form add child input new string type name new string hidden restart restart form add child input new string type name value new string submit restart2 l10n restart node return alert node htmlnode gethtmltext htmlnode alertnode htmlnode alertnode addchild needrestart isusingwrapper alertnode addchild htmlnode restartform alertnode addchild restartform addchild restartform addchild formpassword clientcore formpassword restartform addchild restartform addchild restartform addchild restartnode alertnode override public short get priority class return user alert warning getpriorityclass useralert override public boolean is valid return need restart isvalid needrestart override public boolean user can dismiss return false usercandismiss config toadlet high level simple client client config conf node node node client core core super client config conf this core core this node node configtoadlet highlevelsimpleclient nodeclientcore override public void handle post uri uri http request request toadlet context ctx throws toadlet context closed exception io exception if ctx is allowed full access super send error page ctx 403 l10n get string toadlet unauthorized title l10n get string toadlet unauthorized return string pass request get part as string form password 32 if pass null pass equals core form password multi value table string string headers new multi value table string string headers put location config ctx send reply headers 302 found headers null 0 return if request is part set seclevels handle the security level changes html node page node null html node content null html node ul null html node form node null boolean changed anything false string config name security levels network threat level string confirm security levels network threat level confirm string try confirm security levels network threat level try confirm string network threat level request get part as string config name 128 network threat level new threat level security levels parse network threat level network threat level if new threat level null if new threat level node security levels get network threat level if request is part set confirm request is part set try confirm html node warning node security levels get confirm warning new threat level confirm if warning null if page node null page node ctx get page maker get page node l10n get string config toadlet full title new string name new string node get my name ctx content ctx get page maker get content node page node form node ctx add form child content config form sec levels ul form node add child ul class config html node seclevel group ul add child li seclevel group add child input new string type name value new string hidden config name network threat level html node infobox seclevel group add child div class infobox infobox information infobox add child div class infobox header l10n sec network threat level confirm title mode security levels localised name new threat level html node infobox content infobox add child div class infobox content infobox content add child warning infobox content add child input new string type name value new string hidden try confirm on else apply immediately no confirm needed node security levels set threat level new threat level changed anything true else if request is part set confirm apply immediately user confirmed it node security levels set threat level new threat level changed anything true config name security levels friends threat level confirm security levels friends threat level confirm try confirm security levels friends threat level try confirm string friends threat level request get part as string config name 128 friends threat level new friends level security levels parse friends threat level friends threat level if new friends level null if new friends level node security levels get friends threat level if request is part set confirm request is part set try confirm html node warning node security levels get confirm warning new friends level confirm if warning null if page node null page node ctx get page maker get page node l10n get string config toadlet full title new string name new string node get my name ctx content ctx get page maker get content node page node form node ctx add form child content config form sec levels ul form node add child ul class config html node seclevel group ul add child li seclevel group add child input new string type name value new string hidden config name friends threat level html node infobox seclevel group add child div class infobox infobox information infobox add child div class infobox header l10n sec friends threat level confirm title mode security levels localised name new friends level html node infobox content infobox add child div class infobox content infobox content add child warning infobox content add child input new string type name value new string hidden try confirm on else apply immediately no confirm needed node security levels set threat level new friends level changed anything true else if request is part set confirm apply immediately user confirmed it node security levels set threat level new friends level changed anything true config name security levels physical threat level confirm security levels physical threat level confirm try confirm security levels physical threat level try confirm string physical threat level request get part as string config name 128 physical threat level new physical level security levels parse physical threat level physical threat level if new physical level null if new physical level node security levels get physical threat level no confirmation for changes to physical threat level node security levels set threat level new physical level changed anything true if changed anything core store config if page node null form node add child input new string type name value new string hidden seclevels on form node add child input new string type value new string submit l10n apply form node add child input new string type value new string reset l10n reset writehtml reply ctx 200 ok page node generate return else multi value table string string headers new multi value table string string headers put location config mode mode security levels ctx send reply headers 302 found headers null 0 return other setting not security level goes here sub config sc config get configs string builder errbuf new string builder boolean logminor logger should log logger minor this for int i 0 i sc length i option o sc i get options string prefix sc i get prefix string config name for int j 0 j o length j config name o j get name if logminor logger minor this setting prefix config name we ignore unreconized parameters if request is part set prefix config name string value request get part as string prefix config name max param value size if o j get value string equals value if logminor logger minor this setting prefix config name to value try o j set value value catch invalid config value exception e errbuf append o j get name append append e get message append n catch node need restart exception e need restart true catch exception e errbuf append o j get name append append e append n logger error this caught e e wrapper params string wrapper config name wrapper java maxmemory if request is part set wrapper config name string value request get part as string wrapper config name max param value size if wrapper config get wrapper property wrapper config name equals value if logminor logger minor this setting wrapper config name to value wrapper config set wrapper property wrapper config name value core store config html node page node ctx get page maker get page node l10n applied title ctx html node content node ctx get page maker get content node page node if errbuf length 0 html node infobox content node add child ctx get page maker get infobox infobox success l10n applied title html node content ctx get page maker get content node infobox content add child l10n applied success if need restart content add child br content add child l10n need restart if node is using wrapper content add child br html node restart form ctx add form child content restart form restart form add child input new string type name new string hidden restart restart form add child input new string type name value new string submit restart2 l10n restart node if need restart user alert null need restart user alert new need restart user alert node client core alerts register need restart user alert else html node infobox content node add child ctx get page maker get infobox infobox error l10n applied failure title html node content ctx get page maker get content node infobox add child div class infobox content content add child l10n applied failure exceptions content add child br content add child errbuf to string html node infobox content node add child ctx get page maker get infobox infobox normal l10n possibilities title html node content ctx get page maker get content node infobox content add child a new string href title new string l10n short title handlepost httprequest toadletcontext toadletcontextclosedexception ioexception isallowedfullaccess senderrorpage getstring unauthorizedtitle getstring getpartasstring formpassword formpassword multivaluetable multivaluetable sendreplyheaders ispartset htmlnode pagenode htmlnode htmlnode htmlnode formnode changedanything configname networkthreatlevel networkthreatlevel tryconfirm networkthreatlevel tryconfirm networkthreatlevel getpartasstring configname network_threat_level newthreatlevel securitylevels parsenetworkthreatlevel networkthreatlevel newthreatlevel newthreatlevel securitylevels getnetworkthreatlevel ispartset ispartset tryconfirm htmlnode securitylevels getconfirmwarning newthreatlevel pagenode pagenode getpagemaker getpagenode getstring configtoadlet fulltitle getmyname getpagemaker getcontentnode pagenode formnode addformchild configformseclevels formnode addchild htmlnode seclevelgroup addchild seclevelgroup addchild configname networkthreatlevel htmlnode seclevelgroup addchild addchild l10nsec networkthreatlevelconfirmtitle securitylevels localisedname newthreatlevel htmlnode infoboxcontent addchild infoboxcontent addchild infoboxcontent addchild tryconfirm securitylevels setthreatlevel newthreatlevel changedanything ispartset securitylevels setthreatlevel newthreatlevel changedanything configname friendsthreatlevel friendsthreatlevel tryconfirm friendsthreatlevel tryconfirm friendsthreatlevel getpartasstring configname friends_threat_level newfriendslevel securitylevels parsefriendsthreatlevel friendsthreatlevel newfriendslevel newfriendslevel securitylevels getfriendsthreatlevel ispartset ispartset tryconfirm htmlnode securitylevels getconfirmwarning newfriendslevel pagenode pagenode getpagemaker getpagenode getstring configtoadlet fulltitle getmyname getpagemaker getcontentnode pagenode formnode addformchild configformseclevels formnode addchild htmlnode seclevelgroup addchild seclevelgroup addchild configname friendsthreatlevel htmlnode seclevelgroup addchild addchild l10nsec friendsthreatlevelconfirmtitle securitylevels localisedname newfriendslevel htmlnode infoboxcontent addchild infoboxcontent addchild infoboxcontent addchild tryconfirm securitylevels setthreatlevel newfriendslevel changedanything ispartset securitylevels setthreatlevel newfriendslevel changedanything configname physicalthreatlevel physicalthreatlevel tryconfirm physicalthreatlevel tryconfirm physicalthreatlevel getpartasstring configname physical_threat_level newphysicallevel securitylevels parsephysicalthreatlevel physicalthreatlevel newphysicallevel newphysicallevel securitylevels getphysicalthreatlevel securitylevels setthreatlevel newphysicallevel changedanything changedanything storeconfig pagenode formnode addchild formnode addchild formnode addchild writehtmlreply pagenode multivaluetable multivaluetable mode_security_levels sendreplyheaders subconfig getconfigs stringbuilder stringbuilder shouldlog getoptions getprefix configname configname getname configname ispartset configname getpartasstring configname max_param_value_size getvaluestring configname setvalue invalidconfigvalueexception getname getmessage nodeneedrestartexception needrestart getname wrapperconfigname ispartset wrapperconfigname getpartasstring wrapperconfigname max_param_value_size wrapperconfig getwrapperproperty wrapperconfigname wrapperconfigname wrapperconfig setwrapperproperty wrapperconfigname storeconfig htmlnode pagenode getpagemaker getpagenode appliedtitle htmlnode contentnode getpagemaker getcontentnode pagenode htmlnode contentnode addchild getpagemaker getinfobox appliedtitle htmlnode getpagemaker getcontentnode addchild appliedsuccess needrestart addchild addchild needrestart isusingwrapper addchild htmlnode restartform addformchild restartform restartform addchild restartform addchild restartnode needrestartuseralert needrestartuseralert needrestartuseralert clientcore needrestartuseralert htmlnode contentnode addchild getpagemaker getinfobox appliedfailuretitle htmlnode getpagemaker getcontentnode addchild addchild appliedfailureexceptions addchild addchild tostring htmlnode contentnode addchild getpagemaker getinfobox possibilitiestitle htmlnode getpagemaker getcontentnode addchild shorttitle private static final string l10n string string return l10n get string config toadlet string getstring configtoadlet override public void handle get uri uri http request req toadlet context ctx throws toadlet context closed exception io exception if ctx is allowed full access super send error page ctx 403 l10n get string toadlet unauthorized title l10n get string toadlet unauthorized return sub config sc config get configs arrays sort sc html node page node ctx get page maker get page node l10n get string config toadlet full title new string name new string node get my name ctx html node content node ctx get page maker get content node page node content node add child core alerts create summary final int mode ctx get page maker draw mode selection array core req content node mode security levels security levels title security levels tooltip if mode mode security levels draw security levels page content node ctx else if mode page maker mode advanced html node navigation bar ctx get page maker get infobox navbar l10n config nav title html node navigation content ctx get page maker get content node navigation bar add child ul if l10n get selected language equals l10n language get default navigation content add child a href translation toadlet toadlet url l10n contribute translation html node navigation table navigation content add child table class config navigation html node navigation table row navigation table add child tr html node next table cell navigation table row for int i 0 i sc length i if sc i get prefix equals security levels continue next table cell add child td class config navigation add child li add child a href sc i get prefix l10n sc i get prefix content node add child navigation bar html node infobox content node add child div class infobox infobox normal infobox add child div class infobox header l10n title html node config node infobox add child div class infobox content html node form node ctx add form child config node config form if wrapper config can change properties string config name wrapper java maxmemory string cur value wrapper config get wrapper property config name if cur value null form node add child div class configprefix l10n wrapper html node list form node add child ul class config html node item list add child li fixme how to get the real default string default value 128 item add child span new string class title style new string configshortdesc l10n get string config toadlet default is new string default new string default value cursor help add child l10n gethtml node wrapper config config name short item add child span class config add child input new string type class name value new string text config config name cur value item add child span class configlongdesc add child l10n gethtml node wrapper config config name long for int i 0 i sc length i short displayed config elements 0 if sc i get prefix equals security levels continue option o sc i get options html node config group ul node new html node ul class config for int j 0 j o length j if mode page maker mode simple o j is expert displayed config elements string config name o j get name html node config item node config group ul node add child li config item node add child span new string class title style new string configshortdesc l10n get string config toadlet default is new string default new string o j get default mode page maker mode advanced sc i get prefix o j get name cursor help add child l10n gethtml node o j get short desc html node config item value node config item node add child span class config if o j get value string null logger error this sc i get prefix config name has returned null from config continue config callback callback o j get callback if callback instanceof enumerable option callback config item value node add child add combo box enumerable option callback callback sc i config name callback is read only else if callback instanceof boolean callback config item value node add child add boolean combo box boolean option o j get value sc i config name callback is read only else if callback is read only config item value node add child input new string type class disabled alt name value new string text config disabled o j get short desc sc i get prefix config name o j get value string else config item value node add child input new string type class alt name value new string text config o j get short desc sc i get prefix config name o j get value string config item node add child span class configlongdesc add child l10n gethtml node o j get long desc if displayed config elements 0 form node add child div class configprefix l10n sc i get prefix form node add child a id sc i get prefix form node add child config group ul node form node add child input new string type value new string submit l10n apply form node add child input new string type value new string reset l10n reset this writehtml reply ctx 200 ok page node generate handleget httprequest toadletcontext toadletcontextclosedexception ioexception isallowedfullaccess senderrorpage getstring unauthorizedtitle getstring subconfig getconfigs htmlnode pagenode getpagemaker getpagenode getstring configtoadlet fulltitle getmyname htmlnode contentnode getpagemaker getcontentnode pagenode contentnode addchild createsummary getpagemaker drawmodeselectionarray contentnode mode_security_levels securitylevels securitylevels mode_security_levels drawsecuritylevelspage contentnode pagemaker mode_advanced htmlnode navigationbar getpagemaker getinfobox confignavtitle htmlnode navigationcontent getpagemaker getcontentnode navigationbar addchild getselectedlanguage getdefault navigationcontent addchild translationtoadlet toadlet_url contributetranslation htmlnode navigationtable navigationcontent addchild config_navigation htmlnode navigationtablerow navigationtable addchild htmlnode nexttablecell navigationtablerow getprefix nexttablecell addchild config_navigation addchild addchild getprefix getprefix contentnode addchild navigationbar htmlnode contentnode addchild addchild htmlnode confignode addchild htmlnode formnode addformchild confignode configform wrapperconfig canchangeproperties configname curvalue wrapperconfig getwrapperproperty configname curvalue formnode addchild htmlnode formnode addchild htmlnode addchild defaultvalue addchild getstring configtoadlet defaultis defaultvalue addchild gethtmlnode wrapperconfig configname addchild addchild configname curvalue addchild addchild gethtmlnode wrapperconfig configname displayedconfigelements getprefix getoptions htmlnode configgroupulnode htmlnode pagemaker mode_simple isexpert displayedconfigelements configname getname htmlnode configitemnode configgroupulnode addchild configitemnode addchild getstring configtoadlet defaultis getdefault pagemaker mode_advanced getprefix getname addchild gethtmlnode getshortdesc htmlnode configitemvaluenode configitemnode addchild getvaluestring getprefix configname configcallback getcallback enumerableoptioncallback configitemvaluenode addchild addcombobox enumerableoptioncallback configname isreadonly booleancallback configitemvaluenode addchild addbooleancombobox booleanoption getvalue configname isreadonly isreadonly configitemvaluenode addchild getshortdesc getprefix configname getvaluestring configitemvaluenode addchild getshortdesc getprefix configname getvaluestring configitemnode addchild addchild gethtmlnode getlongdesc displayedconfigelements formnode addchild getprefix formnode addchild getprefix formnode addchild configgroupulnode formnode addchild formnode addchild writehtmlreply pagenode private void draw security levels page html node content node toadlet context ctx html node infobox content node add child div class infobox infobox normal infobox add child div class infobox header l10n sec title html node config node infobox add child div class infobox content html node form node ctx add form child config node config form sec levels network security level form node add child div class configprefix l10n sec network threat level short html node ul form node add child ul class config html node seclevel group ul add child li seclevel group add child l10n sec network threat level network threat level network level node security levels get network threat level string control name security levels network threat level for network threat level level network threat level values html node input if level network level input seclevel group add child p add child input new string type checked name value new string radio on control name level name else input seclevel group add child p add child input new string type name value new string radio control name level name input add child b l10n sec network threat level name level input add child l10n addl10n substitution input security levels network threat level choice level new string bold bold new string b b html node inner input add child p add child i l10n addl10n substitution inner security levels network threat level desc level new string bold bold new string b b friends security level form node add child div class configprefix l10n sec friends threat level short ul form node add child ul class config seclevel group ul add child li seclevel group add child l10n sec friends threat level friends threat level friends level node security levels get friends threat level control name security levels friends threat level for friends threat level level friends threat level values html node input if level friends level input seclevel group add child p add child input new string type checked name value new string radio on control name level name else input seclevel group add child p add child input new string type name value new string radio control name level name input add child b l10n sec friends threat level name level input add child l10n addl10n substitution input security levels friends threat level choice level new string bold bold new string b b html node inner input add child p add child i l10n addl10n substitution inner security levels friends threat level desc level new string bold bold new string b b physical security level form node add child div class configprefix l10n sec physical threat level short ul form node add child ul class config seclevel group ul add child li seclevel group add child l10n sec physical threat level physical threat level physical level node security levels get physical threat level control name security levels physical threat level for physical threat level level physical threat level values html node input if level physical level input seclevel group add child p add child input new string type checked name value new string radio on control name level name else input seclevel group add child p add child input new string type name value new string radio control name level name input add child b l10n sec physical threat level name level input add child l10n addl10n substitution input security levels physical threat level choice level new string bold bold new string b b html node inner input add child p add child i l10n addl10n substitution inner security levels physical threat level desc level new string bold bold new string b b fixme implement the rest it should be very similar to the above form node add child input new string type name value new string hidden seclevels on form node add child input new string type value new string submit l10n apply form node add child input new string type value new string reset l10n reset drawsecuritylevelspage htmlnode contentnode toadletcontext htmlnode contentnode addchild addchild l10nsec htmlnode confignode addchild htmlnode formnode addformchild confignode configformseclevels formnode addchild l10nsec networkthreatlevelshort htmlnode formnode addchild htmlnode seclevelgroup addchild seclevelgroup addchild l10nsec networkthreatlevel network_threat_level networklevel securitylevels getnetworkthreatlevel controlname networkthreatlevel network_threat_level network_threat_level htmlnode networklevel seclevelgroup addchild addchild controlname seclevelgroup addchild addchild controlname addchild l10nsec networkthreatlevel addchild addl10nsubstitution securitylevels networkthreatlevel htmlnode addchild addchild addl10nsubstitution securitylevels networkthreatlevel formnode addchild l10nsec friendsthreatlevelshort formnode addchild seclevelgroup addchild seclevelgroup addchild l10nsec friendsthreatlevel friends_threat_level friendslevel securitylevels getfriendsthreatlevel controlname friendsthreatlevel friends_threat_level friends_threat_level htmlnode friendslevel seclevelgroup addchild addchild controlname seclevelgroup addchild addchild controlname addchild l10nsec friendsthreatlevel addchild addl10nsubstitution securitylevels friendsthreatlevel htmlnode addchild addchild addl10nsubstitution securitylevels friendsthreatlevel formnode addchild l10nsec physicalthreatlevelshort formnode addchild seclevelgroup addchild seclevelgroup addchild l10nsec physicalthreatlevel physical_threat_level physicallevel securitylevels getphysicalthreatlevel controlname physicalthreatlevel physical_threat_level physical_threat_level htmlnode physicallevel seclevelgroup addchild addchild controlname seclevelgroup addchild addchild controlname addchild l10nsec physicalthreatlevel addchild addl10nsubstitution securitylevels physicalthreatlevel htmlnode addchild addchild addl10nsubstitution securitylevels physicalthreatlevel formnode addchild formnode addchild formnode addchild private string l10n sec string key return l10n get string security levels key l10nsec getstring securitylevels private string l10n sec string key string pattern string value return l10n get string security levels key pattern value l10nsec getstring securitylevels override public string supported methods return get post supportedmethods private html node add combo box enumerable option callback o sub config sc string name boolean disabled html node result if disabled result new html node select new string name disabled new string sc get prefix name disabled else result new html node select name sc get prefix name string possible values o get possible values for int i 0 i possible values length i if possible values i equals o get result add child option new string value selected new string possible values i selected possible values i else result add child option value possible values i possible values i return result htmlnode addcombobox enumerableoptioncallback subconfig htmlnode htmlnode getprefix htmlnode getprefix possiblevalues getpossiblevalues possiblevalues possiblevalues addchild possiblevalues possiblevalues addchild possiblevalues possiblevalues private html node add boolean combo box boolean value sub config sc string name boolean disabled html node result if disabled result new html node select new string name disabled new string sc get prefix name disabled else result new html node select name sc get prefix name if value result add child option new string value selected new string true selected l10n true result add child option value false l10n false else result add child option value true l10n true result add child option new string value selected new string false selected l10n false return result htmlnode addbooleancombobox subconfig htmlnode htmlnode getprefix htmlnode getprefix addchild addchild addchild addchild final dda check job check job testdda reply message dda check job job this check job job ddacheckjob checkjob testddareplymessage ddacheckjob checkjob override public simple field set get field set simple field set sfs new simple field set true sfs put single testdda request message directory check job directory to string if check job read filename null sfs put single read filename check job read filename to string if check job write filename null sfs put single write filename check job write filename to string sfs put single content to write check job write content return sfs simplefieldset getfieldset simplefieldset simplefieldset putsingle testddarequestmessage checkjob tostring checkjob readfilename putsingle read_filename checkjob readfilename tostring checkjob writefilename putsingle write_filename checkjob writefilename tostring putsingle content_to_write checkjob writecontent override public string get name return name getname override public void run fcp connection handler handler node node throws message invalid exception throw new message invalid exception protocol error message invalid message name goes from server to client not the other way around name false fcpconnectionhandler messageinvalidexception messageinvalidexception protocolerrormessage invalid_message override public void remove from object container container throw new unsupported operation exception removefrom objectcontainer unsupportedoperationexception protected float h edge matrix sobel h public edge filter hedgematrix sobel_h edgefilter public void setv edge matrix float v edge matrix this v edge matrix v edge matrix setvedgematrix vedgematrix vedgematrix vedgematrix public float getv edge matrix return v edge matrix getvedgematrix vedgematrix public void seth edge matrix float h edge matrix this h edge matrix h edge matrix sethedgematrix hedgematrix hedgematrix hedgematrix public float geth edge matrix return h edge matrix gethedgematrix hedgematrix override protected int filter pixels int width int height int in pixels rectangle transformed space int index 0 int out pixels new int width height for int y 0 y height y for int x 0 x width x int r 0 g 0 b 0 int rh 0 gh 0 bh 0 int rv 0 gv 0 bv 0 int a in pixels y width x 0xff000000 for int row 1 row 1 row int iy y row int ioffset if 0 iy iy height ioffset iy width else ioffset y width int moffset 3 row 1 1 for int col 1 col 1 col int ix x col if 0 ix ix width ix x int rgb in pixels ioffset ix float h h edge matrix moffset col float v v edge matrix moffset col r rgb 0xff0000 16 g rgb 0x00ff00 8 b rgb 0x0000ff rh int h r gh int h g bh int h b rv int v r gv int v g bv int v b r int math sqrt rh rh rv rv 1 8 g int math sqrt gh gh gv gv 1 8 b int math sqrt bh bh bv bv 1 8 r pixel utils clamp r g pixel utils clamp g b pixel utils clamp b out pixels index a r 16 g 8 b return out pixels filterpixels inpixels transformedspace outpixels inpixels inpixels hedgematrix vedgematrix pixelutils pixelutils pixelutils outpixels outpixels override public string to string return blur detect edges tostring public class static toadlet extends toadlet static toadlet super null statictoadlet statictoadlet override public void handle get uri uri http request request toadlet context ctx throws toadlet context closed exception io exception string path uri get path if path starts with root url we should never get any other path anyway return try path path substring root url length catch index out of bounds exception ioobe this send error page ctx 404 l10n path not found title l10n path not found return be very strict about what characters we allow in the path since if path matches a za z0 9 path index of 1 this send error page ctx 404 l10n path not found title l10n path invalid chars return input stream strm get class get resource as stream root path path if strm null this send error page ctx 404 l10n path not found title l10n path not found return bucket data ctx get bucket factory make bucket strm available output stream os data get output stream byte cbuf new byte 4096 while true int r strm read cbuf if r 1 break os write cbuf 0 r strm close os close url url get class get resource root path path date m time get urlm time url ctx send reply headers 200 ok null defaultmime types guessmime type path false data size m time ctx write data data data free handleget httprequest toadletcontext toadletcontextclosedexception ioexception getpath startswith root_url root_url indexoutofboundsexception senderrorpage pathnotfoundtitle pathnotfound _ indexof senderrorpage pathnotfoundtitle pathinvalidchars inputstream getclass getresourceasstream root_path senderrorpage pathnotfoundtitle pathnotfound getbucketfactory makebucket outputstream getoutputstream getclass getresource root_path mtime geturlmtime sendreplyheaders defaultmimetypes guessmimetype mtime writedata try to find the modification time for a url or return null if not possible we usually load our resources from the jar or possibly from a file in some setups so we check the modification time of the jar for resources in a jar and the mtime for files private date get urlm time url url if url get protocol equals jar file f new file url get path substring 0 url get path index of return new date f last modified else if url get protocol equals file file f new file url get path return new date f last modified else return null geturlmtime getprotocol getpath getpath indexof lastmodified getprotocol getpath lastmodified private string l10n string key return l10n get string static toadlet key getstring statictoadlet override public string supported methods return get supportedmethods public renew subscriber control point ctrlp set control point ctrlp renewsubscriber controlpoint setcontrolpoint private control point ctrl point public void set control point control point ctrlp ctrl point ctrlp controlpoint ctrlpoint setcontrolpoint controlpoint ctrlpoint public control point get control point return ctrl point controlpoint getcontrolpoint ctrlpoint public void run control point ctrlp get control point long renew interval interval 1000 while is runnable true try thread sleep renew interval catch interrupted exception e ctrlp renew subscriber service controlpoint getcontrolpoint renewinterval isrunnable renewinterval interruptedexception renewsubscriberservice applies distortion by adding water ripple effect param base image the base image return the distorted image public buffered image get distorted image buffered image base image noise producer noise producer get config get noise impl buffered image distorted image new buffered image base image get width base image get height buffered image type int argb graphics2d graphics graphics2d distorted image get graphics ripple filter ripple filter new ripple filter ripple filter set wave type ripple filter sine ripple filter setx amplitude 2 6f ripple filter sety amplitude 1 7f ripple filter setx wavelength 15 ripple filter sety wavelength 5 ripple filter set edge action transform filter nearest neighbour water filter water filter new water filter water filter set amplitude 1 5f water filter set phase 10 water filter set wavelength 2 buffered image effect image water filter filter base image null effect image ripple filter filter effect image null graphics draw image effect image 0 0 null null graphics dispose noise producer make noise distorted image 1f 1f 25f 25f noise producer make noise distorted image 1f 25f 5f 9f return distorted image baseimage bufferedimage getdistortedimage bufferedimage baseimage noiseproducer noiseproducer getconfig getnoiseimpl bufferedimage distortedimage bufferedimage baseimage getwidth baseimage getheight bufferedimage type_int_argb distortedimage getgraphics ripplefilter ripplefilter ripplefilter ripplefilter setwavetype ripplefilter ripplefilter setxamplitude ripplefilter setyamplitude ripplefilter setxwavelength ripplefilter setywavelength ripplefilter setedgeaction transformfilter nearest_neighbour waterfilter waterfilter waterfilter waterfilter setamplitude waterfilter setphase waterfilter setwavelength bufferedimage effectimage waterfilter baseimage effectimage ripplefilter effectimage drawimage effectimage noiseproducer makenoise distortedimage noiseproducer makenoise distortedimage distortedimage public class color4f extends tuple4f public color4f this 0 0 0 0 public color4f float x this x x 0 this y x 1 this z x 2 this w x 3 public color4f float x float y float z float w this x x this y y this z z this w w public color4f color4f t this x t x this y t y this z t z this w t w public color4f tuple4f t this x t x this y t y this z t z this w t w public color4f color c set c public void set color c set c getrgb components null getrgbcomponents public color get return new color x y z w create a dns record with a name type clazz and ttl dns record string name int type int clazz int ttl super name type clazz this ttl ttl this created system current time millis dnsrecord dnsrecord currenttimemillis true if this record is the same as some other record public boolean equals object other return other instanceof dns record same as dns record other dnsrecord sameas dnsrecord true if this record is the same as some other record boolean same as dns record other return super equals other same value dns record other sameas dnsrecord samevalue dnsrecord true if this record has the same value as some other record abstract boolean same value dns record other samevalue dnsrecord true if this record has the same type as some other record boolean same type dns record other return type other type sametype dnsrecord handles a query represented by this record return returns true if a conflict with one of the services registered with jmdns or with the hostname occured handles a responserepresented by this record return returns true if a conflict with one of the services registered with jmdns or with the hostname occured abstract boolean handle response jmdns impl dns adds this as an answer to the provided outgoing datagram abstract dns outgoing add answer jmdns impl dns dns incoming in inet address addr int port dns outgoing out throws io exception handleresponse jmdnsimpl dnsoutgoing addanswer jmdnsimpl dnsincoming inetaddress dnsoutgoing ioexception true if this record is suppressed by the answers in a message boolean suppressed by dns incoming msg try for int i msg num answers i 0 if suppressed by dns record msg answers get i return true return false catch array index out of bounds exception e logger log level warning suppressed by message msg exception e msg print true return false suppressedby dnsincoming numanswers suppressedby dnsrecord arrayindexoutofboundsexception suppressedby true if this record would be supressed by an answer this is the case if this record would not have a significantly longer ttl boolean suppressed by dns record other if same as other other ttl ttl 2 return true return false suppressedby dnsrecord sameas get the expiration time of this record long get expiration time int percent return created percent ttl 10l getexpirationtime get the remaining ttl for this record int get remainingttl long now return int math max 0 get expiration time 100 now 1000 getremainingttl getexpirationtime check if the record is expired public boolean is expired long now return get expiration time 100 now isexpired getexpirationtime check if the record is stale ie it has outlived more than half of its ttl boolean is stale long now return get expiration time 50 now isstale getexpirationtime reset the ttl of a record this avoids having to update the entire record in the cache void resetttl dns record other created other created ttl other ttl dnsrecord write this record into an outgoing message abstract void write dns outgoing out throws io exception dnsoutgoing ioexception address string name int type int clazz int ttl inet address addr super name type clazz ttl this addr addr inetaddress address string name int type int clazz int ttl byte raw address super name type clazz ttl try this addr inet address get by address raw address catch unknown host exception exception logger log level warning address exception exception rawaddress inetaddress getbyaddress rawaddress unknownhostexception void write dns outgoing out throws io exception if addr null byte buffer addr get address if dns constants type a type if we have a type a records we should answer with a i pv4 address if addr instanceof inet4 address all is good else get the last four bytes byte tempbuffer buffer buffer new byte 4 system arraycopy tempbuffer 12 buffer 0 4 else if we have a type aaaa records we should answer with a i pv6 address if addr instanceof inet4 address byte tempbuffer buffer buffer new byte 16 for int i 0 i 16 i if i 11 buffer i tempbuffer i 12 else buffer i 0 int length buffer length out write bytes buffer 0 length dnsoutgoing ioexception getaddress dnsconstants type_a ipv4 inet4address ipv6 inet4address writebytes boolean same dns record other return same name other same value other dnsrecord samename samevalue boolean same name dns record other return name equals ignore case address other name samename dnsrecord equalsignorecase boolean same value dns record other return addr equals address other get address samevalue dnsrecord getaddress inet address get address return addr inetaddress getaddress creates a byte array representation of this record this is needed for tie break tests according to draft cheshire dnsext multicastdns 04 txt chapter 9 2 private byte to byte array try byte array output stream bout new byte array output stream data output stream dout new data output stream bout dout write name get bytes utf8 dout write short type dout write short clazz dout write int len byte buffer addr get address for int i 0 i buffer length i dout write byte buffer i dout close return bout to byte array catch io exception e throw new internal error tobytearray bytearrayoutputstream bytearrayoutputstream dataoutputstream dataoutputstream getbytes writeshort writeshort writeint getaddress writebyte tobytearray ioexception internalerror does a lexicographic comparison of the byte array representation of this record and that record this is needed for tie break tests according to draft cheshire dnsext multicastdns 04 txt chapter 9 2 private int lex compare dns record address that byte this bytes this to byte array byte that bytes that to byte array for int i 0 n math min this bytes length that bytes length i n i if this bytes i that bytes i return 1 else if this bytes i that bytes i return 1 return this bytes length that bytes length lexcompare dnsrecord thisbytes tobytearray thatbytes tobytearray thisbytes thatbytes thisbytes thatbytes thisbytes thatbytes thisbytes thatbytes does the necessary actions when this as a query boolean handle query jmdns impl dns long expiration time dns record address dns address dns get local host getdns address record this if dns address null if dns address same type this dns address same name this dns address same value this logger finer handle query conflicting probe detected dns state dns get state lex compare lex compare dns address tie breaker test if dns get state is probing lex compare dns address 0 we lost the tie break we have to choose a different name dns get local host increment host name dns get cache clear for iterator i dns get services values iterator i has next service info impl info service info impl i next info revert state dns revert state return true return false handlequery jmdnsimpl expirationtime dnsrecord dnsaddress getlocalhost getdnsaddressrecord dnsaddress dnsaddress sametype dnsaddress samename dnsaddress samevalue handlequery getstate lexcompare dnsaddress getstate isprobing lexcompare dnsaddress getlocalhost incrementhostname getcache getservices hasnext serviceinfoimpl serviceinfoimpl revertstate revertstate does the necessary actions when this as a response boolean handle response jmdns impl dns dns record address dns address dns get local host getdns address record this if dns address null if dns address same type this dns address same name this dns address same value this logger finer handle response denial detected if dns get state is probing dns get local host increment host name dns get cache clear for iterator i dns get services values iterator i has next service info impl info service info impl i next info revert state dns revert state return true return false handleresponse jmdnsimpl dnsrecord dnsaddress getlocalhost getdnsaddressrecord dnsaddress dnsaddress sametype dnsaddress samename dnsaddress samevalue handleresponse getstate isprobing getlocalhost incrementhostname getcache getservices hasnext serviceinfoimpl serviceinfoimpl revertstate revertstate dns outgoing add answer jmdns impl dns dns incoming in inet address addr int port dns outgoing out throws io exception return out dnsoutgoing addanswer jmdnsimpl dnsincoming inetaddress dnsoutgoing ioexception public string to string return to string address addr null addr get host address null tostring tostring gethostaddress public pointer string name int type int clazz int ttl string alias super name type clazz ttl this alias alias void write dns outgoing out throws io exception out write name alias dnsoutgoing ioexception writename boolean same value dns record other return alias equals pointer other alias samevalue dnsrecord boolean handle query jmdns impl dns long expiration time nothing to do i think there is no possibility for conflicts for this record type return false handlequery jmdnsimpl expirationtime boolean handle response jmdns impl dns nothing to do i think there is no possibility for conflicts for this record type return false handleresponse jmdnsimpl string get alias return alias getalias dns outgoing add answer jmdns impl dns dns incoming in inet address addr int port dns outgoing out throws io exception return out dnsoutgoing addanswer jmdnsimpl dnsincoming inetaddress dnsoutgoing ioexception public string to string return to string alias tostring tostring public text string name int type int clazz int ttl byte text super name type clazz ttl this text text void write dns outgoing out throws io exception out write bytes text 0 text length dnsoutgoing ioexception writebytes boolean same value dns record other text txt text other if txt text length text length return false for int i text length i 0 if txt text i text i return false return true samevalue dnsrecord boolean handle query jmdns impl dns long expiration time nothing to do i think there is no possibility for conflicts for this record type return false handlequery jmdnsimpl expirationtime boolean handle response jmdns impl dns nothing to do shouldn t we care if we get a conflict at this level service info info service info dns services get name to lower case if info null if arrays equals text info text info revert state return true return false handleresponse jmdnsimpl serviceinfo serviceinfo tolowercase revertstate dns outgoing add answer jmdns impl dns dns incoming in inet address addr int port dns outgoing out throws io exception return out dnsoutgoing addanswer jmdnsimpl dnsincoming inetaddress dnsoutgoing ioexception public string to string return to string text length 10 new string text 0 7 new string text tostring tostring public service string name int type int clazz int ttl int priority int weight int port string server super name type clazz ttl this priority priority this weight weight this port port this server server void write dns outgoing out throws io exception out write short priority out write short weight out write short port if dns incoming use domain name format for srv target out write name server false else out writeutf server 0 server length add a zero byte to the end just to be safe this is the strange form used by the bonjour conformance test out write byte 0 dnsoutgoing ioexception writeshort writeshort writeshort dnsincoming use_domain_name_format_for_srv_target writename bonjourconformancetest writebyte private byte to byte array try byte array output stream bout new byte array output stream data output stream dout new data output stream bout dout write name get bytes utf8 dout write short type dout write short clazz dout write int len dout write short priority dout write short weight dout write short port dout write server get bytes utf8 dout close return bout to byte array catch io exception e throw new internal error tobytearray bytearrayoutputstream bytearrayoutputstream dataoutputstream dataoutputstream getbytes writeshort writeshort writeint writeshort writeshort writeshort getbytes tobytearray ioexception internalerror private int lex compare dns record service that byte this bytes this to byte array byte that bytes that to byte array for int i 0 n math min this bytes length that bytes length i n i if this bytes i that bytes i return 1 else if this bytes i that bytes i return 1 return this bytes length that bytes length lexcompare dnsrecord thisbytes tobytearray thatbytes tobytearray thisbytes thatbytes thisbytes thatbytes thisbytes thatbytes thisbytes thatbytes boolean same value dns record other service s service other return priority s priority weight s weight port s port server equals s server samevalue dnsrecord boolean handle query jmdns impl dns long expiration time service info impl info service info impl dns get services get name to lower case if info null port info port server equals ignore case dns get local host get name logger finer handle query conflicting probe detected from get record source dns record service local service new dns record service info get qualified name dns constants type srv dns constants class in dns constants class unique dns constants dns ttl info priority info weight info port dns get local host get name this block is useful for debugging race conditions when jmdns is respoding to itself try if dns get interface equals get record source logger warning got conflicting probe from ourselves n incoming this to string n local local service to string catch io exception e e print stack trace int comparison lex compare local service if comparison 0 the 2 records are identical this probably means we are seeing our own record with mutliple interfaces on a single computer it is possible to see our own records come in on different interfaces than the ones they were sent on see section 10 conflict resolution of mdns draft spec logger finer handle query ignoring a identical service query return false tie breaker test if info get state is probing comparison 0 we lost the tie break string old name info get qualified name to lower case info set name dns increment name info get name dns get services remove old name dns get services put info get qualified name to lower case info logger finer handle query lost tie break new unique name chosen info get name we revert the state to start probing again with the new name info revert state else we won the tie break so this conflicting probe should be ignored see paragraph 3 of section 9 2 in mdns draft spec return false return true return false handlequery jmdnsimpl expirationtime serviceinfoimpl serviceinfoimpl getservices tolowercase equalsignorecase getlocalhost getname handlequery getrecordsource dnsrecord localservice dnsrecord getqualifiedname dnsconstants type_srv dnsconstants class_in dnsconstants class_unique dnsconstants dns_ttl getlocalhost getname getinterface getrecordsource tostring localservice tostring ioexception printstacktrace lexcompare localservice handlequery getstate isprobing oldname getqualifiedname tolowercase setname incrementname getname getservices oldname getservices getqualifiedname tolowercase handlequery getname revertstate boolean handle response jmdns impl dns service info impl info service info impl dns get services get name to lower case if info null port info port server equals ignore case dns get local host get name logger finer handle response denial detected if info get state is probing string old name info get qualified name to lower case info set name dns increment name info get name dns get services remove old name dns get services put info get qualified name to lower case info logger finer handle response new unique name chose info get name info revert state return true return false handleresponse jmdnsimpl serviceinfoimpl serviceinfoimpl getservices tolowercase equalsignorecase getlocalhost getname handleresponse getstate isprobing oldname getqualifiedname tolowercase setname incrementname getname getservices oldname getservices getqualifiedname tolowercase handleresponse getname revertstate dns outgoing add answer jmdns impl dns dns incoming in inet address addr int port dns outgoing out throws io exception service info impl info service info impl dns get services get name to lower case if info null if this port info port server equals dns get local host get name return dns add answer in addr port out new dns record service info get qualified name dns constants type srv dns constants class in dns constants class unique dns constants dns ttl info priority info weight info port dns get local host get name return out dnsoutgoing addanswer jmdnsimpl dnsincoming inetaddress dnsoutgoing ioexception serviceinfoimpl serviceinfoimpl getservices tolowercase getlocalhost getname addanswer dnsrecord getqualifiedname dnsconstants type_srv dnsconstants class_in dnsconstants class_unique dnsconstants dns_ttl getlocalhost getname public string to string return to string server port tostring tostring public void set record source inet address source this source source setrecordsource inetaddress public inet address get record source return source inetaddress getrecordsource public string to string string other return to string record ttl get remainingttl system current time millis other tostring tostring getremainingttl currenttimemillis public void set ttl int ttl this ttl ttl setttl public int get ttl return ttl getttl boolean flushing public pin weak hash table int initial capacity threshold int initial capacity load factor table new entry initial capacity pinweakhashtable initialcapacity initialcapacity loadfactor initialcapacity public synchronized boolean remove int oid entry tab table int index oid 0x7fffffff tab length for entry e tab index prev null e null prev e e e next if e oid oid if prev null prev next e next else tab index e next e clear count 1 return true return false protected reference create reference object obj return new weak reference obj createreference weakreference public synchronized void put int oid i persistent obj reference ref create reference obj entry tab table int index oid 0x7fffffff tab length for entry e tab index e null e e next if e oid oid e ref ref return if count threshold flushing rehash the table if the threshold is exceeded rehash tab table index oid 0x7fffffff tab length creates the new entry tab index new entry oid ref tab index count 1 ipersistent createreference public synchronized i persistent get int oid entry tab table int index oid 0x7fffffff tab length for entry e tab index e null e e next if e oid oid if e pin null return e pin return i persistent e ref get return null ipersistent ipersistent public synchronized void flush flushing true for int i 0 i table length i for entry e table i e null e e next i persistent obj e pin if obj null obj store e pin null flushing false if count threshold rehash the table if the threshold is exceeded rehash return ipersistent public synchronized void invalidate for int i 0 i table length i for entry e table i e null e e next i persistent obj e pin if obj null e pin null obj invalidate table i null count 0 ipersistent public synchronized void clear entry tab table for int i 0 i tab length i tab i null count 0 void rehash int old capacity table length entry old map table int i for i old capacity i 0 entry e next prev for prev null e old map i e null e next next e next i persistent obj i persistent e ref get if obj null obj is deleted e pin null count 1 e clear if prev null old map i next else prev next next else prev e if count threshold 1 return int new capacity old capacity 2 1 entry new map new entry new capacity threshold int new capacity load factor table new map for i old capacity i 0 for entry old old map i old null entry e old old old next int index e oid 0x7fffffff new capacity e next new map index new map index e oldcapacity oldmap oldcapacity oldmap ipersistent ipersistent isdeleted oldmap newcapacity oldcapacity newmap newcapacity newcapacity loadfactor newmap oldcapacity oldmap newcapacity newmap newmap public synchronized void set dirty i persistent obj int oid obj get oid entry tab table int index oid 0x7fffffff tab length for entry e tab index e null e e next if e oid oid e pin obj return setdirty ipersistent getoid public synchronized void clear dirty i persistent obj int oid obj get oid entry tab table int index oid 0x7fffffff tab length for entry e tab index e null e e next if e oid oid e pin null return cleardirty ipersistent getoid public int size return count void clear ref clear ref null pin null next null entry int oid reference ref entry chain next chain this oid oid this ref ref public class replication static slave storage impl extends replication slave storage impl public replication static slave storage impl int port this port port replicationstaticslavestorageimpl replicationslavestorageimpl replicationstaticslavestorageimpl public void open i file file int page pool size try acceptor new server socket port catch io exception x throw new storage error storage error bad replication port byte root page new byte page page size int rc file read 0 root page if rc page page size prev index root page db hdr curr index offset initialized root page db hdr initialized offset 0 else initialized false prev index 1 out of sync false super open file page pool size ifile pagepoolsize serversocket ioexception storageerror storageerror bad_replication_port rootpage pagesize rootpage pagesize previndex rootpage db_hdr_curr_index_offset rootpage db_hdr_initialized_offset previndex outofsync pagepoolsize socket get socket throws io exception return acceptor accept getsocket ioexception cancel accept void cancelio try socket s new socket localhost port s close catch io exception x ioexception creates an introduction client public introduction client wot my wot super my wot get plugin respirator get node my wot get plugin respirator gethl simple client wot introduction client m wot my wot m puzzle store m wot get introduction puzzle store m random m wot get plugin respirator get node fast weak random start introductionclient introductionclient mywot mywot getpluginrespirator getnode mywot getpluginrespirator gethlsimpleclient mwot mywot mpuzzlestore mwot getintroductionpuzzlestore mrandom mwot getpluginrespirator getnode fastweakrandom override protected collection client getter create fetch storage return new hash set client getter puzzle request count 2 todo profile tweak clientgetter createfetchstorage hashset clientgetter puzzle_request_count override protected collection base client putter create insert storage return new hash set base client putter puzzle request count 2 todo profile tweak baseclientputter createinsertstorage hashset baseclientputter puzzle_request_count public int get priority return native thread low priority getpriority nativethread low_priority override protected long get startup delay return startup delay 2 m random next int startup delay getstartupdelay startup_delay mrandom nextint startup_delay override protected long get sleep time return thread period 2 m random next int thread period getsleeptime thread_period mrandom nextint thread_period called by the superclass transfer thread after get startup delay milliseconds and then after each get sleep time milliseconds deletes old puzzles fetches new ones and inserts solutions of the user override protected void iterate m puzzle store delete expired puzzles download puzzles insert solutions transferthread getstartupdelay getsleeptime mpuzzlestore deleteexpiredpuzzles downloadpuzzles insertsolutions use this function in the ui to get a list of puzzles for the user to solve fixme is it okay if we do not require users to lock the puzzle store while parsing the returned list because they would have to also lock the wot first to prevent deadlocks the worst thing which can happen is that they display a puzzle which has been deleted already it should be save to parse object containers while the database is being modified shouldn t it public list introduction puzzle get puzzles own identity user puzzle type puzzle type int count deadlocks could occur without the lock on wot because the loop calls functions which lock the wot if something else started to execute while we have already locked the puzzle store which locks the wot and waits for the puzzle store to become available until it releases the wot synchronized m wot synchronized m puzzle store list introduction puzzle puzzles m puzzle store get unsolved puzzles puzzle type array list introduction puzzle result new array list introduction puzzle count 1 hash set identity result has puzzle from new hash set identity count 2 have some room so we do not hit the load factor for introduction puzzle puzzle puzzles try todo maybe also check whether the user has already solved puzzles of the identity which inserted this one if result has puzzle from contains puzzle get inserter int score m wot get score user puzzle get inserter get score if score minimum score for puzzle display try m wot get trust puzzle get inserter user we are already on this identity s trust list so there is no use in solving another puzzle from it catch not trusted exception e result add puzzle result has puzzle from add puzzle get inserter if result size count break catch not in trust tree exception e logger error this wtf e return result puzzlestore objectcontainers introductionpuzzle getpuzzles ownidentity puzzletype puzzletype mwot mpuzzlestore introductionpuzzle mpuzzlestore getunsolvedpuzzles puzzletype arraylist introductionpuzzle arraylist introductionpuzzle hashset resulthaspuzzlefrom hashset introductionpuzzle resulthaspuzzlefrom getinserter mwot getscore getinserter getscore minimum_score_for_puzzle_display mwot gettrust getinserter nottrustedexception resulthaspuzzlefrom getinserter notintrusttreeexception use this function to store the solution of a puzzle and upload it throws invalid parameter exception if the puzzle was already solved public void solve puzzle own identity solver introduction puzzle puzzle string solution throws invalid parameter exception synchronized m puzzle store synchronized puzzle puzzle set solved solver solution m puzzle store store and commit puzzle try insert puzzle solution puzzle catch exception e logger error this insert puzzle solution failed e invalidparameterexception solvepuzzle ownidentity introductionpuzzle invalidparameterexception mpuzzlestore setsolved mpuzzlestore storeandcommit insertpuzzlesolution insertpuzzlesolution private synchronized void download puzzles normally we would lock the whole wot here because we iterate over a list returned by it but because it is not a severe problem if we download a puzzle of an identity which has been deleted or so we do not do that object set identity all identities m wot get all non own identities sorted by modification array list identity identities to download from new array list identity puzzle pool size download puzzles from identities from which we have not downloaded for a certain period this is ensured by keeping the last few hundred identities stored in a fifo with fixed length named m identities normally we would have to lock the wot here first so that no deadlock happens if something else locks the m identities and waits for the wot until it unlocks them but nothing else in this class locks m identities and then the wot synchronized m identities for identity i all identities todo create a boolean provides introduction in identity to use a database query instead of this if i has context introduction puzzle introduction context m identities contains i m wot get best score i minimum score for puzzle download identities to download from add i if identities to download from size puzzle request count break if we run out of identities to download from be less restrictive if identities to download from size 0 m identities clear we probably have less updated identities today than the size of the lru queue empty it for identity i all identities todo create a boolean provides introduction in identity to use a database query instead of this if i has context introduction puzzle introduction context m wot get best score i minimum score for puzzle download identities to download from add i if identities to download from size puzzle request count break i suppose its a good idea to restart downloading the puzzles from the latest updated identities every time the thread iterates this prevents denial of service because people will usually get very new puzzles abort fetches for identity i identities to download from try download puzzle i catch exception e logger error this starting puzzle download failed e downloadpuzzles objectset allidentities mwot getallnonownidentitiessortedbymodification arraylist identitiestodownloadfrom arraylist puzzle_pool_size midentities midentities midentities midentities allidentities providesintroduction hascontext introductionpuzzle introduction_context midentities mwot getbestscore minimum_score_for_puzzle_download identitiestodownloadfrom identitiestodownloadfrom puzzle_request_count identitiestodownloadfrom midentities lruqueue allidentities providesintroduction hascontext introductionpuzzle introduction_context mwot getbestscore minimum_score_for_puzzle_download identitiestodownloadfrom identitiestodownloadfrom puzzle_request_count abortfetches identitiestodownloadfrom downloadpuzzle private void insert solutions abort inserts synchronized m puzzle store object set introduction puzzle puzzles m puzzle store get uninserted solved puzzles for introduction puzzle p puzzles try insert puzzle solution p catch exception e logger error this inserting solution for p failed insertsolutions abortinserts mpuzzlestore objectset introductionpuzzle mpuzzlestore getuninsertedsolvedpuzzles introductionpuzzle insertpuzzlesolution not synchronized because its caller is synchronized already private void insert puzzle solution introduction puzzle puzzle throws io exception transformer exception insert exception assert puzzle was inserted bucket tempb mtbf make bucket 1024 todo set to a reasonable value output stream os null try os tempb get output stream m wot getxml transformer export introduction puzzle get solver os os close os null tempb set read only freeneturi solutionuri puzzle get solutionuri insert block ib new insert block tempb null solutionuri insert context ictx m client get insert context true fixme toad are these parameters correct client putter pu m client insert ib false null false ictx this fixme set to a reasonable value before release plugin manager default is interactive priority pu set priority class request starter update priority class m wot get plugin respirator get node client core client context null add insert pu tempb null logger debug this started to insert puzzle solution of puzzle get solver get nickname at solutionuri finally if tempb null tempb free closer close os insertpuzzlesolution introductionpuzzle ioexception transformerexception insertexception wasinserted makebucket outputstream getoutputstream mwot getxmltransformer exportintroduction getsolver setreadonly getsolutionuri insertblock insertblock insertcontext mclient getinsertcontext clientputter mclient pluginmanager setpriorityclass requeststarter update_priority_class mwot getpluginrespirator getnode clientcore clientcontext addinsert getsolver getnickname finds a random index of a puzzle from the inserter which we did not download yet and downloads it not synchronized because its caller is synchronized already private void download puzzle identity inserter throws fetch exception download puzzle inserter m random next int introduction server get identity puzzle count inserter downloadpuzzle fetchexception downloadpuzzle mrandom nextint introductionserver getidentitypuzzlecount not synchronized because its caller is synchronized already private void download puzzle identity inserter int index throws fetch exception int inserter puzzle count introduction server get identity puzzle count inserter assert index inserter puzzle count 1 we do that so that on success can just call this function with the index increased by 1 index inserter puzzle count date date current timeutc get freeneturi uri synchronized m puzzle store if m puzzle store get of today by inserter inserter size max puzzles per identity return find a free index int count 0 while m puzzle store get by inserter date index inserter date index null count inserter puzzle count index index 1 inserter puzzle count count todo maybe also use the above loop which finds a free index for counting the recent puzzles accurately if count max puzzles per identity we have all puzzles of this identity logger error this should not happen get of today by inserter returned less puzzles than get by inerter day index return uri introduction puzzle generate requesturi inserter date index fetch context fetch context m client get fetch context fixme toad are these parameters correct fetch context max splitfile block retries 1 retry forever fetch context max non splitfile retries 1 retry forever client getter g m client fetch uri xml transformer max introductionpuzzle byte size m wot get request client this fetch context fixme set to a reasonable value before release plugin manager default is interactive priority g set priority class request starter update priority class add fetch g attention do not lock the wot here before locking m identities because there is another synchronized m identities in this class which locks the wot inside the m identities lock synchronized m identities if m identities contains inserter the oldest identity falls out of the fifo and therefore puzzle downloads from that one are allowed again it is only checked in download puzzles whether puzzle downloads are allowed because we download up to max puzzles per identity puzzles per identity the on success starts download of the next one usually m identities poll try m identities put inserter put this identity at the beginning of the fifo catch interrupted exception e logger debug this trying to fetch puzzle from uri to string downloadpuzzle fetchexception inserterpuzzlecount introductionserver getidentitypuzzlecount inserterpuzzlecount onsuccess inserterpuzzlecount currenttimeutc mpuzzlestore mpuzzlestore getoftodaybyinserter max_puzzles_per_identity mpuzzlestore getbyinserterdateindex inserterpuzzlecount inserterpuzzlecount max_puzzles_per_identity getoftodaybyinserter getbyinerterdayindex introductionpuzzle generaterequesturi fetchcontext fetchcontext mclient getfetchcontext fetchcontext maxsplitfileblockretries fetchcontext maxnonsplitfileretries clientgetter mclient xmltransformer max_introductionpuzzle_byte_size mwot getrequestclient fetchcontext pluginmanager setpriorityclass requeststarter update_priority_class addfetch midentities midentities midentities midentities midentities downloadpuzzles max_puzzles_per_identity onsuccess midentities midentities interruptedexception tostring called when a puzzle is successfully fetched public void on success fetch result result client getter state object container container logger debug this fetched puzzle state geturi try introduction puzzle puzzle m wot getxml transformer import introduction puzzle state geturi result as bucket get input stream fixme add logic to call this only once for every few puzzles fetched not for every single one m puzzle store delete oldest unsolved puzzles puzzle pool size download puzzle puzzle get inserter puzzle get index 1 todo also download a random index here maybe catch exception e logger error this parsing failed for state geturi e finally remove fetch state onsuccess fetchresult clientgetter objectcontainer introductionpuzzle mwot getxmltransformer importintroductionpuzzle asbucket getinputstream mpuzzlestore deleteoldestunsolvedpuzzles puzzle_pool_size downloadpuzzle getinserter getindex removefetch called when the node can t fetch a file or when there is a newer edition in our case called when there is no puzzle available public void on failure fetch exception e client getter state object container container if e get mode fetch exception cancelled logger debug this fetch cancelled state geturi return if e get mode fetch exception data not found this is the normal case there is no puzzle available of today because the inserter is offline and has not inserted any we do nothing here the identity stays in the fifo though so we do not try to fetch puzzzle from it again soon try logger debug this downloading puzzle failed state geturi e finally remove fetch state onfailure fetchexception clientgetter objectcontainer getmode fetchexception getmode fetchexception data_not_found removefetch called when a puzzle solution is successfully inserted public void on success base client putter state object container container logger debug this successful insert of puzzle solution state geturi try synchronized m wot get puzzle by requesturi requires this synchronized m puzzle store introduction puzzle puzzle m puzzle store get puzzle by solutionuri state geturi puzzle set inserted m puzzle store store and commit puzzle catch exception e logger error this error e finally remove insert state onsuccess baseclientputter objectcontainer mwot getpuzzlebyrequesturi mpuzzlestore introductionpuzzle mpuzzlestore getpuzzlebysolutionuri setinserted mpuzzlestore storeandcommit removeinsert calling when inserting a puzzle solution failed public void on failure insert exception e base client putter state object container container no synchronization because the worst thing which can happen is that we insert it again if e get mode insert exception cancelled logger debug this insert cancelled state geturi return try logger minor this insert of puzzle solution failed state geturi e finally remove insert state onfailure insertexception baseclientputter objectcontainer getmode insertexception removeinsert not needed functions from the client callback interface only called by inserts public void on fetchable base client putter state object container container clientcallback onfetchable baseclientputter objectcontainer public void on fetchable base client putter state object container container only called by inserts public void on generateduri freeneturi uri base client putter state object container container onfetchable baseclientputter objectcontainer ongenerateduri baseclientputter objectcontainer public void on generateduri freeneturi uri base client putter state object container container called when freenet async thinks that the request should be serialized to disk if it is a persistent request public void on major progress object container container ongenerateduri baseclientputter objectcontainer onmajorprogress objectcontainer private long cooldown time void set cooldown time long time cooldown time time cooldowntime setcooldowntime cooldowntime public long add key key sendable get client object container container assert cooldown time 0 long remove time system current time millis cooldown time container activate key 5 persistent cooldown queue item persistent cooldown queue item new persistent cooldown queue item client key clone key remove time this container store persistent cooldown queue item return remove time sendableget objectcontainer cooldowntime removetime currenttimemillis cooldowntime persistentcooldownqueueitem persistentcooldownqueueitem persistentcooldownqueueitem clonekey removetime persistentcooldownqueueitem removetime public boolean remove key final key key final sendable get client final long time object container container boolean found false final string key as bytes hex util bytes to hex key get full key query query container query query constrain persistent cooldown queue item class query descend key as bytes constrain key as bytes the result from parent will be huge and client may be huge too don t bother with a join just check in the evaluation query descend client constrain client query descend parent constrain this evaluation eval new evaluation public void evaluate candidate candidate persistent cooldown queue item item persistent cooldown queue item candidate get object if item client client candidate include false return if item parent persistent cooldown queue this candidate include false return key k item key candidate object container activate k 5 if k equals key candidate include true else candidate include false candidate object container deactivate k 5 query constrain eval object set results query execute while results has next found true persistent cooldown queue item i persistent cooldown queue item results next i delete container return found removekey sendableget objectcontainer keyasbytes hexutil bytestohex getfullkey persistentcooldownqueueitem keyasbytes keyasbytes persistentcooldownqueueitem persistentcooldownqueueitem getobject persistentcooldownqueue objectcontainer objectcontainer objectset hasnext persistentcooldownqueueitem persistentcooldownqueueitem public void evaluate candidate candidate persistent cooldown queue item item persistent cooldown queue item candidate get object if item client client candidate include false return if item parent persistent cooldown queue this candidate include false return key k item key candidate object container activate k 5 if k equals key candidate include true else candidate include false candidate object container deactivate k 5 persistentcooldownqueueitem persistentcooldownqueueitem getobject persistentcooldownqueue objectcontainer objectcontainer public object remove key before final long now long dont care after millis object container container int max count will be called repeatedly until no more keys are returned so it doesn t matter very much if they re not in order this query returns bogus results cooldown items with times in the future object set results container query new predicate public boolean match persistent cooldown queue item persistent cooldown queue item if persistent cooldown queue item time now return false if persistent cooldown queue item parent persistent cooldown queue this return false return true lets re code it in soda long t start system current time millis query query container query query constrain persistent cooldown queue item class query descend time constrain long value of now smaller and query descend parent constrain this identity object set results query execute if results has next long t end system current time millis if t end t start 1000 logger error this query took t end t start else if logger should log logger minor this logger minor this query took t end t start array list v new array list math min max count results size while results has next v size max count persistent cooldown queue item i persistent cooldown queue item results next if i time now logger error this remove key before time now diff now i time continue if i parent this logger error this parent i parent but should be this continue container activate i key 5 if i client null container ext is stored i client logger normal this client has been removed but not the persistent cooldown queue item time i time for key i key else v add i key clone key i key remove from container i delete container if v is empty return v to array new key v size else query container query query descend time order ascending constrain long value of now dont care after millis smaller and query descend parent constrain this identity results query execute if results has next return persistent cooldown queue item results next time else return null else long t end system current time millis if t end t start 1000 logger error this query took t end t start else if logger should log logger minor this logger minor this query took t end t start return null removekeybefore dontcareaftermillis objectcontainer maxcount objectset persistentcooldownqueueitem persistentcooldownqueueitem persistentcooldownqueueitem persistentcooldownqueueitem persistentcooldownqueue tstart currenttimemillis persistentcooldownqueueitem valueof objectset hasnext tend currenttimemillis tend tstart tend tstart shouldlog tend tstart arraylist arraylist maxcount hasnext maxcount persistentcooldownqueueitem persistentcooldownqueueitem removekeybefore isstored clonekey removefrom isempty toarray orderascending valueof dontcareaftermillis hasnext persistentcooldownqueueitem tend currenttimemillis tend tstart tend tstart shouldlog tend tstart public long size object container container query query container query query constrain persistent cooldown queue item class query descend parent constrain this identity object set results query execute return results size objectcontainer persistentcooldownqueueitem objectset public usk manager node client core core high level simple client client core make client request starter update priority class client set max intermediate length f proxy toadlet max length client set max length f proxy toadlet max length background fetch context client get fetch context background fetch context follow redirects false real fetch context client get fetch context latest known good by clearusk new hash map usk long latest slot by clearusk new hash map usk long subscribers by clearusk new hash map usk usk callback fetchers byusk new hash map usk usk fetcher background fetchers by clearusk new hash map usk usk fetcher temporary background fetcherslru new lru hashtable usk usk fetcher executor core get executor uskmanager nodeclientcore highlevelsimpleclient makeclient requeststarter update_priority_class setmaxintermediatelength fproxytoadlet max_length setmaxlength fproxytoadlet max_length backgroundfetchcontext getfetchcontext backgroundfetchcontext followredirects realfetchcontext getfetchcontext latestknowngoodbyclearusk hashmap latestslotbyclearusk hashmap subscribersbyclearusk hashmap uskcallback fetchersbyusk hashmap uskfetcher backgroundfetchersbyclearusk hashmap uskfetcher temporarybackgroundfetcherslru lruhashtable uskfetcher getexecutor public void init object container container client context context this context context usk manager persistent init this container context objectcontainer clientcontext uskmanagerpersistent look up the latest known working version of the given usk return the latest known edition number or 1 public synchronized long lookup known good usk usk long l latest known good by clearusk get usk clear copy if l null return l long value else return 1 lookupknowngood latestknowngoodbyclearusk clearcopy longvalue look up the latest ssk slot whether the data it links to has been successfully fetched or not of the given usk return the latest known edition number or 1 public synchronized long lookup latest slot usk usk long l latest slot by clearusk get usk clear copy if l null return l long value else return 1 lookuplatestslot latestslotbyclearusk clearcopy longvalue public usk fetcher tag get fetcher usk usk fetch context ctx boolean keep last boolean persistent usk fetcher callback callback boolean own fetch context object container container client context context return usk fetcher tag create usk callback context nodedb handle persistent container ctx keep last 0 own fetch context uskfetchertag getfetcher fetchcontext keeplast uskfetchercallback ownfetchcontext objectcontainer clientcontext uskfetchertag nodedbhandle keeplast ownfetchcontext synchronized usk fetcher get fetcher usk usk fetch context ctx client requester requester boolean keep last data usk fetcher f fetchers byusk get usk if f null if f parent priority class requester priority class f ctx equals ctx f keep last data keep last data return f f new usk fetcher usk this ctx requester 3 false keep last data fetchers byusk put usk f return f uskfetcher getfetcher fetchcontext clientrequester keeplastdata uskfetcher fetchersbyusk priorityclass priorityclass keeplastdata keeplastdata uskfetcher keeplastdata fetchersbyusk public usk fetcher tag get fetcher for insert dont schedule usk usk short prio class usk fetcher callback cb request client client object container container client context context boolean persistent return get fetcher usk persistent new fetch context background fetch context fetch context identical mask false null background fetch context true client persistent cb true container context uskfetchertag getfetcherforinsertdontschedule prioclass uskfetchercallback requestclient objectcontainer clientcontext getfetcher fetchcontext backgroundfetchcontext fetchcontext identical_mask backgroundfetchcontext a non authoritative hint that a specific edition might exist at the moment we just fetch the block we do not fetch the contents and it is possible that usk fetcher s are also fetching the block fixme would it be more efficient to pass it along to a usk fetcher param usk param edition param context public void hint update usk usk long edition client context context if edition lookup latest slot usk return freeneturi uri usk copy edition geturi final client getter get new client getter new null client callback uri new fetch context background fetch context fetch context identical mask false null request starter update priority class usk manager this new null bucket null try get start null context catch fetch exception e ignore uskfetcher uskfetcher hintupdate clientcontext lookuplatestslot clientgetter clientgetter nullclientcallback fetchcontext backgroundfetchcontext fetchcontext identical_mask requeststarter update_priority_class uskmanager nullbucket fetchexception a non authoritative hint that a specific edition might exist at the moment we just fetch the block we do not fetch the contents and it is possible that usk fetcher s are also fetching the block fixme would it be more efficient to pass it along to a usk fetcher param context throws malformedurl exception if the uri passed in is not a usk public void hint update freeneturi uri client context context throws malformedurl exception if uri get suggested edition lookup latest slot usk create uri return final client getter get new client getter new null client callback uri new fetch context background fetch context fetch context identical mask false null request starter update priority class usk manager this new null bucket null try get start null context catch fetch exception e ignore uskfetcher uskfetcher malformedurlexception hintupdate clientcontext malformedurlexception getsuggestededition lookuplatestslot clientgetter clientgetter nullclientcallback fetchcontext backgroundfetchcontext fetchcontext identical_mask requeststarter update_priority_class uskmanager nullbucket fetchexception public void start temporary background fetcher usk usk client context context final fetch context fctx boolean prefetch content usk clear usk clear copy usk fetcher sched null vector usk fetcher to cancel null synchronized this java util iterator i background fetchers by clearusk key set iterator int x 0 while i has next system err println fetcher x i next x usk fetcher f temporary background fetcherslru get clear if f null f new usk fetcher usk this background fetch context new usk fetcher wrapper usk request starter update priority class this 3 false false sched f temporary background fetcherslru push clear f if prefetch content final long min lookup known good usk f add callback new usk fetcher callback public void on cancelled object container container client context context ok public void on failure object container container client context context ok public void on found edition long l usk key object container container client context context boolean metadata short codec byte data boolean new known good boolean new slot too if l min return freeneturi uri key copy l geturi final client getter get new client getter new null client callback uri new fetch context fctx fetch context identical mask false null request starter update priority class usk manager this new null bucket null try get start null context catch fetch exception e ignore public short get polling priority normal return request starter update priority class public short get polling priority progress return request starter update priority class temporary background fetcherslru push clear f while temporary background fetcherslru size node client core max backgroundusk fetchers usk fetcher fetcher temporary background fetcherslru pop value if fetcher has subscribers if to cancel null to cancel new vector usk fetcher 2 to cancel add fetcher else if logger should log logger minor this logger minor this allowing temporary background fetcher to continue as it has subscribers fetcher it will burn itself out anyway as it s a temp fetcher so no big harm here fetcher kill on lose subscribers if to cancel null for int i 0 i to cancel size i usk fetcher fetcher to cancel get i fetcher cancel null context if sched null sched schedule null context starttemporarybackgroundfetcher clientcontext fetchcontext prefetchcontent clearcopy uskfetcher uskfetcher tocancel backgroundfetchersbyclearusk keyset hasnext uskfetcher temporarybackgroundfetcherslru uskfetcher backgroundfetchcontext uskfetcherwrapper requeststarter update_priority_class temporarybackgroundfetcherslru prefetchcontent lookupknowngood addcallback uskfetchercallback oncancelled objectcontainer clientcontext onfailure objectcontainer clientcontext onfoundedition objectcontainer clientcontext newknowngood newslottoo clientgetter clientgetter nullclientcallback fetchcontext fetchcontext identical_mask requeststarter update_priority_class uskmanager nullbucket fetchexception getpollingprioritynormal requeststarter update_priority_class getpollingpriorityprogress requeststarter update_priority_class temporarybackgroundfetcherslru temporarybackgroundfetcherslru nodeclientcore maxbackgrounduskfetchers uskfetcher temporarybackgroundfetcherslru popvalue hassubscribers tocancel tocancel uskfetcher tocancel shouldlog killonlosesubscribers tocancel tocancel uskfetcher tocancel f add callback new usk fetcher callback public void on cancelled object container container client context context ok addcallback uskfetchercallback oncancelled objectcontainer clientcontext public void on failure object container container client context context ok onfailure objectcontainer clientcontext public void on found edition long l usk key object container container client context context boolean metadata short codec byte data boolean new known good boolean new slot too if l min return freeneturi uri key copy l geturi final client getter get new client getter new null client callback uri new fetch context fctx fetch context identical mask false null request starter update priority class usk manager this new null bucket null try get start null context catch fetch exception e ignore onfoundedition objectcontainer clientcontext newknowngood newslottoo clientgetter clientgetter nullclientcallback fetchcontext fetchcontext identical_mask requeststarter update_priority_class uskmanager nullbucket fetchexception public short get polling priority normal return request starter update priority class getpollingprioritynormal requeststarter update_priority_class public short get polling priority progress return request starter update priority class getpollingpriorityprogress requeststarter update_priority_class void update known good final usk origusk final long number final client context context boolean logminor logger should log logger minor this if logminor logger minor this updating origusk geturi number usk clear origusk clear copy final usk callback callbacks boolean new slot false synchronized this long l latest known good by clearusk get clear if logminor logger minor this old known good l if l null number l long value l long value of number latest known good by clearusk put clear l if logminor logger minor this put number else return if it s in known good it will also be in slot l latest slot by clearusk get clear if logminor logger minor this old slot l if l null number l long value l long value of number latest slot by clearusk put clear l if logminor logger minor this put number new slot true callbacks subscribers by clearusk get clear if callbacks null run off thread because of locking and because client callbacks may take some time final usk usk origusk copy number final boolean new slot too new slot for final usk callback callback callbacks context main executor execute new runnable public void run callback on found edition number usk null non persistent context false short 1 null true new slot too usk manager callback executor for callback updateknowngood clientcontext shouldlog clearcopy uskcallback newslot latestknowngoodbyclearusk longvalue valueof latestknowngoodbyclearusk knowngood latestslotbyclearusk longvalue valueof latestslotbyclearusk newslot subscribersbyclearusk newslottoo newslot uskcallback mainexecutor onfoundedition newslottoo uskmanager for final usk callback callback callbacks context main executor execute new runnable public void run callback on found edition number usk null non persistent context false short 1 null true new slot too uskcallback mainexecutor onfoundedition newslottoo void update slot final usk origusk final long number final client context context boolean logminor logger should log logger minor this if logminor logger minor this updating origusk geturi number usk clear origusk clear copy final usk callback callbacks synchronized this long l latest slot by clearusk get clear if logminor logger minor this old slot l if l null number l long value l long value of number latest slot by clearusk put clear l if logminor logger minor this put number else return callbacks subscribers by clearusk get clear if callbacks null run off thread because of locking and because client callbacks may take some time final usk usk origusk copy number for final usk callback callback callbacks context main executor execute new runnable public void run callback on found edition number usk null non persistent context false short 1 null false false usk manager callback executor for callback updateslot clientcontext shouldlog clearcopy uskcallback latestslotbyclearusk longvalue valueof latestslotbyclearusk subscribersbyclearusk uskcallback mainexecutor onfoundedition uskmanager for final usk callback callback callbacks context main executor execute new runnable public void run callback on found edition number usk null non persistent context false short 1 null false false uskcallback mainexecutor onfoundedition subscribe to a given usk callback will be notified when it is updated note that this does not imply that the usk will be checked on a regular basis unless run background fetch true public void subscribe usk origusk usk callback cb boolean run background fetch request client client if logger should log logger minor this logger minor this subscribing to origusk for cb if client persistent throw new unsupported operation exception usk manager subscriptions cannot be persistent usk fetcher sched null long ed origusk suggested edition if ed 0 logger error this subscribing to usk with negative edition number ed ed ed long cur ed cur ed lookup latest slot origusk long good ed good ed lookup known good origusk synchronized this usk clear origusk clear copy usk callback callbacks subscribers by clearusk get clear if callbacks null callbacks new usk callback 1 else for int i 0 i callbacks length i if callbacks i cb return usk callback new callbacks new usk callback callbacks length 1 system arraycopy callbacks 0 new callbacks 0 callbacks length callbacks new callbacks callbacks callbacks length 1 cb subscribers by clearusk put clear callbacks if run background fetch usk fetcher f background fetchers by clearusk get clear if f null f new usk fetcher origusk this background fetch context new usk fetcher wrapper origusk request starter update priority class client 10 true false sched f background fetchers by clearusk put clear f f add subscriber cb if good ed ed cb on found edition good ed origusk copy cur ed null context false short 1 null true cur ed ed else if cur ed ed cb on found edition cur ed origusk copy cur ed null context false short 1 null false false final usk fetcher fetcher sched if fetcher null executor execute new runnable public void run fetcher schedule null context usk manager schedule for fetcher runbackgroundfetch uskcallback runbackgroundfetch requestclient shouldlog unsupportedoperationexception uskmanager uskfetcher suggestededition cured cured lookuplatestslot gooded gooded lookupknowngood clearcopy uskcallback subscribersbyclearusk uskcallback uskcallback newcallbacks uskcallback newcallbacks newcallbacks subscribersbyclearusk runbackgroundfetch uskfetcher backgroundfetchersbyclearusk uskfetcher backgroundfetchcontext uskfetcherwrapper requeststarter update_priority_class backgroundfetchersbyclearusk addsubscriber gooded onfoundedition gooded cured cured cured onfoundedition cured cured uskfetcher uskmanager if fetcher null executor execute new runnable public void run fetcher schedule null context public void unsubscribe usk origusk usk callback cb usk fetcher to cancel null usk fetcher to cancel alt null synchronized this usk clear origusk clear copy usk callback callbacks subscribers by clearusk get clear if callbacks null maybe we should throw something shall we allow multiple unsubscriptions logger error this the callback is null it has been already unsubscribed hasn t it new exception debug return int j 0 for int i 0 i callbacks length i usk callback c callbacks i if c null c cb callbacks j c usk callback new callbacks new usk callback j system arraycopy callbacks 0 new callbacks 0 j if new callbacks length 0 subscribers by clearusk put clear callbacks else subscribers by clearusk remove clear fetchers byusk remove origusk usk fetcher f background fetchers by clearusk get clear if f null f remove subscriber cb context if f has subscribers to cancel f background fetchers by clearusk remove clear f temporary background fetcherslru get clear if f null f remove callback cb if f has callbacks if to cancel null to cancel alt f logger error this subscribed in both background fetchers and temporary background fetchers cb for origusk else to cancel f temporary background fetcherslru remove key clear if to cancel null to cancel cancel null context if to cancel alt null to cancel alt cancel null context uskcallback uskfetcher tocancel uskfetcher tocancelalt clearcopy uskcallback subscribersbyclearusk uskcallback uskcallback newcallbacks uskcallback newcallbacks newcallbacks subscribersbyclearusk subscribersbyclearusk fetchersbyusk uskfetcher backgroundfetchersbyclearusk removesubscriber hassubscribers tocancel backgroundfetchersbyclearusk temporarybackgroundfetcherslru removecallback hascallbacks tocancel tocancelalt backgroundfetchers temporarybackgroundfetchers tocancel temporarybackgroundfetcherslru removekey tocancel tocancel tocancelalt tocancelalt subscribe to a usk when it is updated the content will be fetched subject to the limits in fctx and returned to the callback param origusk the usk to poll param cb callback called when we have downloaded a new key param run background fetch if true start a background fetcher for the key which will run forever until we unsubscribe param fctx fetcher context for actually fetching the keys not used by the usk polling return public usk retriever subscribe content usk origusk usk retriever callback cb boolean run background fetch fetch context fctx short prio request client client usk retriever ret new usk retriever fctx prio client cb origusk subscribe origusk ret run background fetch client return ret runbackgroundfetch uskretriever subscribecontent uskretrievercallback runbackgroundfetch fetchcontext requestclient uskretriever uskretriever runbackgroundfetch public void unsubscribe content usk origusk usk retriever ret boolean run background fetch unsubscribe origusk ret unsubscribecontent uskretriever runbackgroundfetch remove do not synchronize debugging only the result of that method will be displayed on the statistic toadlet it will help catching 1147 afterwards it should be removed it s not usefull return the number of fetchers started by usk manager public int get fetcher byusk size return fetchers byusk size uskmanager getfetcherbyusksize fetchersbyusk the result of that method will be displayed on the statistic toadlet it will help catching 1147 afterwards it should be removed it s not usefull return the number of background fetchers started by usk manager public int get background fetcher byusk size return background fetchers by clearusk size backgroundfetchers uskmanager getbackgroundfetcherbyusksize backgroundfetchersbyclearusk the result of that method will be displayed on the statistic toadlet it will help catching 1147 afterwards it should be removed it s not usefull return the size of temporary background fetcherslru public int get temporary background fetcherslru return temporary background fetcherslru size temporarybackgroundfetcherslru gettemporarybackgroundfetcherslru temporarybackgroundfetcherslru public void on finished usk fetcher fetcher usk orig fetcher get originalusk usk clear orig clear copy synchronized this if background fetchers by clearusk get clear fetcher background fetchers by clearusk remove clear this shouldn t happen it s a sanity check the only way we get cancelled is from usk manager which removes us before calling cancel logger error this on cancelled for fetcher was still registered how did this happen new exception debug if temporary background fetcherslru get clear fetcher temporary background fetcherslru remove key clear if fetchers byusk get orig fetcher fetchers byusk remove clear onfinished uskfetcher getoriginalusk clearcopy backgroundfetchersbyclearusk backgroundfetchersbyclearusk uskmanager oncancelled temporarybackgroundfetcherslru temporarybackgroundfetcherslru removekey fetchersbyusk fetchersbyusk public boolean persistent return false public void remove from object container container throw new unsupported operation exception removefrom objectcontainer unsupportedoperationexception override protected void set up throws exception super set up a new identity uria a true b new identity urib b true trust trust new trust a b byte 100 test ext object container db m wot getdb db store a 5 db store b 5 db store trust db commit setup setup extobjectcontainer mwot public void test trust throws duplicate trust exception not trusted exception trust trust m wot get trust a b assert true trust get truster a assert true trust get trustee b assert true trust get value 100 assert equals test trust get comment testtrust duplicatetrustexception nottrustedexception mwot gettrust asserttrue gettruster asserttrue gettrustee asserttrue getvalue assertequals getcomment public void test trust persistence throws malformedurl exception unknown identity exception duplicate trust exception not trusted exception m wot terminate m wot null system gc system run finalization m wot new wot get database filename a m wot get identity byuri uria b m wot get identity byuri urib trust trust m wot get trust a b assert true trust get truster a assert true trust get trustee b assert true trust get value 100 assert equals test trust get comment testtrustpersistence malformedurlexception unknownidentityexception duplicatetrustexception nottrustedexception mwot mwot runfinalization mwot getdatabasefilename mwot getidentitybyuri mwot getidentitybyuri mwot gettrust asserttrue gettruster asserttrue gettrustee asserttrue getvalue assertequals getcomment public class jsql arithmetic exception extends jsql runtime exception constructor of exception public jsql arithmetic exception string msg super msg null null jsqlarithmeticexception jsqlruntimeexception jsqlarithmeticexception logger register log threshold callback new log threshold callback override public void should update logminor logger should log logger minor this registerlogthresholdcallback logthresholdcallback shouldupdate shouldlog public f proxy fetch in progress f proxy fetch tracker tracker freeneturi key long max size2 long identifier client context context fetch context fctx request client rc this tracker tracker this uri key this max size max size2 this time started system current time millis this identifier identifier fctx new fetch context fctx fetch context identical mask false null fctx max output length fctx max temp length max size fctx event producer add event listener this waiters new array list f proxy fetch waiter results new array list f proxy fetch result getter new client getter this uri fctx f proxy toadlet priority rc null null fproxyfetchinprogress fproxyfetchtracker maxsize2 clientcontext fetchcontext requestclient maxsize maxsize2 timestarted currenttimemillis fetchcontext fetchcontext identical_mask maxoutputlength maxtemplength maxsize eventproducer addeventlistener arraylist fproxyfetchwaiter arraylist fproxyfetchresult clientgetter fproxytoadlet public synchronized f proxy fetch waiter get waiter last touched system current time millis f proxy fetch waiter waiter new f proxy fetch waiter this waiters add waiter return waiter fproxyfetchwaiter getwaiter lasttouched currenttimemillis fproxyfetchwaiter fproxyfetchwaiter synchronized f proxy fetch result inner get result boolean has waited last touched system current time millis f proxy fetch result res if data null res new f proxy fetch result this data mime type time started gone to network geteta has waited else res new f proxy fetch result this mime type size time started gone to network total blocks required blocks fetched blocks failed blocks fatally failed blocks finalized blocks failed geteta has waited results add res return res fproxyfetchresult innergetresult haswaited lasttouched currenttimemillis fproxyfetchresult fproxyfetchresult mimetype timestarted gonetonetwork haswaited fproxyfetchresult mimetype timestarted gonetonetwork totalblocks requiredblocks fetchedblocks failedblocks fatallyfailedblocks finalizedblocks haswaited public void start client context context throws fetch exception try context start getter catch fetch exception e synchronized this this failed e this finished true clientcontext fetchexception fetchexception public void on remove event producer object container container impossible onremoveeventproducer objectcontainer public void receive client event ce object container maybe container client context context if ce instanceof splitfile progress event splitfile progress event split splitfile progress event ce synchronized this int old req required blocks fetched blocks failed blocks fatally failed blocks total blocks split total blocks fetched blocks split succeed blocks required blocks split min successful blocks failed blocks split failed blocks fatally failed blocks split fatally failed blocks finalized blocks split finalized total int req required blocks fetched blocks failed blocks fatally failed blocks if req 1024 old req 1024 return else if ce instanceof sending to network event synchronized this if gone to network return gone to network true fetched blocks pre network fetched blocks else if ce instanceof expectedmime event synchronized this this mime type expectedmime event ce expectedmime type else if ce instanceof expected file size event synchronized this this size expected file size event ce expected size else return wake waiters false clientevent objectcontainer maybecontainer clientcontext splitfileprogressevent splitfileprogressevent splitfileprogressevent oldreq requiredblocks fetchedblocks failedblocks fatallyfailedblocks totalblocks totalblocks fetchedblocks succeedblocks requiredblocks minsuccessfulblocks failedblocks failedblocks fatallyfailedblocks fatallyfailedblocks finalizedblocks finalizedtotal requiredblocks fetchedblocks failedblocks fatallyfailedblocks oldreq sendingtonetworkevent gonetonetwork gonetonetwork fetchedblocksprenetwork fetchedblocks expectedmimeevent mimetype expectedmimeevent expectedmimetype expectedfilesizeevent expectedfilesizeevent expectedsize wakewaiters private void wake waiters boolean finished f proxy fetch waiter waiting synchronized this waiting waiters to array new f proxy fetch waiter waiters size for f proxy fetch waiter w waiting w wake up finished wakewaiters fproxyfetchwaiter toarray fproxyfetchwaiter fproxyfetchwaiter wakeup public void on failure fetch exception e client getter state object container container synchronized this this failed e this finished true wake waiters true onfailure fetchexception clientgetter objectcontainer wakewaiters public void on failure insert exception e base client putter state object container container impossible onfailure insertexception baseclientputter objectcontainer public void on fetchable base client putter state object container container impossible onfetchable baseclientputter objectcontainer public void on generateduri freeneturi uri base client putter state object container container impossible ongenerateduri baseclientputter objectcontainer public void on major progress object container container ignore onmajorprogress objectcontainer public void on success fetch result result client getter state object container container synchronized this this data result as bucket this mime type result get mime type this finished true wake waiters true onsuccess fetchresult clientgetter objectcontainer asbucket mimetype getmimetype wakewaiters public void on success base client putter state object container container ignore onsuccess baseclientputter objectcontainer public boolean has data return data null hasdata public boolean finished return finished public void close f proxy fetch waiter waiter synchronized this waiters remove waiter if results is empty return if waiters is empty return tracker queue cancel this fproxyfetchwaiter isempty isempty queuecancel caller should take the lock on f proxy toadlet fetchers then call this function if it returns true then finish the cancel outside the lock public synchronized boolean can cancel if waiters is empty return false if results is empty return false if last touched lifetime system current time millis if logminor logger minor this not able to cancel for this uri max size return false if logminor logger minor this can cancel for this uri max size return true fproxytoadlet cancancel isempty isempty lasttouched currenttimemillis maxsize maxsize public void finish cancel if logminor logger minor this finishing cancel for this uri max size if data null try data free catch throwable t ensure we get to the next bit logger error this failed to free t t try getter cancel catch throwable t ensure we get to the next bit logger error this failed to cancel t t finishcancel maxsize public void close f proxy fetch result result synchronized this results remove result if results is empty return if waiters is empty return tracker queue cancel this fproxyfetchresult isempty isempty queuecancel public synchronized long geteta if gone to network return 1 if required blocks 0 return 1 if fetched blocks required blocks return 1 if fetched blocks fetched blocks pre network 5 return 1 return system current time millis time started required blocks fetched blocks pre network fetched blocks fetched blocks pre network gonetonetwork requiredblocks fetchedblocks requiredblocks fetchedblocks fetchedblocksprenetwork currenttimemillis timestarted requiredblocks fetchedblocksprenetwork fetchedblocks fetchedblocksprenetwork public synchronized boolean not finished or fatally finished if data null failed null return true if failed null failed is fatal return true if failed null has notified failure has notified failure true return true return false notfinishedorfatallyfinished isfatal hasnotifiedfailure hasnotifiedfailure public synchronized boolean has notified failure return true hasnotifiedfailure private final node node public meaningful node name user alert node n super true null null null null user alert warning true l10n get string user alert hide false null this node n meaningfulnodenameuseralert useralert getstring useralert override public string get title return l10n no node nick title gettitle nonodenicktitle private string l10n string key return l10n get string meaningful node name user alert key getstring meaningfulnodenameuseralert override public string get text return l10n no node nick gettext nonodenick override public string get short text return l10n no node nick short getshorttext nonodenickshort override public html node gethtml text sub config sc node config get node option o sc get option name html node alert node new html node div html node text node alert node add child div text node add child l10n no node nick html node form node alert node add child form new string action method new string config post form node add child input new string type name value new string hidden form password node client core form password html node list node form node add child ul class config html node item node list node add child li item node add child span new string class title style new string configshortdesc l10n get string config toadlet default is new string default new string o get default cursor help add child l10n gethtml node o get short desc item node add child input new string type class alt name value new string text config o get short desc node name o get value string item node add child span class configlongdesc add child l10n gethtml node o get long desc form node add child input new string type value new string submit l10n get string user alert apply form node add child input new string type value new string reset l10n get string user alert reset return alert node htmlnode gethtmltext subconfig getoption htmlnode alertnode htmlnode htmlnode textnode alertnode addchild textnode addchild nonodenick htmlnode formnode alertnode addchild formnode addchild formpassword clientcore formpassword htmlnode listnode formnode addchild htmlnode itemnode listnode addchild itemnode addchild getstring configtoadlet defaultis getdefault addchild gethtmlnode getshortdesc itemnode addchild getshortdesc getvaluestring itemnode addchild addchild gethtmlnode getlongdesc formnode addchild getstring useralert formnode addchild getstring useralert alertnode override public boolean is valid return node peers any darknet peers isvalid anydarknetpeers public class outline filter extends binary filter public outline filter new color 0xffffffff outlinefilter binaryfilter outlinefilter newcolor override protected int filter pixels int width int height int in pixels rectangle transformed space int index 0 int out pixels new int width height for int y 0 y height y for int x 0 x width x int pixel in pixels y width x if black function is black pixel int neighbours 0 for int dy 1 dy 1 dy int iy y dy int ioffset if 0 iy iy height ioffset iy width for int dx 1 dx 1 dx int ix x dx if dy 0 dx 0 0 ix ix width int rgb in pixels ioffset ix if black function is black rgb neighbours else neighbours if neighbours 9 pixel new color out pixels index pixel return out pixels filterpixels inpixels transformedspace outpixels inpixels blackfunction isblack inpixels blackfunction isblack newcolor outpixels outpixels override public string to string return binary outline tostring public void object on activate object container container only activate the arrays container activate waiting for 1 container activate waiting for block set 1 container activate waiting for fetchable 1 objectonactivate objectcontainer waitingfor waitingforblockset waitingforfetchable public multi put completion callback put completion callback cb base client putter parent object token boolean persistent this cb cb waiting for new vector client put state waiting for block set new vector client put state waiting for fetchable new vector client put state this parent parent this token token finished false this persistent persistent multiputcompletioncallback putcompletioncallback baseclientputter waitingfor clientputstate waitingforblockset clientputstate waitingforfetchable clientputstate public void on success client put state state object container container client context context on block set finished state container context on fetchable state container if persistent container activate waiting for 2 boolean complete true synchronized this if finished logger error this already finished but got on success for state on this return waiting for remove state waiting for block set remove state waiting for fetchable remove state if waiting for is empty started if persistent container ext store waiting for 1 complete false if state generator generator null if persistent container store this if persistent container ext store waiting for 2 container ext store waiting for block set 2 container ext store waiting for fetchable 2 state remove from container context if complete logger minor this completing complete null container context onsuccess clientputstate objectcontainer clientcontext onblocksetfinished onfetchable waitingfor onsuccess waitingfor waitingforblockset waitingforfetchable waitingfor isempty waitingfor waitingfor waitingforblockset waitingforfetchable removefrom public void on failure insert exception e client put state state object container container client context context boolean complete true synchronized this if finished logger error this already finished but got on failure for state on this return waiting for remove state waiting for block set remove state waiting for fetchable remove state if waiting for is empty started if this e null if persistent container activate this e 10 this e remove from container this e e if persistent container store this complete false if state generator generator null if persistent container store this if persistent container ext store waiting for 2 container ext store waiting for block set 2 container ext store waiting for fetchable 2 state remove from container context if complete complete e container context onfailure insertexception clientputstate objectcontainer clientcontext onfailure waitingfor waitingforblockset waitingforfetchable waitingfor isempty removefrom waitingfor waitingforblockset waitingforfetchable removefrom private void complete insert exception e object container container client context context synchronized this if finished return finished true if e null this e null this e e if persistent container activate this e 10 if e get mode insert exception cancelled cancelled is okay ignore it we cancel after failure sometimes ignore the new failure mode use the old one e this e if persistent e e clone since we will remove it we can t pass it on else delete the old failure mode use the new one this e remove from container this e e if e null e this e if persistent e null container activate e 10 e e clone since we will remove it we can t pass it on if persistent container store this container activate cb 1 if e null cb on failure e this container context else cb on success this container context insertexception objectcontainer clientcontext getmode insertexception removefrom onfailure onsuccess public synchronized void adduri generator client put state ps object container container add ps container generator ps if persistent container store this addurigenerator clientputstate objectcontainer public synchronized void add client put state ps object container container if finished return waiting for add ps waiting for block set add ps waiting for fetchable add ps if persistent container store ps container ext store waiting for 2 container ext store waiting for block set 2 container ext store waiting for fetchable 2 clientputstate objectcontainer waitingfor waitingforblockset waitingforfetchable waitingfor waitingforblockset waitingforfetchable public void arm object container container client context context boolean all done boolean all got blocks synchronized this started true all done waiting for is empty all got blocks waiting for block set is empty if persistent container store this container activate cb 1 if all got blocks cb on block set finished this container context if all done complete e container context objectcontainer clientcontext alldone allgotblocks alldone waitingfor isempty allgotblocks waitingforblockset isempty allgotblocks onblocksetfinished alldone public base client putter get parent return parent baseclientputter getparent public void on encode base client key key client put state state object container container client context context synchronized this if state generator return if persistent container activate cb 1 cb on encode key this container context onencode baseclientkey clientputstate objectcontainer clientcontext onencode public void cancel object container container client context context client put state states new client put state waiting for size synchronized this states waiting for to array states boolean logdebug logger should log logger debug this for int i 0 i states length i if persistent container activate states i 1 if logdebug logger minor this cancelling state i of states length states i states i cancel container context objectcontainer clientcontext clientputstate clientputstate waitingfor waitingfor toarray shouldlog public synchronized void on transition client put state old state client put state new state object container container if generator old state generator new state if old state new state return for int i 0 i waiting for size i if waiting for get i old state waiting for set i new state container ext store waiting for 2 for int i 0 i waiting for block set size i if waiting for block set get i old state waiting for block set set i new state container ext store waiting for 2 for int i 0 i waiting for fetchable size i if waiting for fetchable get i old state waiting for fetchable set i new state container ext store waiting for 2 if persistent container store this ontransition clientputstate oldstate clientputstate newstate objectcontainer oldstate newstate oldstate newstate waitingfor waitingfor oldstate waitingfor newstate waitingfor waitingforblockset waitingforblockset oldstate waitingforblockset newstate waitingfor waitingforfetchable waitingforfetchable oldstate waitingforfetchable newstate waitingfor public synchronized void on metadata metadata m client put state state object container container client context context if persistent container activate cb 1 if generator state cb on metadata m this container context else logger error this got metadata for state onmetadata clientputstate objectcontainer clientcontext onmetadata public void on block set finished client put state state object container container client context context if persistent container activate waiting for block set 2 synchronized this this waiting for block set remove state if persistent container ext store waiting for block set 2 if started return if waiting for block set is empty return if persistent container activate cb 1 cb on block set finished this container context onblocksetfinished clientputstate objectcontainer clientcontext waitingforblockset waitingforblockset waitingforblockset waitingforblockset isempty onblocksetfinished public void schedule object container container client context context throws insert exception do nothing objectcontainer clientcontext insertexception public object get token return token gettoken public void on fetchable client put state state object container container if persistent container activate waiting for fetchable 2 synchronized this this waiting for fetchable remove state if persistent container ext store waiting for fetchable 2 if started return if waiting for fetchable is empty return if persistent container activate cb 1 cb on fetchable this container onfetchable clientputstate objectcontainer waitingforfetchable waitingforfetchable waitingforfetchable waitingforfetchable isempty onfetchable public void remove from object container container client context context container activate waiting for 2 container activate waiting for block set 2 container activate waiting for fetchable 2 should have been cleared by now if waiting for is empty logger error this waiting for not empty in remove from on this waiting for if waiting for block set is empty logger error this waiting for block set not empty in remove from on this waiting for if waiting for fetchable is empty logger error this waiting for fetchable not empty in remove from on this waiting for container delete waiting for container delete waiting for block set container delete waiting for fetchable cb is at a higher level we don t remove that it removes itself generator is just a reference to one of the waiting for s parent removes itself if e null container activate e 5 e remove from container whoever set the token is responsible for removing it container delete this removefrom objectcontainer clientcontext waitingfor waitingforblockset waitingforfetchable waitingfor isempty waitingfor removefrom waitingfor waitingforblockset isempty waitingforblockset removefrom waitingfor waitingforfetchable isempty waitingforfetchable removefrom waitingfor waitingfor waitingforblockset waitingforfetchable waitingfor removefrom public final class average composite extends rgb composite public average composite float alpha super alpha averagecomposite rgbcomposite averagecomposite public composite context create context color model src color model color model dst color model rendering hints hints return new context extra alpha src color model dst color model compositecontext createcontext colormodel srccolormodel colormodel dstcolormodel renderinghints extraalpha srccolormodel dstcolormodel static class context extends rgb composite context public context float alpha color model src color model color model dst color model super alpha src color model dst color model rgbcompositecontext colormodel srccolormodel colormodel dstcolormodel srccolormodel dstcolormodel override public void composergb int src int dst float alpha int w src length for int i 0 i w i 4 int sr src i int dir dst i int sg src i 1 int dig dst i 1 int sb src i 2 int dib dst i 2 int sa src i 3 int dia dst i 3 int dor dog dob dor dir sr 2 dog dig sg 2 dob dib sb 2 float a alpha sa 255f float ac 1 a dst i int a dor ac dir dst i 1 int a dog ac dig dst i 2 int a dob ac dib dst i 3 int sa alpha dia ac compare i th component of two objects param m1 first object param m2 second object param i component index return left undefined if value of i th component of m1 is null and value of i th component of m2 is not null right undefined if value of i th component of m1 is not null and value of i th component of m2 is null eq if both values are null otherwise lt eq or gt depending on result of their comparison left_undefined right_undefined get number of dimensions return number of dimensions create clone of the specified object contining copy of the specified field param obj original object param i component index return clone of the object public abstract t clone field t obj int i protected multidimensional comparator storage storage super storage clonefield multidimensionalcomparator protected multidimensional comparator multidimensionalcomparator public fcp server string ip to bind to string allowed hosts string allowed hosts full access int port node node node client core core boolean persistent downloads enabled string persistent downloads dir boolean is enabled boolean assumedda download allowed boolean assumedda upload allowed object container container throws io exception invalid config value exception this bind to ip to bind to this allowed hosts allowed hosts this allowed hosts full access new allowed hosts allowed hosts full access this port port this enabled is enabled this enable persistent downloads persistent downloads enabled set persistent downloads file new file persistent downloads dir this node node this core core this assume downloaddda is allowed assumedda download allowed this assume uploaddda is allowed assumedda upload allowed reboot clients by name new weak hash map string fcp client this one is only used to get the default settings individual fcp conns will make their own high level simple client client core make client short 0 default fetch context client get fetch context default insert context client get insert context false global reboot client new fcp client global queue null true null client request persist reboot null null logminor logger should log logger minor this persistent root fcp persistent root create node nodedb handle container global forever client persistent root global forever client if enabled enable persistent downloads logger error this persistent downloads enabled attempting to migrate old persistent downloads to database logger error this note that we will not write to downloads dat gz we will read from it and rename it if migration is successful load persistent requests container else logger error this not loading persistent requests enabled enabled enable persistent downloads enable persistent downloads fcpserver iptobindto allowedhosts allowedhostsfullaccess nodeclientcore persistentdownloadsenabled persistentdownloadsdir isenabled assumeddadownloadallowed assumeddauploadallowed objectcontainer ioexception invalidconfigvalueexception bindto iptobindto allowedhosts allowedhosts allowedhostsfullaccess allowedhosts allowedhostsfullaccess isenabled enablepersistentdownloads persistentdownloadsenabled setpersistentdownloadsfile persistentdownloadsdir assumedownloadddaisallowed assumeddadownloadallowed assumeuploadddaisallowed assumeddauploadallowed rebootclientsbyname weakhashmap fcpclient highlevelsimpleclient makeclient defaultfetchcontext getfetchcontext defaultinsertcontext getinsertcontext globalrebootclient fcpclient clientrequest persist_reboot shouldlog persistentroot fcppersistentroot nodedbhandle globalforeverclient persistentroot globalforeverclient enablepersistentdownloads loadpersistentrequests enablepersistentdownloads private void maybe get network interface if this network interface null return network interface temp network interface null try if ssl temp network interface ssl network interface create port bind to allowed hosts node executor true else temp network interface network interface create port bind to allowed hosts node executor true catch io exception be logger error this couldn t bind to fcp port bind to port fcp server not started be system out println couldn t bind to fcp port bind to port fcp server not started this network interface temp network interface maybegetnetworkinterface networkinterface networkinterface tempnetworkinterface tempnetworkinterface sslnetworkinterface bindto allowedhosts tempnetworkinterface networkinterface bindto allowedhosts ioexception bindto bindto networkinterface tempnetworkinterface public void maybe start if this enabled maybe get network interface logger normal this starting fcp server on bind to port system out println starting fcp server on bind to port if this network interface null thread t new thread this fcp server t set daemon true t start else logger normal this not starting fcp server as it s disabled system out println not starting fcp server as it s disabled this network interface null maybestart maybegetnetworkinterface bindto bindto networkinterface setdaemon networkinterface public void run freenet support logger os thread logpid this while true try real run catch io exception e if logminor logger minor this caught e e catch out of memory error e oom handler handleoom e catch throwable t logger error this caught t t if wrapper manager has shutdown hook been triggered return try thread sleep 2000 catch interrupted exception e osthread realrun ioexception outofmemoryerror oomhandler wrappermanager hasshutdownhookbeentriggered interruptedexception private void real run throws io exception if node is has started return accept a connection socket s network interface accept fcp connection handler ch new fcp connection handler s this ch start realrun ioexception ishasstarted networkinterface fcpconnectionhandler fcpconnectionhandler private final node client core node fcp port number callback node client core node this node node nodeclientcore fcpportnumbercallback nodeclientcore override public integer get return node getfcp server port getfcpserver override public void set integer val throws invalid config value exception if get equals val throw new invalid config value exception cannot change fcp port number on the fly invalidconfigvalueexception invalidconfigvalueexception override public boolean is read only return true isreadonly final node client core node fcp enabled callback node client core node this node node nodeclientcore fcpenabledcallback nodeclientcore override public boolean get return node getfcp server enabled getfcpserver todo allow it override public void set boolean val throws invalid config value exception if get equals val throw new invalid config value exception l10n cannot start or stop on the fly invalidconfigvalueexception invalidconfigvalueexception cannotstartorstoponthefly override public boolean is read only return true isreadonly static class fcpssl callback extends boolean callback override public boolean get return ssl fcpsslcallback booleancallback override public void set boolean val throws invalid config value exception if get equals val return if ssl available throw new invalid config value exception enable ssl support before use ssl with fcp ssl val throw new invalid config value exception cannot change ssl on the fly please restart freenet invalidconfigvalueexception invalidconfigvalueexception invalidconfigvalueexception override public boolean is read only return true isreadonly final node client core node fcp bindto callback node client core node this node node nodeclientcore fcpbindtocallback nodeclientcore override public string get return node getfcp server bind to getfcpserver bindto override public void set string val throws invalid config value exception if val equals get try node getfcp server network interface set bind to val true node getfcp server bind to val catch io exception e this is an advanced option for reasons of reducing clutter but it is expected to be used by regular users not devs so we translate the error messages throw new invalid config value exception l10n could not change bind to error e get localized message invalidconfigvalueexception getfcpserver networkinterface setbindto getfcpserver bindto ioexception invalidconfigvalueexception couldnotchangebindto getlocalizedmessage private final node client core node public fcp allowed hosts callback node client core node this node node nodeclientcore fcpallowedhostscallback nodeclientcore override public string get fcp server server node getfcp server if server null return network interface default bind to network interface net iface server network interface return net iface null network interface default bind to net iface get allowed hosts fcpserver getfcpserver networkinterface default_bind_to networkinterface netiface networkinterface netiface networkinterface default_bind_to netiface getallowedhosts override public void set string val if val equals get node getfcp server network interface set allowed hosts val getfcpserver networkinterface setallowedhosts boolean enabled override public boolean get return enabled override public void set boolean set throws invalid config value exception this option will be removed completely soon so there is little point in translating it fixme remove if set boolean value enabled throw new invalid config value exception cannot disable enable persistent download loading support on the fly invalidconfigvalueexception booleanvalue invalidconfigvalueexception private final node client core node public fcp allowed hosts full access callback node client core node this node node nodeclientcore fcpallowedhostsfullaccesscallback nodeclientcore override public string get return node getfcp server allowed hosts full access get allowed hosts getfcpserver allowedhostsfullaccess getallowedhosts override public void set string val if val equals get node getfcp server allowed hosts full access set allowed hosts val getfcpserver allowedhostsfullaccess setallowedhosts fcp server server override public string get return server persistent downloads file to string fcpserver persistentdownloadsfile tostring override public void set string val throws invalid config value exception file f new file val if f equals server persistent downloads file return server set persistent downloads file f invalidconfigvalueexception persistentdownloadsfile setpersistentdownloadsfile fcp server server override public boolean get return server assume downloaddda is allowed fcpserver assumedownloadddaisallowed override public void set boolean val throws invalid config value exception if get equals val return server assume downloaddda is allowed val invalidconfigvalueexception assumedownloadddaisallowed fcp server server override public boolean get return server assume uploaddda is allowed fcpserver assumeuploadddaisallowed override public void set boolean val throws invalid config value exception if get equals val return server assume uploaddda is allowed val invalidconfigvalueexception assumeuploadddaisallowed public static fcp server maybe create node node node client core core config config object container container throws io exception invalid config value exception sub config fcp config new sub config fcp config short sort order 0 fcp config register enabled true sort order true false fcp server is enabled fcp server is enabled long new fcp enabled callback core fcp config register ssl false sort order true true fcp server ssl fcp server ssl long new fcpssl callback fcp config register port fcp server default fcp port anagram of 1984 and 1000 up from old number 2 true true fcp server port number fcp server port number long new fcp port number callback core false fcp config register bind to network interface default bind to sort order true true fcp server bind to fcp server bind to long new fcp bindto callback core fcp config register allowed hosts network interface default bind to sort order true true fcp server allowed hosts fcp server allowed hosts long new fcp allowed hosts callback core fcp config register allowed hosts full access network interface default bind to sort order true true fcp server allowed hosts full access fcp server allowed hosts full access long new fcp allowed hosts full access callback core persistent downloads file callback cb2 persistent downloads enabled callback enabledcb new persistent downloads enabled callback fcp config register persistent downloads enabled true sort order true true fcp server enable persistent download fcp server enable persistent download long enabledcb fcp config register persistent downloads file downloads dat sort order true false fcp server filename to storep data fcp server filename to storep data long cb2 new persistent downloads file callback fcp config register persistent downloads interval 5 60 1000 sort order true false fcp server interval between writes fcp server interval between writes long int callback null false string persistent downloads dir fcp config get string persistent downloads file boolean persistent downloads enabled fcp config get boolean persistent downloads enabled enabledcb enabled persistent downloads enabled assumedda download is allowed callback cb4 assumedda upload is allowed callback cb5 fcp config register assume downloaddda is allowed false sort order true false fcp server assume downloaddda is allowed fcp server assume downloaddda is allowed long cb4 new assumedda download is allowed callback fcp config register assume uploaddda is allowed false sort order true false fcp server assume uploaddda is allowed fcp server assume uploaddda is allowed long cb5 new assumedda upload is allowed callback if ssl available ssl fcp config get boolean ssl fcp server fcp new fcp server fcp config get string bind to fcp config get string allowed hosts fcp config get string allowed hosts full access fcp config get int port node core persistent downloads enabled persistent downloads dir fcp config get boolean enabled fcp config get boolean assume downloaddda is allowed fcp config get boolean assume uploaddda is allowed container if fcp null cb2 server fcp cb4 server fcp cb5 server fcp fcp config finished initialization return fcp fcpserver maybecreate nodeclientcore objectcontainer ioexception invalidconfigvalueexception subconfig fcpconfig subconfig sortorder fcpconfig sortorder fcpserver isenabled fcpserver isenabledlong fcpenabledcallback fcpconfig sortorder fcpserver fcpserver ssllong fcpsslcallback fcpconfig fcpserver default_fcp_port fcpserver portnumber fcpserver portnumberlong fcpportnumbercallback fcpconfig bindto networkinterface default_bind_to sortorder fcpserver bindto fcpserver bindtolong fcpbindtocallback fcpconfig allowedhosts networkinterface default_bind_to sortorder fcpserver allowedhosts fcpserver allowedhostslong fcpallowedhostscallback fcpconfig allowedhostsfullaccess networkinterface default_bind_to sortorder fcpserver allowedhostsfullaccess fcpserver allowedhostsfullaccesslong fcpallowedhostsfullaccesscallback persistentdownloadsfilecallback persistentdownloadsenabledcallback persistentdownloadsenabledcallback fcpconfig persistentdownloadsenabled sortorder fcpserver enablepersistentdownload fcpserver enablepersistentdownloadlong fcpconfig persistentdownloadsfile sortorder fcpserver filenametostorepdata fcpserver filenametostorepdatalong persistentdownloadsfilecallback fcpconfig persistentdownloadsinterval sortorder fcpserver intervalbetweenwrites fcpserver intervalbetweenwriteslong intcallback persistentdownloadsdir fcpconfig getstring persistentdownloadsfile persistentdownloadsenabled fcpconfig getboolean persistentdownloadsenabled persistentdownloadsenabled assumeddadownloadisallowedcallback assumeddauploadisallowedcallback fcpconfig assumedownloadddaisallowed sortorder fcpserver assumedownloadddaisallowed fcpserver assumedownloadddaisallowedlong assumeddadownloadisallowedcallback fcpconfig assumeuploadddaisallowed sortorder fcpserver assumeuploadddaisallowed fcpserver assumeuploadddaisallowedlong assumeddauploadisallowedcallback fcpconfig getboolean fcpserver fcpserver fcpconfig getstring bindto fcpconfig getstring allowedhosts fcpconfig getstring allowedhostsfullaccess fcpconfig getint persistentdownloadsenabled persistentdownloadsdir fcpconfig getboolean fcpconfig getboolean assumedownloadddaisallowed fcpconfig getboolean assumeuploadddaisallowed fcpconfig finishedinitialization public void set persistent downloads file file f throws invalid config value exception synchronized persistence sync check file f file temp new file f get path tmp check file temp else is ok persistent downloads file f persistent downloads temp file temp setpersistentdownloadsfile invalidconfigvalueexception persistencesync checkfile getpath checkfile persistentdownloadsfile persistentdownloadstempfile private void check file file f throws invalid config value exception if f is directory throw new invalid config value exception l10n downloads file is directory if f is file f can read f can write throw new invalid config value exception l10n downloads file unreadable file parent f get parent file if parent null parent exists throw new invalid config value exception l10n downloads file parent does not exist if f exists try if f create new file if f exists if f can read f can write throw new invalid config value exception l10n downloads file exists cannot read or write else ok else throw new invalid config value exception l10n downloads file does not exist cannot create else if f can read f can write throw new invalid config value exception l10n downloads file can create cannot read or write catch io exception e throw new invalid config value exception l10n downloads file does not exist cannot create e get localized message finally must be deleted otherwise we will read from it and ignore the temp file lose the queue f delete checkfile invalidconfigvalueexception isdirectory invalidconfigvalueexception downloadsfileisdirectory isfile canread canwrite invalidconfigvalueexception downloadsfileunreadable getparentfile invalidconfigvalueexception downloadsfileparentdoesnotexist createnewfile canread canwrite invalidconfigvalueexception downloadsfileexistscannotreadorwrite invalidconfigvalueexception downloadsfiledoesnotexistcannotcreate canread canwrite invalidconfigvalueexception downloadsfilecancreatecannotreadorwrite ioexception invalidconfigvalueexception downloadsfiledoesnotexistcannotcreate getlocalizedmessage private static string l10n string key return l10n get string fcp server key getstring fcpserver private static string l10n string key string pattern string value return l10n get string fcp server key pattern value getstring fcpserver public fcp client register reboot client string name node client core core fcp connection handler handler fcp client old client synchronized this old client reboot clients by name get name if old client null create new client fcp client client new fcp client name handler false null client request persist reboot null null reboot clients by name put name client return client else fcp connection handler old conn old client get connection have existing client if old conn null easy old client set connection handler return old client else kill old connection old conn set killed dupe old conn output handler queue new close connection duplicate client name message old conn close old client set connection handler return old client fcpclient registerrebootclient nodeclientcore fcpconnectionhandler fcpclient oldclient oldclient rebootclientsbyname oldclient fcpclient fcpclient clientrequest persist_reboot rebootclientsbyname fcpconnectionhandler oldconn oldclient getconnection oldconn oldclient setconnection oldclient oldconn setkilleddupe oldconn outputhandler closeconnectionduplicateclientnamemessage oldconn oldclient setconnection oldclient public fcp client register forever client string name node client core core fcp connection handler handler object container container return persistent root register forever client name core handler this container fcpclient registerforeverclient nodeclientcore fcpconnectionhandler objectcontainer persistentroot registerforeverclient public void unregister client fcp client client object container container if client persistence type client request persist reboot assert container null synchronized this string name client name reboot clients by name remove name else persistent root maybe unregister client client container unregisterclient fcpclient objectcontainer persistencetype clientrequest persist_reboot rebootclientsbyname persistentroot maybeunregisterclient private void load persistent requests object container container logger normal this loading persistent requests file input stream fis null buffered input stream bis null gzip input stream gis null try file file new file persistent downloads file gz fis new file input stream file gis new gzip input stream fis bis new buffered input stream gis logger normal this loading persistent requests from file if file length 0 load persistent requests bis container else throw new io exception file empty if it s empty try the temp file catch io exception e logger error this ioe e get message e file file new file persistent downloads temp file gz logger normal this let s try to load file then closer close bis closer close gis closer close fis try fis new file input stream file bis new buffered input stream fis load persistent requests bis container catch io exception e1 logger normal this it s corrupted too not reading any persistent requests from disk e1 return finally closer close bis closer close gis closer close fis loadpersistentrequests objectcontainer fileinputstream bufferedinputstream gzipinputstream persistentdownloadsfile fileinputstream gzipinputstream bufferedinputstream loadpersistentrequests ioexception ioexception getmessage persistentdownloadstempfile fileinputstream bufferedinputstream loadpersistentrequests ioexception private void load persistent requests input stream is object container container throws io exception synchronized persistence sync input stream reader ris new input stream reader is utf 8 buffered reader br new buffered reader ris try string r br read line int count try count integer parse int r catch number format exception e logger error this corrupt persistent downloads file cannot parse r as integer throw new io exception e to string for int i 0 i count i wrapper manager signal starting 20 60 1000 20 minutes per request must be ds lock timeout 10 minutes system out println loading persistent request i 1 of count humans count from 1 client request read and register br this container core client context logger normal this loaded count persistent requests finally closer close br closer close ris loadpersistentrequests inputstream objectcontainer ioexception persistencesync inputstreamreader inputstreamreader bufferedreader bufferedreader readline parseint numberformatexception ioexception tostring wrappermanager signalstarting clientrequest readandregister clientcontext public client request get global requests object container container list client request v new array list client request global reboot client add persistent requests v false null if container ext is active global forever client logger error this somebody deactivated the global queue container activate global forever client 2 global forever client add persistent requests v false container return v to array new client request v size clientrequest getglobalrequests objectcontainer clientrequest arraylist clientrequest globalrebootclient addpersistentrequests isactive globalforeverclient globalforeverclient globalforeverclient addpersistentrequests toarray clientrequest public boolean remove global request blocking final string identifier throws message invalid exception if global reboot client remove by identifier identifier true this null core client context final object sync new object final mutable boolean done new mutable boolean final mutable boolean success new mutable boolean done value false core client context job runner queue new db job public void run object container container client context context boolean succeeded false try succeeded global forever client remove by identifier identifier true fcp server this container core client context catch throwable t logger error this caught removing identifier identifier t t finally synchronized sync success value succeeded done value true sync notify all native thread high priority false synchronized sync while done value try sync wait catch interrupted exception e ignore return success value else return true removeglobalrequestblocking messageinvalidexception globalrebootclient removebyidentifier clientcontext mutableboolean mutableboolean mutableboolean mutableboolean clientcontext jobrunner dbjob objectcontainer clientcontext globalforeverclient removebyidentifier fcpserver clientcontext notifyall nativethread high_priority interruptedexception public void run object container container client context context boolean succeeded false try succeeded global forever client remove by identifier identifier true fcp server this container core client context catch throwable t logger error this caught removing identifier identifier t t finally synchronized sync success value succeeded done value true sync notify all objectcontainer clientcontext globalforeverclient removebyidentifier fcpserver clientcontext notifyall public boolean remove all global requests blocking global reboot client remove all null core client context final object sync new object final mutable boolean done new mutable boolean final mutable boolean success new mutable boolean done value false core client context job runner queue new db job public void run object container container client context context boolean succeeded false try global forever client remove all container core client context succeeded true catch throwable t logger error this caught while processing panic t t system err println panic incomplete caught t t print stack trace system err println your requests have not been deleted finally synchronized sync success value succeeded done value true sync notify all native thread high priority false synchronized sync while done value try sync wait catch interrupted exception e ignore return success value removeallglobalrequestsblocking globalrebootclient removeall clientcontext mutableboolean mutableboolean mutableboolean mutableboolean clientcontext jobrunner dbjob objectcontainer clientcontext globalforeverclient removeall clientcontext printstacktrace notifyall nativethread high_priority interruptedexception public void run object container container client context context boolean succeeded false try global forever client remove all container core client context succeeded true catch throwable t logger error this caught while processing panic t t system err println panic incomplete caught t t print stack trace system err println your requests have not been deleted finally synchronized sync success value succeeded done value true sync notify all objectcontainer clientcontext globalforeverclient removeall clientcontext printstacktrace notifyall public void make persistent global request blocking final freeneturi fetchuri final string expected mime type final string persistence type string final string return type string throws not allowed exception io exception class output wrapper not allowed exception ne io exception ioe boolean done final output wrapper ow new output wrapper core client context job runner queue new db job public void run object container container client context context not allowed exception ne null io exception ioe null try make persistent global request fetchuri expected mime type persistence type string return type string container catch not allowed exception e ne e catch io exception e ioe e catch throwable t unexpected and severe might even be oom just log it logger error this failed to make persistent request t t finally synchronized ow ow ne ne ow ioe ioe ow done true ow notify all native thread high priority false synchronized ow while true if ow done try ow wait catch interrupted exception e ignore continue if ow ioe null throw ow ioe if ow ne null throw ow ne return makepersistentglobalrequestblocking expectedmimetype persistencetypestring returntypestring notallowedexception ioexception outputwrapper notallowedexception ioexception outputwrapper outputwrapper clientcontext jobrunner dbjob objectcontainer clientcontext notallowedexception ioexception makepersistentglobalrequest expectedmimetype persistencetypestring returntypestring notallowedexception ioexception notifyall nativethread high_priority interruptedexception public void run object container container client context context not allowed exception ne null io exception ioe null try make persistent global request fetchuri expected mime type persistence type string return type string container catch not allowed exception e ne e catch io exception e ioe e catch throwable t unexpected and severe might even be oom just log it logger error this failed to make persistent request t t finally synchronized ow ow ne ne ow ioe ioe ow done true ow notify all objectcontainer clientcontext notallowedexception ioexception makepersistentglobalrequest expectedmimetype persistencetypestring returntypestring notallowedexception ioexception notifyall public boolean modify global request blocking final string identifier final string new token final short new priority client request req this global reboot client get request identifier null if req null req modify request new token new priority this null return true else class output wrapper boolean success boolean done final output wrapper ow new output wrapper core client context job runner queue new db job public void run object container container client context context boolean success false try client request req global forever client get request identifier container container activate req 1 if req null req modify request new token new priority fcp server this container container deactivate req 1 success true finally synchronized ow ow success success ow done true ow notify all native thread high priority false synchronized ow while true if ow done try ow wait catch interrupted exception e ignore continue return ow success modifyglobalrequestblocking newtoken newpriority clientrequest globalrebootclient getrequest modifyrequest newtoken newpriority outputwrapper outputwrapper outputwrapper clientcontext jobrunner dbjob objectcontainer clientcontext clientrequest globalforeverclient getrequest modifyrequest newtoken newpriority fcpserver notifyall nativethread high_priority interruptedexception public void run object container container client context context boolean success false try client request req global forever client get request identifier container container activate req 1 if req null req modify request new token new priority fcp server this container container deactivate req 1 success true finally synchronized ow ow success success ow done true ow notify all objectcontainer clientcontext clientrequest globalforeverclient getrequest modifyrequest newtoken newpriority fcpserver notifyall create a persistent globally queued request for a file param fetchuri the file to fetch param persistence the persistence type param return type the return type throws not allowed exception throws io exception public void make persistent global request freeneturi fetchuri string expected mime type string persistence type string string return type string object container container throws not allowed exception io exception boolean persistence persistence type string equals ignore case reboot short return type client get message parse return type return type string file return filename null return temp filename null if return type client get message return type disk return filename make return filename fetchuri expected mime type return temp filename make temp return filename return filename public client get fcp client global client freeneturi uri boolean ds only boolean ignoreds int max splitfile retries int max non splitfile retries long max output length short return type boolean persist reboot only string identifier int verbosity short prio class file return filename file return temp filename throws identifier collision exception try inner make persistent global request fetchuri persistence return type f proxy fetchuri get preferred filename return filename return temp filename container return catch identifier collision exception ee try inner make persistent global request fetchuri persistence return type f proxy fetchuri get doc name return filename return temp filename container return catch identifier collision exception e try inner make persistent global request fetchuri persistence return type f proxy fetchuri to string false false return filename return temp filename container return catch identifier collision exception e1 fixme maybe use date format try inner make persistent global request fetchuri persistence return type f proxy system current time millis return filename return temp filename container return catch identifier collision exception e2 while true byte buf new byte 8 try core random next bytes buf string id f proxy base64 encode buf inner make persistent global request fetchuri persistence return type id return filename return temp filename container return catch identifier collision exception e3 returntype notallowedexception ioexception makepersistentglobalrequest expectedmimetype persistencetypestring returntypestring objectcontainer notallowedexception ioexception persistencetypestring equalsignorecase returntype clientgetmessage parsereturntype returntypestring returnfilename returntempfilename returntype clientgetmessage return_type_disk returnfilename makereturnfilename expectedmimetype returntempfilename maketempreturnfilename returnfilename clientget fcpclient globalclient dsonly maxsplitfileretries maxnonsplitfileretries maxoutputlength returntype persistrebootonly prioclass returnfilename returntempfilename identifiercollisionexception innermakepersistentglobalrequest returntype fproxy getpreferredfilename returnfilename returntempfilename identifiercollisionexception innermakepersistentglobalrequest returntype fproxy getdocname returnfilename returntempfilename identifiercollisionexception innermakepersistentglobalrequest returntype fproxy tostring returnfilename returntempfilename identifiercollisionexception dateformat innermakepersistentglobalrequest returntype fproxy currenttimemillis returnfilename returntempfilename identifiercollisionexception nextbytes fproxy innermakepersistentglobalrequest returntype returnfilename returntempfilename identifiercollisionexception private file make temp return filename file return filename return new file return filename to string freenet tmp maketempreturnfilename returnfilename returnfilename tostring private file make return filename freeneturi uri string expected mime type string ext if expected mime type null expected mime type length 0 expected mime type equals defaultmime types default mime type ext defaultmime types get extension expected mime type else ext null string ext add ext null ext string preferred uri get preferred filename string preferred with ext preferred if ext null preferred with ext ends with ext preferred with ext ext add file f new file core get download dir preferred with ext file f1 new file core get download dir preferred with ext freenet tmp int x 0 string builder sb new string builder for f exists f1 exists sb set length 0 sb append preferred sb append sb append x sb append ext add f new file core get download dir sb to string f1 new file core get download dir sb append freenet tmp to string x return f makereturnfilename expectedmimetype expectedmimetype expectedmimetype expectedmimetype defaultmimetypes default_mime_type defaultmimetypes getextension expectedmimetype extadd getpreferredfilename preferredwithext preferredwithext endswith preferredwithext extadd getdownloaddir preferredwithext getdownloaddir preferredwithext stringbuilder stringbuilder setlength extadd getdownloaddir tostring getdownloaddir tostring private void inner make persistent global request freeneturi fetchuri boolean persist reboot only short return type string id file return filename file return temp filename object container container throws identifier collision exception not allowed exception io exception final client get cg new client get persist reboot only global reboot client global forever client fetchuri default fetch context local request only default fetch context ignore store queue max retries queue max retries queue max data size return type persist reboot only id integer max value request starter bulk splitfile priority class return filename return temp filename this container cg register container false false cg start container core client context innermakepersistentglobalrequest persistrebootonly returntype returnfilename returntempfilename objectcontainer identifiercollisionexception notallowedexception ioexception clientget clientget persistrebootonly globalrebootclient globalforeverclient defaultfetchcontext localrequestonly defaultfetchcontext ignorestore queue_max_retries queue_max_retries queue_max_data_size returntype persistrebootonly max_value requeststarter bulk_splitfile_priority_class returnfilename returntempfilename clientcontext start requests which were not started immediately because it might have taken some time to start them public void finish start if enable persistent downloads boolean moved main false if logminor logger minor this persistent downloads file should be persistent downloads file logger minor this persistent downloads temp file should be persistent downloads temp file file from new file persistent downloads file get path gz file from temp new file persistent downloads temp file get path gz rename if from exists file target new file from get path old pre db4o if logminor logger minor this trying to move persistent downloads file to target if from rename to target logger error this successfully migrated persistent downloads and renamed from get name to target get name moved main true if from temp exists file target new file from temp get path old pre db4o if logminor logger minor this trying to move from temp to target if from temp rename to target moved main logger error this successfully migrated persistent downloads and renamed from temp get name to target get name has finished start true finishstart enablepersistentdownloads movedmain persistentdownloadsfile persistentdownloadstempfile persistentdownloadsfile getpath fromtemp persistentdownloadstempfile getpath getpath persistentdownloadsfile renameto getname getname movedmain fromtemp fromtemp getpath fromtemp fromtemp renameto movedmain fromtemp getname getname hasfinishedstart returns the global fcp client return the global fcp client public fcp client get global forever client return global forever client fcpclient getglobalforeverclient globalforeverclient public client request get global request string identifier object container container client request req global reboot client get request identifier null if req null req global forever client get request identifier container return req clientrequest getglobalrequest objectcontainer clientrequest globalrebootclient getrequest globalforeverclient getrequest protected boolean is downloaddda always allowed return assume downloaddda is allowed isdownloadddaalwaysallowed assumedownloadddaisallowed protected boolean is uploaddda always allowed return assume uploaddda is allowed isuploadddaalwaysallowed assumeuploadddaisallowed public boolean has finished start return has finished start hasfinishedstart hasfinishedstart public void set completion callback request completion callback cb if global forever client set request completion callback cb null logger error this replacing request completion callback cb new exception error if global reboot client set request completion callback cb null logger error this replacing request completion callback cb new exception error setcompletioncallback requestcompletioncallback globalforeverclient setrequestcompletioncallback globalrebootclient setrequestcompletioncallback public void start blocking final client request req object container container client context context throws identifier collision exception if req persistence type client request persist reboot req start null core client context else class output wrapper boolean done identifier collision exception collided if container null don t activate it may not be stored yet req register container false false req start container context container deactivate req 1 else final output wrapper ow new output wrapper core client context job runner queue new db job public void run object container container client context context don t activate it may not be stored yet try req register container false false req start container context catch identifier collision exception e ow collided e finally synchronized ow ow done true ow notify all container deactivate req 1 native thread high priority false synchronized ow while true if ow done try ow wait catch interrupted exception e ignore else if ow collided null throw ow collided return startblocking clientrequest objectcontainer clientcontext identifiercollisionexception persistencetype clientrequest persist_reboot clientcontext outputwrapper identifiercollisionexception outputwrapper outputwrapper clientcontext jobrunner dbjob objectcontainer clientcontext identifiercollisionexception notifyall nativethread high_priority interruptedexception public boolean restart blocking final string identifier client request req global reboot client get request identifier null if req null req restart null core client context return true else class output wrapper boolean done boolean success final output wrapper ow new output wrapper core client context job runner queue new db job public void run object container container client context context boolean success false try client request req global forever client get request identifier container if req null req restart container context success true finally synchronized ow ow success success ow done true ow notify all native thread high priority false synchronized ow while true if ow done return ow success try ow wait catch interrupted exception e ignore restartblocking clientrequest globalrebootclient getrequest clientcontext outputwrapper outputwrapper outputwrapper clientcontext jobrunner dbjob objectcontainer clientcontext clientrequest globalforeverclient getrequest notifyall nativethread high_priority interruptedexception public void run object container container client context context boolean success false try client request req global forever client get request identifier container if req null req restart container context success true finally synchronized ow ow success success ow done true ow notify all objectcontainer clientcontext clientrequest globalforeverclient getrequest notifyall public temp fetch result get completed request blocking final freeneturi key client get get global reboot client get completed request key null if get null fixme race condition with free arrange refcounting for the data to prevent this return new temp fetch result new client metadata get getmime type null get get bucket null false class output wrapper temp fetch result result boolean done final output wrapper ow new output wrapper core client context job runner queue new db job public void run object container container client context context temp fetch result result null try client get get global forever client get completed request key container container activate get 1 if get null bucket orig data get get bucket container container activate orig data 5 boolean copied false bucket new data try new data orig data create shadow catch io exception e logger error this caught error e trying to create shallow copy copying data e new data null if new data null try new data core temp bucket factory make bucket orig data size bucket tools copy orig data new data catch io exception e logger error this unable to copy data e e result null return copied true result new temp fetch result new client metadata get getmime type container new data copied container deactivate get 1 finally synchronized ow ow result result ow done true ow notify all native thread high priority false synchronized ow while true if ow done return ow result else try ow wait catch interrupted exception e ignore tempfetchresult getcompletedrequestblocking clientget globalrebootclient getcompletedrequest tempfetchresult clientmetadata getmimetype getbucket outputwrapper tempfetchresult outputwrapper outputwrapper clientcontext jobrunner dbjob objectcontainer clientcontext tempfetchresult clientget globalforeverclient getcompletedrequest origdata getbucket origdata newdata newdata origdata createshadow ioexception newdata newdata newdata tempbucketfactory makebucket origdata buckettools origdata newdata ioexception tempfetchresult clientmetadata getmimetype newdata notifyall nativethread high_priority interruptedexception public void run object container container client context context temp fetch result result null try client get get global forever client get completed request key container container activate get 1 if get null bucket orig data get get bucket container container activate orig data 5 boolean copied false bucket new data try new data orig data create shadow catch io exception e logger error this caught error e trying to create shallow copy copying data e new data null if new data null try new data core temp bucket factory make bucket orig data size bucket tools copy orig data new data catch io exception e logger error this unable to copy data e e result null return copied true result new temp fetch result new client metadata get getmime type container new data copied container deactivate get 1 finally synchronized ow ow result result ow done true ow notify all objectcontainer clientcontext tempfetchresult clientget globalforeverclient getcompletedrequest origdata getbucket origdata newdata newdata origdata createshadow ioexception newdata newdata newdata tempbucketfactory makebucket origdata buckettools origdata newdata ioexception tempfetchresult clientmetadata getmimetype newdata notifyall public boolean object can new object container container logger error this not storing fcp server in database new exception error return false objectcannew objectcontainer fcpserver public quoted printable encoding string extra quoted chars boolean space as underscore boolean literalcrlf this extra quoted chars extra quoted chars get bytes this space as underscore space as underscore this literalcrlf literalcrlf ignore errors false quotedprintableencoding extraquotedchars spaceasunderscore extraquotedchars extraquotedchars getbytes spaceasunderscore spaceasunderscore ignoreerrors public void set ignore errors boolean ignore ignore errors ignore setignoreerrors ignoreerrors output a soft line break one the reader should ignore private void put soft break output buffer append byte output buffer byte output buffer append byte output buffer byte r output buffer append byte output buffer byte n output line width 0 putsoftbreak outputbuffer appendbyte outputbuffer outputbuffer appendbyte outputbuffer outputbuffer appendbyte outputbuffer outputlinewidth output a literal byte private void put char byte b if output line width 74 put soft break output buffer append byte output buffer b output line width putchar outputlinewidth putsoftbreak outputbuffer appendbyte outputbuffer outputlinewidth convert a value 0 15 to an ascii hex digit private byte hex digit int v if v 10 return byte 0x30 v else return byte 0x41 v 10 hexdigit output a byte in hex encoding private void put encoded byte b if output line width 72 put soft break output buffer append byte output buffer byte output buffer append byte output buffer hex digit b 4 0xf output buffer append byte output buffer hex digit b 0xf output line width 3 putencoded outputlinewidth putsoftbreak outputbuffer appendbyte outputbuffer outputbuffer appendbyte outputbuffer hexdigit outputbuffer appendbyte outputbuffer hexdigit outputlinewidth determine if this byte value must be quoted private boolean must quote byte byte b if b 0x7e b 0x20 b byte return true if space as underscore b byte return true for int i 0 i extra quoted chars length i if b extra quoted chars i return true return false mustquotebyte spaceasunderscore _ extraquotedchars extraquotedchars public synchronized byte buffer encode byte buffer input boolean cr false output buffer byte buffer allocate 100 output line width 0 while input has remaining byte b input get if cr b 10 put encoded byte 13 if literalcrlf b 13 cr true else if literalcrlf cr b 10 put char byte 13 put char byte 10 output line width 0 cr false else if must quote byte b put encoded b cr false else put char b cr false output buffer flip return output buffer bytebuffer bytebuffer outputbuffer bytebuffer outputlinewidth hasremaining putencoded putchar putchar outputlinewidth mustquotebyte putencoded putchar outputbuffer outputbuffer private int hex value byte b if b 0x30 b 0x39 return b 0x30 else if b 0x41 b 0x46 return b 0x41 10 else if b 0x61 b 0x66 return b 0x61 10 else throw new illegal argument exception hexvalue illegalargumentexception public byte buffer decode byte buffer input throws invalid encoded text exception byte buffer result byte buffer allocate 100 while input has remaining byte b input get if b byte space as underscore result append byte result byte else if b byte result append byte result b else byte c d if input has remaining if ignore errors result append byte result b break else throw new invalid encoded text exception quoted printable data ends prematurely c input get check for soft newline if c 13 if input has remaining d input get if d 10 input position input position 1 else if c 10 if input has remaining if ignore errors result append byte result b result append byte result c break else throw new invalid encoded text exception quoted printable data ends prematurely d input get try int high hex value c int low hex value d result append byte result byte high 4 low catch illegal argument exception e if ignore errors result append byte result b input position input position 2 else throw new invalid encoded text exception invalid quote sequence in quoted printable data result flip return result bytebuffer bytebuffer invalidencodedtextexception bytebuffer bytebuffer hasremaining _ spaceasunderscore appendbyte appendbyte hasremaining ignoreerrors appendbyte invalidencodedtextexception hasremaining hasremaining ignoreerrors appendbyte appendbyte invalidencodedtextexception hexvalue hexvalue appendbyte illegalargumentexception ignoreerrors appendbyte invalidencodedtextexception private float octaves 1 0f public fractal sum function function2d basis super basis fractalsumfunction public float evaluate float x float y float t 0 0f for float f 1 0f f octaves f 2 t basis evaluate f x f y f return t public short option sub config conf string option name short default value int sort order boolean expert boolean force write string short desc string long desc short callback cb boolean is size super conf option name cb sort order expert force write short desc long desc option data type number this default value default value this current value default value this is size is size shortoption subconfig optionname defaultvalue sortorder forcewrite shortdesc longdesc shortcallback issize optionname sortorder forcewrite shortdesc longdesc datatype defaultvalue defaultvalue currentvalue defaultvalue issize issize private string l10n string key string pattern string value return l10n get string short option key pattern value getstring shortoption override protected short parse string string val throws invalid config value exception short x try x fields parse short val catch number format exception e throw new invalid config value exception l10n unrecognised short val val return x parsestring invalidconfigvalueexception parseshort numberformatexception invalidconfigvalueexception unrecognisedshort override protected string to string short val return fields short to string val is size tostring shorttostring issize override public void should update logminor logger should log logger minor this logdebug logger should log logger minor this shouldupdate shouldlog shouldlog private final int hash code override public int hash code return hash code hashcode hashcode hashcode param parent param cb param block param metadata param ctx param dont compress param getchk only param report metadata only if true don t insert the metadata just report it param insert as archive manifest if true insert the metadata as an archive manifest param free data if true free the data when possible param target filename param early encode if true try to get a uri as quickly as possible throws insert exception single file inserter base client putter parent put completion callback cb insert block block boolean metadata insert context ctx boolean dont compress boolean getchk only boolean report metadata only object token archive type archive type boolean free data string target filename boolean early encode hash code super hash code this early encode early encode this report metadata only report metadata only this token token this parent parent this block block this ctx ctx this metadata metadata this cb cb this getchk only getchk only this archive type archive type this free data free data this target filename target filename this persistent parent persistent if logminor logger minor this created this persistent persistent free data free data dontcompress getchkonly reportmetadataonly insertasarchivemanifest freedata targetfilename earlyencode insertexception singlefileinserter baseclientputter putcompletioncallback insertblock insertcontext dontcompress getchkonly reportmetadataonly archive_type archivetype freedata targetfilename earlyencode hashcode hashcode earlyencode earlyencode reportmetadataonly reportmetadataonly getchkonly getchkonly archivetype archivetype freedata freedata targetfilename targetfilename freedata freedata public void start simple field set fs object container container client context context throws insert exception if fs null string type fs get type if type equals split handler try to reconstruct split handler if we succeed we bypass both compression and fec encoding try split handler sh new split handler sh start fs false container context boolean was active true if persistent was active container ext is active cb if was active container activate cb 1 cb on transition this sh container sh schedule container context if was active container deactivate cb 1 return catch resume exception e logger error this failed to restore e e if persistent container activate block 1 will cascade try compress container context simplefieldset objectcontainer clientcontext insertexception splithandler splithandler splithandler splithandler wasactive wasactive isactive wasactive ontransition wasactive resumeexception trycompress void on compressed compression output output object container container client context context boolean cb active true if persistent cb active container ext is active cb if cb active container activate cb 1 if started logger error this already started not starting again new exception error return if cancelled logger error this already cancelled not starting return if persistent container activate block 1 try on compressed inner output container context catch insert exception e cb on failure e single file inserter this container context catch out of memory error e oom handler handleoom e system err println off thread compressor thread above failed might not be heap so try anyway cb on failure new insert exception insert exception internal error e null single file inserter this container context catch throwable t logger error this caught in off thread compressor t t system err println caught in off thread compressor t t print stack trace try to fail gracefully cb on failure new insert exception insert exception internal error t null single file inserter this container context if cb active container deactivate cb 1 oncompressed compressionoutput objectcontainer clientcontext cbactive cbactive isactive cbactive oncompressedinner insertexception onfailure singlefileinserter outofmemoryerror oomhandler offthreadcompressor onfailure insertexception insertexception internal_error singlefileinserter offthreadcompressor offthreadcompressor printstacktrace onfailure insertexception insertexception internal_error singlefileinserter cbactive void on compressed inner compression output output object container container client context context throws insert exception boolean parent was active true if container null container activate block 2 parent was active container ext is active parent if parent was active container activate parent 1 long orig size block get data size bucket best compressed data output data long best compressed data size best compressed data size bucket data best compressed data compressor type best codec output best codec boolean should free data free data if best codec null if logminor logger minor this the best compression algorithm is best codec we have gained 100 best compressed data size 100 orig size orig size best compressed data size should free data true must be freed regardless of whether the original data was to be freed if free data block get data free if persistent block get data remove from container block null data if persistent container store block else data block get data int block size int one block compressed size boolean ischk false if persistent container activate block desireduri 5 string type block desireduri get key type if type equals ssk type equals ksk type equals usk block size ssk block data length one block compressed size ssk block max compressed data length else if type equals chk block size chk block data length one block compressed size chk block max compressed data length ischk true else throw new insert exception insert exception invalid uri unknown key type type null compressed data now insert it we do not need to switch threads here the actual compression is done by insert compressor on the real compressor thread which then switches either to the database thread or to a new executable to run this method if parent cb if persistent container activate ctx 1 container activate ctx event producer 1 ctx event producer produce event new finished compression event best codec null 1 best codec metadataid orig size data size container context if logminor logger minor this compressed orig size to data size on this insert it short codec number best codec null 1 best codec metadataid long compressed data size data size boolean fits in one block as is best codec null compressed data size block size compressed data size one block compressed size boolean fits in onechk best codec null compressed data size chk block data length compressed data size chk block max compressed data length if fits in one block as is fits in onechk orig size integer max value throw new insert exception insert exception internal error 2gb should not encode to one block null boolean no metadata block client metadata null block client metadata is trivial target filename null if no metadata archive type null if fits in one block as is if persistent data instanceof not persistent bucket data fix not persistent data context just insert it client put state bi create inserter parent data codec number ctx cb metadata int orig size 1 getchk only true container context should free data if logminor logger minor this inserting without metadata bi for this cb on transition this bi container if early encode bi instanceof single block inserter ischk single block inserter bi get block container context true bi schedule container context cb on block set finished this container context started true if persistent if parent was active container deactivate parent 1 block null data block remove from container block null remove from container context return if fits in onechk insert single block then insert pointer to it if persistent data instanceof not persistent bucket data fix not persistent data context if report metadata only single block inserter data putter new single block inserter parent data codec number persistent freeneturi empty chk uri clone freeneturi empty chk uri ctx cb metadata int orig size 1 getchk only true true token container context persistent should free data if logminor logger minor this inserting with metadata data putter for this metadata meta make metadata archive type data putter geturi container context cb on metadata meta this container context cb on transition this data putter container data putter schedule container context cb on block set finished this container context else multi put completion callback mcb new multi put completion callback cb parent token persistent single block inserter data putter new single block inserter parent data codec number persistent freeneturi empty chk uri clone freeneturi empty chk uri ctx mcb metadata int orig size 1 getchk only true false token container context persistent should free data if logminor logger minor this inserting data data putter for this metadata meta make metadata archive type data putter geturi container context bucket metadata bucket try metadata bucket bucket tools make immutable bucket context get bucket factory persistent meta write to byte array catch io exception e logger error this caught e e throw new insert exception insert exception bucket error e null catch metadata unresolved exception e impossible we re not inserting a manifest logger error this caught e e throw new insert exception insert exception internal error got metadata unresolved exception in single file inserter e to string null client put state meta putter create inserter parent metadata bucket short 1 ctx mcb true int orig size 1 getchk only true container context true if logminor logger minor this inserting metadata meta putter for this mcb adduri generator meta putter container mcb add data putter container cb on transition this mcb container logger minor this mcb data data putter meta meta putter mcb arm container context data putter schedule container context if early encode meta putter instanceof single block inserter single block inserter meta putter get block container context true meta putter schedule container context cb on block set finished this container context started true if persistent if parent was active container deactivate parent 1 block null data block remove from container block null remove from container context return otherwise the file is too big to fit into one block we therefore must make a splitfile job of split handler when the splitinserter has the metadata insert it then when the splitinserter has finished and the metadata insert has finished too tell the master callback if report metadata only split file inserter sfi new split file inserter parent cb data best codec orig size block client metadata ctx getchk only metadata token archive type should free data persistent container context if logminor logger minor this inserting as splitfile sfi for this cb on transition this sfi container sfi start container context if early encode sfi force encode container context if persistent container store sfi container deactivate sfi 1 block null data block null metadata if persistent remove from container context else split handler sh new split handler split file inserter sfi new split file inserter parent sh data best codec orig size block client metadata ctx getchk only metadata token archive type should free data persistent container context sh sfi sfi if logminor logger minor this inserting as splitfile sfi for sh for this if persistent container store sh cb on transition this sh container sfi start container context if early encode sfi force encode container context if persistent container store sfi container deactivate sfi 1 started true if persistent container store this if persistent if parent was active container deactivate parent 1 oncompressedinner compressionoutput objectcontainer clientcontext insertexception parentwasactive parentwasactive isactive parentwasactive origsize getdata bestcompresseddata bestcompresseddatasize bestcompresseddata bestcompresseddata compressor_type bestcodec bestcodec shouldfreedata freedata bestcodec bestcodec bestcompresseddatasize origsize origsize bestcompresseddatasize shouldfreedata freedata getdata getdata removefrom nulldata getdata blocksize oneblockcompressedsize getkeytype blocksize sskblock data_length oneblockcompressedsize sskblock max_compressed_data_length blocksize chkblock data_length oneblockcompressedsize chkblock max_compressed_data_length insertexception insertexception invalid_uri insertcompressor realcompressor eventproducer eventproducer produceevent finishedcompressionevent bestcodec bestcodec origsize origsize codecnumber bestcodec bestcodec compresseddatasize fitsinoneblockasis bestcodec compresseddatasize blocksize compresseddatasize oneblockcompressedsize fitsinonechk bestcodec compresseddatasize chkblock data_length compresseddatasize chkblock max_compressed_data_length fitsinoneblockasis fitsinonechk origsize max_value insertexception insertexception internal_error nometadata clientmetadata clientmetadata istrivial targetfilename nometadata archivetype fitsinoneblockasis notpersistentbucket fixnotpersistent clientputstate createinserter codecnumber origsize getchkonly shouldfreedata ontransition earlyencode singleblockinserter singleblockinserter getblock onblocksetfinished parentwasactive nulldata removefrom removefrom fitsinonechk notpersistentbucket fixnotpersistent reportmetadataonly singleblockinserter dataputter singleblockinserter codecnumber empty_chk_uri empty_chk_uri origsize getchkonly shouldfreedata dataputter makemetadata archivetype dataputter onmetadata ontransition dataputter dataputter onblocksetfinished multiputcompletioncallback multiputcompletioncallback singleblockinserter dataputter singleblockinserter codecnumber empty_chk_uri empty_chk_uri origsize getchkonly shouldfreedata dataputter makemetadata archivetype dataputter metadatabucket metadatabucket buckettools makeimmutablebucket getbucketfactory writetobytearray ioexception insertexception insertexception bucket_error metadataunresolvedexception insertexception insertexception internal_error metadataunresolvedexception singlefileinserter tostring clientputstate metaputter createinserter metadatabucket origsize getchkonly metaputter addurigenerator metaputter dataputter ontransition dataputter metaputter dataputter earlyencode metaputter singleblockinserter singleblockinserter metaputter getblock metaputter onblocksetfinished parentwasactive nulldata removefrom removefrom splithandler reportmetadataonly splitfileinserter splitfileinserter bestcodec origsize clientmetadata getchkonly archivetype shouldfreedata ontransition earlyencode forceencode nulldata nullmetadata removefrom splithandler splithandler splitfileinserter splitfileinserter bestcodec origsize clientmetadata getchkonly archivetype shouldfreedata ontransition earlyencode forceencode parentwasactive private bucket fix not persistent bucket data client context context throws insert exception boolean skip false if data instanceof segmented bucket chain bucket segmented bucket chain bucket seg segmented bucket chain bucket data bucket buckets seg get buckets if buckets length 1 seg clear data buckets 0 skip true if logminor logger minor this using bucket 0 of segmented bucket chain bucket try if skip if logminor logger minor this copying data from data length data size bucket new data context persistent bucket factory make bucket data size bucket tools copy data new data data free data new data catch io exception e logger error this caught e while copying non persistent data e throw new insert exception insert exception bucket error e null note that segmentedbcb does support splitting so we don t need to do anything to the data if it doesn t fit in a single block return data fixnotpersistent clientcontext insertexception segmentedbucketchainbucket segmentedbucketchainbucket segmentedbucketchainbucket getbuckets segmentedbucketchainbucket newdata persistentbucketfactory makebucket buckettools newdata newdata ioexception insertexception insertexception bucket_error private void try compress object container container client context context throws insert exception first determine how small it needs to be bucket orig data block get data bucket data orig data int block size int one block compressed size boolean dont compress ctx dont compress long orig size data size if persistent container activate block desireduri 5 string type block desireduri get key type to upper case if type equals ssk type equals ksk type equals usk block size ssk block data length one block compressed size ssk block max compressed data length else if type equals chk block size chk block data length one block compressed size chk block max compressed data length else throw new insert exception insert exception invalid uri unknown key type type null boolean try compress orig size block size ctx dont compress dont compress if try compress insert compressor start container context this orig data one block compressed size context get bucket factory persistent persistent else compression output output new compression output data null on compressed output container context trycompress objectcontainer clientcontext insertexception origdata getdata origdata blocksize oneblockcompressedsize dontcompress dontcompress origsize getkeytype touppercase blocksize sskblock data_length oneblockcompressedsize sskblock max_compressed_data_length blocksize chkblock data_length oneblockcompressedsize chkblock max_compressed_data_length insertexception insertexception invalid_uri trycompress origsize blocksize dontcompress dontcompress trycompress insertcompressor origdata oneblockcompressedsize getbucketfactory compressionoutput compressionoutput oncompressed private metadata make metadata archive type archive type freeneturi uri metadata meta null if archive type null meta new metadata metadata archive manifest archive type null uri block client metadata else redirect meta new metadata metadata simple redirect archive type null uri block client metadata if target filename null hash map string object hm new hash map string object hm put target filename meta meta metadata mk redirection manifest with metadata hm return meta makemetadata archive_type archivetype archivetype archive_manifest archivetype clientmetadata simple_redirect archivetype clientmetadata targetfilename hashmap hashmap targetfilename mkredirectionmanifestwithmetadata private client put state create inserter base client putter parent bucket data short compression codec insert context ctx put completion callback cb boolean is metadata int source length int token boolean getchk only boolean add to parent object container container client context context boolean free data throws insert exception freeneturi uri block desireduri uri check inserturi will throw an exception if needed if uri get key type equals usk try return new usk inserter parent data compression codec uri ctx cb is metadata source length token getchk only add to parent this token container context free data persistent catch malformedurl exception e throw new insert exception insert exception invalid uri e null else single block inserter sbi new single block inserter parent data compression codec uri ctx cb is metadata source length token getchk only add to parent false this token container context persistent free data pass uri to sbi block nulluri if persistent container store block return sbi clientputstate createinserter baseclientputter compressioncodec insertcontext putcompletioncallback ismetadata sourcelength getchkonly addtoparent objectcontainer clientcontext freedata insertexception checkinserturi getkeytype uskinserter compressioncodec ismetadata sourcelength getchkonly addtoparent freedata malformedurlexception insertexception insertexception invalid_uri singleblockinserter singleblockinserter compressioncodec ismetadata sourcelength getchkonly addtoparent freedata private final int hash code override public int hash code return hash code hashcode hashcode hashcode create a split handler from a stored progress simple field set param force metadata if true the insert is metadata regardless of what the encompassing split file inserter says i e it s multi level metadata throws resume exception thrown if the resume fails throws insert exception thrown if some other error prevents the insert from starting void start simple field set fs boolean force metadata object container container client context context throws resume exception insert exception boolean parent was active true if persistent parent was active container ext is active parent if parent was active container activate parent 1 boolean meta metadata force metadata don t include the booleans wait for the callback simple field set sfifs fs subset split file inserter if sfifs null throw new resume exception no split file inserter client put state newsfi new meta putter null newsfi new split file inserter parent this force metadata null block client metadata ctx getchk only meta token archive type sfifs container context if logminor logger minor this starting newsfi for this fs remove subset split file inserter simple field set metafs fs subset metadata putter if metafs null try string type metafs get type if type equals split file inserter fixme insert as archive manifest new meta putter new split file inserter parent this null ctx getchk only true token archive type metafs container context else if type equals split handler new meta putter new split handler split handler new meta putter start metafs true container context catch resume exception e new meta putter null logger error this caught e e will be reconstructed later if logminor logger minor this metadata putter metadata putter for this fs remove subset metadata putter synchronized this sfi newsfi metadata putter new meta putter if persistent container store this if parent was active container deactivate parent 1 splithandler simplefieldset forcemetadata splitfileinserter resumeexception insertexception simplefieldset forcemetadata objectcontainer clientcontext resumeexception insertexception parentwasactive parentwasactive isactive parentwasactive forcemetadata simplefieldset splitfileinserter resumeexception splitfileinserter clientputstate newmetaputter splitfileinserter forcemetadata clientmetadata getchkonly archivetype removesubset splitfileinserter simplefieldset metadataputter splitfileinserter insertasarchivemanifest newmetaputter splitfileinserter getchkonly archivetype splithandler newmetaputter splithandler splithandler newmetaputter resumeexception newmetaputter metadataputter removesubset metadataputter metadataputter newmetaputter parentwasactive public split handler default constructor this persistent single file inserter this persistent this hash code super hash code splithandler singlefileinserter hashcode hashcode public synchronized void on transition client put state old state client put state new state object container container if persistent fixme debug point if logminor logger minor this transition old state new state if old state sfi sfi new state if old state metadata putter metadata putter new state if persistent container store this ontransition clientputstate oldstate clientputstate newstate objectcontainer oldstate newstate oldstate newstate oldstate metadataputter metadataputter newstate public void on success client put state state object container container client context context if persistent container activate block 2 if logminor logger minor this on success state for this boolean late start false client put state to remove null synchronized this if finished return if state sfi if logminor logger minor this splitfile insert succeeded for this state split insert success true if meta insert success meta insert started late start true else if logminor logger minor this metadata already started for this success meta insert success started meta insert started sfi null to remove state else if state metadata putter if logminor logger minor this metadata insert succeeded for this state meta insert success true metadata putter null to remove state else logger error this unknown state for this new exception debug if split insert success meta insert success if logminor logger minor this both succeeded for this finished true if free data block free container else block null data if persistent container store block if to remove null persistent to remove remove from container context if persistent container store this if late start start metadata container context else if finished if persistent container activate cb 1 cb on success this container context if persistent container deactivate cb 1 onsuccess clientputstate objectcontainer clientcontext onsuccess latestart clientputstate toremove splitinsertsuccess metainsertsuccess metainsertstarted latestart metainsertsuccess metainsertstarted toremove metadataputter metainsertsuccess metadataputter toremove splitinsertsuccess metainsertsuccess freedata nulldata toremove toremove removefrom latestart startmetadata onsuccess public void on failure insert exception e client put state state object container container client context context if persistent container activate block 1 boolean to fail true boolean to remove false synchronized this if state sfi to remove true sfi null if metadata putter null if persistent container store this else if state metadata putter to remove true metadata putter null if sfi null if persistent container store this else logger error this on failure on unknown state state on this new exception debug if finished to fail false already failed if to remove persistent state remove from container context fail will cancel the other one so we don t need to when it does it will come back here and we won t call fail because fail has already set finished true if to fail fail e container context onfailure insertexception clientputstate objectcontainer clientcontext tofail toremove toremove metadataputter metadataputter toremove metadataputter onfailure tofail toremove removefrom tofail public void on metadata metadata meta client put state state object container container client context context if persistent container activate cb 1 container activate block 2 insert exception e null synchronized this if finished return if report metadata only if state sfi logger error this got metadata from unknown object state when expecting to report metadata return meta insert success true else if state metadata putter logger error this got metadata for metadata e new insert exception insert exception internal error did not expect to get metadata for metadata inserter null else if state sfi logger error this got metadata from unknown state state sfi sfi metadata putter metadata putter on this persistent persistent new exception debug e new insert exception insert exception internal error got metadata from unknown state null else already started metadata putter in which case we ve got the metadata twice if metadata putter null return if report metadata only if persistent container store this cb on metadata meta this container context return if e null on failure e state container context return byte meta bytes if persistent load keys container activate meta 100 try meta bytes meta write to byte array catch metadata unresolved exception e1 logger error this impossible e1 e1 insert exception ex new insert exception insert exception internal error metadata unresolved exception in single file inserter split handler e1 null ex init cause e1 fail ex container context return string meta putter target filename target filename if target filename null if meta bytes length short max value hash map string object hm new hash map string object hm put target filename meta meta metadata mk redirection manifest with metadata hm meta putter target filename null try meta bytes meta write to byte array catch metadata unresolved exception e1 logger error this impossible 2 e1 e1 insert exception ex new insert exception insert exception internal error metadata unresolved exception in single file inserter split handler 2 e1 null ex init cause e1 fail ex container context return bucket metadata bucket try metadata bucket bucket tools make immutable bucket context get bucket factory persistent meta bytes catch io exception e1 insert exception ex new insert exception insert exception bucket error e1 null fail ex container context return insert block new block new insert block metadata bucket null block desireduri synchronized this metadata putter new single file inserter parent this new block true ctx false getchk only false token archive type true meta putter target filename early encode if early encode then start the metadata insert asap to get the key otherwise wait until the data is fetchable to improve persistence if logminor logger minor this created metadata putter for this metadata putter bucket metadata bucket size metadata bucket size if persistent container store this if early encode split insert success return if logminor logger minor this putting metadata on metadata putter from sfi split file inserter sfi get length start metadata container context onmetadata clientputstate objectcontainer clientcontext insertexception reportmetadataonly metainsertsuccess metadataputter insertexception insertexception internal_error metadataputter metadataputter insertexception insertexception internal_error metadataputter reportmetadataonly onmetadata onfailure metabytes metabytes writetobytearray metadataunresolvedexception insertexception insertexception insertexception internal_error metadataunresolvedexception singlefileinserter splithandler initcause metaputtertargetfilename targetfilename targetfilename metabytes max_value hashmap hashmap targetfilename mkredirectionmanifestwithmetadata metaputtertargetfilename metabytes writetobytearray metadataunresolvedexception insertexception insertexception insertexception internal_error metadataunresolvedexception singlefileinserter splithandler initcause metadatabucket metadatabucket buckettools makeimmutablebucket getbucketfactory metabytes ioexception insertexception insertexception insertexception bucket_error insertblock newblock insertblock metadatabucket metadataputter singlefileinserter newblock getchkonly archivetype metaputtertargetfilename earlyencode earlyencode metadataputter metadatabucket metadatabucket earlyencode splitinsertsuccess metadataputter splitfileinserter getlength startmetadata private void fail insert exception e object container container client context context if logminor logger minor this failing e e client put state oldsfi null client put state old metadata putter null synchronized this if finished return finished true oldsfi sfi old metadata putter metadata putter if persistent container store this if oldsfi null container activate oldsfi 1 if old metadata putter null container activate old metadata putter 1 if oldsfi null oldsfi cancel container context if old metadata putter null old metadata putter cancel container context if persistent container activate block 2 container activate cb 1 synchronized this if free data block free container else block null data if persistent container store block cb on failure e this container context insertexception objectcontainer clientcontext clientputstate clientputstate oldmetadataputter oldmetadataputter metadataputter oldmetadataputter oldmetadataputter oldmetadataputter oldmetadataputter freedata nulldata onfailure public base client putter get parent return parent baseclientputter getparent public void on encode base client key key client put state state object container container client context context if persistent fixme debug point if logminor logger minor this on encode for this state key synchronized this if state metadata putter if logminor logger minor this ignored on encode for this state return if persistent container activate cb 1 cb on encode key this container context onencode baseclientkey clientputstate objectcontainer clientcontext onencode metadataputter onencode onencode public void cancel object container container client context context if logminor logger minor this cancelling this client put state oldsfi null client put state old metadata putter null synchronized this oldsfi sfi old metadata putter metadata putter if persistent container store this if oldsfi null container activate oldsfi 1 if old metadata putter null container activate old metadata putter 1 if oldsfi null oldsfi cancel container context if old metadata putter null old metadata putter cancel container context fixme in the other cases fail and on success we only free when we set finished but we haven t set finished here can we rely on the callback and not do anything here note that it is in fact safe to double free it s not safe to not free if free data if persistent container activate block 2 block free container else block null data if persistent container store block objectcontainer clientcontext clientputstate clientputstate oldmetadataputter oldmetadataputter metadataputter oldmetadataputter oldmetadataputter oldmetadataputter oldmetadataputter onsuccess freedata nulldata public void on block set finished client put state state object container container client context context synchronized this if state sfi split insert set blocks true else if state metadata putter meta insert set blocks true if persistent container store this if split insert set blocks meta insert set blocks return if persistent container activate cb 1 cb on block set finished this container context onblocksetfinished clientputstate objectcontainer clientcontext splitinsertsetblocks metadataputter metainsertsetblocks splitinsertsetblocks metainsertsetblocks onblocksetfinished public void schedule object container container client context context throws insert exception if persistent container activate sfi 1 sfi schedule container context objectcontainer clientcontext insertexception public object get token return token gettoken public void on fetchable client put state state object container container if persistent fixme debug point if logminor logger minor this on fetchable on this if logminor logger minor this on fetchable state boolean meta synchronized this meta state metadata putter if meta if meta insert started logger error this metadata insert not started yet got on fetchable for it state on this if logminor logger minor this metadata fetchable meta fetchable already if meta fetchable return meta fetchable true if persistent container store this else if state sfi logger error this on fetchable for unknown state state return if persistent container store this if logminor logger minor this data fetchable if meta insert started return if meta if persistent container activate cb 1 cb on fetchable this container onfetchable clientputstate objectcontainer onfetchable onfetchable metadataputter metainsertstarted onfetchable metafetchable metafetchable metafetchable onfetchable metainsertstarted onfetchable private void start metadata object container container client context context if persistent fixme debug point if logminor logger minor this start metadata on this try client put state putter client put state split inserter synchronized this if meta insert started return if persistent metadata putter null container activate metadata putter 1 putter metadata putter if putter null if logminor logger minor this cannot start metadata yet no metadata putter else meta insert started true split inserter sfi if persistent container store this if putter null if logminor logger minor this starting metadata inserter putter for this putter schedule container context if logminor logger minor this started metadata inserter putter for this else get all the ur is asap so we can start to insert the metadata if persistent container activate split inserter 1 split file inserter split inserter force encode container context catch insert exception e1 logger error this failing this e1 e1 fail e1 container context return startmetadata objectcontainer clientcontext startmetadata clientputstate clientputstate splitinserter metainsertstarted metadataputter metadataputter metadataputter metadataputter metainsertstarted splitinserter uris splitinserter splitfileinserter splitinserter forceencode insertexception public void object on activate object container container chain to containing class since we use its members extensively container activate single file inserter this 1 objectonactivate objectcontainer singlefileinserter public void remove from object container container client context context if logminor logger minor this remove from on this container delete this remove parent as well since we always transition from parent to sh i e it will not get a remove from single file inserter this remove from container context removefrom objectcontainer clientcontext removefrom removefrom singlefileinserter removefrom public boolean object can update object container container if logdebug logger debug this object can update on this new exception debug return true objectcanupdate objectcontainer objectcanupdate public boolean object can new object container container if finished logger error this object can new but finished on this new exception error else if logdebug logger debug this object can new on this new exception debug return true objectcannew objectcontainer objectcannew objectcannew public base client putter get parent return parent baseclientputter getparent public void cancel object container container client context context if logminor logger minor this cancel this synchronized this if cancelled return cancelled true if free data if persistent container activate block 1 block free container if persistent container store this if persistent container activate cb 1 must call on failure so get remove from ed cb on failure new insert exception insert exception cancelled this container context objectcontainer clientcontext freedata onfailure removefrom onfailure insertexception insertexception public void schedule object container container client context context throws insert exception start null container context objectcontainer clientcontext insertexception public object get token return token gettoken public void on start compression compressor type ctype object container container client context context if persistent container activate ctx 2 if parent cb if ctx null throw new null pointer exception if ctx event producer null throw new null pointer exception ctx event producer produce event new started compression event ctype container context onstartcompression compressor_type objectcontainer clientcontext nullpointerexception eventproducer nullpointerexception eventproducer produceevent startedcompressionevent boolean cancelled return cancelled boolean started return started public void remove from object container container client context context if logminor logger minor this remove from on this new exception debug parent removes self token is passed in creator of token is responsible for removing it if block null container activate block 1 block remove from container ctx is passed in creator is responsible for removing it cb removes itself container delete this removefrom objectcontainer clientcontext removefrom removefrom public boolean object can update object container container if logminor logger minor this object can update on this new exception debug return true objectcanupdate objectcontainer objectcanupdate public boolean object can new object container container if logminor logger minor this object can new on this new exception debug return true objectcannew objectcontainer objectcannew protected abstract user alert this user can dismiss false this title null this text null this html text null this priority class 0 this valid true this dismiss button text null this should unregister on dismiss false this user identifier null this short text null abstractuseralert usercandismiss htmltext priorityclass dismissbuttontext shouldunregisterondismiss useridentifier shorttext protected abstract user alert boolean user can dismiss string title string text string short text html node html text short priority class boolean valid string dismiss button text boolean should unregister on dismiss object user identifier this user can dismiss user can dismiss this title title this text text this short text short text this html text html text this priority class priority class this valid valid this dismiss button text dismiss button text this should unregister on dismiss should unregister on dismiss this user identifier user identifier abstractuseralert usercandismiss shorttext htmlnode htmltext priorityclass dismissbuttontext shouldunregisterondismiss useridentifier usercandismiss usercandismiss shorttext shorttext htmltext htmltext priorityclass priorityclass dismissbuttontext dismissbuttontext shouldunregisterondismiss shouldunregisterondismiss useridentifier useridentifier inherit doc public boolean user can dismiss return user can dismiss inheritdoc usercandismiss usercandismiss inherit doc public string get title return title inheritdoc gettitle inherit doc public string get text return text inheritdoc gettext public string get short text return short text getshorttext shorttext inherit doc public html node gethtml text return html text inheritdoc htmlnode gethtmltext htmltext inherit doc public short get priority class return priority class inheritdoc getpriorityclass priorityclass inherit doc public boolean is valid return valid inheritdoc isvalid inherit doc public void is valid boolean valid if user can dismiss this valid valid inheritdoc isvalid usercandismiss inherit doc public string dismiss button text return dismiss button text inheritdoc dismissbuttontext dismissbuttontext inherit doc public boolean should unregister on dismiss return should unregister on dismiss inheritdoc shouldunregisterondismiss shouldunregisterondismiss inherit doc public void on dismiss inheritdoc ondismiss inherit doc public object get user identifier return user identifier inheritdoc getuseridentifier useridentifier public string anchor return integer to string hash code tostring hashcode public boolean is event notification return false iseventnotification final string section final int d threshold public detailed threshold string section int thresh this section section this d threshold thresh dthreshold detailedthreshold dthreshold logger hook int thresh this threshold thresh loggerhook logger hook string thresh throws invalid threshold exception this threshold priority of thresh loggerhook invalidthresholdexception priorityof log a message param o the object where this message was generated param source the class where this message was generated param message a clear and verbose message describing the event param e logs this exception with the message param priority the priority of the mesage one of logger error logger normal logger minor or logger debug override public abstract void log object o class source string message throwable e log a message param source the source object where this message was generated param message a clear and verbose message describing the event param priority the priority of the mesage one of logger error logger normal logger minor or logger debug override public void log object source string message int priority if instance should log priority source return log source source null null source get class message null priority instanceshouldlog getclass log a message with an exception param o the source object where this message was generated param message a clear and verbose message describing the event param e logs this exception with the message param priority the priority of the mesage one of logger error logger normal logger minor or logger debug see log object o string message int priority override public void log object o string message throwable e int priority if instance should log priority o return log o o null null o get class message e priority instanceshouldlog getclass log a message from static code param c the class where this message was generated param message a clear and verbose message describing the event param priority the priority of the mesage one of logger error logger normal logger minor or logger debug override public void log class c string message int priority if instance should log priority c return log null c message null priority instanceshouldlog override public void log class c string message throwable e int priority if instance should log priority c return log null c message e priority instanceshouldlog public boolean accept priority int prio return prio threshold acceptpriority override public void set threshold int thresh this threshold thresh notify log threshold callbacks setthreshold notifylogthresholdcallbacks override public int get threshold return threshold getthreshold override public void set threshold string symbolic threshold throws invalid threshold exception set threshold priority of symbolic threshold setthreshold symbolicthreshold invalidthresholdexception setthreshold priorityof symbolicthreshold override public void set detailed thresholds string details throws invalid threshold exception if details null details length 0 return string tokenizer st new string tokenizer details false array list detailed threshold stuff new array list detailed threshold while st has more tokens string token st next token if token length 0 continue int x token index of if x 0 continue if x token length 1 continue string section token substring 0 x string value token substring x 1 token length int thresh logger hook priority of value stuff add new detailed threshold section thresh detailed threshold new thresholds new detailed threshold stuff size stuff to array new thresholds synchronized this detailed thresholds new thresholds notify log threshold callbacks setdetailedthresholds invalidthresholdexception stringtokenizer stringtokenizer arraylist detailedthreshold arraylist detailedthreshold hasmoretokens nexttoken indexof loggerhook priorityof detailedthreshold detailedthreshold newthresholds detailedthreshold toarray newthresholds detailedthresholds newthresholds notifylogthresholdcallbacks public string get detailed thresholds detailed threshold thresh null synchronized this thresh detailed thresholds string builder sb new string builder for int i 0 i thresh length i if i 0 sb append sb append thresh i section sb append sb append logger hook priority of thresh i d threshold return sb to string getdetailedthresholds detailedthreshold detailedthresholds stringbuilder stringbuilder loggerhook priorityof dthreshold tostring returns the priority level matching the string if no priority matches logger normal is returned param s a string matching one of the logging priorities case insensitive public static int priority of string s throws invalid threshold exception if s equals ignore case error return logger error else if s equals ignore case normal return logger normal else if s equals ignore case minor return logger minor else if s equals ignore case debugging return logger debug else if s equals ignore case debug return logger debug else throw new invalid threshold exception l10n get string logger hook unrecognised priority name s return logger normal priorityof invalidthresholdexception equalsignorecase equalsignorecase equalsignorecase equalsignorecase equalsignorecase invalidthresholdexception getstring loggerhook unrecognisedpriority private static final long serial versionuid 1 invalid threshold exception string msg super msg serialversionuid invalidthresholdexception returns the name of the priority matching a number null if none do param priority the priority public static string priority of int priority switch priority case error return error case normal return normal case minor return minor case debug return debug default return null priorityof override public boolean instance should log int priority class c detailed threshold thresholds int thresh synchronized this thresholds detailed thresholds thresh threshold if c null thresholds length 0 string cname c get name for detailed threshold dt thresholds if cname starts with dt section thresh dt d threshold return priority thresh instanceshouldlog detailedthreshold detailedthresholds getname detailedthreshold startswith dthreshold override public final boolean instance should log int prio object o return instance should log prio o null null o get class instanceshouldlog instanceshouldlog getclass override public synchronized final void instance register log threshold callback log threshold callback ltc log threshold callback newltc new log threshold callback thresholds callbacks length 1 newltc 0 ltc system arraycopy thresholds callbacks 0 newltc 1 thresholds callbacks length thresholds callbacks newltc call the new callback to avoid code duplication ltc should update instanceregisterlogthresholdcallback logthresholdcallback logthresholdcallback logthresholdcallback thresholdscallbacks thresholdscallbacks thresholdscallbacks thresholdscallbacks shouldupdate private synchronized final void notify log threshold callbacks for log threshold callback ltc thresholds callbacks ltc should update notifylogthresholdcallbacks logthresholdcallback thresholdscallbacks shouldupdate public abstract long min flags ignore unless all these bits set minflags public abstract long min flags ignore unless all these bits set public abstract long not flags reject if any of these bits set minflags notflags public abstract long not flags reject if any of these bits set public abstract long any flags accept if any of these bits set notflags anyflags private boolean m identity publishes puzzles null public create identity wizard web interface my web interface http request request super my web interface null request midentitypublishespuzzles createidentitywizard webinterface mywebinterface httprequest mywebinterface public void make make create identity box makecreateidentitybox private void make create identity box html node create box add content box create an own identity html node create form add form child create box self uri create identity create identity boolean randomssk false exception requestur iproblem null exception insertur iproblem null exception nickname problem null stage 1 parse the passed form data int previous step m request is part set step integer parse int m request get part as string step 1 0 parse the generate random ssk boolean specified in step 1 if m request is part set generate randomssk randomssk m request get part as string generate randomssk 5 equals true if randomssk m identityuri m freetalk get plugin respirator gethl simple client generate key pair parse the uri specified in step 1 if m request is part set requesturi m request is part set inserturi assert randomssk false m identityuri new freeneturi 2 try m identityuri 0 new freeneturi m request get part as string inserturi 256 catch exception e insertur iproblem e try m identityuri 1 new freeneturi m request get part as string requesturi 256 catch exception e requestur iproblem e if insertur iproblem null requestur iproblem null m identityuri null fixme check whether the uri pair is correct i e if the insert uri really is one if the request uri really is one and if the two belong together how to do this parse the nickname specified in step 2 if m request is part set nickname try m identity nickname m request get part as string nickname 256 wot identity validate nickname m identity nickname catch exception e nickname problem e m identity nickname null parse the preferences specified in step 3 if previous step 3 we cannot just use is part set publish trust list because it won t be set if the checkbox is unchecked if m request is part set publish trust list m identity publishes trust list m request get part as string publish trust list 5 equals true else m identity publishes trust list false stage 2 display the wizard stage at which we are step 1 uri if m identityuri null html node chooseur ibox get content box step 1 of 3 choose the ssk uri create form add child chooseur ibox chooseur ibox add child p the ssk uri of your identity is a public private keypair which uniquely identifies your identity on the network you can either let freenet generate a new random one for you or enter an existing ssk uri pair for example if you own a freesite you can re use it s uri to show others that your identity belongs to your freesite if m request is part set generate randomssk html node p chooseur ibox add child p p add child input new string type name value checked new string radio generate randomssk true checked p add child generate a new random ssk keypair for the identity p chooseur ibox add child p p add child input new string type name value new string radio generate randomssk false p add child i want to use an existing ssk uri keypair for the identity else assert randomssk false html node p chooseur ibox add child p p add child input new string type name value checked new string radio generate randomssk false checked p add child i want to use an existing ssk uri keypair for the identity if requestur iproblem null p add child p style color red add child request uri error requestur iproblem get localized message if insertur iproblem null p add child p style color red add child insert uri error insertur iproblem get localized message p add child please enter the ssk uri pair p add child br chooseur ibox add child request uri p add child input new string type name size value new string text requesturi 70 m request get part as string requesturi 256 p add child br chooseur ibox add child insert uri p add child input new string type name size value new string text inserturi 70 m request get part as string inserturi 256 step 2 nickname if m identityuri null m identity nickname null add hidden form data create form 2 html node choose name box get content box step 2 of 3 choose the nickname create form add child choose name box choose name box add child p the nickname of an identity cannot be changed after the identity has been created please choose it carefully you cannot use spaces and some special characters in the nickname html node p choose name box add child p if nickname problem null p add child p style color red add child nickname error nickname problem get localized message p add child nickname p add child input new string type name size value new string text nickname 50 m request get part as string nickname 50 step 3 preferences if m identityuri null m identity nickname null m identity publishes trust list null add hidden form data create form 3 html node choose prefs box get content box step 3 of 3 choose your preferences create form add child choose prefs box html node tl box get content box trust list choose prefs box add child tl box html node p tl box add child p trust lists are the p add child b fundament of freetalk p add child you can publish a p add child b trust value p add child for every identity in your trust list the trust value can be between 100 and 100 inclusive and is a measurement for how valuable you rate the messages of an identity if someone posts spam you can give a negative trust value if he writes useful posts you can assign a positive one p tl box add child p for every identity freetalk will accumulate trust values which it has received by other identities and calculate a p add child b score p add child a weighted average from those if the score of an identity is negative freetalk will not download messages from that identity anymore unless you tell it to do so therefore the purpose of the trust system is to p add child b prevent spam p add child but it is p add child b not to punish authors for having a different opinion than yours p add child please respect that when assigning trust values p tl box add child p here you can choose whether freetalk should publish a trust list for your identity it is generally a good idea because it helps the other users however you can tell freetalk not to publish your trust list if you are concernced that it might compromise your anonymity because the trust values among several of your identities might correlate p tl box add child p p add child input new string type name value checked new string checkbox publish trust list true checked p add child publish the trust list of the identitiy if m identityuri null m identity nickname null m identity publishes trust list null add hidden form data create form 4 try wot own identity id wot own identity m freetalk get identity manager create own identity m identity nickname m identity publishes trust list true m identityuri 1 m identityuri 0 html node summary box get content box identity created create form add child summary box summary box add child a href self uri log in own identityid id getuid your identity was successfully created you can log in with it now catch exception e html node error box get alert box sorry there was a problem creating your identity create form add child error box error box add child p e get localized message return todo instead of just returning provide a go back button if creation fails etc create form add child input new string type name value new string submit submit continue makecreateidentitybox htmlnode createbox addcontentbox htmlnode createform addformchild createbox self_uri createidentity createidentity requesturiproblem inserturiproblem nicknameproblem previousstep mrequest ispartset parseint mrequest getpartasstring mrequest ispartset generaterandomssk mrequest getpartasstring generaterandomssk midentityuri mfreetalk getpluginrespirator gethlsimpleclient generatekeypair mrequest ispartset mrequest ispartset midentityuri midentityuri mrequest getpartasstring inserturiproblem midentityuri mrequest getpartasstring requesturiproblem inserturiproblem requesturiproblem midentityuri mrequest ispartset midentitynickname mrequest getpartasstring wotidentity validatenickname midentitynickname nicknameproblem midentitynickname previousstep ispartset publishtrustlist mrequest ispartset publishtrustlist midentitypublishestrustlist mrequest getpartasstring publishtrustlist midentitypublishestrustlist midentityuri htmlnode chooseuribox getcontentbox createform addchild chooseuribox chooseuribox addchild mrequest ispartset generaterandomssk htmlnode chooseuribox addchild addchild generaterandomssk addchild chooseuribox addchild addchild generaterandomssk addchild htmlnode chooseuribox addchild addchild generaterandomssk addchild requesturiproblem addchild addchild requesturiproblem getlocalizedmessage inserturiproblem addchild addchild inserturiproblem getlocalizedmessage addchild addchild chooseuribox addchild addchild mrequest getpartasstring addchild chooseuribox addchild addchild mrequest getpartasstring midentityuri midentitynickname addhiddenformdata createform htmlnode choosenamebox getcontentbox createform addchild choosenamebox choosenamebox addchild htmlnode choosenamebox addchild nicknameproblem addchild addchild nicknameproblem getlocalizedmessage addchild addchild mrequest getpartasstring midentityuri midentitynickname midentitypublishestrustlist addhiddenformdata createform htmlnode chooseprefsbox getcontentbox createform addchild chooseprefsbox htmlnode tlbox getcontentbox chooseprefsbox addchild tlbox htmlnode tlbox addchild addchild addchild addchild addchild tlbox addchild addchild addchild addchild addchild addchild addchild tlbox addchild tlbox addchild addchild publishtrustlist addchild midentityuri midentitynickname midentitypublishestrustlist addhiddenformdata createform wotownidentity wotownidentity mfreetalk getidentitymanager createownidentity midentitynickname midentitypublishestrustlist midentityuri midentityuri htmlnode summarybox getcontentbox createform addchild summarybox summarybox addchild self_uri login ownidentityid htmlnode errorbox getalertbox createform addchild errorbox errorbox addchild getlocalizedmessage createform addchild stores the form data which the user has already specified as hidden elements param my form the html node of the parent form private void add hidden form data html node my form string step my form add child input new string type name value new string hidden step step if m identityuri null my form add child input new string type name value new string hidden inserturi m identityuri 0 to string my form add child input new string type name value new string hidden requesturi m identityuri 1 to string if m identity nickname null my form add child input new string type name value new string hidden nickname m identity nickname if m identity publishes trust list null my form add child input new string type name value new string hidden publish trust list m identity publishes trust list to string myform htmlnode addhiddenformdata htmlnode myform myform addchild midentityuri myform addchild midentityuri tostring myform addchild midentityuri tostring midentitynickname myform addchild midentitynickname midentitypublishestrustlist myform addchild publishtrustlist midentitypublishestrustlist tostring public chosen block sendable request item token key key client key ckey boolean local request only boolean cache local requests boolean ignore store request scheduler sched this token token this key key this ckey ckey this local request only local request only this cache local requests cache local requests this ignore store ignore store chosenblock sendablerequestitem clientkey localrequestonly cachelocalrequests ignorestore requestscheduler localrequestonly localrequestonly cachelocalrequests cachelocalrequests ignorestore ignorestore public abstract boolean is persistent ispersistent public abstract boolean is persistent public abstract boolean is cancelled ispersistent iscancelled public abstract boolean is cancelled public abstract void on failure low level put exception e client context context iscancelled onfailure lowlevelputexception clientcontext public abstract void on failure low level put exception e client context context public abstract void on insert success client context context onfailure lowlevelputexception clientcontext oninsertsuccess clientcontext public abstract void on insert success client context context public abstract void on failure low level get exception e client context context oninsertsuccess clientcontext onfailure lowlevelgetexception clientcontext the actual data delivery goes through crs trip pending key this is just a notification for book keeping purposes we call the scheduler to tell it that the request succeeded so that it can be rescheduled soon for more requests param context might be useful trippendingkey public abstract void on fetch success client context context public abstract short get priority onfetchsuccess clientcontext getpriority public abstract short get priority public boolean send node client core core request scheduler sched client context context sched get context return get sender context send core sched context this getpriority nodeclientcore requestscheduler clientcontext getcontext getsender public abstract sendable request sender get sender client context context sendablerequestsender getsender clientcontext public abstract sendable request sender get sender client context context public void on dumped token dump sendablerequestsender getsender clientcontext ondumped public class database constructor of database this method initialize database if it not initialized yet starting from 2 72 version of perst net it supports automatic creation of table descriptors when database class is used so now it is not necessary to explicitly create tables and indices the database class will create them itself on demand indexable attribute should be used to mark key fields for which index should be created table descriptor is created when instance of the correspondent class is first time stored in the database perst creates table descriptors for all derived classes up to the root java lang object class param storage opened storage storage should be either empty non initialized either previously initialized by the this method it is not possible to open storage with root object other than table index created by this constructor param multithreaded code true code if database should support concurrent access to the data from multiple threads public database storage storage boolean multithreaded this storage multithreaded true null constructor of database this method initialize database if it not initialized yet param storage opened storage storage should be either empty non initialized either previously initialized by the this method it is not possible to open storage with root object other than table index created by this constructor param multithreaded code true code if database should support concurrent access to the data from multiple threads param auto register tables automatically create tables descriptors for instances of new param helper helper for full text index classes inserted in the database public database storage storage boolean multithreaded boolean auto register tables full text search helper helper this storage storage this multithreaded multithreaded this auto register tables auto register tables if multithreaded storage set property perst alternative btree boolean true i persistent root storage get root boolean schema updated false if root instanceof index backward compatibility begin transaction metadata new metadata storage index root helper storage set root metadata schema updated true else if root null begin transaction metadata new metadata storage helper storage set root metadata schema updated true else metadata metadata root iterator iterator metadata metaclasses entry iterator tables new hash map class table while iterator has next map entry map map entry iterator next table table table map get value class cls class descriptor load class storage string map get key table set class cls tables put cls table schema updated add indices table cls if schema updated commit transaction autoregistertables autoregistertables fulltextsearchhelper autoregistertables autoregistertables setproperty ipersistent getroot schemaupdated begintransaction setroot schemaupdated begintransaction setroot schemaupdated entryiterator hashmap hasnext getvalue classdescriptor loadclass getkey setclass schemaupdated addindices schemaupdated committransaction constructor of single threaded database this method initialize database if it not initialized yet param storage opened storage storage should be either empty non initialized either previously initialized by the this method it is not possible to open storage with root object other than table index created by this constructor public database storage storage this storage false begin transaction public void begin transaction if multithreaded storage begin thread transaction storage serializable transaction begintransaction beginthreadtransaction serializable_transaction commit transaction public void commit transaction if multithreaded storage end thread transaction else storage commit committransaction endthreadtransaction rollback transaction public void rollback transaction if multithreaded storage rollback thread transaction else storage rollback rollbacktransaction rollbackthreadtransaction create table for the specified class this function does nothing if table for such class already exists param table class corresponding to the table return code true code if table is created code false code if table alreay exists deprecated since version 2 75 of perst it is not necessary to create table and index descriptors explicitly them are automatically create when object is inserted in the database first time to mark fields for which indices should be created use indexable annotation public boolean create table class table if multithreaded metadata exclusive lock if tables get table null table t new table t extent storage create set t indices storage create link t indices map new hash map t set class table tables put table t metadata metaclasses put table get name t add indices t table return true return false createtable exclusivelock createset createlink indicesmap hashmap setclass getname addindices private boolean add indices table table class cls boolean schema updated false for field f cls get declared fields indexable idx indexable f get annotation indexable class if idx null schema updated create index table cls f get name idx unique idx case insensitive return schema updated addindices schemaupdated getdeclaredfields getannotation schemaupdated createindex getname caseinsensitive schemaupdated drop table associated with this class do nothing if there is no such table in the database param table class corresponding to the table return code true code if table is deleted code false code if table is not found public boolean drop table class table if multithreaded metadata exclusive lock if tables remove table null metadata metaclasses remove table get name return true return false droptable exclusivelock getname add new record to the table record is inserted in table corresponding to the class of the object record will be automatically added to all indices existed for this table if there is not table associated with class of this object then database will search for table associated with superclass and so on param record object to be inserted in the table return code true code if record was successfully added to the table code false code if there is already such record object with the same id in the table or there is some record with the same value of unique key field exception storage error class not found exception is thrown if there is no table corresponding to record class public t extends i persistent boolean add record t record return add record record get class record storageerror class_not_found ipersistent addrecord addrecord getclass private table locate table class cls boolean exclusive return locate table cls exclusive true locatetable locatetable private table locate table class cls boolean exclusive boolean should exist table table null if multithreaded metadata shared lock for class c cls c null table tables get c null c c get superclass if table null if should exist throw new storage error storage error class not found cls get name return null if multithreaded if exclusive table extent exclusive lock else table extent shared lock return table locatetable shouldexist sharedlock getsuperclass shouldexist storageerror storageerror class_not_found getname exclusivelock sharedlock private void register table class cls if multithreaded metadata shared lock if auto register tables boolean exclusive lock set false for class c cls c object class c c get superclass table t tables get c if t null if exclusive lock set metadata unlock try to avoid deadlock caused by concurrent insertion of objects exclusive lock set true create table c registertable sharedlock autoregistertables exclusivelockset getsuperclass exclusivelockset exclusivelockset createtable update full text index for modified record param record updated record public t extends i persistent void update full text index t record if multithreaded metadata full text index exclusive lock if record instanceof full text searchable metadata full text index add full text searchable record else string buffer full text new string buffer for class c record get class c null c c get superclass table t tables get c if t null for field f t full text indexable fields object text try text f get record catch illegal access exception x throw new illegal access error if text null full text append full text append text to string metadata full text index add record new string reader full text to string null ipersistent updatefulltextindex fulltextindex exclusivelock fulltextsearchable fulltextindex fulltextsearchable stringbuffer fulltext stringbuffer getclass getsuperclass fulltextindexablefields illegalaccessexception illegalaccesserror fulltext fulltext tostring fulltextindex stringreader fulltext tostring add new record to the specified table record is inserted in table corresponding to the specified class record will be automatically added to all indices existed for this table param table class corresponding to the table param record object to be inserted in the table return code true code if record was successfully added to the table code false code if there is already such record object with the same id in the table or there is some record with the same value of unique key field exception storage error class not found exception is thrown if there is no table corresponding to record class public t extends i persistent boolean add record class table t record boolean added false boolean found false register table table array list was inserted in new array list string buffer full text new string buffer for class c table c null c c get superclass table t tables get c if t null found true if multithreaded t extent exclusive lock if t extent add record was inserted in add t extent iterator iterator t indices map values iterator while iterator has next field index index field index iterator next if index put record was inserted in add index else iterator was inserted in iterator while iterator has next object idx iterator next if idx instanceof i persistent set i persistent set idx remove record else field index idx remove record return false for field f t full text indexable fields object text try text f get record catch illegal access exception x throw new illegal access error if text null full text append full text append text to string added true if found throw new storage error storage error class not found table get name if record instanceof full text searchable full text length 0 if multithreaded metadata full text index exclusive lock if record instanceof full text searchable metadata full text index add full text searchable record else metadata full text index add record new string reader full text to string null return added storageerror class_not_found ipersistent addrecord registertable arraylist wasinsertedin arraylist stringbuffer fulltext stringbuffer getsuperclass exclusivelock wasinsertedin indicesmap hasnext fieldindex fieldindex wasinsertedin wasinsertedin hasnext ipersistentset ipersistentset fieldindex fulltextindexablefields illegalaccessexception illegalaccesserror fulltext fulltext tostring storageerror storageerror class_not_found getname fulltextsearchable fulltext fulltextindex exclusivelock fulltextsearchable fulltextindex fulltextsearchable fulltextindex stringreader fulltext tostring delete record from the table record is removed from the table corresponding to the class of the object record will be automatically added to all indices existed for this table if there is not table associated with class of this object then database will search for table associated with superclass and so on object represented the record will be also deleted from the storage param record object to be deleted from the table return code true code if record was successfully deleted from the table code false code if there is not such record object with the same id in the table exception storage error class not found exception is thrown if there is no table corresponding to record class public t extends i persistent boolean delete record t record return delete record record get class record storageerror class_not_found ipersistent deleterecord deleterecord getclass delete record from the specified table record is removed from the table corresponding to the specified class record will be automatically added to all indices existed for this table object represented the record will be also deleted from the storage param table class corresponding to the table param record object to be deleted from the table return code true code if record was successfully deleted from the table code false code if there is not such record object with the same id in the table exception storage error class not found exception is thrown if there is no table corresponding to specified class public t extends i persistent boolean delete record class table t record boolean removed false if multithreaded metadata shared lock boolean full text indexed false for class c table c null c c get superclass table t tables get c if t null if multithreaded t extent exclusive lock if t extent remove record iterator iterator t indices map values iterator while iterator has next field index index field index iterator next index remove record if t full text indexable fields size 0 full text indexed true removed true if removed if record instanceof full text searchable full text indexed if multithreaded metadata full text index exclusive lock metadata full text index delete record record deallocate return removed storageerror class_not_found ipersistent deleterecord sharedlock fulltextindexed getsuperclass exclusivelock indicesmap hasnext fieldindex fieldindex fulltextindexablefields fulltextindexed fulltextsearchable fulltextindexed fulltextindex exclusivelock fulltextindex add new index to the table if such index already exists this method does nothing param table class corresponding to the table param key field of the class to be indexed param unique if index is unique or not exception storage error class not found exception is thrown if there is no table corresponding to the specified class return code true code if index is created code false code if index already exists deprecated since version 2 75 of perst it is not necessary to create table and index descriptors explicitly them are automatically create when object is inserted in the database first time to mark fields for which indices should be created use indexable annotation public boolean create index class table string key boolean unique return create index locate table table true table key unique false storageerror class_not_found createindex createindex locatetable add new index to the table if such index already exists this method does nothing param table class corresponding to the table param key field of the class to be indexed param unique if index is unique or not param case insensitive if string index is case insensitive exception storage error class not found exception is thrown if there is no table corresponding to the specified class return code true code if index is created code false code if index already exists deprecated since version 2 75 of perst it is not necessary to create table and index descriptors explicitly them are automatically cerate when objct is inserted in the database first time to mark fields for which indices should be created use indexable annotaion public boolean create index class table string key boolean unique boolean case insensitive return create index locate table table true table key unique case insensitive caseinsensitive storageerror class_not_found createindex caseinsensitive createindex locatetable caseinsensitive private boolean create index table t class c string key boolean unique boolean case insensitive if t indices map get key null field index index storage create field index c key unique case insensitive t indices map put key index t indices add index return true return false createindex caseinsensitive indicesmap fieldindex createfieldindex caseinsensitive indicesmap drop index for the specified table and key does nothing if there is no such index param table class corresponding to the table param key field of the class to be indexed exception storage error class not found exception is thrown if there is no table corresponding to the specified class return code true code if index is deleted code false code if index is not found public boolean drop index class table string key table t locate table table true field index index field index t indices map remove key if index null t indices remove t indices index of index return true return false storageerror class_not_found dropindex locatetable fieldindex fieldindex indicesmap indexof get indices for the specified table param table class corresponding to the table return map of table indices public hash map get indices class table table t locate table table true false return t null new hash map t indices map hashmap getindices locatetable hashmap indicesmap exclude record from specified index this method is needed to perform update of indexed field key before updating the record it is necessary to exclude it from indices which keys are affected after updating the field record should be reinserted in these indices using include in index method p if there is not table associated with class of this object then database will search for table associated with superclass and so on p this method does nothing if there is no index for the specified field param record object to be excluded from the specified index param key name of the indexed field exception storage error class not found exception is thrown if there is no table corresponding to record class return code true code if record is excluded from index code false code if there is no such index public boolean exclude from index i persistent record string key return exclude from index record get class record key includeinindex storageerror class_not_found excludefromindex ipersistent excludefromindex getclass exclude record from specified index this method is needed to perform update of indexed field key before updating the record it is necessary to exclude it from indices which keys are affected after updating the field record should be reinserted in these indices using include in index method p if there is not table associated with class of this object then database will search for table associated with superclass and so on p this method does nothing if there is no index for the specified field param table class corresponding to the table param record object to be excluded from the specified index param key name of the indexed field exception storage error class not found exception is thrown if there is no table corresponding to the specified class return code true code if record is excluded from index code false code if there is no such index public boolean exclude from index class table i persistent record string key table t locate table table true field index index field index t indices map get key if index null index remove record return true return false includeinindex storageerror class_not_found excludefromindex ipersistent locatetable fieldindex fieldindex indicesmap include record in the specified index this method is needed to perform update of indexed field key before updating the record it is necessary to exclude it from indices which keys are affected using exclude from index method after updating the field record should be reinserted in these indices using this method p if there is not table associated with class of this object then database will search for table associated with superclass and so on p this method does nothing if there is no index for the specified field param record object to be excluded from the specified index param key name of the indexed field exception storage error class not found exception is thrown if there is no table corresponding to the specified class return code true code if record is included in index code false code if there is no such index public boolean include in index i persistent record string key return include in index record get class record key excludefromindex storageerror class_not_found includeinindex ipersistent includeinindex getclass include record in the specified index this method is needed to perform update of indexed field key before updating the record it is necessary to exclude it from indices which keys are affected using exclude from index method after updating the field record should be reinserted in these indices using this method p if there is not table associated with class of this object then database will search for table associated with superclass and so on p this method does nothing if there is no index for the specified field param table class corresponding to the table param record object to be excluded from the specified index param key name of the indexed field exception storage error class not found exception is thrown if there is no table corresponding to the specified class return code true code if record is included in index code false code if there is no such index public boolean include in index class table i persistent record string key table t locate table table true field index index field index t indices map get key if index null index put record return true return false excludefromindex storageerror class_not_found includeinindex ipersistent locatetable fieldindex fieldindex indicesmap select record from specified table param table class corresponding to the table param predicate search predicate exception storage error class not found exception is thrown if there is no table corresponding to the specified class return iterator through selected records this iterator doesn t support remove method exception compile error exception is thrown if predicate is not valid jsql exception exception jsql runtime exception exception is thrown if there is runtime error during query execution public t extends i persistent iterable iterator t select class table string predicate return select table predicate false storageerror class_not_found compileerror jsqlruntimeexception ipersistent iterableiterator select record from specified table param table class corresponding to the table param predicate search predicate param for update code true code if records are selected for update in this case exclusive lock is set for the table to avoid deadlock exception storage error class not found exception is thrown if there is no table corresponding to the specified class return iterator through selected records this iterator doesn t support remove method exception compile error exception is thrown if predicate is not valid jsql exception exception jsql runtime exception exception is thrown if there is runtime error during query execution public t extends i persistent iterable iterator t select class table string predicate boolean for update query q prepare table predicate for update return q execute get records table forupdate storageerror class_not_found compileerror jsqlruntimeexception ipersistent iterableiterator forupdate forupdate getrecords prepare jsql query prepare is needed for queries with parameters also preparing query can improve speed if query will be executed multiple times using prepare it is compiled only once p to execute prepared query you should use query execute db get records xyz class method param table class corresponding to the table param predicate search predicate exception storage error class not found exception is thrown if there is no table corresponding to the specified class exception compile error exception is thrown if predicate is not valid jsql exception public t extends i persistent query t prepare class table string predicate return prepare table predicate false getrecords storageerror class_not_found compileerror ipersistent prepare jsql query prepare is needed for queries with parameters also preparing query can improve speed if query will be executed multiple times using prepare it is compiled only once p to execute prepared query you should use query execute db get records xyz class method param table class corresponding to the table param predicate search predicate param for update code true code if records are selected for update in this case exclusive lock is set for the table to avoid deadlock exception storage error class not found exception is thrown if there is no table corresponding to the specified class exception compile error exception is thrown if predicate is not valid jsql exception public t extends i persistent query t prepare class table string predicate boolean for update table t locate table table for update false query q storage create query q prepare table predicate while t null iterator iterator t indices map entry set iterator while iterator has next map entry entry map entry iterator next field index index field index entry get value string key string entry get key q add index key index t locate table t type get superclass for update false return q getrecords forupdate storageerror class_not_found compileerror ipersistent forupdate locatetable forupdate createquery indicesmap entryset hasnext fieldindex fieldindex getvalue getkey addindex locatetable getsuperclass forupdate get iterator through all table records param table class corresponding to the table return iterator through all table records exception storage error class not found exception is thrown if there is no table corresponding to the specified class public t extends i persistent iterable iterator t get records class table return get records table false storageerror class_not_found ipersistent iterableiterator getrecords getrecords get iterator through all table records param table class corresponding to the table param for update code true code if records are selected for update in this case exclusive lock is set for the table to avoid deadlock return iterator through all table records exception storage error class not found exception is thrown if there is no table corresponding to the specified class public t extends i persistent iterable iterator t get records class table boolean for update table t locate table table for update false return new iterator wrapper t t null new linked list t iterator t extent iterator forupdate storageerror class_not_found ipersistent iterableiterator getrecords forupdate locatetable forupdate iteratorwrapper linkedlist get storage associated with this database return underlying storage public storage get storage return storage getstorage parse and execute full text search query param query text of the query oaram language language if the query param max results maximal amount of selected documents param time limit limit for query execution time erturn result of query execution ordered by rank or null in case of empty or incorrect query public full text search result search string query string language int max results int time limit if multithreaded metadata full text index shared lock return metadata full text index search query language max results time limit maxresults timelimit fulltextsearchresult maxresults timelimit fulltextindex sharedlock fulltextindex maxresults timelimit execute full text search query param query prepared query param max results maximal amount of selected documents param time limit limit for query execution time erturn result of query execution ordered by rank or null in case of empty or incorrect query public full text search result search full text query query int max results int time limit if multithreaded metadata full text index shared lock return metadata full text index search query max results time limit maxresults timelimit fulltextsearchresult fulltextquery maxresults timelimit fulltextindex sharedlock fulltextindex maxresults timelimit metadata storage storage index index full text search helper helper super storage metaclasses index full text index helper null storage create full text index helper storage create full text index fulltextsearchhelper fulltextindex createfulltextindex createfulltextindex metadata storage storage full text search helper helper super storage metaclasses storage create index string class true full text index helper null storage create full text index helper storage create full text index fulltextsearchhelper createindex fulltextindex createfulltextindex createfulltextindex metadata void set class class cls type cls full text indexable fields new array list field for field f cls get declared fields full text indexable idx full text indexable f get annotation full text indexable class if idx null try f set accessible true catch exception x full text indexable fields add f setclass fulltextindexablefields arraylist getdeclaredfields fulltextindexable fulltextindexable getannotation fulltextindexable setaccessible fulltextindexablefields public void on load for int i indices size i 0 field index index field index indices get i indices map put index get key fields 0 get name index onload fieldindex fieldindex indicesmap getkeyfields getname public class util public static bucket fetch bucket string uri plugin respirator plugin respirator throws fetch exception malformedurl exception try local file first file file new file uri if file exists file can read return new file bucket file true false false false false freeneturi try to fetch from freenet high level simple client hlsc plugin respirator gethl simple client freeneturi u new freeneturi uri fetch result res while true try res hlsc fetch u break catch fetch exception e if e newuri null u e newuri continue else throw e return res as bucket fetchbucket pluginrespirator pluginrespirator fetchexception malformedurlexception canread filebucket highlevelsimpleclient pluginrespirator gethlsimpleclient fetchresult fetchexception asbucket public ssdp response set version http version 11 ssdpresponse setversion version_11 public void setst string value set header http st value setheader public string getst return get header value http st getheadervalue public void set location string value set header http location value setlocation setheader public string get location return get header value http location getlocation getheadervalue public void setusn string value set header http usn value setheader public string getusn return get header value http usn getheadervalue public void setmyname string value set header http myname value setheader public string getmyname return get header value http myname getheadervalue public void set lease time int len set header http cache control max age integer to string len setleasetime setheader cache_control tostring public int get lease time string cache ctrl get header value http cache control return ssdp get lease time cache ctrl getleasetime cachectrl getheadervalue cache_control getleasetime cachectrl public string get header string builder str new string builder str append get status line string str append get header string str append http crlf for intel u pnp control points return str to string getheader stringbuilder stringbuilder getstatuslinestring getheaderstring upnp tostring private static class precalc buffer fill extends native thread public precalc buffer fill super diffie hellman precalc native thread min priority false set daemon true precalcbufferfill nativethread precalcbufferfill nativethread min_priority setdaemon override public void run super run while true while precalc buffer size precalc max precalc buffer push gen params synchronized precalc buffer notify a waiting thread that new data is available precalc buffer notify synchronized precalcer wait obj try do not set the thread priority here because the thread may have been stopped while holding the precalcer wait obj lock the stop causes the thread group to be cleared and set priority to throw a npe precalcer wait obj wait precalc timeout todo this timeout might very well be unneccsary catch interrupted exception ie ignored precalcbuffer precalc_max precalcbuffer genparams precalcbuffer precalcbuffer precalcerwaitobj precalcerwaitobj setpriority precalcerwaitobj precalc_timeout interruptedexception public static void init random random r random precalc thread start precalcthread will ask the precalc thread to refill the buffer if necessary private static void ask refill if the buffer size is below the threshold then wake the precalc thread if precalc buffer size precalc resume synchronized precalcer wait obj precalcer wait obj notify askrefill precalcbuffer precalc_resume precalcerwaitobj precalcerwaitobj create a diffie hellman light context public static diffie hellman light context generate light context long time1 system current time millis native big integer params get params long time2 system current time millis if time2 time1 300 logger error null diffie hellman generate light context time2 is more than 300ms after time1 time2 time1 return new diffie hellman light context params 0 params 1 diffiehellmanlightcontext diffiehellmanlightcontext generatelightcontext currenttimemillis nativebiginteger getparams currenttimemillis diffiehellman generatelightcontext diffiehellmanlightcontext public static native big integer get params synchronized precalc buffer ensure that we will have something to pop at least pretty soon ask refill if precalc buffer is empty return precalc buffer pop logger normal diffie hellman class diffie hellman had to generate a parameter on thread report if that happens often return gen params nativebiginteger getparams precalcbuffer askrefill precalcbuffer isempty precalcbuffer diffiehellman diffiehellman genparams private static native big integer gen params native big integer params new native big integer 2 don t need native big integer do params 0 new native big integer 256 r params 1 native big integer group getg mod pow params 0 group getp while diffie hellman checkdh exponential validity diffie hellman class params 1 return params nativebiginteger genparams nativebiginteger nativebiginteger nativebiginteger nativebiginteger nativebiginteger modpow diffiehellman checkdhexponentialvalidity diffiehellman check the validity of a dh exponential param a big integer the exponential to test return a boolean whether the dh exponential provided is acceptable or not see http securitytracker com alerts 2005 aug 1014739 html see http www it iitb ac in praj acads netsec final report pdf public static boolean checkdh exponential validity class caller big integer exponential int ones count 0 zeros count 0 ensure that we have at least 16 bits of each gender for int i 0 i exponential bit length i if exponential test bit i ones count else zeros count if ones count 16 zeros count 16 logger error caller the provided exponential contains zeros count zeros and ones count ones wich is unacceptable return false ensure that g x 2 24 if min exponential value compare to exponential 1 logger error caller the provided exponential is smaller than 2 24 which is unacceptable return false ensure that g x p 2 24 if max exponential value compare to exponential 1 logger error diffie hellman class the provided exponential is bigger than p 2 24 which is unacceptable return false return true biginteger finalreport checkdhexponentialvalidity biginteger onescount zeroscount bitlength testbit onescount zeroscount onescount zeroscount zeroscount onescount min_exponential_value compareto max_exponential_value compareto diffiehellman public static dh group get group return group dhgroup getgroup return the length in bytes of the modulus exponentials will fit into this length public static int modulus length in bytes int bit length get group getp bit length return bit length 8 bit length 8 0 1 0 moduluslengthinbytes bitlength getgroup bitlength bitlength bitlength public fcp plugin reply string pluginname string identifier2 simple field set fs bucket bucket2 bucket bucket2 if bucket null data length 1 else bucket set read only data length bucket size plugname pluginname identifier identifier2 plugparams fs fcppluginreply simplefieldset datalength setreadonly datalength override string get identifier return identifier getidentifier override boolean is global return false isglobal override long data length return data length datalength datalength override string get end string if data length 0 return data else return end message getendstring datalength endmessage override public simple field set get field set simple field set sfs new simple field set true sfs put single plugin name plugname sfs put single identifier identifier if data length 0 sfs put data length data length sfs put replies plugparams return sfs simplefieldset getfieldset simplefieldset simplefieldset putsingle pluginname putsingle datalength datalength datalength override public string get name return name getname override public void run fcp connection handler handler node node throws message invalid exception throw new message invalid exception protocol error message invalid message name goes from server to client not the other way around null false fcpconnectionhandler messageinvalidexception messageinvalidexception protocolerrormessage invalid_message override public void remove from object container container throw new unsupported operation exception removefrom objectcontainer unsupportedoperationexception suppress warnings serial public class node need restart exception extends config exception public node need restart exception string msg super msg suppresswarnings nodeneedrestartexception configexception nodeneedrestartexception static logger register log threshold callback new log threshold callback override public void should update logminor logger should log logger minor this registerlogthresholdcallback logthresholdcallback shouldupdate shouldlog public static network interface create int port string bind to string allowed hosts executor executor boolean ignore unbindableip6 throws io exception network interface iface new network interface port allowed hosts executor try iface set bind to bind to ignore unbindableip6 catch io exception e try iface close catch io exception e1 logger error network interface class caught e1 closing after catching e binding while constructing e1 ignore throw e return iface networkinterface bindto allowedhosts ignoreunbindableip6 ioexception networkinterface networkinterface allowedhosts setbindto bindto ignoreunbindableip6 ioexception ioexception networkinterface creates a new network interface that can bind to several addresses and allows connection filtering on ip address level param bind to a comma separated list of addresses to bind to param allowed hosts a comma separated list of allowed addresses protected network interface int port string allowed hosts executor executor throws io exception this port port this allowed hosts new allowed hosts allowed hosts this executor executor bindto allowedhosts networkinterface allowedhosts ioexception allowedhosts allowedhosts allowedhosts protected server socket create server socket throws io exception return new server socket serversocket createserversocket ioexception serversocket sets the list of ip address this network interface binds to param bind to a comma separated list of ip address to bind to public void set bind to string bind to boolean ignore unbindableip6 throws io exception if bind to null bind to equals bind to network interface default bind to string tokenizer bind to tokens new string tokenizer bind to list string bind to token list new array list string while bind to tokens has more tokens bind to token list add bind to tokens next token trim stop the old acceptors for int acceptor index 0 acceptor count acceptors size acceptor index acceptor count acceptor index acceptor acceptor acceptors get acceptor index try acceptor close catch io exception e swallow exception synchronized sync object while running acceptors 0 try sync object wait catch interrupted exception e acceptors clear for int server socket index 0 server socket index bind to token list size server socket index server socket server socket create server socket inet socket address addr null try addr new inet socket address bind to token list get server socket index port server socket set reuse address true server socket bind addr catch socket exception e if ignore unbindableip6 addr null addr get address instanceof inet6 address continue else throw e acceptor acceptor new acceptor server socket acceptors add acceptor set so timeout timeout synchronized sync object for acceptor acceptor this acceptors executor execute acceptor network interface acceptor for acceptor server socket bindto setbindto bindto ignoreunbindableip6 ioexception bindto bindto bindto networkinterface default_bind_to stringtokenizer bindtotokens stringtokenizer bindto bindtotokenlist arraylist bindtotokens hasmoretokens bindtotokenlist bindtotokens nexttoken acceptorindex acceptorcount acceptorindex acceptorcount acceptorindex acceptorindex ioexception syncobject runningacceptors syncobject interruptedexception serversocketindex serversocketindex bindtotokenlist serversocketindex serversocket serversocket createserversocket inetsocketaddress inetsocketaddress bindtotokenlist serversocketindex serversocket setreuseaddress serversocket socketexception ignoreunbindableip6 getaddress inet6address serversocket setsotimeout syncobject serversocket public void set allowed hosts string allowed hosts this allowed hosts set allowed hosts allowed hosts setallowedhosts allowedhosts allowedhosts setallowedhosts allowedhosts sets the so timeout value on the server sockets param timeout the timeout in milliseconds code 0 code to disable throws socket exception if the so timeout value can not be set see server socket set so timeout int public void set so timeout int timeout throws socket exception for acceptor acceptor acceptors acceptor set so timeout timeout this timeout timeout so_timeout socketexception so_timeout serversocket setsotimeout setsotimeout socketexception setsotimeout waits for a connection if a timeout has been set using link set so timeout int and no connection is established this method will return after the specified timeout has been expired throwing a link socket timeout exception if no timeout has been set this method will wait until a connection has been established return the socket that is connected to the client or null if the timeout has expired waiting for a connection public socket accept synchronized sync object while accepted sockets size 0 if shutdown return null if wrapper manager has shutdown hook been triggered return null if acceptors size 0 return null try sync object wait timeout catch interrupted exception ie1 if timeout 0 accepted sockets size 0 return null return accepted sockets remove 0 setsotimeout sockettimeoutexception syncobject acceptedsockets wrappermanager hasshutdownhookbeentriggered syncobject interruptedexception acceptedsockets acceptedsockets closes this interface and all underlying server sockets throws io exception if an i o exception occurs see server socket close public void close throws io exception io exception exception null shutdown true for acceptor acceptor acceptors try acceptor close catch io exception ioe1 exception ioe1 synchronized sync object sync object notify all if exception null throw exception ioexception serversocket ioexception ioexception ioexception syncobject syncobject notifyall gets called by an acceptor if it has stopped private void acceptor stopped synchronized sync object running acceptors sync object notify all acceptorstopped syncobject runningacceptors syncobject notifyall creates a new acceptor on the specified server socket param server socket the server socket to listen on public acceptor server socket server socket this server socket server socket serversocket serversocket serversocket serversocket serversocket sets the so timeout value on this acceptor s server socket param timeout the timeout in milliseconds or code 0 code to disable throws socket exception if the so timeout value can not be set see server socket set so timeout int public void set so timeout int timeout throws socket exception server socket set so timeout timeout so_timeout socketexception so_timeout serversocket setsotimeout setsotimeout socketexception serversocket setsotimeout closes this acceptor and the underlying server socket throws io exception if an i o exception occurs see server socket close public void close throws io exception closed true server socket close ioexception serversocket ioexception serversocket main method that accepts connections and checks the address against the list of allowed hosts see network interface allowed hosts public void run freenet support logger os thread logpid this while closed try socket client socket server socket accept inet address client address client socket get inet address if logminor logger minor acceptor class connection from client address address type client address type address identifier get address type client address get host address check if the ip address is allowed if allowed hosts allowed client address type client address synchronized sync object accepted sockets add client socket sync object notify all else try client socket close catch io exception ioe1 logger normal acceptor class denied connection to client address catch socket timeout exception ste1 if logminor logger minor this timeout catch io exception ioe1 if logminor logger minor this caught ioe1 network interface this acceptor stopped networkinterface allowedhosts osthread clientsocket serversocket inetaddress clientaddress clientsocket getinetaddress clientaddress addresstype clientaddresstype addressidentifier getaddresstype clientaddress gethostaddress allowedhosts clientaddresstype clientaddress syncobject acceptedsockets clientsocket syncobject notifyall clientsocket ioexception clientaddress sockettimeoutexception ioexception networkinterface acceptorstopped public string get allowed hosts return allowed hosts get allowed hosts getallowedhosts allowedhosts getallowedhosts private final long m size size in bytes public attachment freeneturi myuri long my size muri myuri m size my size msize mysize msize mysize public freeneturi geturi return muri public long get size return m size getsize msize get a list of fields which the database should create an index on public static string get indexed fields return new string mid indexed because it is our primary key m threadid indexed for being able to query all messages of a thread m parentid indexed for being able to get all replies to a message m fetch date indexed because frost needs to query for all messages after the time it has last done so getindexedfields mthreadid mparentid mfetchdate protected message messageuri newuri freeneturi new realuri string newid message list new message list messageuri new threaduri messageuri new parenturi set board new boards board new reply to board ft identity new author string new title date new date string new text list attachment new attachments throws invalid parameter exception we only assert instead of throwing because the constructor is protected and the construct function should verify this assert newuri null arrays equals newuri get freeneturi get routing key new author get requesturi get routing key fixme assert new message list get author new author fixme assert new realuri null new message list contains new realuri verifyid new author newid if new parenturi null new threaduri null logger error this message with parent uri but without thread uri created newuri if new boards is empty throw new invalid parameter exception no boards in message newuri if new reply to board null new boards contains new reply to board logger error this message created with reply to board not being in new boards newuri new boards add new reply to board muri newuri m realuri new realuri m message list new message list m author new author mid newid m parenturi new parenturi m parentid m parenturi null m parenturi get messageid null if a message has no thread uri specified this is a bug in the client which inserted it we store the parent uri as thread uri instead this will be corrected later by set parent m threaduri new threaduri null new threaduri m parenturi m threadid m threaduri null m threaduri get messageid m parentid m boards new boards to array new board new boards size arrays sort m boards m reply to board new reply to board m title make title valid new title m date new date todo check out whether date provides a function for getting the timezone and throw an exception if not utc m fetch date current timeutc get m text make text valid new text if is title valid m title throw new invalid parameter exception invalid message title in message newuri if is text valid m text throw new invalid parameter exception invalid message text in message newuri m attachments new attachments null null new attachments to array new attachment new attachments size newrealuri messagelist newmessagelist newthreaduri newparenturi newboards newreplytoboard ftidentity newauthor newtitle newdate newtext newattachments invalidparameterexception getfreeneturi getroutingkey newauthor getrequesturi getroutingkey newmessagelist getauthor newauthor newrealuri newmessagelist newrealuri newauthor newparenturi newthreaduri newboards isempty invalidparameterexception newreplytoboard newboards newreplytoboard replytoboard newboards newboards newreplytoboard mrealuri newrealuri mmessagelist newmessagelist mauthor newauthor mparenturi newparenturi mparentid mparenturi mparenturi getmessageid setparent mthreaduri newthreaduri newthreaduri mparenturi mthreadid mthreaduri mthreaduri getmessageid mparentid mboards newboards toarray newboards mboards mreplytoboard newreplytoboard mtitle maketitlevalid newtitle mdate newdate mfetchdate currenttimeutc mtext maketextvalid newtext istitlevalid mtitle invalidparameterexception istextvalid mtext invalidparameterexception mattachments newattachments newattachments toarray newattachments has to be used after loading a ft board object from the database to initialize the transient fields public void initialize transient ext object container mydb message manager my message manager assert mydb null assert my message manager null db mydb m message manager my message manager ftboard initializetransient extobjectcontainer messagemanager mymessagemanager mymessagemanager mmessagemanager mymessagemanager verifies that the given message id begins with the routing key of the author throws invalid parameter exception if the id is not valid public static void verifyid ft identity author string id throws invalid parameter exception if id ends with base64 encode author get requesturi get routing key false throw new invalid parameter exception illegal id id invalidparameterexception ftidentity invalidparameterexception endswith getrequesturi getroutingkey invalidparameterexception get the uri of the message public messageuri geturi not synchronized because only own message might change the uri return muri ownmessage public string getid not synchronized because only own message might change the id return mid ownmessage get the messageuri of the thread this message belongs to throws no such message exception public synchronized messageuri get threaduri throws no such message exception if m threaduri null throw new no such message exception return m threaduri nosuchmessageexception getthreaduri nosuchmessageexception mthreaduri nosuchmessageexception mthreaduri get the id of the thread this message belongs to should not be used by the user interface for querying the database as the parent thread might not have been downloaded yet use get thread getid instead return the id of the message s parent thread throws no such message exception if the message is a thread itself public synchronized string get threadid throws no such message exception if m threadid null throw new no such message exception return m threadid getthread nosuchmessageexception getthreadid nosuchmessageexception mthreadid nosuchmessageexception mthreadid used internally for correcting the thread ur is of messages which have specified them wrong in the xml protected synchronized void set threaduri andid messageuri new threaduri m threaduri new threaduri m threadid m threaduri get messageid store uris setthreaduriandid newthreaduri mthreaduri newthreaduri mthreadid mthreaduri getmessageid get the messageuri to which this message is a reply null if the message is a thread public messageuri get parenturi throws no such message exception if m parenturi null throw new no such message exception return m parenturi getparenturi nosuchmessageexception mparenturi nosuchmessageexception mparenturi public string get parentid throws no such message exception if m parentid null throw new no such message exception return m parentid getparentid nosuchmessageexception mparentid nosuchmessageexception mparentid public boolean is thread return m parenturi null isthread mparenturi get the boards to which this message was posted the boards are returned in alphabetical order the transient fields of the returned boards are initialized already public board get boards for board b m boards b initialize transient db m message manager return m boards getboards mboards initializetransient mmessagemanager mboards public board get reply to board return m reply to board getreplytoboard mreplytoboard get the author of the message public ft identity get author m author initialize transient db m message manager get identity manager return m author ftidentity getauthor mauthor initializetransient mmessagemanager getidentitymanager mauthor get the title of the message public string get title return m title gettitle mtitle get the date when the message was written in strong utc time strong public date get date return m date getdate mdate get the date when the message was fetched by freetalk public date get fetch date return m fetch date getfetchdate mfetchdate get the text of the message public string get text return m text gettext mtext get the attachments of the message in the order in which they were received public attachment get attachments return m attachments getattachments mattachments get the thread to which this message belongs the transient fields of the returned message will be initialized already this might not always return the real parent thread it will return the topmost parent message if the parent thread has not been downloaded yet public synchronized message get thread throws no such message exception todo find all usages of this function and check whether we should put the activate here and what the fitting depth is db activate this 3 if m thread null throw new no such message exception m thread initialize transient db m message manager return m thread getthread nosuchmessageexception mthread nosuchmessageexception mthread initializetransient mmessagemanager mthread public synchronized void set thread message new parent thread assert m thread null if new parent thread getid equals m threadid throw new illegal argument exception trying to set a message as thread which has the wrong id new parent thread getid if new parent thread is thread throw new illegal argument exception trying to set thread not a thread m thread new parent thread store setthread newparentthread mthread newparentthread mthreadid illegalargumentexception newparentthread newparentthread isthread illegalargumentexception setthread mthread newparentthread get the message to which this message is a reply the transient fields of the returned message will be initialized already public synchronized message get parent throws no such message exception todo find all usages of this function and check whether we should put the activate here and what the fitting depth is db activate this 3 if m parent null throw new no such message exception m parent initialize transient db m message manager return m parent getparent nosuchmessageexception mparent nosuchmessageexception mparent initializetransient mmessagemanager mparent public synchronized void set parent message new parent if new parent getid equals m parentid throw new illegal argument exception trying to set a message as parent which has the wrong id new parent getid todo assert new parent contains at least one board which m boards contains m parent new parent check whether m threaduri id is correct if it is not adopt the thread uri id of the parent message and also set this on all our children and their children i thought about how to handle incorrect thread uri id for about 3 hours and it seems to me like this is the way to go requires lots of brainwork to imagine what side effects can happen due to incorrect thread uri id and the conclusion is that they must be corrected otherwise those messages will disappear in get all thread replies synchronized m parent string real threadid new parent is thread new parent getid m parent m threadid if real threadid equals m threadid logger error this correcting thread uri id of geturi it is unpredictable what messages will be affected by this code because we modify all children so unfortunately we should probably lock all changes to messages here synchronized message class if m parent is thread set threaduri andid m parent geturi set thread m parent else set threaduri andid m parent m threaduri use depth first search for setting the uri id on the children this is dangerous an attacker might cause very high memory usage if we do not ensure that we use dfs properly so that only 1 message must be in memory at once message child this boolean found child do found child false for message c child get children null if m threadid equals c m threadid db deactivate child 1 child c child set threaduri andid m threaduri found child true break if found child child this try child child get parent found child true catch no such message exception e logger error this should never happen while found child store setparent newparent newparent mparentid illegalargumentexception newparent newparent mboards mparent newparent mthreaduri getallthreadreplies mparent realthreadid newparent isthread newparent mparent mthreadid realthreadid mthreadid mparent isthread setthreaduriandid mparent setthread mparent setthreaduriandid mparent mthreaduri foundchild foundchild getchildren mthreadid mthreadid setthreaduriandid mthreaduri foundchild foundchild getparent foundchild nosuchmessageexception foundchild returns an iterator over the children of the message sorted descending by date the transient fields of the children will be initialized already suppress warnings unchecked public synchronized iterable message get children final board target board return new iterable message public iterator message iterator return new iterator message private iterator message iter private board board private message next board target board todo accelerate this query configure db4o to keep a per message date sorted index of children not very important for now since threads are usually small query q db query q constrain message class q descend m parent constrain this q descend m date order descending iter q execute iterator next iter has next iter next null public boolean has next if board null return next null while next null if arrays binary search next get boards board 0 return true next iter has next iter next null return false public message next if has next we have to call has next to ignore messages which do not belong to the selected board assert false however the users of the function should do this for us throw new no such element exception message child next next iter has next iter next null child initialize transient db m message manager return child public void remove throw new unsupported operation exception use child set parent null instead suppresswarnings getchildren targetboard targetboard mparent mdate orderdescending hasnext hasnext binarysearch getboards hasnext hasnext hasnext nosuchelementexception hasnext initializetransient mmessagemanager unsupportedoperationexception setparent return new iterable message public iterator message iterator return new iterator message private iterator message iter private board board private message next board target board todo accelerate this query configure db4o to keep a per message date sorted index of children not very important for now since threads are usually small query q db query q constrain message class q descend m parent constrain this q descend m date order descending iter q execute iterator next iter has next iter next null public boolean has next if board null return next null while next null if arrays binary search next get boards board 0 return true next iter has next iter next null return false public message next if has next we have to call has next to ignore messages which do not belong to the selected board assert false however the users of the function should do this for us throw new no such element exception message child next next iter has next iter next null child initialize transient db m message manager return child public void remove throw new unsupported operation exception use child set parent null instead targetboard mparent mdate orderdescending hasnext hasnext binarysearch getboards hasnext hasnext hasnext nosuchelementexception hasnext initializetransient mmessagemanager unsupportedoperationexception setparent public boolean has next if board null return next null while next null if arrays binary search next get boards board 0 return true next iter has next iter next null return false hasnext binarysearch getboards hasnext public message next if has next we have to call has next to ignore messages which do not belong to the selected board assert false however the users of the function should do this for us throw new no such element exception message child next next iter has next iter next null child initialize transient db m message manager return child hasnext hasnext nosuchelementexception hasnext initializetransient mmessagemanager public void remove throw new unsupported operation exception use child set parent null instead unsupportedoperationexception setparent checks whether the title of the message is valid validity conditions not empty no line breaks tabs or any other control characters no invalid characters no invalid formatting unpaired direction or annotation characters static public boolean is title valid string title return title null title length 0 string validity checker contains no invalid characters title string validity checker contains no linebreaks title string validity checker contains no control characters title string validity checker contains no invalid formatting title istitlevalid stringvaliditychecker containsnoinvalidcharacters stringvaliditychecker containsnolinebreaks stringvaliditychecker containsnocontrolcharacters stringvaliditychecker containsnoinvalidformatting checks whether the text of the message is valid validity conditions static public boolean is text valid string text if text null return false if text length max message text length return false try if text get bytes utf 8 length max message text byte length return false catch unsupported encoding exception e return false return true istextvalid max_message_text_length getbytes max_message_text_byte_length unsupportedencodingexception makes the passed title valid in means of code is title valid code see is title valid static public string make title valid string title fixme the newline handling here is based on the rfc 822 format newline linear white space single space if necessary we could move that part of the cleaning up to ui nntp article parser but the same algorithm should work fine in the general case string builder result new string builder boolean replacing newline false int dir count 0 boolean in annotated text false boolean in annotation false for int i 0 i title length int c title code point at i i character char count c if c r c n if replacing newline replacing newline true result append else if c t c if replacing newline result append else if c 0x202a left to right embedding c 0x202b right to left embedding c 0x202d left to right override c 0x202e right to left override dir count result append code point c else if c 0x202c pop directional formatting if dir count 0 dir count result append code point c else if c 0xfff9 interlinear annotation anchor if in annotated text in annotation result append code point c in annotated text true else if c 0xfffa interlinear annotation separator if in annotated text result append code point c in annotated text false in annotation true else if c 0xfffb interlinear annotation terminator if in annotation result append code point c in annotation false else if c 0xfffe 0xfffe invalid character ignore else replacing newline false switch character get type c case character control case character surrogate case character line separator case character paragraph separator break default result append code point c if in annotated text result append code point 0xfffa result append code point 0xfffb else if in annotation result append code point 0xfffb while dir count 0 result append code point 0x202c dir count return result to string istitlevalid istitlevalid maketitlevalid articleparser stringbuilder stringbuilder replacingnewline dircount inannotatedtext inannotation codepointat charcount replacingnewline replacingnewline replacingnewline dircount appendcodepoint dircount dircount appendcodepoint inannotatedtext inannotation appendcodepoint inannotatedtext inannotatedtext appendcodepoint inannotatedtext inannotation inannotation appendcodepoint inannotation replacingnewline gettype line_separator paragraph_separator appendcodepoint inannotatedtext appendcodepoint appendcodepoint inannotation appendcodepoint dircount appendcodepoint dircount tostring makes the passed text valid in means of code is text valid code see is text valid static public string make text valid string text return text replace r n n istextvalid istextvalid maketextvalid public synchronized void store fixme check for duplicates also notice that an own message which is equal might exist synchronized db lock if db ext is stored this db ext is active this throw new runtime exception trying to store a non active message object if m author null throw new runtime exception trying to store a message with m author null if muri null db store muri if m realuri null db store m realuri if m threaduri null db store m threaduri if m parenturi null db store m parenturi db store m boards not stored because it is a primitive for db4o db store m date not stored because it is a primitive for db4o db store m attachments not stored because it is a primitive for db4o db store this db commit ownmessage isstored isactive runtimeexception mauthor runtimeexception mauthor mrealuri mrealuri mthreaduri mthreaduri mparenturi mparenturi mboards mdate mattachments public int compare to message other return m date compare to other m date compareto mdate compareto mdate public final client requester parent get a numbered key to fetch public abstract client key get key object token object container container clientrequester clientkey getkey objectcontainer override public key get node key sendable request item token object container container client key key get key token container if key null return null return key get node key getnodekey sendablerequestitem objectcontainer clientkey getkey getnodekey what keys are we interested in for purposes of checking the datastore this is in sendable get not key listener in order to deal with it in smaller chunks param container database handle sendableget keylistener public abstract key list keys object container container get the fetch context settings object public abstract fetch context get context listkeys objectcontainer fetchcontext getcontext public abstract fetch context get context called when if the low level request fails public abstract void on failure low level get exception e object token object container container client context context fetchcontext getcontext onfailure lowlevelgetexception objectcontainer clientcontext public abstract void on failure low level get exception e object token object container container client context context should the request ignore the datastore public abstract boolean ignore store onfailure lowlevelgetexception objectcontainer clientcontext ignorestore public abstract boolean ignore store if true don t cache local requests param container public abstract boolean dont cache object container container ignorestore dontcache objectcontainer implementation public sendable get client requester parent super parent persistent this parent parent sendableget clientrequester static final sendable get request sender sender new sendable get request sender override public sendable request sender get sender object container container client context context return sender sendablegetrequestsender sendablegetrequestsender sendablerequestsender getsender objectcontainer clientcontext override public client request scheduler get scheduler client context context if isssk return context get ssk fetch scheduler else return context get chk fetch scheduler clientrequestscheduler getscheduler clientcontext getsskfetchscheduler getchkfetchscheduler get the time at which the key specified by the given token will wake up from the cooldown queue param token return public abstract long get cooldown wakeup object token object container container public abstract long get cooldown wakeup by key key key object container container getcooldownwakeup objectcontainer getcooldownwakeupbykey objectcontainer public abstract long get cooldown wakeup by key key key object container container reset the cooldown times when the request is reregistered public abstract void reset cooldown times object container container getcooldownwakeupbykey objectcontainer resetcooldowntimes objectcontainer an internal error occurred effecting this sendable get independantly of any chosen block s override public void internal error final throwable t final request scheduler sched object container container client context context boolean persistent sched call failure this new low level get exception low level get exception internal error t get message t native thread max priority persistent sendableget chosenblock internalerror requestscheduler objectcontainer clientcontext callfailure lowlevelgetexception lowlevelgetexception internal_error getmessage nativethread max_priority requeue a key after it has been on the cooldown queue for a while only requeue if our requeue time is less than or equal to the given time param key public abstract void requeue after cooldown key key long time object container container client context context override public final boolean is insert return false requeueaftercooldown objectcontainer clientcontext isinsert public void remove from object container container client context context container delete this removefrom objectcontainer clientcontext public class vector4f extends tuple4f public vector4f this 0 0 0 0 public vector4f float x this x x 0 this y x 1 this z x 2 this w x 2 public vector4f float x float y float z float w this x x this y y this z z this w w public vector4f vector4f t x t x y t y z t z w t w public vector4f tuple4f t x t x y t y z t z w t w public float dot vector4f v return v x x v y y v z z v w w public float length return float math sqrt x x y y z z w w public void normalize float d 1 0f x x y y z z w w x d y d z d w d uri newuri public permanent redirect exception super permanentredirectexception public permanent redirect exception uri newuri this newuri newuri permanentredirectexception public class device data extends node data public device data devicedata nodedata devicedata private file description file null public file get description file return description file descriptionfile getdescriptionfile descriptionfile public string get descriptionuri return descriptionuri getdescriptionuri public void set description file file description file this description file description file setdescriptionfile descriptionfile descriptionfile descriptionfile public void set descriptionuri string descriptionuri this descriptionuri descriptionuri setdescriptionuri private string location public string get location return location getlocation public void set location string location this location location setlocation private int lease time device default lease time public int get lease time return lease time leasetime default_lease_time getleasetime leasetime public void set lease time int val lease time val setleasetime leasetime private http server list http server list new http server list public http server list gethttp server list return http server list httpserverlist httpserverlist httpserverlist httpserverlist gethttpserverlist httpserverlist private int http port device http default port public int gethttp port return http port httpport http_default_port gethttpport httpport public void sethttp port int port http port port sethttpport httpport private listener list control action listener list new listener list public listener list get control action listener list return control action listener list listenerlist controlactionlistenerlist listenerlist listenerlist getcontrolactionlistenerlist controlactionlistenerlist private ssdp search socket list ssdp search socket list new ssdp search socket list public ssdp search socket list getssdp search socket list return ssdp search socket list ssdpsearchsocketlist ssdpsearchsocketlist ssdpsearchsocketlist ssdpsearchsocketlist getssdpsearchsocketlist ssdpsearchsocketlist private ssdp packet ssdp packet null public ssdp packet getssdp packet return ssdp packet ssdppacket ssdppacket ssdppacket getssdppacket ssdppacket public void setssdp packet ssdp packet packet ssdp packet packet setssdppacket ssdppacket ssdppacket private advertiser advertiser null public void set advertiser advertiser adv advertiser adv setadvertiser public advertiser get advertiser return advertiser getadvertiser logger register log threshold callback new log threshold callback override public void should update logminor logger should log logger minor this logdebug logger should log logger debug this registerlogthresholdcallback logthresholdcallback shouldupdate shouldlog shouldlog node dispatcher node node this node node this node stats node node stats node get ticker queue timed job this stale context check nodedispatcher nodestats nodestats getticker queuetimedjob stale_context_check byte counter ping counter new byte counter public void received bytes int x node node stats ping counter received x bytecounter pingcounter bytecounter receivedbytes nodestats pingcounterreceived public void sent bytes int x node node stats ping counter sent x sentbytes nodestats pingcountersent public void sent payload int x ignore sentpayload public interface node dispatcher callback public void snoop message m node n nodedispatchercallback public boolean handle message message m peer node source peer node m get source if source null node has been disconnected and garbage collected already ouch return true if logminor logger minor this dispatching m from source if callback null try callback snoop m node catch throwable t logger error this callback threw t t message type spec m get spec if spec dmt fnp ping send an fnp pong message reply dmt createfnp pong m get int dmt ping seqno try source send async reply null ping counter nothing we can do if can t contact source catch not connected exception e if logminor logger minor this lost connection replying to m return true else if spec dmt fnp store secret return node netid handle store secret m else if spec dmt fnp secret ping return node netid handle secret ping m else if spec dmt fnp detectedip address peer p peer m get object dmt external address source set remote detected peer p node ip detector redetect address return true else if spec dmt fnp time return handle time m source else if spec dmt fnp uptime return handle uptime m source else if spec dmt fnp sent packets source handle sent packets m return true else if spec dmt fnp void return true else if spec dmt fnp disconnect handle disconnect m source return true else if spec dmt node to node message node received node to node message m source return true else if spec dmt uom announce source is real connection return node node updater uom handle announce m source else if spec dmt uom request revocation source is real connection return node node updater uom handle request revocation m source else if spec dmt uom sending revocation source is real connection return node node updater uom handle sending revocation m source else if spec dmt uom request main source is real connection return node node updater uom handle request jar m source false else if spec dmt uom request extra source is real connection return node node updater uom handle request jar m source true else if spec dmt uom sending main source is real connection return node node updater uom handle sending main m source else if spec dmt uom sending extra source is real connection return node node updater uom handle sending ext m source else if spec dmt fnp opennet announce request return handle announce request m source else if spec dmt fnp routing status if source instanceof darknet peer node boolean value m get boolean dmt routing enabled if logminor logger minor this the peer source asked us to set routing value darknet peer node source set routing status value false we claim it in any case return true else if source is real connection spec dmt fnp loc change notification new double new loc m get double dmt location short buffer buffer short buffer m get object dmt peer locations double locs fields bytes to doubles buffer get data do not remove the sanity check below see http archives freenetproject org message 20080718 144240 359e16d3 en html if opennet manager max peers for scaling locs length source is opennet if locs length opennet manager max peers for scaling 2 this can t happen by accident logger error this we received locs length locations from source to string that should not happen possible attack source force disconnect true return true else a few extra can happen by accident just use the first 20 logger normal this too many locations from source to string locs length could be an accident using the first opennet manager max peers for scaling double first locs new double opennet manager max peers for scaling system arraycopy locs 0 first locs 0 opennet manager max peers for scaling locs first locs we are on darknet and we trust our peers or we are on opennet and the amount of locations sent to us seems reasonable source update location new loc locs return true if source is routable return false if logdebug logger debug this not routable if spec dmt fnp networkid source handlefnp networkid m return true else if spec dmt fnp swap request return node lm handle swap request m source else if spec dmt fnp swap reply return node lm handle swap reply m source else if spec dmt fnp swap rejected return node lm handle swap rejected m source else if spec dmt fnp swap commit return node lm handle swap commit m source else if spec dmt fnp swap complete return node lm handle swap complete m source else if spec dmt fnpchk data request return handle data request m source false else if spec dmt fnpssk data request return handle data request m source true else if spec dmt fnp insert request return handle insert request m source false else if spec dmt fnpssk insert request return handle insert request m source true else if spec dmt fnpssk insert request new return handle insert request m source true else if spec dmt fnprh probe request return handle probe request m source else if spec dmt fnp routed ping return handle routed m source else if spec dmt fnp routed pong return handle routed reply m else if spec dmt fnp routed rejected return handle routed rejected m fixme implement threaded probe requests of various kinds old probe request code was a major pain never really worked we should have threaded probe requests for simple code and one for each routing strategy else if spec dmt fnp probe request return handle probe request m source else if spec dmt fnp probe reply return handle probe reply m source else if spec dmt fnp probe rejected return handle probe rejected m source else if spec dmt fnp probe trace return handle probe trace m source else if spec dmt fnp offer key return handle offer key m source else if spec dmt fnp get offered key return handle get offered key m source return false handlemessage peernode peernode getsource messagetype getspec fnpping fnppong createfnppong getint ping_seqno sendasync pingcounter notconnectedexception fnpstoresecret handlestoresecret fnpsecretping handlesecretping fnpdetectedipaddress getobject external_address setremotedetectedpeer ipdetector redetectaddress fnptime handletime fnpuptime handleuptime fnpsentpackets handlesentpackets fnpvoid fnpdisconnect handledisconnect nodetonodemessage receivednodetonodemessage uomannounce isrealconnection nodeupdater handleannounce uomrequestrevocation isrealconnection nodeupdater handlerequestrevocation uomsendingrevocation isrealconnection nodeupdater handlesendingrevocation uomrequestmain isrealconnection nodeupdater handlerequestjar uomrequestextra isrealconnection nodeupdater handlerequestjar uomsendingmain isrealconnection nodeupdater handlesendingmain uomsendingextra isrealconnection nodeupdater handlesendingext fnpopennetannouncerequest handleannouncerequest fnproutingstatus darknetpeernode getboolean routing_enabled darknetpeernode setroutingstatus isrealconnection fnplocchangenotificationnew newloc getdouble shortbuffer shortbuffer getobject peer_locations bytestodoubles getdata opennetmanager max_peers_for_scaling isopennet opennetmanager max_peers_for_scaling tostring forcedisconnect tostring opennetmanager max_peers_for_scaling firstlocs opennetmanager max_peers_for_scaling firstlocs opennetmanager max_peers_for_scaling firstlocs updatelocation newloc isroutable fnpnetworkid handlefnpnetworkid fnpswaprequest handleswaprequest fnpswapreply handleswapreply fnpswaprejected handleswaprejected fnpswapcommit handleswapcommit fnpswapcomplete handleswapcomplete fnpchkdatarequest handledatarequest fnpsskdatarequest handledatarequest fnpinsertrequest handleinsertrequest fnpsskinsertrequest handleinsertrequest fnpsskinsertrequestnew handleinsertrequest fnprhproberequest handleproberequest fnproutedping handlerouted fnproutedpong handleroutedreply fnproutedrejected handleroutedrejected fnpproberequest handleproberequest fnpprobereply handleprobereply fnpproberejected handleproberejected fnpprobetrace handleprobetrace fnpofferkey handleofferkey fnpgetofferedkey handlegetofferedkey private boolean handle uptime message m peer node source byte uptime m get byte dmt uptime percent 48h source set uptime uptime return true handleuptime peernode getbyte uptime_percent_48h setuptime private boolean handle offer key message m peer node source key key key m get object dmt key byte authenticator short buffer m get object dmt offer authenticator get data node failure table on offer key source authenticator return true handleofferkey peernode getobject shortbuffer getobject offer_authenticator getdata failuretable onoffer private boolean handle get offered key message m peer node source key key key m get object dmt key byte authenticator short buffer m get object dmt offer authenticator get data long uid m get long dmt uid if hmac verify withsha256 node failure table offer authenticator key key get full key authenticator logger error this invalid offer request from source authenticator did not verify try source send async dmt createfnp get offered key invalid uid dmt get offered key rejected bad authenticator null node failure table sender counter catch not connected exception e too bad return true if logminor logger minor this valid get offered key for key from source do we want it we can reject overload if we don t have the bandwidth boolean isssk key instanceof nodessk offer reply tag tag new offer reply tag isssk node lockuid uid isssk false true false tag boolean need pub key try need pub key m get boolean dmt need pub key string reject node stats should reject request true false isssk false true source if reject null logger normal this rejecting fnp get offered key from source for key reject message rejected dmt createfnp rejected overload uid true try source send async rejected null node failure table sender counter catch not connected exception e logger normal this rejecting overload data request from source get peer e node unlockuid uid isssk false false true false tag return true catch error e node unlockuid uid isssk false false true false tag throw e catch runtime exception e node unlockuid uid isssk false false true false tag throw e otherwise send offered key is responsible for unlocking accept it try node failure table send offered key key isssk need pub key uid source tag catch not connected exception e too bad return true handlegetofferedkey peernode getobject shortbuffer getobject offer_authenticator getdata getlong verifywithsha256 failuretable offerauthenticatorkey getfullkey sendasync createfnpgetofferedkeyinvalid get_offered_key_rejected_bad_authenticator failuretable sendercounter notconnectedexception getofferedkey rejectoverload offerreplytag offerreplytag needpubkey needpubkey getboolean need_pub_key nodestats shouldrejectrequest fnpgetofferedkey createfnprejectedoverload sendasync failuretable sendercounter notconnectedexception getpeer runtimeexception sendofferedkey failuretable sendofferedkey needpubkey notconnectedexception private void handle disconnect final message m final peer node source must run on the packet sender thread as it sends a packet directly node get ticker queue timed job new fast runnable public void run send the ack source send any urgent notifications true finish disconnect m source 0 handledisconnect peernode getticker queuetimedjob fastrunnable sendanyurgentnotifications finishdisconnect node get ticker queue timed job new fast runnable public void run send the ack source send any urgent notifications true finish disconnect m source getticker queuetimedjob fastrunnable sendanyurgentnotifications finishdisconnect private void finish disconnect final message m final peer node source source disconnected true true if true remove from active routing table likely to be down for a while otherwise just dump all current connection state and keep trying to connect boolean remove m get boolean dmt remove if remove node peers disconnect source false false false if true purge all references to this node otherwise we can keep the node around in secondary tables etc in order to more easily reconnect later mostly used on opennet boolean purge m get boolean dmt purge if purge opennet manager om node get opennet if om null om purge old opennet peer source process parting message int type m get int dmt node to node message type short buffer message data short buffer m get object dmt node to node message data if message data get length 0 return node received node to node message source type message data true finishdisconnect peernode getboolean getboolean opennetmanager getopennet purgeoldopennetpeer getint node_to_node_message_type shortbuffer messagedata shortbuffer getobject node_to_node_message_data messagedata getlength receivednodetonodemessage messagedata private boolean handle time message m peer node source long delta m get long dmt time system current time millis source set time delta delta return true handletime peernode getlong currenttimemillis settimedelta handle an incoming fnp data request private boolean handle data request message m peer node source boolean isssk long id m get long dmt uid byte counter ctr isssk node node stats ssk request ctr node node stats chk request ctr if node recently completed id message rejected dmt createfnp rejected loop id try source send async rejected null ctr catch not connected exception e logger normal this rejecting data request loop finished e return true short htl m get short dmt htl key key key m get object dmt freenet routing key final request tag tag new request tag isssk request tag start remote if node lockuid id isssk false false false tag if logminor logger minor this could not lock id id rejecting already running message rejected dmt createfnp rejected loop id try source send async rejected null ctr catch not connected exception e logger normal this rejecting request from source get peer e node failure table on final failure key null htl 1 source return true else if logminor logger minor this locked id string reject reason node stats should reject request isssk false isssk false false source if reject reason null can accept 1 chk request every so often but not with ss ks because they aren t throttled so won t sort out bwlimit delay time which was the whole reason for accepting them when overloaded logger normal this rejecting isssk ssk chk request from source get peer preemptively because reject reason message rejected dmt createfnp rejected overload id true try source send async rejected null ctr catch not connected exception e logger normal this rejecting overload data request from source get peer e tag set rejected node unlockuid id isssk false false false false tag do not tell failure table otherwise an attacker can flood us with requests very cheaply and purge our failure table even though we didn t accept any of them return true node stats report incoming request location key to normalized double if node lockuid id return false request handler rh new request handler m source id node htl key tag node executor execute rh request handler for uid id on node get darknet port number return true fnpdatarequest handledatarequest peernode getlong bytecounter nodestats sskrequestctr nodestats chkrequestctr recentlycompleted createfnprejectedloop sendasync notconnectedexception getshort getobject freenet_routing_key requesttag requesttag requesttag createfnprejectedloop sendasync notconnectedexception getpeer failuretable onfinalfailure rejectreason nodestats shouldrejectrequest rejectreason ssks bwlimitdelaytime getpeer rejectreason createfnprejectedoverload sendasync notconnectedexception getpeer setrejected nodestats reportincomingrequestlocation tonormalizeddouble requesthandler requesthandler requesthandler getdarknetportnumber private boolean handle insert request message m peer node source boolean isssk byte counter ctr isssk node node stats ssk insert ctr node node stats chk insert ctr long id m get long dmt uid if node recently completed id message rejected dmt createfnp rejected loop id try source send async rejected null ctr catch not connected exception e logger normal this rejecting insert request from source get peer e return true insert tag tag new insert tag isssk insert tag start remote if node lockuid id isssk true false false tag if logminor logger minor this could not lock id id rejecting already running message rejected dmt createfnp rejected loop id try source send async rejected null ctr catch not connected exception e logger normal this rejecting insert request from source get peer e return true ss ks don t fix bwlimit delay time so shouldn t be accepted when overloaded string reject reason node stats should reject request isssk true isssk false false source if reject reason null logger normal this rejecting insert from source get peer preemptively because reject reason message rejected dmt createfnp rejected overload id true try source send async rejected null ctr catch not connected exception e logger normal this rejecting overload insert request from source get peer e node unlockuid id isssk true false false false tag return true long now system current time millis if m get spec equals dmt fnpssk insert request nodessk key nodessk m get object dmt freenet routing key byte data short buffer m get object dmt data get data byte headers short buffer m get object dmt block headers get data short htl m get short dmt htl ssk insert handler rh new ssk insert handler key data headers htl source id node now tag rh received bytes m received byte count node executor execute rh ssk insert handler for id on node get darknet port number else if m get spec equals dmt fnpssk insert request new nodessk key nodessk m get object dmt freenet routing key short htl m get short dmt htl ssk insert handler rh new ssk insert handler key null null htl source id node now tag rh received bytes m received byte count node executor execute rh ssk insert handler for id on node get darknet port number else chk insert handler rh new chk insert handler m source id node now tag node executor execute rh chk insert handler for id on node get darknet port number if logminor logger minor this started insert handler for id return true handleinsertrequest peernode bytecounter nodestats sskinsertctr nodestats chkinsertctr getlong recentlycompleted createfnprejectedloop sendasync notconnectedexception getpeer inserttag inserttag inserttag createfnprejectedloop sendasync notconnectedexception getpeer ssks bwlimitdelaytime rejectreason nodestats shouldrejectrequest rejectreason getpeer rejectreason createfnprejectedoverload sendasync notconnectedexception getpeer currenttimemillis getspec fnpsskinsertrequest getobject freenet_routing_key shortbuffer getobject getdata shortbuffer getobject block_headers getdata getshort sskinserthandler sskinserthandler receivedbytes receivedbytecount sskinserthandler getdarknetportnumber getspec fnpsskinsertrequestnew getobject freenet_routing_key getshort sskinserthandler sskinserthandler receivedbytes receivedbytecount sskinserthandler getdarknetportnumber chkinserthandler chkinserthandler chkinserthandler getdarknetportnumber inserthandler private boolean handle probe request message m peer node source long id m get long dmt uid if node recently completed id message rejected dmt createfnp rejected loop id try source send async rejected null node node stats probe request ctr catch not connected exception e logger normal this rejecting probe request from source get peer e return true lets not bother with full lockuid just add it to the recently completed list node completed id ss ks don t fix bwlimit delay time so shouldn t be accepted when overloaded if source should reject probe request logger normal this rejecting probe request from source get peer message rejected dmt createfnp rejected overload id true try source send async rejected null node node stats probe request ctr catch not connected exception e logger normal this rejecting overload insert request from source get peer e return true double target m get double dmt target location if target 1 0 target 0 0 logger normal this rejecting invalid target target probe request from source get peer message rejected dmt createfnp rejected overload id true try source send async rejected null node node stats probe request ctr catch not connected exception e logger normal this rejecting invalid insert request from source get peer e return true resettinghtl probe request handler start m source node target return true handleproberequest peernode getlong recentlycompleted createfnprejectedloop sendasync nodestats proberequestctr notconnectedexception getpeer ssks bwlimitdelaytime shouldrejectproberequest getpeer createfnprejectedoverload sendasync nodestats proberequestctr notconnectedexception getpeer getdouble target_location getpeer createfnprejectedoverload sendasync nodestats proberequestctr notconnectedexception getpeer resettinghtlproberequesthandler private boolean handle announce request message m peer node source long uid m get long dmt uid opennet manager om node get opennet if om null source can accept announcements message msg dmt createfnp opennet disabled uid try source send async msg null node node stats announce byte counter catch not connected exception e ok return true if node recently completed uid message msg dmt createfnp rejected loop uid try source send async msg null node node stats announce byte counter catch not connected exception e ok return true boolean success false no way to check whether it s actually running atm so lets report it to the completed list immediately fixme we should probably keep a list node completed uid try if source should accept announce uid message msg dmt createfnp rejected overload uid true try source send async msg null node node stats announce byte counter catch not connected exception e ok return true announce sender sender new announce sender m uid source om node node executor execute sender announcement sender for uid success true return true finally if success source completed announce uid handleannouncerequest peernode getlong opennetmanager getopennet canacceptannouncements createfnpopennetdisabled sendasync nodestats announcebytecounter notconnectedexception recentlycompleted createfnprejectedloop sendasync nodestats announcebytecounter notconnectedexception shouldacceptannounce createfnprejectedoverload sendasync nodestats announcebytecounter notconnectedexception announcesender announcesender completedannounce routed context message msg peer node source byte identity created time access time system current time millis this source source routed to new hash set peer node this msg msg last htl msg get short dmt htl this identity identity routedcontext peernode createdtime accesstime currenttimemillis routedto hashset peernode lasthtl getshort void add sent peer node n routed to add n addsent peernode routedto cleanup any old stale routing contexts and reschedule execution public void run long now system current time millis synchronized routed contexts iterator routed context i routed contexts values iterator while i has next routed context rc i next if now rc created time stale context i remove node get ticker queue timed job this stale context check currenttimemillis routedcontexts routedcontext routedcontexts hasnext routedcontext createdtime stale_context getticker queuetimedjob stale_context_check handle an fnp routed rejected message private boolean handle routed rejected message m long id m get long dmt uid long lid long value of id routed context rc routed contexts get lid if rc null gah logger error this unrecognized fnp routed rejected return false locally originated short htl rc last htl if rc source null htl rc source decrementhtl htl short ohtl m get short dmt htl if ohtl htl htl ohtl if htl 0 equivalent to dnf relay if rc source null try rc source send async dmt createfnp routed rejected id short 0 null node stats routed message ctr catch not connected exception e ouch logger error this unable to relay probe dnf peer disconnected rc source else try routing to the next node forward rc msg id rc source htl rc msg get double dmt target location rc rc identity return true fnproutedrejected handleroutedrejected getlong valueof routedcontext routedcontexts fnproutedrejected lasthtl getshort sendasync createfnproutedrejected nodestats routedmessagectr notconnectedexception getdouble target_location handle a routed to a specific node message param m return false if we want the message put back on the queue boolean handle routed message m peer node source if logminor logger minor this handle routed m long id m get long dmt uid long lid long value of id short htl m get short dmt htl byte identity short buffer m get object dmt node identity get data if source null htl source decrementhtl htl routed context ctx ctx routed contexts get lid if ctx null try source send async dmt createfnp routed rejected id htl null node stats routed message ctr catch not connected exception e if logminor logger minor this lost connection rejecting m return true ctx new routed context m source identity synchronized routed contexts routed contexts put lid ctx source null originated locally keep full htl double target m get double dmt target location if logminor logger minor this id id from source htl htl target target if math abs node lm get location target double min value if logminor logger minor this dispatching m get spec on node get darknet port number handle locally message type specific processing dispatch routed message m source id return true else if htl 0 message reject dmt createfnp routed rejected id short 0 if source null try source send async reject null node stats routed message ctr catch not connected exception e if logminor logger minor this lost connection rejecting m return true else return forward m id source htl target ctx identity handlerouted peernode handlerouted getlong valueof getshort shortbuffer getobject node_identity getdata routedcontext routedcontexts sendasync createfnproutedrejected nodestats routedmessagectr notconnectedexception routedcontext routedcontexts routedcontexts getdouble target_location getlocation min_value getspec getdarknetportnumber dispatchroutedmessage createfnproutedrejected sendasync nodestats routedmessagectr notconnectedexception boolean handle routed reply message m long id m get long dmt uid if logminor logger minor this got reply m long lid long value of id routed context ctx routed contexts get lid if ctx null logger error this unrecognized routed reply m return false peer node pn ctx source if pn null return false try pn send async m null node stats routed message ctr catch not connected exception e if logminor logger minor this lost connection forwarding m to pn return true handleroutedreply getlong valueof routedcontext routedcontexts peernode sendasync nodestats routedmessagectr notconnectedexception private boolean forward message m long id peer node pn short htl double target routed context ctx byte target identity if logminor logger minor this should forward forward m pre forward m htl while true peer node next node peers get by identity target identity if next null next is connected logger error this found target but disconnected next next null if next null next node peers closer peer pn ctx routed to target true node is advanced mode enabled 1 null null if logminor logger minor this next next message m if next null next is connected or at least has been next get peer cannot be null if logminor logger minor this forwarding m get spec to next get peer get port ctx add sent next try next send async m null node stats routed message ctr catch not connected exception e continue else if logminor logger minor this reached dead end for m get spec on node get darknet port number reached a dead end message reject dmt createfnp routed rejected id htl if pn null try pn send async reject null node stats routed message ctr catch not connected exception e logger error this cannot send reject message back to source pn return true return true peernode routedcontext targetidentity preforward peernode getbyidentity targetidentity isconnected closerpeer routedto isadvancedmodeenabled getpeer getspec getpeer getport addsent sendasync nodestats routedmessagectr notconnectedexception getspec getdarknetportnumber createfnproutedrejected sendasync nodestats routedmessagectr notconnectedexception prepare a routed to node message for forwarding private message pre forward message m short newhtl m set dmt htl newhtl update htl if m get spec dmt fnp routed ping int x m get int dmt counter x m set dmt counter x return m preforward getspec fnproutedping getint deal with a routed to node message that landed on this node this is where message type specific code executes param m return private boolean dispatch routed message message m peer node src long id if m get spec dmt fnp routed ping if logminor logger minor this routed ping reached other side id int x m get int dmt counter message reply dmt createfnp routed pong id x if logminor logger minor this replying counter x for id try src send async reply null node stats routed message ctr catch not connected exception e if logminor logger minor this lost connection replying to m in dispatch routed message return true return false dispatchroutedmessage peernode getspec fnproutedping routedping getint createfnproutedpong sendasync nodestats routedmessagectr notconnectedexception dispatchroutedmessage void start node stats stats this node stats stats nodestats nodestats public static string peersui ds to string long peerui ds double peer locs string builder sb new string builder peerui ds length 23 peer locs length 26 int min math min peerui ds length peer locs length for int i 0 i min i double loc peer locs i long uid peerui ds i sb append loc sb append sb append uid if i min 1 sb append if peerui ds length min for int i min i peerui ds length i sb append u sb append peerui ds i else if peer locs length min for int i min i peer locs length i sb append l sb append peer locs i return sb to string peersuidstostring peeruids peerlocs stringbuilder stringbuilder peeruids peerlocs peeruids peerlocs peerlocs peeruids peeruids peeruids peeruids peerlocs peerlocs peerlocs tostring public void start probe final double target final probe callback cb final long uid node random next long resettinghtl probe request sender rs new resettinghtl probe request sender target node maxhtl uid node node get location true null 2 0 rs add listener new resettinghtl probe request sender listener public void on completion double nearest double best short counter short unique counter short linear counter throws not connected exception cb on completed completed target best nearest uid counter unique counter linear counter public void onrnf short htl double nearest double best short counter short unique counter short linear counter throws not connected exception cb on completed rnf target best nearest uid counter unique counter linear counter public void on received reject overload double nearest double best short counter short unique counter short linear counter string reason throws not connected exception cb on reject overload public void on timeout double nearest double best short counter short unique counter short linear counter string reason throws not connected exception cb on completed timeout target best nearest uid counter unique counter linear counter public void on trace long uid double nearest double best short htl short counter short unique counter double location long myuid short buffer peer locs short buffer peerui ds short fork count short linear counter string reason long prevuid throws not connected exception cb on trace uid target nearest best htl counter location myuid fields bytes to doubles peer locs get data fields bytes to longs peerui ds get data new double 0 fork count linear counter reason prevuid rs start startprobe probecallback nextlong resettinghtlproberequestsender resettinghtlproberequestsender getlocation addlistener resettinghtlproberequestsender oncompletion uniquecounter linearcounter notconnectedexception oncompleted uniquecounter linearcounter uniquecounter linearcounter notconnectedexception oncompleted uniquecounter linearcounter onreceivedrejectoverload uniquecounter linearcounter notconnectedexception onrejectoverload ontimeout uniquecounter linearcounter notconnectedexception oncompleted uniquecounter linearcounter ontrace uniquecounter shortbuffer peerlocs shortbuffer peeruids forkcount linearcounter notconnectedexception ontrace bytestodoubles peerlocs getdata bytestolongs peeruids getdata forkcount linearcounter rs add listener new resettinghtl probe request sender listener public void on completion double nearest double best short counter short unique counter short linear counter throws not connected exception cb on completed completed target best nearest uid counter unique counter linear counter addlistener resettinghtlproberequestsender oncompletion uniquecounter linearcounter notconnectedexception oncompleted uniquecounter linearcounter public void onrnf short htl double nearest double best short counter short unique counter short linear counter throws not connected exception cb on completed rnf target best nearest uid counter unique counter linear counter uniquecounter linearcounter notconnectedexception oncompleted uniquecounter linearcounter public void on received reject overload double nearest double best short counter short unique counter short linear counter string reason throws not connected exception cb on reject overload onreceivedrejectoverload uniquecounter linearcounter notconnectedexception onrejectoverload public void on timeout double nearest double best short counter short unique counter short linear counter string reason throws not connected exception cb on completed timeout target best nearest uid counter unique counter linear counter ontimeout uniquecounter linearcounter notconnectedexception oncompleted uniquecounter linearcounter public void on trace long uid double nearest double best short htl short counter short unique counter double location long myuid short buffer peer locs short buffer peerui ds short fork count short linear counter string reason long prevuid throws not connected exception cb on trace uid target nearest best htl counter location myuid fields bytes to doubles peer locs get data fields bytes to longs peerui ds get data new double 0 fork count linear counter reason prevuid ontrace uniquecounter shortbuffer peerlocs shortbuffer peeruids forkcount linearcounter notconnectedexception ontrace bytestodoubles peerlocs getdata bytestolongs peeruids getdata forkcount linearcounter public void set hook node dispatcher callback cb this callback cb sethook nodedispatchercallback public blur filter super blur matrix blurfilter blurmatrix override public string to string return blur simple blur tostring public new reply page web interface my web interface ft own identity viewer http request request throws no such board exception no such message exception super my web interface viewer request m board m freetalk get message manager get board by name request get part as string board name board max boardname text length m parent message m freetalk get message manager get request get part as string parent messageid 128 todo adapt to maximal id length when it has been decided newreplypage webinterface mywebinterface ftownidentity httprequest nosuchboardexception nosuchmessageexception mywebinterface mboard mfreetalk getmessagemanager getboardbyname getpartasstring boardname max_boardname_text_length mparentmessage mfreetalk getmessagemanager getpartasstring parentmessageid public void make if m request is part set create reply hash set board boards new hash set board boards add m board string reply subject m request get part as string reply subject message max message title text length string reply text m request get part as string reply text message max message title text length try m freetalk get message manager post message m parent message boards m board m own identity reply subject null reply text null html node success box add content box reply created success box add child p the reply was put into your outbox freetalk will upload it after some time try we use get thread getid instead of get parent threadid because the message s thread might not have been downloaded yet success box add child new html node a href self uri show thread identity m own identity getuid board m board get name id m parent message is thread m parent message getid m parent message get thread getid go back to parent thread success box add child br catch no such message exception e logger error this should not happen e success box add child new html node a href self uri show board identity m own identity getuid name m board get name go back to m board get name catch exception e html node alert box add alert box the reply could not be created alert box add child div e get message make new reply page reply subject reply text else string subject m parent message get title if subject starts with re subject re subject make new reply page subject quoting get full quote m parent message mrequest ispartset createreply hashset hashset mboard replysubject mrequest getpartasstring replysubject max_message_title_text_length replytext mrequest getpartasstring replytext max_message_title_text_length mfreetalk getmessagemanager postmessage mparentmessage mboard mownidentity replysubject replytext htmlnode successbox addcontentbox successbox addchild getthread getparentthreadid successbox addchild htmlnode self_uri showthread mownidentity mboard getname mparentmessage isthread mparentmessage mparentmessage getthread successbox addchild nosuchmessageexception successbox addchild htmlnode self_uri showboard mownidentity mboard getname mboard getname htmlnode alertbox addalertbox alertbox addchild getmessage makenewreplypage replysubject replytext mparentmessage gettitle startswith makenewreplypage getfullquote mparentmessage private void make new reply page string reply subject string reply text html node reply box add content box new reply to m board get name html node new reply form add form child reply box self uri new reply new reply new reply form add child input new string type name value new string hidden board name m board get name new reply form add child input new string type name value new string hidden parent messageid m parent message getid html node author box new reply form add child get content box author author box add child input new string type name value new string hidden own identityid m own identity getuid author box add child b m own identity get freetalk address html node subject box new reply form add child get content box subject subject box add child input new string type name size value new string text reply subject 100 reply subject fixme find a reasonable maximal subject length and specify here and elsewhere html node text box new reply form add child get content box text text box add child textarea new string name cols rows new string reply text 80 30 reply text new reply form add child input new string type name value new string submit create reply submit makenewreplypage replysubject replytext htmlnode replybox addcontentbox mboard getname htmlnode newreplyform addformchild replybox self_uri newreply newreply newreplyform addchild boardname mboard getname newreplyform addchild parentmessageid mparentmessage htmlnode authorbox newreplyform addchild getcontentbox authorbox addchild ownidentityid mownidentity authorbox addchild mownidentity getfreetalkaddress htmlnode subjectbox newreplyform addchild getcontentbox subjectbox addchild replysubject replysubject htmlnode textbox newreplyform addchild getcontentbox textbox addchild replytext replytext newreplyform addchild createreply public static final short code 404 not found public not found pluginhttp exception string error message string location super error message location notfoundpluginhttpexception errormessage errormessage constructor for received messages public static wot message construct message list new message list freeneturi my realuri string newid wot messageuri new threaduri wot messageuri new parenturi set board new boards board new reply to board ft identity new author string new title date new date string new text list attachment new attachments throws invalid parameter exception if new message list null new boards null new author null throw new illegal argument exception if new message list get author new author throw new invalid parameter exception trying to construct a message of new author with a messagelist which belong to a different author new message list get author return new wot message calculateuri new message list newid my realuri newid new message list new threaduri new parenturi new boards new reply to board new author new title new date new text new attachments wotmessage messagelist newmessagelist myrealuri wotmessageuri newthreaduri wotmessageuri newparenturi newboards newreplytoboard ftidentity newauthor newtitle newdate newtext newattachments invalidparameterexception newmessagelist newboards newauthor illegalargumentexception newmessagelist getauthor newauthor invalidparameterexception newauthor newmessagelist getauthor wotmessage newmessagelist myrealuri newmessagelist newthreaduri newparenturi newboards newreplytoboard newauthor newtitle newdate newtext newattachments protected wot message wot messageuri newuri freeneturi new realuri string newid message list new message list wot messageuri new threaduri wot messageuri new parenturi set board new boards board new reply to board ft identity new author string new title date new date string new text list attachment new attachments throws invalid parameter exception super newuri new realuri newid new message list new threaduri new parenturi new boards new reply to board new author new title new date new text new attachments wotmessage wotmessageuri newrealuri messagelist newmessagelist wotmessageuri newthreaduri wotmessageuri newparenturi newboards newreplytoboard ftidentity newauthor newtitle newdate newtext newattachments invalidparameterexception newrealuri newmessagelist newthreaduri newparenturi newboards newreplytoboard newauthor newtitle newdate newtext newattachments public static wot messageuri calculateuri message list my message list string myid return new wot messageuri my message list geturi myid wotmessageuri messagelist mymessagelist wotmessageuri mymessagelist override public void start document state v1 state main header key null header value null startdocument v1state headerkey headervalue override public void characters char ch int start int length throws sax exception if state v1 state header inner header key null return header value append ch start length saxexception v1state header_inner headerkey headervalue override public void start element string uri string local name string q name attributes attributes throws sax exception switch state case main main start element uri local name q name attributes break case header header start element uri local name q name attributes break case header inner header inner start element uri local name q name attributes break case keywords keywords start element uri local name q name attributes break startelement localname qname saxexception mainstartelement localname qname headerstartelement localname qname header_inner headerinnerstartelement localname qname keywordsstartelement localname qname private void main start element string uri string local name string q name attributes attributes throws sax exception if main index equals local name state v1 state main else if header equals local name state v1 state header else if keywords equals local name state v1 state keywords else if prefix equals local name ignore else throw new sax exception bad tag local name in main location mainstartelement localname qname saxexception main_index localname v1state localname v1state localname v1state localname saxexception localname private void header start element string uri string local name string q name attributes attributes header key local name header value new string builder state v1 state header inner headerstartelement localname qname headerkey localname headervalue stringbuilder v1state header_inner private void header inner start element string uri string local name string q name attributes attributes throws sax exception throw new sax exception bad tag local name in header location headerinnerstartelement localname qname saxexception saxexception localname private void keywords start element string uri string local name string q name attributes attributes throws sax exception if sub index equals local name new sax exception bad tag local name in keywords location string key attributes get value key if key null key length 1 key length 32 key matches 0 9a fa f throw new sax exception bad sub index tag location key key to lower case locale us sub indice add key keywordsstartelement localname qname saxexception subindex localname saxexception localname getvalue saxexception subindex tolowercase subindice override public void end element string uri string local name string q name throws sax exception switch state case main main end element uri local name q name break case header header end element uri local name q name break case header inner header inner end element uri local name q name break case keywords keywords end element uri local name q name break endelement localname qname saxexception mainendelement localname qname headerendelement localname qname header_inner headerinnerendelement localname qname keywordsendelement localname qname private void main end element string uri string local name string q name throws sax exception if main index equals local name prefix equals local name throw new sax exception bad close tag local name in main location mainendelement localname qname saxexception main_index localname localname saxexception localname private void header end element string uri string local name string q name throws sax exception if header equals local name throw new sax exception bad close tag local name in header location state v1 state main headerendelement localname qname saxexception localname saxexception localname v1state private void header inner end element string uri string local name string q name throws sax exception if local name equals header key throw new sax exception bad close tag local name in header location header put header key header value to string header key null header value null state v1 state header headerinnerendelement localname qname saxexception localname headerkey saxexception localname headerkey headervalue tostring headerkey headervalue v1state private void keywords end element string uri string local name string q name throws sax exception if sub index equals local name ignore else if keywords equals local name state v1 state main else throw new sax exception bad close tag local name in keywords location keywordsendelement localname qname saxexception subindex localname localname v1state saxexception localname protected locator locator override public void characters char ch int start int length throws sax exception handler characters ch start length saxexception override public void set document locator locator locator this locator locator setdocumentlocator override public void start document header new hash map string string sub indice new hash set string site indice new hash set string handler null startdocument hashmap subindice hashset siteindice hashset override public void start element string uri string local name string q name attributes attributes throws sax exception if handler null version detect version uri local name q name attributes switch version case 1 handler new v1 handler break default throw new sax exception unsupported version location version handler start document handler start element uri local name q name attributes startelement localname qname saxexception detectversion localname qname v1handler saxexception startdocument startelement localname qname override public void end element string uri string local name string q name throws sax exception handler end element uri local name q name endelement localname qname saxexception endelement localname qname override public void end document throws sax exception handler end document enddocument saxexception enddocument private int detect version string uri string local name string q name attributes attributes throws sax exception if main index equals local name return 1 else throw new sax exception unknown tag location local name detectversion localname qname saxexception main_index localname saxexception localname private string location if locator null return locator get line number locator get column number else return getlinenumber getcolumnnumber public int get version return version getversion public string get header string key return header get key getheader public set string get sub indice return sub indice getsubindice subindice public set string get site indice return site indice getsiteindice siteindice public usk proxy completion callback usk usk get completion callback cb boolean persistent this usk usk this cb cb this persistent persistent uskproxycompletioncallback getcompletioncallback public void on success fetch result result client get state state object container container client context context if container null persistent container activate cb 1 container activate usk 5 context usk manager update known good usk usk suggested edition context cb on success result state container context if persistent remove from container onsuccess fetchresult clientgetstate objectcontainer clientcontext uskmanager updateknowngood suggestededition onsuccess removefrom private void remove from object container container container activate usk 5 usk remove from container container delete this removefrom objectcontainer removefrom public void on failure fetch exception e client get state state object container container client context context switch e mode case fetch exception not enough path components case fetch exception permanent redirect context usk manager update known good usk usk suggested edition context if persistent container activate cb 1 container activate usk 5 freeneturi uri e newuri if uri null uri usk turn myssk intousk uri e new fetch exception e uri cb on failure e state container context if persistent remove from container onfailure fetchexception clientgetstate objectcontainer clientcontext fetchexception not_enough_path_components fetchexception permanent_redirect uskmanager updateknowngood suggestededition turnmysskintousk fetchexception onfailure removefrom public void on block set finished client get state state object container container client context context if container null persistent container activate cb 1 cb on block set finished state container context onblocksetfinished clientgetstate objectcontainer clientcontext onblocksetfinished public void on transition client get state old state client get state new state object container container ignore ontransition clientgetstate oldstate clientgetstate newstate objectcontainer public void on expectedmime string mime object container container client context context if container null persistent container activate cb 1 cb on expectedmime mime container context onexpectedmime objectcontainer clientcontext onexpectedmime public void on expected size long size object container container client context context if container null persistent container activate cb 1 cb on expected size size container context onexpectedsize objectcontainer clientcontext onexpectedsize public void on finalized metadata object container container if container null persistent container activate cb 1 cb on finalized metadata container onfinalizedmetadata objectcontainer onfinalizedmetadata public final class own message reference extends message reference public own message reference own message my message super my message getid my message get realuri null ownmessagereference messagereference ownmessagereference ownmessage mymessage mymessage mymessage getrealuri public own message list ft own identity new author int new index super new author new index ownmessagelist ftownidentity newauthor newindex newauthor newindex get the ssk insert uri of this message list return public freeneturi get inserturi return generateuri ft own identity m author get inserturi m index ssk forusk getinserturi ftownidentity mauthor getinserturi mindex sskforusk add an code own message code to this code message list code this function synchronizes on the code message list code and the given message throws exception if the message list is full public synchronized void add message wot own message new message throws exception synchronized new message if i am being inserted i was inserted throw new illegal argument exception trying to add a message to a message list which is already being inserted if new message get author m author throw new illegal argument exception trying to add a message with wrong author new message get author to an own message list of m author own message reference ref new own message reference new message m messages add ref if m messages size 1 fits into container false m messages remove ref throw new exception own message list is full todo chose a better exception new message set message list this store ownmessage messagelist messagelist addmessage wotownmessage newmessage newmessage iambeinginserted iwasinserted illegalargumentexception newmessage getauthor mauthor illegalargumentexception newmessage getauthor mauthor ownmessagereference ownmessagereference newmessage mmessages mmessages fitsintocontainer mmessages ownmessagelist newmessage setmessagelist public synchronized int get message count return m messages size getmessagecount mmessages protected abstract boolean fits into container fitsintocontainer protected abstract boolean fits into container public synchronized void begin of insert i am being inserted true store fitsintocontainer beginofinsert iambeinginserted public synchronized void cancel insert if i was inserted throw new runtime exception the own message list was already inserted i am being inserted false store cancelinsert iwasinserted runtimeexception ownmessagelist iambeinginserted public synchronized boolean was inserted return i was inserted wasinserted iwasinserted public synchronized void mark as inserted i was inserted true store markasinserted iwasinserted constructs a new jar class loader that loads classes from the jar file with the given name in the local file system param file name the name of the jar file throws io exception if an i o error occurs public jar class loader string file name throws io exception this new file file name filename ioexception jarclassloader filename ioexception filename constructs a new jar class loader that loads classes from the specified url param file url the url to load the jar file from param length the length of the jar file if known code 1 code otherwise throws io exception if an i o error occurs public jar class loader url file url long length throws io exception copy file to temp file url open stream length fileurl ioexception jarclassloader fileurl ioexception copyfiletotemp fileurl openstream constructs a new jar class loader that loads classes from the specified file param file the file to load classes from throws io exception if an i o error occurs public jar class loader file file throws io exception temp jar file new jar file file ioexception jarclassloader ioexception tempjarfile jarfile copies the contents of the input stream which are supposed to be the contents of a jar file to a temporary location param input stream the input stream to read from param length the length of the stream if known code 1 code if the length is not known throws io exception if an i o error occurs private void copy file to temp input stream input stream long length throws io exception file temp file file create temp file jar tmp file output stream file output stream new file output stream temp file file util copy input stream file output stream length file output stream close temp file delete on exit temp jar file new jar file temp file inputstream ioexception copyfiletotemp inputstream inputstream ioexception tempfile createtempfile fileoutputstream fileoutputstream fileoutputstream tempfile fileutil inputstream fileoutputstream fileoutputstream tempfile deleteonexit tempjarfile jarfile tempfile inherit doc p this method searches the temporary copy of the jar file for an entry that is specified by the given class name see java lang class loader find class java lang string override protected class find class string name throws class not found exception try string path name transform name name jar entry jar entry temp jar file get jar entry path name if jar entry null long size jar entry get size input stream jar entry input stream temp jar file get input stream jar entry byte array output stream class bytes output stream new byte array output stream int size file util copy jar entry input stream class bytes output stream size class bytes output stream close jar entry input stream close byte class bytes class bytes output stream to byte array class clazz define class name class bytes 0 class bytes length return clazz throw new class not found exception could not find jar entry for class name catch io exception e throw new class not found exception e get message e inheritdoc classloader findclass findclass classnotfoundexception pathname transformname jarentry jarentry tempjarfile getjarentry pathname jarentry jarentry getsize inputstream jarentryinputstream tempjarfile getinputstream jarentry bytearrayoutputstream classbytesoutputstream bytearrayoutputstream fileutil jarentryinputstream classbytesoutputstream classbytesoutputstream jarentryinputstream classbytes classbytesoutputstream tobytearray defineclass classbytes classbytes classnotfoundexception ioexception classnotfoundexception getmessage inherit doc see java lang class loader find resource java lang string override protected url find resource string name compatibility code remove when all plugins are fixed if name starts with name name substring 1 try return new url jar new file temp jar file get name touri tourl name catch malformedurl exception e return null inheritdoc classloader findresource findresource startswith tempjarfile getname malformedurlexception transforms the class name into a file name that can be used to locate an entry in the jar file param name the name of the class return the path name of the entry in the jar file private string transform name string name return name replace class transformname public void close throws io exception temp jar file close ioexception tempjarfile private static class item public item string string2 this string string2 public string counter map new hash map string item stringcounter hashmap public synchronized void inc string string item item map get string if item null item new item string item counter 1 map put string item else item counter public int get string string item item map get string if item null return 0 return item counter private synchronized item items return map values to array new item map size toarray private synchronized item sorted items final boolean ascending item items items arrays sort items new comparator item public int compare item it0 item it1 int ret if it0 counter it1 counter ret 1 else if it0 counter it1 counter ret 1 else ret it0 string compare to it1 string if ascending ret ret return ret return items sorteditems compareto arrays sort items new comparator item public int compare item it0 item it1 int ret if it0 counter it1 counter ret 1 else if it0 counter it1 counter ret 1 else ret it0 string compare to it1 string if ascending ret ret return ret compareto public string to long string item items sorted items false string builder sb new string builder for int i 0 i items length i if i 0 sb append n item it items i sb append it string sb append t sb append it counter return sb to string tolongstring sorteditems stringbuilder stringbuilder tostring public int to table rows html node table item items sorted items false for int i 0 i items length i item it items i html node row table add child tr row add child td integer to string it counter u00a0 row add child td it string return items length totablerows htmlnode sorteditems htmlnode addchild addchild tostring addchild construct a shadow filter public shadow filter shadowfilter shadowfilter construct a shadow filter param radius the radius of the shadow param x offset the x offset of the shadow param y offset the y offset of the shadow param opacity the opacity of the shadow public shadow filter float radius float x offset float y offset float opacity this radius radius this angle float math atan2 y offset x offset this distance float math sqrt x offset x offset y offset y offset this opacity opacity shadowfilter xoffset yoffset shadowfilter xoffset yoffset yoffset xoffset xoffset xoffset yoffset yoffset specifies the angle of the shadow param angle the angle of the shadow angle see get angle public void set angle float angle this angle angle getangle setangle returns the angle of the shadow return the angle of the shadow see set angle public float get angle return angle setangle getangle set the distance of the shadow param distance the distance see get distance public void set distance float distance this distance distance getdistance setdistance get the distance of the shadow return the distance see set distance public float get distance return distance setdistance getdistance set the radius of the kernel and hence the amount of blur the bigger the radius the longer this filter will take param radius the radius of the blur in pixels see get radius public void set radius float radius this radius radius getradius setradius get the radius of the kernel return the radius see set radius public float get radius return radius setradius getradius set the opacity of the shadow param opacity the opacity see get opacity public void set opacity float opacity this opacity opacity getopacity setopacity get the opacity of the shadow return the opacity see set opacity public float get opacity return opacity setopacity getopacity set the color of the shadow param shadow color the color see get shadow color public void set shadow color int shadow color this shadow color shadow color shadowcolor getshadowcolor setshadowcolor shadowcolor shadowcolor shadowcolor get the color of the shadow return the color see set shadow color public int get shadow color return shadow color setshadowcolor getshadowcolor shadowcolor set whether to increase the size of the output image to accomodate the shadow param add margins true to add margins see get add margins public void set add margins boolean add margins this add margins add margins addmargins getaddmargins setaddmargins addmargins addmargins addmargins get whether to increase the size of the output image to accomodate the shadow return true to add margins see set add margins public boolean get add margins return add margins setaddmargins getaddmargins addmargins set whether to only draw the shadow without the original image param shadow only true to only draw the shadow see get shadow only public void set shadow only boolean shadow only this shadow only shadow only shadowonly getshadowonly setshadowonly shadowonly shadowonly shadowonly get whether to only draw the shadow without the original image return true to only draw the shadow see set shadow only public boolean get shadow only return shadow only setshadowonly getshadowonly shadowonly override public rectangle2d get bounds2d buffered image src rectangle r new rectangle 0 0 src get width src get height if add margins float x offset distance float math cos angle float y offset distance float math sin angle r width int math abs x offset 2 radius r height int math abs y offset 2 radius return r getbounds2d bufferedimage getwidth getheight addmargins xoffset yoffset xoffset yoffset override public point2d get point2d point2d src pt point2d dst pt if dst pt null dst pt new point2d double if add margins float x offset distance float math cos angle float y offset distance float math sin angle float top shadow math max 0 radius y offset float left shadow math max 0 radius x offset dst pt set location src pt getx left shadow src pt gety top shadow else dst pt set location src pt getx src pt gety return dst pt getpoint2d srcpt dstpt dstpt dstpt addmargins xoffset yoffset topshadow yoffset leftshadow xoffset dstpt setlocation srcpt leftshadow srcpt topshadow dstpt setlocation srcpt srcpt dstpt public buffered image filter buffered image src buffered image dst int width src get width int height src get height if dst null if add margins color model cm src get color model dst new buffered image cm cm create compatible writable raster src get width src get height cm is alpha premultiplied null else dst create compatible dest image src null float shadowr shadow color 16 0xff 255f float shadowg shadow color 8 0xff 255f float shadowb shadow color 0xff 255f make a black mask from the image s alpha channel float extract alpha 0 0 0 shadowr 0 0 0 shadowg 0 0 0 shadowb 0 0 0 opacity buffered image shadow new buffered image width height buffered image type int argb new band combine op extract alpha null filter src get raster shadow get raster shadow new gaussian filter radius filter shadow null float x offset distance float math cos angle float y offset distance float math sin angle graphics2d g dst create graphics g set composite alpha composite get instance alpha composite src over opacity if add margins float radius2 radius 2 float top shadow math max 0 radius y offset float left shadow math max 0 radius x offset g translate top shadow left shadow g draw rendered image shadow affine transform get translate instance x offset y offset if shadow only g set composite alpha composite src over g draw rendered image src null g dispose return dst bufferedimage bufferedimage bufferedimage getwidth getheight addmargins colormodel getcolormodel bufferedimage createcompatiblewritableraster getwidth getheight isalphapremultiplied createcompatibledestimage shadowcolor shadowcolor shadowcolor extractalpha bufferedimage bufferedimage bufferedimage type_int_argb bandcombineop extractalpha getraster getraster gaussianfilter xoffset yoffset creategraphics setcomposite alphacomposite getinstance alphacomposite src_over addmargins topshadow yoffset leftshadow xoffset topshadow leftshadow drawrenderedimage affinetransform gettranslateinstance xoffset yoffset shadowonly setcomposite alphacomposite srcover drawrenderedimage override public string to string return stylize drop shadow tostring connects to a fcp server and adds a reference param args public static void main string args if args length 1 system err println please provide a file name as the first argument system exit 1 final file reference new file args 0 if reference null reference is file reference can read system err println please provide a file name as the first argument system exit 1 new add ref reference isfile canread addref add ref file reference socket fcp socket null fcp message fcpm simple field set sfs new simple field set true try fcp socket new socket 127 0 0 1 fcp server default fcp port fcp socket set so timeout 2000 input stream is fcp socket get input stream line reading input stream lis new line reading input stream is output stream os fcp socket get output stream try sfs put single name add ref sfs put single expected version 2 0 fcpm fcp message create client hello sfs fcpm send os os flush string message name lis read line 128 128 true sfs get message lis fcpm fcp message create message name sfs if fcpm null fcpm instanceof node hello message system err println not a valid fred node system exit 1 catch message invalid exception me me print stack trace try sfs simple field set read from reference false true fcpm fcp message create add peer name sfs fcpm send os os flush todo we ought to do stricter checking fixme some checks even catch message invalid exception me system err println invalid reference file me me print stack trace lis close is close os close fcp socket close system out println that reference has been added catch socket exception se system err println se se print stack trace system exit 1 catch io exception ioe system err println ioe ioe print stack trace system exit 2 finally try thread sleep 3000 catch interrupted exception e addref fcpsocket fcpmessage simplefieldset simplefieldset fcpsocket fcpserver default_fcp_port fcpsocket setsotimeout inputstream fcpsocket getinputstream linereadinginputstream linereadinginputstream outputstream fcpsocket getoutputstream putsingle addref putsingle expectedversion fcpmessage clienthello messagename readline getmessage fcpmessage messagename nodehellomessage messageinvalidexception printstacktrace simplefieldset readfrom fcpmessage addpeer messageinvalidexception printstacktrace fcpsocket socketexception printstacktrace ioexception printstacktrace interruptedexception protected simple field set get message line reading input stream lis simple field set sfs new simple field set true try while lis available 0 string line lis read line 128 128 true int index line index of if index 1 line starts with end return sfs sfs put single line substring 0 index line substring index 1 catch io exception e return sfs return sfs simplefieldset getmessage linereadinginputstream simplefieldset simplefieldset readline indexof startswith putsingle ioexception mime type string type string ext string extra types string extra exts boolean safe to read boolean safe to write content data filter read filter content data filter write filter boolean dangerous links boolean dangerous inlines boolean dangerous scripting boolean dangerous read metadata boolean dangerous write metadata boolean dangerous to write even with filter string read description string write description boolean takesa charset string default charset charset extractor charset extractor this primary mime type type this primary extension ext this alternate mime types extra types this alternate extensions extra exts this safe to read safe to read this safe to write safe to write this read filter read filter this write filter write filter this dangerous links dangerous links this dangerous inlines dangerous inlines this dangerous scripting dangerous scripting this dangerous read metadata dangerous read metadata this dangerous write metadata dangerous write metadata this dangerous to write even with filter dangerous to write even with filter this read description read description this write description write description this takesa charset takesa charset this default charset default charset this charset extractor charset extractor mimetype extratypes extraexts safetoread safetowrite contentdatafilter readfilter contentdatafilter writefilter dangerouslinks dangerousinlines dangerousscripting dangerousreadmetadata dangerouswritemetadata dangeroustowriteevenwithfilter readdescription writedescription takesacharset defaultcharset charsetextractor charsetextractor primarymimetype primaryextension alternatemimetypes extratypes alternateextensions extraexts safetoread safetoread safetowrite safetowrite readfilter readfilter writefilter writefilter dangerouslinks dangerouslinks dangerousinlines dangerousinlines dangerousscripting dangerousscripting dangerousreadmetadata dangerousreadmetadata dangerouswritemetadata dangerouswritemetadata dangeroustowriteevenwithfilter dangeroustowriteevenwithfilter readdescription readdescription writedescription writedescription takesacharset takesacharset defaultcharset defaultcharset charsetextractor charsetextractor throw an exception indicating that this is a dangerous content type public void throw unsafe content type exception throws known unsafe content type exception throw new known unsafe content type exception this throwunsafecontenttypeexception knownunsafecontenttypeexception knownunsafecontenttypeexception occurrence constructor param word lowercased word param position offset of word from the beginning of document text param kind word occurrence kind should be less than 8 public occurrence string word int position int kind this word word this position position this kind kind public int compare to object o occurrence occ occurrence o int diff word compare to occ word if diff 0 diff position occ position return diff compareto compareto public bump filter super emboss matrix bumpfilter embossmatrix override public string to string return blur emboss edges tostring return random chinese text public string get text return simplified chinese texts new random next int simplified chinese texts length gettext simplifiedchinesetexts nextint simplifiedchinesetexts public class option format exception extends invalid config value exception private static final long serial versionuid 1 public option format exception string msg super msg optionformatexception invalidconfigvalueexception serialversionuid optionformatexception data filter exception string raw string encoded string explanation html node html explanation this raw title raw this encoded title encoded this explanation explanation this html explanation html explanation datafilterexception htmlnode htmlexplanation rawtitle encodedtitle htmlexplanation htmlexplanation override public string get explanation return explanation getexplanation override public html node gethtml explanation return html explanation htmlnode gethtmlexplanation htmlexplanation override public string gethtml encoded title return encoded title gethtmlencodedtitle encodedtitle override public string get raw title return raw title getrawtitle rawtitle override public string to string return raw title tostring rawtitle public block receiver message core usm peer context sender long uid partially received block prb byte counter ctr ticker ticker boolean do too long sender sender prb prb uid uid usm usm ctr ctr ticker ticker dotoolong do too long blockreceiver messagecore peercontext partiallyreceivedblock bytecounter dotoolong _sender _prb _uid _usm _ctr _ticker _dotoolong dotoolong public void send aborted int reason string desc throws not connected exception usm send sender dmt create send aborted uid reason desc ctr sent aborted true sendaborted notconnectedexception _usm _sender createsendaborted _uid _ctr sentaborted public byte receive throws retrieval exception long start time system current time millis if dotoolong ticker queue timed job new runnable public void run if sender is connected return try if prb all received return catch aborted exception e return logger error this transfer took too long uid from sender synchronized block receiver this took too long true sender transfer failed took too long still running too long timeout int consecutive missing packet reports 0 try message filter mf packet transmit message filter create set timeout receipt timeout set type dmt packet transmit set field dmt uid uid set source sender message filter mf all sent message filter create set timeout receipt timeout set type dmt all sent set field dmt uid uid set source sender message filter mf send aborted message filter create set timeout receipt timeout set type dmt send aborted set field dmt uid uid set source sender message filter relevant messages mf packet transmit or mf all sent or mf send aborted while prb all received message m1 try m1 usm wait for relevant messages ctr if sender is connected throw new disconnected exception catch disconnected exception e1 logger normal this disconnected during receive uid from sender prb abort retrieval exception sender disconnected disconnected during receive throw new retrieval exception retrieval exception sender disconnected if logminor logger minor this received m1 if m1 null m1 get spec equals dmt send aborted string desc m1 get string dmt description if desc index of upstream 0 desc upstream transmit error desc prb abort m1 get int dmt reason desc synchronized this sender aborted true throw new retrieval exception m1 get int dmt reason desc if m1 null m1 get spec equals dmt packet transmit consecutive missing packet reports 0 packet transmit received int packet no m1 get int dmt packet no bit array sent bit array m1 get object dmt sent buffer data buffer m1 get object dmt data prb add packet packet no data remove it from rrmp if its in there recentlyreportedmissingpackets remove packet no check that we have what the sender thinks we have linked list integer missing new linked list integer for int x 0 x sent get size x if sent bit at x prb is received x sender thinks we have a block which we don t but have we already re requested it recently long resend time recentlyreportedmissingpackets get x if resend time null system current time millis resend time long value make a note of the earliest time we should resend this based on the number of other packets we are already waiting for long resend wait system current time millis max round trip time recentlyreportedmissingpackets size max send interval recentlyreportedmissingpackets put x resend wait missing add x if logminor logger minor this missing missing size if missing size 0 message mn dmt create missing packet notification uid missing usm send sender mn ctr consecutive missing packet reports if missing size 50 logger normal this excessive packet loss mn if m1 null m1 get spec equals dmt all sent if consecutive missing packet reports max consecutive missing packet reports prb abort retrieval exception sender died sender unresponsive to resend requests throw new retrieval exception retrieval exception sender died sender unresponsive to resend requests linked list integer missing new linked list integer for int x 0 x prb get num packets x if prb is received x missing add x message mn dmt create missing packet notification uid missing usm send sender mn ctr consecutive missing packet reports if missing size 50 logger normal this sending large missing packet notification due to packet receiver timeout after receipt timeout ms usm send sender dmt create all received uid ctr discard end time system current time millis cleanup timeout discard filter relevant messages maybe reset discard filter long end time system current time millis long transfer time end time start time if logminor synchronized avg time taken avg time taken report transfer time logger minor this block transfer took transfer time ms average is avg time taken return prb get block catch not connected exception e throw new retrieval exception retrieval exception sender disconnected catch aborted exception e we didn t cause it logger error this caught in receive probably a bug as receive sets it e throw new retrieval exception retrieval exception unknown aborted finally try if prb is aborted sent aborted send aborted prb get abort reason prb get abort description catch not connected exception e ignore retrievalexception starttime currenttimemillis _dotoolong _ticker queuetimedjob _sender isconnected _prb allreceived abortedexception _uid _sender blockreceiver tooktoolong _sender transferfailed too_long_timeout consecutivemissingpacketreports messagefilter mfpackettransmit messagefilter settimeout receipt_timeout settype packettransmit setfield _uid setsource _sender messagefilter mfallsent messagefilter settimeout receipt_timeout settype allsent setfield _uid setsource _sender messagefilter mfsendaborted messagefilter settimeout receipt_timeout settype sendaborted setfield _uid setsource _sender messagefilter relevantmessages mfpackettransmit mfallsent mfsendaborted _prb allreceived _usm waitfor relevantmessages _ctr _sender isconnected disconnectedexception disconnectedexception _uid _sender _prb retrievalexception sender_disconnected retrievalexception retrievalexception sender_disconnected getspec sendaborted getstring indexof _prb getint senderaborted retrievalexception getint getspec packettransmit consecutivemissingpacketreports packettransmit packetno getint packet_no bitarray bitarray getobject getobject _prb addpacket packetno _recentlyreportedmissingpackets packetno linkedlist linkedlist getsize bitat _prb isreceived resendtime _recentlyreportedmissingpackets resendtime currenttimemillis resendtime longvalue resendwait currenttimemillis max_round_trip_time _recentlyreportedmissingpackets max_send_interval _recentlyreportedmissingpackets resendwait createmissingpacketnotification _uid _usm _sender _ctr consecutivemissingpacketreports getspec allsent consecutivemissingpacketreports max_consecutive_missing_packet_reports _prb retrievalexception sender_died retrievalexception retrievalexception sender_died linkedlist linkedlist _prb getnumpackets _prb isreceived createmissingpacketnotification _uid _usm _sender _ctr consecutivemissingpacketreports missingpacketnotification receipt_timeout _usm _sender createallreceived _uid _ctr discardendtime currenttimemillis cleanup_timeout discardfilter relevantmessages mayberesetdiscardfilter endtime currenttimemillis transfertime endtime starttime avgtimetaken avgtimetaken transfertime transfertime avgtimetaken _prb getblock notconnectedexception retrievalexception retrievalexception sender_disconnected abortedexception retrievalexception retrievalexception _prb isaborted sentaborted sendaborted _prb getabortreason _prb getabortdescription notconnectedexception private void maybe reset discard filter long timeleft discard end time system current time millis if timeleft 0 try discard filter set timeout int timeleft usm add async filter discard filter this catch disconnected exception e ignore mayberesetdiscardfilter discardendtime currenttimemillis discardfilter settimeout _usm addasyncfilter discardfilter disconnectedexception used to discard leftover messages usually just packet transmit and all sent all sent is quite common as the receive routine usually quits immeadiately on receiving all packets packet transmit is less common when receive requested what it thought was a missing packet only reordered public void on matched message m if logminor logger minor this discarding message post receive m maybe reset discard filter packettransmit allsent allsent packettransmit onmatched mayberesetdiscardfilter public boolean should timeout return false shouldtimeout public void on timeout ignore ontimeout public void on disconnect peer context ctx ignore ondisconnect peercontext public void on restarted peer context ctx ignore onrestarted peercontext public synchronized boolean sender aborted return sender aborted senderaborted senderaborted public notify request notifyrequest public notify request http request http req set http req notifyrequest httprequest httpreq httpreq public void setnt string value set header http nt value setheader public void setnts string value set header http nts value setheader public void setsid string id set header http sid subscription tosid header string id setheader tosidheaderstring public string getsid return subscription getsid get header value http sid getheadervalue public void setseq long value set header http seq long to string value setheader tostring public long getseq return get long header value http seq getlongheadervalue public boolean set request subscriber sub string var name string value string sid sub getsid long notify cnt sub get notify count string host sub get delivery host string path sub get delivery path int port sub get delivery port set method http notify seturi path set host host port setnt nt event setnts nts propchange setsid sid setseq notify cnt set content type xml content type node prop set node create property set node var name value set content prop set node return true setrequest varname notifycnt getnotifycount getdeliveryhost getdeliverypath getdeliveryport setmethod sethost notifycnt setcontenttype content_type propsetnode createpropertysetnode varname setcontent propsetnode private node create property set node string var name string value node prop set node new node xmlns soap delim propertyset prop set node set name space xmlns subscription xmlns node prop node new node xmlns soap delim property prop set node add node prop node thanks for giordano sassaroli sassarol cefriel it 05 22 03 node var name node new node xmlns soap delim var name node var name node new node var name var name node set value value prop node add node var name node return prop set node createpropertysetnode varname propsetnode propsetnode setnamespace propnode propsetnode addnode propnode varnamenode varname varnamenode varname varnamenode setvalue propnode addnode varnamenode propsetnode thanks for giordano sassaroli sassarol cefriel it 09 08 03 private property get property node var node property prop new property if var node null return prop remove the event namespace string variable name var node get name int index variable name last index of if index 1 variable name variable name substring index 1 prop set name variable name prop set value var node get value return prop getproperty varnode varnode variablename varnode getname variablename lastindexof variablename variablename setname variablename setvalue varnode getvalue thanks for giordano sassaroli sassarol cefriel it 09 08 03 public property list get property list property list properties new property list node var set node get envelope node for int i 0 i var set node getn nodes i node prop node var set node get node i if prop node null continue property prop get property prop node get node 0 properties add prop return properties propertylist getpropertylist propertylist propertylist varsetnode getenvelopenode varsetnode getnnodes propnode varsetnode getnode propnode getproperty propnode getnode public get plugin info simple field set fs throws message invalid exception identifier fs get identifier optional detailed fields string to bool fs get detailed false plugname fs get plugin name if plugname null throw new message invalid exception protocol error message missing field get plugin info must contain a plugin name field null false getplugininfo simplefieldset messageinvalidexception stringtobool pluginname messageinvalidexception protocolerrormessage missing_field getplugininfo pluginname override public simple field set get field set return new simple field set true simplefieldset getfieldset simplefieldset override public string get name return name getname override public void run fcp connection handler handler node node throws message invalid exception if detailed handler has full access throw new message invalid exception protocol error message access denied get plugin info detailed requires full access identifier false plugin info wrapper pi node plugin manager getfcp plugin info plugname if pi null handler output handler queue new protocol error message protocol error message no such plugin false plugin plugname does not exist or is not a fcp plugin identifier false else handler output handler queue new plugin info message pi identifier detailed fcpconnectionhandler messageinvalidexception hasfullaccess messageinvalidexception protocolerrormessage access_denied getplugininfo plugininfowrapper pluginmanager getfcpplugininfo outputhandler protocolerrormessage protocolerrormessage no_such_plugin outputhandler plugininfomessage override public void remove from object container container container delete this removefrom objectcontainer static string get svn revision return svn revision getsvnrevision svnrevision public static void main string args system out println system out println svn revision system out println svnrevision public static string get marketing version return 0 4 0 beta get svn revision getmarketingversion getsvnrevision public static long get real version return version getrealversion public final static boolean is all device string value if value null return false if value equals all device true return true return value equals all device isalldevice all_device all_device public final static boolean is root device string value if value null return false if value equals root device true return true return value equals root device isrootdevice root_device root_device public final static boolean isuuid device string value if value null return false if value starts with uuid device true return true return value starts with uuid device isuuiddevice startswith uuid_device startswith uuid_device public final static boolean isurn device string value if value null return false if value starts with urn device true return true return value starts with urn device isurndevice startswith urn_device startswith urn_device public final static boolean isurn service string value if value null return false if value starts with urn service true return true return value starts with urn service isurnservice startswith urn_service startswith urn_service persistent chosen request sendable request req short prio int retry count object container container request scheduler sched client context context throws no valid blocks exception request req this prio prio this retry count retry count if req instanceof sendable get sendable get sg sendable get req fetch context ctx sg get context if container null container activate ctx 1 local request only ctx local request only cache local requests ctx cache local requests ignore store ctx ignore store else sendable insert sg sendable insert req local request only false cache local requests sg cache inserts container ignore store false blocks not started new array list persistent chosen block blocks started new array list persistent chosen block blocks finished new array list persistent chosen block this scheduler sched fill up blocks not started boolean req active container ext is active req if req active container activate req 1 list persistent chosen block candidates req make blocks this sched container context if candidates null if req active container deactivate req 1 throw new no valid blocks exception for persistent chosen block block candidates key key block key if key null sched has fetching key key block on dumped continue blocks not started add block sender req get sender container context if req active container deactivate req 1 logminor logger should log logger minor this persistentchosenrequest sendablerequest retrycount objectcontainer requestscheduler clientcontext novalidblocksexception retrycount retrycount sendableget sendableget sendableget fetchcontext getcontext localrequestonly localrequestonly cachelocalrequests cachelocalrequests ignorestore ignorestore sendableinsert sendableinsert localrequestonly cachelocalrequests cacheinserts ignorestore blocksnotstarted arraylist persistentchosenblock blocksstarted arraylist persistentchosenblock blocksfinished arraylist persistentchosenblock blocksnotstarted reqactive isactive reqactive persistentchosenblock makeblocks reqactive novalidblocksexception persistentchosenblock hasfetchingkey ondumped blocksnotstarted getsender reqactive shouldlog void on finished persistent chosen block block client context context logminor logger should log logger minor this if logminor logger minor this on finished on this for block new exception debug synchronized this remove by pointer for int i 0 i blocks not started size i if blocks not started get i block blocks not started remove i logger error this block finished but was in blocks not started block for this new exception error i for int i 0 i blocks started size i if blocks started get i block blocks started remove i i for persistent chosen block cmp blocks finished if cmp block logger error this block already in blocks finished block for this return blocks finished add block if blocks not started is empty blocks started is empty if logminor logger minor this not finishing yet blocks not started blocks not started size started blocks started size finished blocks finished size return all finished context job runner queue new db job public void run object container container client context context finish container context false false native thread norm priority 1 false onfinished persistentchosenblock clientcontext shouldlog onfinished blocksnotstarted blocksnotstarted blocksnotstarted blocksnotstarted blocksstarted blocksstarted blocksstarted persistentchosenblock blocksfinished blocksfinished blocksfinished blocksnotstarted isempty blocksstarted isempty blocksnotstarted blocksstarted blocksfinished jobrunner dbjob objectcontainer clientcontext nativethread norm_priority context job runner queue new db job public void run object container container client context context finish container context false false jobrunner dbjob objectcontainer clientcontext private void finish object container container client context context boolean dumping boolean already active if container ext is stored request if logminor logger minor this request apparently already deleted request on this scheduler remove running request request return if already active container ext is active request logger error this already activated request new exception debug if already active container activate request 1 logger normal this finishing this for request call all the callbacks persistent chosen block finished blocks int started size synchronized this if finished if blocks finished is empty okay if already active container deactivate request 1 don t remove running request because we ve already done that return else logger error this finished but blocks finished not empty on this new exception debug process the blocks started size blocks started size if started size 0 logger error this still waiting for callbacks on this for started size blocks wait if we set finished we have to process them now and we can t process them now because we haven t had the callbacks we don t know what the outcome will be don t remove running request because we re not finished yet return finished true finished blocks blocks finished to array new persistent chosen block blocks finished size if finished blocks length 0 if dumping logger error this no finished blocks in finish on this else if logminor logger minor this no finished blocks in finish on this remove from running requests we won t be called scheduler remove running request request if already active container deactivate request 1 return if request instanceof sendable get boolean supports bulk request instanceof supports bulk call failure vector bulk call failure item bulk fail items null for persistent chosen block block finished blocks if block fetch succeeded low level get exception e block failed get if supports bulk if bulk fail items null bulk fail items new vector bulk call failure item bulk fail items add new bulk call failure item e block token else sendable get request on failure e block token container context container commit db4o is read committed so we need to commit here if bulk fail items null supports bulk call failure request on failure bulk fail items to array new bulk call failure item bulk fail items size container context container commit db4o is read committed so we need to commit here else if request instanceof sendable insert container activate request 1 for persistent chosen block block finished blocks container activate block 1 if block insert succeeded sendable insert request on success block token container context container commit db4o is read committed so we need to commit here else sendable insert request on failure block failed put block token container context container commit db4o is read committed so we need to commit here scheduler remove running request request if request instanceof sendable insert more blocks may have been added because splitfile inserts do not separate retries into separate sendable insert s if container ext is active request container activate request 1 if request is empty container request is cancelled container request get scheduler context maybe add to starter queue request container null request get scheduler context wake starter if already active container deactivate request 1 objectcontainer clientcontext alreadyactive isstored removerunningrequest alreadyactive isactive alreadyactive persistentchosenblock finishedblocks startedsize blocksfinished isempty alreadyactive removerunningrequest blocksfinished startedsize blocksstarted startedsize startedsize removerunningrequest finishedblocks blocksfinished toarray persistentchosenblock blocksfinished finishedblocks removerunningrequest alreadyactive sendableget supportsbulk supportsbulkcallfailure bulkcallfailureitem bulkfailitems persistentchosenblock finishedblocks fetchsucceeded lowlevelgetexception failedget supportsbulk bulkfailitems bulkfailitems bulkcallfailureitem bulkfailitems bulkcallfailureitem sendableget onfailure bulkfailitems supportsbulkcallfailure onfailure bulkfailitems toarray bulkcallfailureitem bulkfailitems sendableinsert persistentchosenblock finishedblocks insertsucceeded sendableinsert onsuccess sendableinsert onfailure failedput removerunningrequest sendableinsert sendableinsert isactive isempty iscancelled getscheduler maybeaddtostarterqueue getscheduler wakestarter alreadyactive public chosen block grab not started random random request scheduler sched array list persistent chosen block dumped null try synchronized this while true int size blocks not started size if size 0 return null persistent chosen block ret if size 1 ret blocks not started remove 0 else ret blocks not started remove random next int size key key ret key if key null sched has fetching key key already fetching remove from list if dumped null dumped new array list persistent chosen block dumped add ret continue blocks started add ret return ret finally if dumped null for persistent chosen block block dumped block on dumped chosenblock grabnotstarted requestscheduler arraylist persistentchosenblock blocksnotstarted persistentchosenblock blocksnotstarted blocksnotstarted nextint hasfetchingkey arraylist persistentchosenblock blocksstarted persistentchosenblock ondumped public synchronized int size not started return blocks not started size sizenotstarted blocksnotstarted public void on dumped client request scheduler core core object container container boolean req already active if logminor logger minor this dumping this scheduler remove running request request boolean was started persistent chosen block blocks synchronized this blocks blocks not started to array new persistent chosen block blocks not started size blocks not started clear was started blocks started is empty for persistent chosen block block blocks block on dumped if was started if logminor logger minor this finishing immediately in on dumped as nothing pending this finish container core sched client context true req already active ondumped clientrequestschedulercore objectcontainer reqalreadyactive removerunningrequest wasstarted persistentchosenblock blocksnotstarted toarray persistentchosenblock blocksnotstarted blocksnotstarted wasstarted blocksstarted isempty persistentchosenblock ondumped wasstarted ondumped clientcontext reqalreadyactive public synchronized void prune duplicates client request scheduler sched for int i 0 i blocks not started size i persistent chosen block block blocks not started get i key key block key if key null continue if sched has fetching key key blocks not started remove i if logminor logger minor this pruned duplicate block from this i pruneduplicates clientrequestscheduler blocksnotstarted persistentchosenblock blocksnotstarted hasfetchingkey blocksnotstarted copy from the input stream of code src code to the output stream of code dest code param src param dst throws io exception public final static void copy bucket src bucket dst throws io exception output stream out dst get output stream input stream in src get input stream readable byte channel read channel channels new channel in writable byte channel write channel channels new channel out byte buffer buffer byte buffer allocate direct block size while read channel read buffer 1 buffer flip while buffer has remaining write channel write buffer buffer clear write channel close read channel close ioexception ioexception outputstream getoutputstream inputstream getinputstream readablebytechannel readchannel newchannel writablebytechannel writechannel newchannel bytebuffer bytebuffer allocatedirect block_size readchannel hasremaining writechannel writechannel readchannel public final static void zero pad bucket b long size throws io exception output stream out b get output stream initialized to zero by default byte buffer new byte 16384 long count 0 while count size long n required buffer length if n required size count n required size count out write buffer 0 int n required count n required out close zeropad ioexception outputstream getoutputstream nrequired nrequired nrequired nrequired nrequired public final static void padded copy bucket from bucket to long n bytes int block size throws io exception if n bytes block size throw new illegal argument exception n bytes block size output stream out null input stream in null try out to get output stream byte buffer new byte 16384 in from get input stream long count 0 while count n bytes long n required n bytes count if n required buffer length n required buffer length long n read in read buffer 0 int n required if n read 1 throw new io exception not enough data in source bucket out write buffer 0 int n read count n read if count block size hmmm better to just allocate a new buffer instead of explicitly zeroing the old one zero pad to block size long pad length buffer length if pad length block size n bytes pad length block size n bytes for int i 0 i pad length i buffer i 0 while count block size long n required block size count if block size count buffer length n required buffer length out write buffer 0 int n required count n required finally if in null in close if out null out close paddedcopy nbytes blocksize ioexception nbytes blocksize illegalargumentexception nbytes blocksize outputstream inputstream getoutputstream getinputstream nbytes nrequired nbytes nrequired nrequired nread nrequired nread ioexception nread nread blocksize blocksize padlength padlength blocksize nbytes padlength blocksize nbytes padlength blocksize nrequired blocksize blocksize nrequired nrequired nrequired public static bucket make buckets bucket factory bf int count int size throws io exception bucket ret new bucket count for int i 0 i count i ret i bf make bucket size return ret makebuckets bucketfactory ioexception makebucket public final static int null indices bucket array list integer list new array list integer for int i 0 i array length i if array i null list add i int ret new int list size for int i 0 i list size i ret i list get i return ret nullindices arraylist public final static int non null indices bucket array list integer list new array list integer for int i 0 i array length i if array i null list add i int ret new int list size for int i 0 i list size i ret i list get i return ret nonnullindices arraylist public final static bucket non null buckets bucket array list bucket list new array list bucket array length for int i 0 i array length i if array i null list add array i bucket ret new bucket list size return list to array ret nonnullbuckets arraylist toarray read the entire bucket in as a byte array not a good idea unless it is very small don t call if concurrent writes may be happening throws io exception if there was an error reading from the bucket throws out of memory error if it was not possible to allocate enough memory to contain the entire bucket public final static byte to byte array bucket bucket throws io exception long size bucket size if size integer max value throw new out of memory error byte data new byte int size input stream is bucket get input stream data input stream dis null try dis new data input stream is dis read fully data finally closer close dis closer close is return data ioexception outofmemoryerror tobytearray ioexception max_value outofmemoryerror inputstream getinputstream datainputstream datainputstream readfully public static int to byte array bucket bucket byte output throws io exception long size bucket size if size output length throw new illegal argument exception data does not fit in provided buffer input stream is null try is bucket get input stream int moved 0 while true if moved size return moved int x is read output moved int size moved if x 1 return moved moved x finally if is null is close tobytearray ioexception illegalargumentexception inputstream getinputstream public static bucket make immutable bucket bucket factory bucket factory byte data throws io exception return make immutable bucket bucket factory data data length makeimmutablebucket bucketfactory bucketfactory ioexception makeimmutablebucket bucketfactory public static bucket make immutable bucket bucket factory bucket factory byte data int length throws io exception bucket bucket bucket factory make bucket length output stream os bucket get output stream os write data 0 length os close bucket set read only return bucket makeimmutablebucket bucketfactory bucketfactory ioexception bucketfactory makebucket outputstream getoutputstream setreadonly public static byte hash bucket data throws io exception input stream is data get input stream try message digest md sha256 get message digest try long bucket length data size long bytes read 0 byte buf new byte 4096 while bytes read bucket length bucket length 1 int read bytes is read buf if read bytes 0 break bytes read read bytes if read bytes 0 md update buf 0 read bytes if bytes read bucket length bucket length 0 throw new eof exception if bytes read bucket length bucket length 0 throw new io exception read bytes read but bucket length bucket length on data byte retval md digest return retval finally sha256 return message digest md finally if is null is close ioexception inputstream getinputstream messagedigest getmessagedigest bucketlength bytesread bytesread bucketlength bucketlength readbytes readbytes bytesread readbytes readbytes readbytes bytesread bucketlength bucketlength eofexception bytesread bucketlength bucketlength ioexception bytesread bucketlength returnmessagedigest copy the given quantity of data from the given bucket to the given output stream throws io exception if there was an error reading from the bucket or writing to the stream public static long copy to bucket decoded data output stream os long truncate length throws io exception if truncate length 0 return 0 if truncate length 0 truncate length long max value input stream is decoded data get input stream try byte buf new byte 4096 long moved 0 while moved truncate length do not move the int inside the math min big numbers truncate to negative numbers int bytes int math min buf length truncate length moved if bytes 0 throw new illegal state exception bytes bytes truncate length truncate length moved moved bytes is read buf 0 bytes if bytes 0 if truncate length long max value break io exception io exception new io exception could not move required quantity of data in copy to bytes moved moved of truncate length unable to read from is io exception print stack trace throw io exception os write buf 0 bytes moved bytes return moved finally is close os flush outputstream ioexception copyto decodeddata outputstream truncatelength ioexception truncatelength truncatelength truncatelength max_value inputstream decodeddata getinputstream truncatelength truncatelength illegalstateexception truncatelength truncatelength truncatelength max_value ioexception ioexception ioexception copyto truncatelength ioexception printstacktrace ioexception copy data from an input stream into a bucket public static void copy from bucket bucket input stream is long truncate length throws io exception output stream os bucket get output stream byte buf new byte 4096 if truncate length 0 truncate length long max value try long moved 0 while moved truncate length do not move the int inside the math min big numbers truncate to negative numbers int bytes int math min buf length truncate length moved if bytes 0 throw new illegal state exception bytes bytes truncate length truncate length moved moved bytes is read buf 0 bytes if bytes 0 if truncate length long max value break io exception io exception new io exception could not move required quantity of data in copy from bytes moved moved of truncate length unable to read from is io exception print stack trace throw io exception os write buf 0 bytes moved bytes finally os close inputstream copyfrom inputstream truncatelength ioexception outputstream getoutputstream truncatelength truncatelength max_value truncatelength truncatelength illegalstateexception truncatelength truncatelength truncatelength max_value ioexception ioexception ioexception copyfrom truncatelength ioexception printstacktrace ioexception split the data into a series of read only bucket s param orig data the original data bucket param split size the number of bytes to put into each bucket if the passed in bucket is a file bucket will be efficiently split into read only file slice buckets otherwise new buckets are created and the data written to them note that this method will allocate a buffer of size split size param free data param persistent if true the data is persistent this method is responsible for ensuring that the returned buckets have already been stored to the database using the provided handle the point segmentedbcb s buckets have already been stored param container database handle only needed if persistent true throws io exception if there is an error creating buckets reading from the provided bucket or writing to created buckets public static bucket split bucket orig data int split size bucket factory bf boolean free data boolean persistent object container container throws io exception if orig data instanceof file bucket if free data logger error bucket tools class asked to free data when splitting a file bucket not freeing as this would clobber the split result bucket buckets file bucket orig data split split size if persistent for bucket bucket buckets bucket store to container return buckets if orig data instanceof bucket chain bucket if persistent throw new illegal argument exception splitting a bucket chain bucket but persistent true bucket chain bucket data bucket chain bucket orig data if data bucket size split size bucket buckets data get buckets if free data data clear return buckets else logger error bucket tools class incompatible split size splitting a bucket chain bucket his split size is data bucket size but mine is split size we will copy the data but this suggests a bug new exception debug if orig data instanceof segmented bucket chain bucket segmented bucket chain bucket data segmented bucket chain bucket orig data if data bucket size split size bucket buckets data get buckets if free data data clear if persistent free data data remove from container buckets have already been stored no need to store to return buckets else logger error bucket tools class incompatible split size splitting a bucket chain bucket his split size is data bucket size but mine is split size we will copy the data but this suggests a bug new exception debug long length orig data size if length long integer max value split size throw new illegal argument exception way too big length for split size int bucket count int length split size if length split size 0 bucket count if logger should log logger minor bucket tools class logger minor bucket tools class splitting bucket orig data of size length into bucket count buckets bucket buckets new bucket bucket count input stream is orig data get input stream data input stream dis null try dis new data input stream is long remaining length length byte buf new byte split size for int i 0 i bucket count i int len int math min split size remaining length bucket bucket bf make bucket len buckets i bucket dis read fully buf 0 len remaining length len output stream os bucket get output stream try os write buf 0 len finally os close finally if dis null dis close else is close if free data orig data free if persistent free data orig data remove from container if persistent for bucket bucket buckets bucket store to container return buckets origdata splitsize filebucket readonlyfileslicebuckets splitsize freedata ioexception origdata splitsize bucketfactory freedata objectcontainer ioexception origdata filebucket freedata buckettools filebucket filebucket origdata splitsize storeto origdata bucketchainbucket illegalargumentexception bucketchainbucket bucketchainbucket bucketchainbucket origdata bucketsize splitsize getbuckets freedata buckettools bucketchainbucket bucketsize splitsize origdata segmentedbucketchainbucket segmentedbucketchainbucket segmentedbucketchainbucket origdata bucketsize splitsize getbuckets freedata freedata removefrom storeto buckettools bucketchainbucket bucketsize splitsize origdata max_value splitsize illegalargumentexception splitsize bucketcount splitsize splitsize bucketcount shouldlog buckettools buckettools origdata bucketcount bucketcount inputstream origdata getinputstream datainputstream datainputstream remaininglength splitsize bucketcount splitsize remaininglength makebucket readfully remaininglength outputstream getoutputstream freedata origdata freedata origdata removefrom storeto pad a bucket with random data param old bucket param block length param bucket factory param length return the paded bucket public static bucket pad bucket old bucket int block length bucket factory bf int length throws io exception byte hash bucket tools hash old bucket bucket b bf make bucket block length mersenne twister mt new mersenne twister hash output stream os b get output stream try bucket tools copy to old bucket os length byte buf new byte 4096 for int x length x block length int remaining block length x int this cycle math min remaining buf length mt next bytes buf fixme os write buf 0 this cycle x this cycle os close os null if b size block length throw new illegal state exception the bucket s size is b size whereas it should be block length return b finally closer close os oldbucket blocklength bucketfactory oldbucket blocklength bucketfactory ioexception buckettools oldbucket makebucket blocklength mersennetwister mersennetwister outputstream getoutputstream buckettools copyto oldbucket blocklength blocklength thiscycle nextbytes thiscycle thiscycle blocklength illegalstateexception blocklength final fcp connection handler handler public plugin reply senderfcp fcp connection handler handler2 string pluginname2 string identifier2 super pluginname2 identifier2 handler handler2 fcpconnectionhandler pluginreplysenderfcp fcpconnectionhandler override public void send simple field set params bucket bucket throws plugin not found exception like in linux everthing is a file in plugintalker everything is a plugin so it throws plugin not found exception instead fcp connection errors if handler is closed throw new plugin not found exception fcp connection closed fcp plugin reply reply new fcp plugin reply pluginname identifier params bucket handler output handler queue reply simplefieldset pluginnotfoundexception pluginnotfoundexception isclosed pluginnotfoundexception fcppluginreply fcppluginreply outputhandler public buffered image create compatible dest image buffered image src color model dstcm if dstcm null dstcm src get color model return new buffered image dstcm dstcm create compatible writable raster src get width src get height dstcm is alpha premultiplied null bufferedimage createcompatibledestimage bufferedimage colormodel getcolormodel bufferedimage createcompatiblewritableraster getwidth getheight isalphapremultiplied public rectangle2d get bounds2d buffered image src return new rectangle 0 0 src get width src get height getbounds2d bufferedimage getwidth getheight public point2d get point2d point2d src pt point2d dst pt if dst pt null dst pt new point2d double dst pt set location src pt getx src pt gety return dst pt getpoint2d srcpt dstpt dstpt dstpt dstpt setlocation srcpt srcpt dstpt public rendering hints get rendering hints return null renderinghints getrenderinghints a convenience method for getting argb pixels from an image this tries to avoid the performance penalty of buffered image getrgb unmanaging the image param image a buffered image object param x the left edge of the pixel block param y the right edge of the pixel block param width the width of the pixel arry param height the height of the pixel arry param pixels the array to hold the returned pixels may be null return the pixels see setrgb public int getrgb buffered image image int x int y int width int height int pixels int type image get type if type buffered image type int argb type buffered image type int rgb return int image get raster get data elements x y width height pixels return image getrgb x y width height pixels 0 width bufferedimage bufferedimage bufferedimage gettype bufferedimage type_int_argb bufferedimage type_int_rgb getraster getdataelements a convenience method for setting argb pixels in an image this tries to avoid the performance penalty of buffered image setrgb unmanaging the image param image a buffered image object param x the left edge of the pixel block param y the right edge of the pixel block param width the width of the pixel arry param height the height of the pixel arry param pixels the array of pixels to set see getrgb public void setrgb buffered image image int x int y int width int height int pixels int type image get type if type buffered image type int argb type buffered image type int rgb image get raster set data elements x y width height pixels else image setrgb x y width height pixels 0 width bufferedimage bufferedimage bufferedimage gettype bufferedimage type_int_argb bufferedimage type_int_rgb getraster setdataelements override public object clone try return super clone catch clone not supported exception e return null clonenotsupportedexception protected key byte routing key this routing key routing key hash fields hash code routing key cached normalized double 1 routingkey routingkey routingkey hashcode routingkey cachednormalizeddouble protected key key key this hash key hash this cached normalized double key cached normalized double this routing key new byte key routing key length system arraycopy key routing key 0 routing key 0 routing key length cachednormalizeddouble cachednormalizeddouble routingkey routingkey routingkey routingkey routingkey public abstract key clone key clonekey write to disk take up exactly 22 bytes param index _index read a key from a random access file param raf the file to read from return a key or throw an exception or return null if the key is not parsable public static final key read data input raf throws io exception byte type raf read byte byte subtype raf read byte if type nodechk base type return nodechk readchk raf subtype else if type nodessk base type return nodessk readssk raf subtype throw new io exception unrecognized format type randomaccessfile datainput ioexception readbyte readbyte base_type base_type ioexception public static key block create block short key type byte key bytes byte headers bytes byte data bytes byte pubkey bytes throws key verify exception byte type byte key type 8 byte subtype byte key type 0xff if type nodechk base type return chk block construct data bytes headers bytes else if type nodessk base type dsa public key pub key try pub key new dsa public key pubkey bytes catch io exception e throw new key verify exception failed to construct pubkey e e catch crypt format exception e throw new key verify exception failed to construct pubkey e e nodessk key new nodessk pub key as bytes hash key bytes pub key subtype return new ssk block data bytes headers bytes key false else throw new key verify exception no such key type integer to hex string type keyblock createblock keytype keybytes headersbytes databytes pubkeybytes keyverifyexception keytype keytype base_type chkblock databytes headersbytes base_type dsapublickey pubkey pubkey dsapublickey pubkeybytes ioexception keyverifyexception cryptformatexception keyverifyexception pubkey asbyteshash keybytes pubkey sskblock databytes headersbytes keyverifyexception tohexstring convert the key to a double between 0 0 and 1 0 normally we will hash the key first in order to make chosen key attacks harder public synchronized double to normalized double if cached normalized double 0 return cached normalized double message digest md sha256 get message digest if routing key null throw new null pointer exception md update routing key int type get type md update byte type 8 md update byte type byte digest md digest sha256 return message digest md md null long as long math abs fields bytes to long digest math abs can actually return negative if as long long min value as long long max value cached normalized double double as long double long max value return cached normalized double tonormalizeddouble cachednormalizeddouble cachednormalizeddouble messagedigest getmessagedigest routingkey nullpointerexception routingkey gettype returnmessagedigest aslong bytestolong aslong min_value aslong max_value cachednormalizeddouble aslong max_value cachednormalizeddouble public abstract short get type gettype public abstract short get type override public int hash code return hash gettype hashcode override public boolean equals object o if o null o instanceof key return false return arrays equals routing key key o routing key routingkey routingkey static bucket decompress boolean is compressed byte output int output length bucket factory bf long max length short compression algorithm boolean short length throws chk decode exception io exception if max length 0 throw new illegal argument exception maxlength max length if is compressed if logger should log logger minor key class logger minor key class decompressing output length bytes in decode with codec compression algorithm if output length short length 3 5 throw new chk decode exception no bytes to decompress decompress first get the length int len if short length len output 0 0xff 8 output 1 0xff else len output 0 0xff 8 output 1 0xff 8 output 2 0xff 8 output 3 0xff if len max length throw new too big exception invalid precompressed size len maxlength max length compressor type decompressor compressor type get compressor by metadataid compression algorithm if decompressor null throw new chk decode exception unknown compression algorithm compression algorithm bucket input bucket new simple read only array bucket output short length 2 4 output length short length 2 4 try return decompressor decompress input bucket bf max length 1 null catch compression output size exception e throw new too big exception too big else return bucket tools make immutable bucket bf output output length iscompressed outputlength bucketfactory maxlength compressionalgorithm shortlength chkdecodeexception ioexception maxlength illegalargumentexception maxlength iscompressed shouldlog compressionalgorithm shortlength chkdecodeexception shortlength maxlength toobigexception maxlength compressor_type compressor_type getcompressorbymetadataid compressionalgorithm chkdecodeexception compressionalgorithm inputbucket simplereadonlyarraybucket shortlength outputlength shortlength inputbucket maxlength compressionoutputsizeexception toobigexception buckettools makeimmutablebucket outputlength static class compressed public compressed byte final data short compression algorithm2 this compressed data final data this compression algorithm compression algorithm2 finaldata compressionalgorithm2 compresseddata finaldata compressionalgorithm compressionalgorithm2 static compressed compress bucket source data boolean dont compress short already compressed codec long source length long max length before compression int max compressed data length boolean short length throws key encode exception io exception byte final data null short compression algorithm 1 int max compressed data length max compressed data length if short length max compressed data length 2 else max compressed data length 4 if source data size max length before compression throw new key encode exception too big if dont compress already compressed codec 0 byte cbuf null if already compressed codec 0 if source data size max compressed data length throw new too big exception too big precompressed compression algorithm already compressed codec cbuf bucket tools to byte array source data if source length max length before compression throw new too big exception too big else if source data size max compressed data length determine the best algorithm for compressor type comp compressor type values array bucket compressed data try compressed data array bucket comp compress source data new array bucket factory long max value max compressed data length catch io exception e throw new error e catch compression output size exception e continue if compressed data size max compressed data length compression algorithm comp metadataid source length source data size try cbuf bucket tools to byte array compressed data fixme provide a method in array bucket catch io exception e throw new error e break if cbuf null use it int compressed length cbuf length final data new byte compressed length short length 2 4 system arraycopy cbuf 0 final data short length 2 4 compressed length if short length final data 0 byte source length 24 0xff final data 1 byte source length 16 0xff final data 2 byte source length 8 0xff final data 3 byte source length 0xff else final data 0 byte source length 8 0xff final data 1 byte source length 0xff if final data null not compressed or not compressible no size bytes to be added if source data size max compressed data length throw new chk encode exception too big source data size should be max compressed data length final data bucket tools to byte array source data return new compressed final data compression algorithm sourcedata dontcompress alreadycompressedcodec sourcelength max_length_before_compression max_compressed_data_length shortlength keyencodeexception ioexception finaldata compressionalgorithm maxcompresseddatalength max_compressed_data_length shortlength maxcompresseddatalength maxcompresseddatalength sourcedata max_length_before_compression keyencodeexception dontcompress alreadycompressedcodec alreadycompressedcodec sourcedata maxcompresseddatalength toobigexception compressionalgorithm alreadycompressedcodec buckettools tobytearray sourcedata sourcelength max_length_before_compression toobigexception sourcedata maxcompresseddatalength compressor_type compressor_type arraybucket compresseddata compresseddata arraybucket sourcedata arraybucketfactory max_value maxcompresseddatalength ioexception compressionoutputsizeexception compresseddata maxcompresseddatalength compressionalgorithm sourcelength sourcedata buckettools tobytearray compresseddata arraybucket ioexception compressedlength finaldata compressedlength shortlength finaldata shortlength compressedlength shortlength finaldata sourcelength finaldata sourcelength finaldata sourcelength finaldata sourcelength finaldata sourcelength finaldata sourcelength finaldata sourcedata max_compressed_data_length chkencodeexception sourcedata max_compressed_data_length finaldata buckettools tobytearray sourcedata finaldata compressionalgorithm public byte get routing key return routing key getroutingkey routingkey not just the routing key enough data to reconstruct the key excluding any pubkey needed public byte get key bytes return routing key getkeybytes routingkey public static client key block create key block client key key key block block throws key verify exception if key instanceof clientssk return clientssk block construct ssk block block clientssk key else if key instanceof clientchk return new clientchk block chk block block clientchk key clientkeyblock createkeyblock clientkey keyblock keyverifyexception clientsskblock sskblock clientchkblock chkblock get the full key including any crypto type bytes everything needed to construct a key object public abstract byte get full key getfullkey public abstract byte get full key public void remove from object container container container delete this getfullkey removefrom objectcontainer returns a dsa signature given a group private key x a random nonce k and the hash of the message m static dsa signature sign dsa group g dsa private key x big integer k big integer m random source random if k signum 1 throw new illegal argument exception if m signum 1 throw new illegal argument exception if g getq bit length 256 m m and signature mask if m compare to g getq 1 throw new illegal argument exception big integer r g getg mod pow k g getp mod g getq big integer k inv k mod inverse g getq return sign g x r k inv m random dsasignature dsagroup dsaprivatekey biginteger biginteger randomsource illegalargumentexception illegalargumentexception bitlength signature_mask compareto illegalargumentexception biginteger modpow biginteger kinv modinverse kinv public static dsa signature sign dsa group g dsa private key x big integer m random source r big integer k dsa generatek g r return sign g x k m r dsasignature dsagroup dsaprivatekey biginteger randomsource biginteger returns a dsa signature given a group private key x the precalculated values of r and k 1 and the hash of the message m static dsa signature sign dsa group g dsa private key x big integer r big integer k inv big integer m random source random big integer s1 m add x getx multiply r mod g getq big integer s k inv multiply s1 mod g getq if r compare to big integer zero 0 s compare to big integer zero 0 logger normal dsa class r or s equals 0 weird behaviour detected please report if seen too often return sign g x r generatek g random m random return new dsa signature r s dsasignature dsagroup dsaprivatekey biginteger biginteger kinv biginteger randomsource biginteger biginteger kinv compareto biginteger compareto biginteger dsasignature private static big integer generatek dsa group g random r if g getq bit length dsa group q bit length throw new illegal argument exception q is too short g getq bit length dsa group q bit length big integer k do k new native big integer dsa group q bit length r while g getq compare to k 1 k compare to big integer zero 1 return k biginteger dsagroup bitlength dsagroup q_bit_length illegalargumentexception bitlength dsagroup q_bit_length biginteger nativebiginteger dsagroup q_bit_length compareto compareto biginteger verifies the message authenticity given a group the public key y a signature and the hash of the message m param force mod if enabled skip the clipping m to 255 bits public static boolean verify dsa public key kp dsa signature sig big integer m boolean force mod if m signum 1 throw new illegal argument exception if kp get group getq bit length 256 force mod m m and signature mask try 0 r q has to be true if sig getr compare to big integer zero 1 kp getq compare to sig getr 1 if logger should log logger minor dsa class logger minor dsa class r 0 r q r sig getr q kp getq return false 0 s q has to be true as well if sig gets compare to big integer zero 1 kp getq compare to sig gets 1 if logger should log logger minor dsa class logger minor dsa class s 0 s q s sig gets q kp getq return false big integer w sig gets mod inverse kp getq big integer u1 m multiply w mod kp getq big integer u2 sig getr multiply w mod kp getq big integer v1 kp getg mod pow u1 kp getp big integer v2 kp gety mod pow u2 kp getp big integer v v1 multiply v2 mod kp getp mod kp getq return v equals sig getr fixme is there a better way to handle this exception raised on the w line above catch arithmetic exception e catch error raised by invalid data if logger should log logger minor dsa class logger minor dsa class verify failed e e return false and report that that data is bad forcemod dsapublickey dsasignature biginteger forcemod illegalargumentexception getgroup bitlength forcemod signature_mask compareto biginteger compareto shouldlog compareto biginteger compareto shouldlog biginteger modinverse biginteger biginteger biginteger modpow biginteger modpow biginteger arithmeticexception shouldlog public static void main string args throws exception dsa group g dsa group read from field args 0 dsa group g global ds agroup biga yarrow y new yarrow dummy random source y new dummy random source dsa private key pk new dsa private key g y dsa public key pub new dsa public key g pk dsa signature sig sign g pk big integer zero y system err println verify pub sig big integer zero false while true long total time signing 0 long total time verifying 0 long totalr size 0 long totals size 0 long total pub key size 0 long total priv key size 0 int max priv key size 0 int max pub key size 0 int maxr size 0 int maxs size 0 int totalr unsigned bit size 0 int maxr unsigned bit size 0 random r new random y next long byte msg new byte 32 for int i 0 i 1000 i r next bytes msg big integer m new big integer 1 msg pk new dsa private key g r int priv key size pk as bytes length total priv key size priv key size if priv key size max priv key size max priv key size priv key size pub new dsa public key g pk int pub key size pub as bytes length total pub key size pub key size if pub key size max pub key size max pub key size pub key size long t1 system current time millis sig sign g pk m y long t2 system current time millis if verify pub sig m false system err println failed to verify long t3 system current time millis total time signing t2 t1 total time verifying t3 t2 int r size sig getr bit length r size r size 8 r size 8 0 0 1 totalr size r size if r size maxr size maxr size r size int r unsigned bit size sig getr bit length totalr unsigned bit size r unsigned bit size maxr unsigned bit size math max maxr unsigned bit size r unsigned bit size int s size sig gets bit length s size s size 8 s size 8 0 0 1 totals size s size if s size maxs size maxs size s size system out println total time signing total time signing system out println total time verifying total time verifying system out println total r size totalr size max maxr size system out println total s size totals size max maxs size system out println total r unsigned bitsize totalr unsigned bit size system out println total pub key size total pub key size max max pub key size system out println total priv key size total priv key size max max priv key size dsagroup dsagroup readfromfield dsagroup dsagroupbiga dummyrandomsource dummyrandomsource dsaprivatekey dsaprivatekey dsapublickey dsapublickey dsasignature biginteger biginteger totaltimesigning totaltimeverifying totalrsize totalssize totalpubkeysize totalprivkeysize maxprivkeysize maxpubkeysize maxrsize maxssize totalrunsignedbitsize maxrunsignedbitsize nextlong nextbytes biginteger biginteger dsaprivatekey privkeysize asbytes totalprivkeysize privkeysize privkeysize maxprivkeysize maxprivkeysize privkeysize dsapublickey pubkeysize asbytes totalpubkeysize pubkeysize pubkeysize maxpubkeysize maxpubkeysize pubkeysize currenttimemillis currenttimemillis currenttimemillis totaltimesigning totaltimeverifying rsize bitlength rsize rsize rsize totalrsize rsize rsize maxrsize maxrsize rsize runsignedbitsize bitlength totalrunsignedbitsize runsignedbitsize maxrunsignedbitsize maxrunsignedbitsize runsignedbitsize ssize bitlength ssize ssize ssize totalssize ssize ssize maxssize maxssize ssize totaltimesigning totaltimeverifying totalrsize maxrsize totalssize maxssize totalrunsignedbitsize totalpubkeysize maxpubkeysize totalprivkeysize maxprivkeysize private dns state string name this name name sequence add this dnsstate public final string to string return name tostring returns the next advanced state in general this advances one step in the following sequence probing 1 probing 2 probing 3 announcing 1 announcing 2 announced does not advance for announced and canceled state public final dns state advance return is probing is announcing dns state sequence get ordinal 1 this probing_1 probing_2 probing_3 announcing_1 announcing_2 dnsstate isprobing isannouncing dnsstate returns to the next reverted state all states except canceled revert to probing 1 status canceled does not revert public final dns state revert return this canceled this probing 1 probing_1 dnsstate probing_1 returns true if this is a probing state public boolean is probing return compare to probing 1 0 compare to probing 3 0 isprobing compareto probing_1 compareto probing_3 returns true if this is an announcing state public boolean is announcing return compare to announcing 1 0 compare to announcing 2 0 isannouncing compareto announcing_1 compareto announcing_2 returns true if this is an announced state public boolean is announced return compare to announced 0 isannounced compareto compares two states the states compare as follows probing 1 lt probing 2 lt probing 3 lt announcing 1 lt announcing 2 lt responding lt announced lt canceled public int compare to object o return ordinal dns state o ordinal probing_1 probing_2 probing_3 announcing_1 announcing_2 compareto dnsstate public class projection from extends i persistent to extends i persistent extends hash set to constructor of projection specified by class and field name of projected objects param type base class for selected objects param field name field name used to perform projection public projection class type string field name set projection field type field name ipersistent ipersistent hashset fieldname fieldname setprojectionfield fieldname default constructor of projection this constructor should be used only when you are going to derive your class from projection and redefine map method in it or specify type and field name later using set projection field method fieldname setprojectionfield specify class of the projected objects and projection field name param type base class for selected objects param field name field name used to perform projection public void set projection field class type string field name try field type get declared field field name field set accessible true catch exception x throw new storage error storage error key not found x fieldname setprojectionfield fieldname getdeclaredfield fieldname setaccessible storageerror storageerror key_not_found project specified selection param selection array with selected object public void project from selection for int i 0 i selection length i map selection i project specified object param obj selected object public void project from obj map obj project specified selection param selection iterator specifying selected objects public void project iterator from selection while selection has next map selection next hasnext project specified selection param c selection iterator specifying selected objects public void project collection from c for from o c map o join this projection with another projection result of this join is set of objects present in both projections public void join projection from to prj retain all prj retainall get result of preceding project and join operations return array of objects public i persistent to persistent array return i persistent to array new i persistent size ipersistent topersistentarray ipersistent toarray ipersistent reset projection clear result of preceding project and join operations public void reset clear add object to the set param obj objet to be added public boolean add to obj if obj null return super add obj return false get related objects for the object obj it is possible to redifine this method in derived classes to provide application specific mapping param obj object from the selection protected void map from obj if field null add to obj else try object o field get obj if o instanceof link object arr link o to array for int i 0 i arr length i add to arr i else if o instanceof object object arr object o for int i 0 i arr length i add to arr i else add to o catch exception x throw new storage error storage error access violation x toarray storageerror storageerror access_violation static logger register log threshold callback new log threshold callback override public void should update logminor logger should log logger minor this registerlogthresholdcallback logthresholdcallback shouldupdate shouldlog node client core node node config config sub config node config file node dir int port number int sort order simple field set old config sub config fproxy config simple toadlet server toadlets object container container throws node init exception this node node this node stats node node stats this random node random fec queue fec queue create node nodedb handle container this background block encoder new background block encoder client database executor new prioritized serial executor native thread norm priority native thread max priority 1 native thread norm priority true store checker new datastore checker node byte pwd buf new byte 16 random next bytes pwd buf compressor new real compressor node executor this form password base64 encode pwd buf alerts new user alert manager this restart jobs queue node restart jobs queue init node nodedb handle container startup database jobs restart jobs queue get early restart database jobs container if startup database jobs null startup database jobs length 0 queue startup job runner native thread high priority false restart jobs queue add late restart database jobs this container persister new configurable persister this node config client throttle file client throttle dat sort order true false node client core file for client stats node client core file for client stats long node ps node dir simple field set throttlefs persister read if logminor logger minor this read throttlefs n throttlefs if logminor logger minor this serializing request starter group from n throttlefs temp files node config register temp dir new file node dir temp port number to string sort order true true node client core temp dir node client core temp dir long new string callback override public string get return temp dir get path override public void set string val throws invalid config value exception if temp dir equals new file val return fixme throw new invalid config value exception l10n moving temp dir on the fly not supported override public boolean is read only return true temp dir new file node config get string temp dir if temp dir exists temp dir is directory temp dir mkdir string msg could not find or create temporary directory throw new node init exception node init exception exit bad temp dir msg try temp filename generator new filename generator random true temp dir temp catch io exception e string msg could not find or create temporary directory filename generator throw new node init exception node init exception exit bad temp dir msg usk manager new usk manager this persistent temp files node config register encrypt persistent temp buckets true sort order true false node client core encrypt persistent temp buckets node client core encrypt persistent temp buckets long new boolean callback override public boolean get return persistent temp bucket factory null true persistent temp bucket factory is encrypting override public void set boolean val throws invalid config value exception if get equals val persistent temp bucket factory null return persistent temp bucket factory set encryption val node config register persistent temp dir new file node dir persistent temp port number to string sort order true false node client core persistent temp dir node client core persistent temp dir long new string callback override public string get return persistent temp bucket factory get dir to string override public void set string val throws invalid config value exception if get equals val return fixme throw new invalid config value exception moving persistent temp directory on the fly not supported at present override public boolean is read only return true try file dir new file node config get string persistent temp dir string prefix freenet temp persistent temp bucket factory persistent temp bucket factory load dir prefix random node fast weak random container node nodedb handle node config get boolean encrypt persistent temp buckets this node get ticker persistent temp bucket factory init dir prefix random node fast weak random persistent filename generator persistent temp bucket factory fg catch io exception e2 string msg could not find or create persistent temporary directory e2 e2 print stack trace throw new node init exception node init exception exit bad temp dir msg node config register maxram bucket size 128 kib sort order true false node client core maxram bucket size node client core maxram bucket size long new long callback override public long get return temp bucket factory null 0 temp bucket factory get maxram bucket size override public void set long val throws invalid config value exception if get equals val temp bucket factory null return temp bucket factory set maxram bucket size val true node config register ram bucket pool size 10 mib sort order true false node client core ram bucket pool size node client core ram bucket pool size long new long callback override public long get return temp bucket factory null 0 temp bucket factory get max ram used override public void set long val throws invalid config value exception if get equals val temp bucket factory null return temp bucket factory set max ram used val true node config register encrypt temp buckets true sort order true false node client core encrypt temp buckets node client core encrypt temp buckets long new boolean callback override public boolean get return temp bucket factory null true temp bucket factory is encrypting override public void set boolean val throws invalid config value exception if get equals val temp bucket factory null return temp bucket factory set encryption val temp bucket factory new temp bucket factory node executor temp filename generator node config get long maxram bucket size node config get long ram bucket pool size random node fast weak random node config get boolean encrypt temp buckets archive manager new archive manager max archive handlers max cached archive data max archived file size max cached elements temp bucket factory healing queue new simple healing queue new insert context temp bucket factory temp bucket factory persistent temp bucket factory 0 2 1 0 0 new simple event producer node dont cache local requests request starter prefetch priority class 512 fixme make configurable client context new client context this fec queue node executor background block encoder archive manager persistent temp bucket factory temp bucket factory healing queue usk manager random node fast weak random node get ticker temp filename generator persistent filename generator compressor compressor set client context client context store checker set context client context request starters new request starter group node this port number random config throttlefs client context client context init request starters client request scheduler load key listeners container client context insert compressor load container client context node security levels add physical threat level listener new security level listener physical threat level public void on change physical threat level old level physical threat level new level if new level physical threat level low if temp bucket factory is encrypting temp bucket factory set encryption false if persistent temp bucket factory is encrypting persistent temp bucket factory set encryption false else new level physical threat level normal if temp bucket factory is encrypting temp bucket factory set encryption true if persistent temp bucket factory is encrypting persistent temp bucket factory set encryption true downloads directory node config register downloads dir downloads sort order true true node client core download dir node client core download dir long new string callback override public string get return download dir get path override public void set string val throws invalid config value exception if download dir equals new file val return file f new file val if f exists f is directory f mkdir relatively commonly used despite being advanced i e not something we want to show to newbies so translate it throw new invalid config value exception l10n could not find or create dir download dir new file val string val node config get string downloads dir download dir new file val if download dir exists download dir is directory download dir mkdir throw new node init exception node init exception exit bad downloads dir could not find or create default downloads directory downloads allowed uploads allowed node config register download allowed dirs new string all sort order true true node client core download allowed dirs node client core download allowed dirs long new string arr callback override public string get synchronized node client core this if download allowed everywhere return new string all string dirs nodeclientcore subconfig nodeconfig nodedir portnumber sortorder simplefieldset oldconfig subconfig fproxyconfig simpletoadletserver objectcontainer nodeinitexception nodestats nodestats fecqueue fecqueue nodedbhandle backgroundblockencoder backgroundblockencoder clientdatabaseexecutor prioritizedserialexecutor nativethread norm_priority nativethread max_priority nativethread norm_priority storechecker datastorechecker pwdbuf nextbytes pwdbuf realcompressor formpassword pwdbuf useralertmanager restartjobsqueue noderestartjobsqueue nodedbhandle startupdatabasejobs restartjobsqueue getearlyrestartdatabasejobs startupdatabasejobs startupdatabasejobs startupjobrunner nativethread high_priority restartjobsqueue addlaterestartdatabasejobs configurablepersister nodeconfig clientthrottlefile sortorder nodeclientcore fileforclientstats nodeclientcore fileforclientstatslong nodedir simplefieldset requeststartergroup nodeconfig tempdir nodedir portnumber tostring sortorder nodeclientcore tempdir nodeclientcore tempdirlong stringcallback tempdir getpath invalidconfigvalueexception tempdir invalidconfigvalueexception movingtempdirontheflynotsupported isreadonly tempdir nodeconfig getstring tempdir tempdir tempdir isdirectory tempdir nodeinitexception nodeinitexception exit_bad_temp_dir tempfilenamegenerator filenamegenerator tempdir ioexception nodeinitexception nodeinitexception exit_bad_temp_dir uskmanager uskmanager nodeconfig encryptpersistenttempbuckets sortorder nodeclientcore encryptpersistenttempbuckets nodeclientcore encryptpersistenttempbucketslong booleancallback persistenttempbucketfactory persistenttempbucketfactory isencrypting invalidconfigvalueexception persistenttempbucketfactory persistenttempbucketfactory setencryption nodeconfig persistenttempdir nodedir portnumber tostring sortorder nodeclientcore persistenttempdir nodeclientcore persistenttempdirlong stringcallback persistenttempbucketfactory getdir tostring invalidconfigvalueexception invalidconfigvalueexception isreadonly nodeconfig getstring persistenttempdir persistenttempbucketfactory persistenttempbucketfactory fastweakrandom nodedbhandle nodeconfig getboolean encryptpersistenttempbuckets getticker persistenttempbucketfactory fastweakrandom persistentfilenamegenerator persistenttempbucketfactory ioexception printstacktrace nodeinitexception nodeinitexception exit_bad_temp_dir nodeconfig maxrambucketsize 128kib sortorder nodeclientcore maxrambucketsize nodeclientcore maxrambucketsizelong longcallback tempbucketfactory tempbucketfactory getmaxrambucketsize invalidconfigvalueexception tempbucketfactory tempbucketfactory setmaxrambucketsize nodeconfig rambucketpoolsize 10mib sortorder nodeclientcore rambucketpoolsize nodeclientcore rambucketpoolsizelong longcallback tempbucketfactory tempbucketfactory getmaxramused invalidconfigvalueexception tempbucketfactory tempbucketfactory setmaxramused nodeconfig encrypttempbuckets sortorder nodeclientcore encrypttempbuckets nodeclientcore encrypttempbucketslong booleancallback tempbucketfactory tempbucketfactory isencrypting invalidconfigvalueexception tempbucketfactory tempbucketfactory setencryption tempbucketfactory tempbucketfactory tempfilenamegenerator nodeconfig getlong maxrambucketsize nodeconfig getlong rambucketpoolsize fastweakrandom nodeconfig getboolean encrypttempbuckets archivemanager archivemanager max_archive_handlers max_cached_archive_data max_archived_file_size max_cached_elements tempbucketfactory healingqueue simplehealingqueue insertcontext tempbucketfactory tempbucketfactory persistenttempbucketfactory simpleeventproducer dont_cache_local_requests requeststarter prefetch_priority_class clientcontext clientcontext fecqueue backgroundblockencoder archivemanager persistenttempbucketfactory tempbucketfactory healingqueue uskmanager fastweakrandom getticker tempfilenamegenerator persistentfilenamegenerator setclientcontext clientcontext storechecker setcontext clientcontext requeststarters requeststartergroup portnumber clientcontext clientcontext requeststarters clientrequestscheduler loadkeylisteners clientcontext insertcompressor clientcontext securitylevels addphysicalthreatlevellistener securitylevellistener physical_threat_level onchange physical_threat_level oldlevel physical_threat_level newlevel newlevel physical_threat_level tempbucketfactory isencrypting tempbucketfactory setencryption persistenttempbucketfactory isencrypting persistenttempbucketfactory setencryption newlevel physical_threat_level tempbucketfactory isencrypting tempbucketfactory setencryption persistenttempbucketfactory isencrypting persistenttempbucketfactory setencryption nodeconfig downloadsdir sortorder nodeclientcore downloaddir nodeclientcore downloaddirlong stringcallback downloaddir getpath invalidconfigvalueexception downloaddir isdirectory invalidconfigvalueexception couldnotfindorcreatedir downloaddir nodeconfig getstring downloadsdir downloaddir downloaddir downloaddir isdirectory downloaddir nodeinitexception nodeinitexception exit_bad_downloads_dir nodeconfig downloadalloweddirs sortorder nodeclientcore downloadalloweddirs nodeclientcore downloadalloweddirslong stringarrcallback nodeclientcore downloadallowedeverywhere new string callback override public string get return temp dir get path stringcallback tempdir getpath override public void set string val throws invalid config value exception if temp dir equals new file val return fixme throw new invalid config value exception l10n moving temp dir on the fly not supported invalidconfigvalueexception tempdir invalidconfigvalueexception movingtempdirontheflynotsupported override public boolean is read only return true isreadonly node config register encrypt persistent temp buckets true sort order true false node client core encrypt persistent temp buckets node client core encrypt persistent temp buckets long new boolean callback override public boolean get return persistent temp bucket factory null true persistent temp bucket factory is encrypting nodeconfig encryptpersistenttempbuckets sortorder nodeclientcore encryptpersistenttempbuckets nodeclientcore encryptpersistenttempbucketslong booleancallback persistenttempbucketfactory persistenttempbucketfactory isencrypting override public void set boolean val throws invalid config value exception if get equals val persistent temp bucket factory null return persistent temp bucket factory set encryption val invalidconfigvalueexception persistenttempbucketfactory persistenttempbucketfactory setencryption new string callback override public string get return persistent temp bucket factory get dir to string stringcallback persistenttempbucketfactory getdir tostring override public void set string val throws invalid config value exception if get equals val return fixme throw new invalid config value exception moving persistent temp directory on the fly not supported at present invalidconfigvalueexception invalidconfigvalueexception override public boolean is read only return true isreadonly node config register maxram bucket size 128 kib sort order true false node client core maxram bucket size node client core maxram bucket size long new long callback override public long get return temp bucket factory null 0 temp bucket factory get maxram bucket size nodeconfig maxrambucketsize 128kib sortorder nodeclientcore maxrambucketsize nodeclientcore maxrambucketsizelong longcallback tempbucketfactory tempbucketfactory getmaxrambucketsize override public void set long val throws invalid config value exception if get equals val temp bucket factory null return temp bucket factory set maxram bucket size val invalidconfigvalueexception tempbucketfactory tempbucketfactory setmaxrambucketsize node config register ram bucket pool size 10 mib sort order true false node client core ram bucket pool size node client core ram bucket pool size long new long callback override public long get return temp bucket factory null 0 temp bucket factory get max ram used nodeconfig rambucketpoolsize 10mib sortorder nodeclientcore rambucketpoolsize nodeclientcore rambucketpoolsizelong longcallback tempbucketfactory tempbucketfactory getmaxramused override public void set long val throws invalid config value exception if get equals val temp bucket factory null return temp bucket factory set max ram used val invalidconfigvalueexception tempbucketfactory tempbucketfactory setmaxramused node config register encrypt temp buckets true sort order true false node client core encrypt temp buckets node client core encrypt temp buckets long new boolean callback override public boolean get return temp bucket factory null true temp bucket factory is encrypting nodeconfig encrypttempbuckets sortorder nodeclientcore encrypttempbuckets nodeclientcore encrypttempbucketslong booleancallback tempbucketfactory tempbucketfactory isencrypting override public void set boolean val throws invalid config value exception if get equals val temp bucket factory null return temp bucket factory set encryption val invalidconfigvalueexception tempbucketfactory tempbucketfactory setencryption public void on change physical threat level old level physical threat level new level if new level physical threat level low if temp bucket factory is encrypting temp bucket factory set encryption false if persistent temp bucket factory is encrypting persistent temp bucket factory set encryption false else new level physical threat level normal if temp bucket factory is encrypting temp bucket factory set encryption true if persistent temp bucket factory is encrypting persistent temp bucket factory set encryption true onchange physical_threat_level oldlevel physical_threat_level newlevel newlevel physical_threat_level tempbucketfactory isencrypting tempbucketfactory setencryption persistenttempbucketfactory isencrypting persistenttempbucketfactory setencryption newlevel physical_threat_level tempbucketfactory isencrypting tempbucketfactory setencryption persistenttempbucketfactory isencrypting persistenttempbucketfactory setencryption node config register downloads dir downloads sort order true true node client core download dir node client core download dir long new string callback override public string get return download dir get path nodeconfig downloadsdir sortorder nodeclientcore downloaddir nodeclientcore downloaddirlong stringcallback downloaddir getpath override public void set string val throws invalid config value exception if download dir equals new file val return file f new file val if f exists f is directory f mkdir relatively commonly used despite being advanced i e not something we want to show to newbies so translate it throw new invalid config value exception l10n could not find or create dir download dir new file val invalidconfigvalueexception downloaddir isdirectory invalidconfigvalueexception couldnotfindorcreatedir downloaddir override public string get synchronized node client core this if download allowed everywhere return new string all string dirs new string download allowed dirs length include download dir 1 0 for int i 0 i download allowed dirs length i dirs i download allowed dirs i get path if include download dir dirs download allowed dirs length downloads return dirs nodeclientcore downloadallowedeverywhere downloadalloweddirs includedownloaddir downloadalloweddirs downloadalloweddirs getpath includedownloaddir downloadalloweddirs override public void set string val throws invalid config value exception set download allowed dirs val invalidconfigvalueexception setdownloadalloweddirs override public string get synchronized node client core this if upload allowed everywhere return new string all string dirs new string upload allowed dirs length for int i 0 i upload allowed dirs length i dirs i upload allowed dirs i get path return dirs nodeclientcore uploadallowedeverywhere uploadalloweddirs uploadalloweddirs uploadalloweddirs getpath override public void set string val throws invalid config value exception set upload allowed dirs val invalidconfigvalueexception setuploadalloweddirs node client core maxusk fetchers long new int callback override public integer get return max backgroundusk fetchers nodeclientcore maxuskfetcherslong intcallback maxbackgrounduskfetchers override public void set integer usk fetch throws invalid config value exception if usk fetch 0 throw new invalid config value exception l10n maxusk fetchers must be greater than zero max backgroundusk fetchers usk fetch uskfetch invalidconfigvalueexception uskfetch invalidconfigvalueexception maxuskfetchersmustbegreaterthanzero maxbackgrounduskfetchers uskfetch private static string l10n string key return l10n get string node client core key getstring nodeclientcore protected synchronized void set download allowed dirs string val int x 0 download allowed everywhere false include download dir false int i 0 download allowed dirs new file val length for i 0 i download allowed dirs length i string s val i if s equals downloads include download dir true else if s equals all download allowed everywhere true else download allowed dirs x new file val i if x i file new dirs new file x system arraycopy download allowed dirs 0 new dirs 0 x download allowed dirs new dirs setdownloadalloweddirs downloadallowedeverywhere includedownloaddir downloadalloweddirs downloadalloweddirs includedownloaddir downloadallowedeverywhere downloadalloweddirs newdirs downloadalloweddirs newdirs downloadalloweddirs newdirs protected synchronized void set upload allowed dirs string val int x 0 int i 0 upload allowed everywhere false upload allowed dirs new file val length for i 0 i upload allowed dirs length i string s val i if s equals all upload allowed everywhere true else upload allowed dirs x new file val i if x i file new dirs new file x system arraycopy upload allowed dirs 0 new dirs 0 x upload allowed dirs new dirs setuploadalloweddirs uploadallowedeverywhere uploadalloweddirs uploadalloweddirs uploadallowedeverywhere uploadalloweddirs newdirs uploadalloweddirs newdirs uploadalloweddirs newdirs public void start config config throws node init exception background block encoder set context client context node executor execute background block encoder background block encoder client context job runner queue new db job public void run object container container client context context archive manager init container context context nodedb handle native thread max priority false persister start store checker start node executor datastore checker if fcp server null fcp server maybe start if tmci null tmci start background block encoder run persistent queue client context node executor execute compressor compression scheduler node executor execute new prio runnable public void run logger normal this resuming persistent requests call it anyway if we are not lazy it won t have to start any requests but it does other things too fcp server finish start persistent temp bucket factory completed init node plugin manager start node config node ip detector ip detector manager start fixme most of the work is done after this point on splitfile starter threads so do we want to make a fuss fixme but a better solution is real request resuming logger normal this completed startup all persistent requests resumed or restarted alerts unregister starting up alert public int get priority return native thread low priority startup completion thread client database executor start node executor client database access thread nodeinitexception backgroundblockencoder setcontext clientcontext backgroundblockencoder clientcontext jobrunner dbjob objectcontainer clientcontext archivemanager nodedbhandle nativethread max_priority storechecker fcpserver fcpserver maybestart backgroundblockencoder runpersistentqueue clientcontext priorunnable fcpserver finishstart persistenttempbucketfactory completedinit pluginmanager ipdetector ipdetectormanager startingupalert getpriority nativethread low_priority clientdatabaseexecutor client context job runner queue new db job public void run object container container client context context archive manager init container context context nodedb handle clientcontext jobrunner dbjob objectcontainer clientcontext archivemanager nodedbhandle public void run logger normal this resuming persistent requests call it anyway if we are not lazy it won t have to start any requests but it does other things too fcp server finish start persistent temp bucket factory completed init node plugin manager start node config node ip detector ip detector manager start fixme most of the work is done after this point on splitfile starter threads so do we want to make a fuss fixme but a better solution is real request resuming logger normal this completed startup all persistent requests resumed or restarted alerts unregister starting up alert fcpserver finishstart persistenttempbucketfactory completedinit pluginmanager ipdetector ipdetectormanager startingupalert public int get priority return native thread low priority getpriority nativethread low_priority public void run object container container client context context restartdb job job startup database jobs startup database jobs done try container activate job job 1 remove before execution to allow it to re add itself if it wants to system err println cleaning up after restart job job restart jobs queue remove restart job job job job prio container job job run container context container commit catch throwable t logger error this caught t in startup job job t try again next time restart jobs queue queue restart job job job job prio container true startup database jobs done if startup database jobs done startup database jobs length startup database jobs null else context job runner queue startup job runner native thread high priority false objectcontainer clientcontext restartdbjob startupdatabasejobs startupdatabasejobsdone restartjobsqueue removerestartjob restartjobsqueue queuerestartjob startupdatabasejobsdone startupdatabasejobsdone startupdatabasejobs startupdatabasejobs jobrunner startupjobrunner nativethread high_priority public interface simple request sender completion listener public void completed boolean success simplerequestsendercompletionlistener public void async get key key boolean cache boolean offers only final simple request sender completion listener listener final long uid random next long final boolean isssk key instanceof nodessk final request tag tag new request tag isssk request tag start async get if node lockuid uid isssk false false true tag logger error this could not lock uid just randomly generated uid probably indicates broken prng return async get key isssk cache offers only uid new request sender listener public void onchk transfer begins ignore public void on received reject overload ignore public void on request sender finished int status if transfer coalescing has happened we may have already unlocked node unlockuid uid isssk false true false true tag tag set request sender finished status if listener null listener completed status request sender success public void on abort downstream transfers int reason string desc ignore on request sender finished will also be called tag asyncget offersonly simplerequestsendercompletionlistener nextlong requesttag requesttag requesttag async_get asyncget offersonly requestsender onchktransferbegins onreceivedrejectoverload onrequestsenderfinished setrequestsenderfinished requestsender onabortdownstreamtransfers onrequestsenderfinished async get key isssk cache offers only uid new request sender listener public void onchk transfer begins ignore asyncget offersonly requestsender onchktransferbegins public void on received reject overload ignore onreceivedrejectoverload public void on request sender finished int status if transfer coalescing has happened we may have already unlocked node unlockuid uid isssk false true false true tag tag set request sender finished status if listener null listener completed status request sender success onrequestsenderfinished setrequestsenderfinished requestsender public void on abort downstream transfers int reason string desc ignore on request sender finished will also be called onabortdownstreamtransfers onrequestsenderfinished start an asynchronous fetch of the key in question which will complete to the datastore it will not decode the data because we don t provide a client key it will not return anything and will run asynchronously caller is responsible for unlocking the uid param key void async get key key boolean isssk boolean cache boolean offers only long uid request sender listener listener request tag tag try object o node make request sender key node maxhtl uid null false cache false offers only if o instanceof key block tag served from datastore true node unlockuid uid isssk false true false true tag return already have it request sender rs request sender o tag set sender rs rs add listener listener if rs uid uid node unlockuid uid isssk false false false true tag else it has started a request if logminor logger minor this started o for uid for key catch runtime exception e logger error this caught error trying to start request e e node unlockuid uid isssk false true false true tag catch error e logger error this caught error trying to start request e e node unlockuid uid isssk false true false true tag clientkey asyncget offersonly requestsender requesttag makerequestsender offersonly keyblock servedfromdatastore requestsender requestsender setsender addlistener runtimeexception public client key block real get key client key key boolean local only boolean cache boolean ignore store throws low level get exception if key instanceof clientchk return real getchk clientchk key local only cache ignore store else if key instanceof clientssk return real getssk clientssk key local only cache ignore store else throw new illegal argument exception not a chk or ssk key clientkeyblock realgetkey clientkey localonly ignorestore lowlevelgetexception realgetchk localonly ignorestore realgetssk localonly ignorestore illegalargumentexception clientchk block real getchk clientchk key boolean local only boolean cache boolean ignore store throws low level get exception long start time system current time millis long uid random next long request tag tag new request tag false request tag start local if node lockuid uid false false false true tag logger error this could not lock uid just randomly generated uid probably indicates broken prng throw new low level get exception low level get exception internal error try object o node make request sender key get nodechk node maxhtl uid null local only cache ignore store false if o instanceof chk block try tag set served from datastore return new clientchk block chk block o key catch chk verify exception e logger error this does not verify e e throw new low level get exception low level get exception decode failed if o null throw new low level get exception low level get exception data not found in store request sender rs request sender o boolean rejected overload false short wait status 0 while true wait status rs wait until status change wait status if rejected overload wait status request sender wait rejected overload 0 see below inserts count both request starters rejected overload false false rejected overload true int status rs get status if rs aborted downstream transfers status request sender transfer failed if status request sender not finished continue if status request sender timed out status request sender generated rejected overload status request sender internal error if logminor logger minor this chk fetch cost rs get total sent bytes rs get total received bytes bytes status node stats local chk fetch bytes sent average report rs get total sent bytes node stats local chk fetch bytes received average report rs get total received bytes if status request sender success see comments above declaration of successful we don t report sent bytes here node stats successful chk fetch bytes sent average report rs get total sent bytes node stats successful chk fetch bytes received average report rs get total received bytes if status request sender timed out status request sender generated rejected overload if rejected overload see below request starters rejected overload false false rejected overload true long rtt system current time millis start time node node stats reportchk time rtt false else if rs has forwarded status request sender data not found status request sender recently failed status request sender success status request sender route not found status request sender verify failure status request sender get offer verify failure long rtt system current time millis start time if rejected overload request starters request completed false false key get node key count towards rtt even if got a rejected overload but not if timed out request starters chk request throttle successful completion rtt node node stats reportchk time rtt status request sender success if status request sender success logger minor this successful chk fetch took rtt if status request sender success try return new clientchk block rs getprb get block rs get headers key true catch chk verify exception e logger error this does not verify e e throw new low level get exception low level get exception decode failed catch aborted exception e logger error this impossible e e throw new low level get exception low level get exception internal error else switch status case request sender not finished logger error this rs still running in getchk rs throw new low level get exception low level get exception internal error case request sender data not found throw new low level get exception low level get exception data not found case request sender recently failed throw new low level get exception low level get exception recently failed case request sender route not found throw new low level get exception low level get exception route not found case request sender transfer failed case request sender get offer transfer failed throw new low level get exception low level get exception transfer failed case request sender verify failure case request sender get offer verify failure throw new low level get exception low level get exception verify failed case request sender generated rejected overload case request sender timed out throw new low level get exception low level get exception rejected overload case request sender internal error throw new low level get exception low level get exception internal error default logger error this unknown request sender code in getchk status on rs throw new low level get exception low level get exception internal error finally node unlockuid uid false false true false true tag clientchkblock realgetchk localonly ignorestore lowlevelgetexception starttime currenttimemillis nextlong requesttag requesttag requesttag lowlevelgetexception lowlevelgetexception internal_error makerequestsender getnodechk localonly ignorestore chkblock setservedfromdatastore clientchkblock chkblock chkverifyexception lowlevelgetexception lowlevelgetexception decode_failed lowlevelgetexception lowlevelgetexception data_not_found_in_store requestsender requestsender rejectedoverload waitstatus waitstatus waituntilstatuschange waitstatus rejectedoverload waitstatus requestsender wait_rejected_overload requeststarters rejectedoverload rejectedoverload getstatus aborteddownstreamtransfers requestsender transfer_failed requestsender not_finished requestsender timed_out requestsender generated_rejected_overload requestsender internal_error gettotalsentbytes gettotalreceivedbytes nodestats localchkfetchbytessentaverage gettotalsentbytes nodestats localchkfetchbytesreceivedaverage gettotalreceivedbytes requestsender nodestats successfulchkfetchbytessentaverage gettotalsentbytes nodestats successfulchkfetchbytesreceivedaverage gettotalreceivedbytes requestsender timed_out requestsender generated_rejected_overload rejectedoverload requeststarters rejectedoverload rejectedoverload currenttimemillis starttime nodestats reportchktime hasforwarded requestsender data_not_found requestsender recently_failed requestsender requestsender route_not_found requestsender verify_failure requestsender get_offer_verify_failure currenttimemillis starttime rejectedoverload requeststarters requestcompleted getnodekey rejectedoverload requeststarters chkrequestthrottle successfulcompletion nodestats reportchktime requestsender requestsender requestsender clientchkblock getblock getheaders chkverifyexception lowlevelgetexception lowlevelgetexception decode_failed abortedexception lowlevelgetexception lowlevelgetexception internal_error requestsender not_finished lowlevelgetexception lowlevelgetexception internal_error requestsender data_not_found lowlevelgetexception lowlevelgetexception data_not_found requestsender recently_failed lowlevelgetexception lowlevelgetexception recently_failed requestsender route_not_found lowlevelgetexception lowlevelgetexception route_not_found requestsender transfer_failed requestsender get_offer_transfer_failed lowlevelgetexception lowlevelgetexception transfer_failed requestsender verify_failure requestsender get_offer_verify_failure lowlevelgetexception lowlevelgetexception verify_failed requestsender generated_rejected_overload requestsender timed_out lowlevelgetexception lowlevelgetexception rejected_overload requestsender internal_error lowlevelgetexception lowlevelgetexception internal_error requestsender lowlevelgetexception lowlevelgetexception internal_error clientssk block real getssk clientssk key boolean local only boolean cache boolean ignore store throws low level get exception long start time system current time millis long uid random next long request tag tag new request tag true request tag start local if node lockuid uid true false false true tag logger error this could not lock uid just randomly generated uid probably indicates broken prng throw new low level get exception low level get exception internal error try object o node make request sender key get node key node maxhtl uid null local only cache ignore store false if o instanceof ssk block try tag set served from datastore ssk block block ssk block o key set public key block get pub key return clientssk block construct block key catch ssk verify exception e logger error this does not verify e e throw new low level get exception low level get exception decode failed if o null throw new low level get exception low level get exception data not found in store request sender rs request sender o boolean rejected overload false short wait status 0 while true wait status rs wait until status change wait status if rejected overload wait status request sender wait rejected overload 0 request starters rejected overload true false rejected overload true int status rs get status if status request sender not finished continue if status request sender timed out status request sender generated rejected overload status request sender internal error if logminor logger minor this ssk fetch cost rs get total sent bytes rs get total received bytes bytes status node stats local ssk fetch bytes sent average report rs get total sent bytes node stats local ssk fetch bytes received average report rs get total received bytes if status request sender success see comments above successful ssk fetch bytes sent average we don t relay the data so reporting the sent bytes would be inaccurate node stats successful ssk fetch bytes sent average report rs get total sent bytes node stats successful ssk fetch bytes received average report rs get total received bytes if status request sender timed out status request sender generated rejected overload if rejected overload request starters rejected overload true false rejected overload true else if rs has forwarded status request sender data not found status request sender recently failed status request sender success status request sender route not found status request sender verify failure status request sender get offer verify failure long rtt system current time millis start time if rejected overload request starters request completed true false key get node key count towards rtt even if got a rejected overload but not if timed out request starters ssk request throttle successful completion rtt if rs get status request sender success try ssk block block rs getssk block key set public key block get pub key return clientssk block construct block key catch ssk verify exception e logger error this does not verify e e throw new low level get exception low level get exception decode failed else switch rs get status case request sender not finished logger error this rs still running in getchk rs throw new low level get exception low level get exception internal error case request sender data not found throw new low level get exception low level get exception data not found case request sender recently failed throw new low level get exception low level get exception recently failed case request sender route not found throw new low level get exception low level get exception route not found case request sender transfer failed case request sender get offer transfer failed logger error this wtf transfer failed on an ssk on uid throw new low level get exception low level get exception transfer failed case request sender verify failure case request sender get offer verify failure throw new low level get exception low level get exception verify failed case request sender generated rejected overload case request sender timed out throw new low level get exception low level get exception rejected overload case request sender internal error default logger error this unknown request sender code in getchk rs get status on rs throw new low level get exception low level get exception internal error finally node unlockuid uid true false true false true tag clientsskblock realgetssk localonly ignorestore lowlevelgetexception starttime currenttimemillis nextlong requesttag requesttag requesttag lowlevelgetexception lowlevelgetexception internal_error makerequestsender getnodekey localonly ignorestore sskblock setservedfromdatastore sskblock sskblock setpublickey getpubkey clientsskblock sskverifyexception lowlevelgetexception lowlevelgetexception decode_failed lowlevelgetexception lowlevelgetexception data_not_found_in_store requestsender requestsender rejectedoverload waitstatus waitstatus waituntilstatuschange waitstatus rejectedoverload waitstatus requestsender wait_rejected_overload requeststarters rejectedoverload rejectedoverload getstatus requestsender not_finished requestsender timed_out requestsender generated_rejected_overload requestsender internal_error gettotalsentbytes gettotalreceivedbytes nodestats localsskfetchbytessentaverage gettotalsentbytes nodestats localsskfetchbytesreceivedaverage gettotalreceivedbytes requestsender successfulsskfetchbytessentaverage nodestats successfulsskfetchbytessentaverage gettotalsentbytes nodestats successfulsskfetchbytesreceivedaverage gettotalreceivedbytes requestsender timed_out requestsender generated_rejected_overload rejectedoverload requeststarters rejectedoverload rejectedoverload hasforwarded requestsender data_not_found requestsender recently_failed requestsender requestsender route_not_found requestsender verify_failure requestsender get_offer_verify_failure currenttimemillis starttime rejectedoverload requeststarters requestcompleted getnodekey rejectedoverload requeststarters sskrequestthrottle successfulcompletion getstatus requestsender sskblock getsskblock setpublickey getpubkey clientsskblock sskverifyexception lowlevelgetexception lowlevelgetexception decode_failed getstatus requestsender not_finished lowlevelgetexception lowlevelgetexception internal_error requestsender data_not_found lowlevelgetexception lowlevelgetexception data_not_found requestsender recently_failed lowlevelgetexception lowlevelgetexception recently_failed requestsender route_not_found lowlevelgetexception lowlevelgetexception route_not_found requestsender transfer_failed requestsender get_offer_transfer_failed lowlevelgetexception lowlevelgetexception transfer_failed requestsender verify_failure requestsender get_offer_verify_failure lowlevelgetexception lowlevelgetexception verify_failed requestsender generated_rejected_overload requestsender timed_out lowlevelgetexception lowlevelgetexception rejected_overload requestsender internal_error requestsender getstatus lowlevelgetexception lowlevelgetexception internal_error public void real put key block block boolean cache throws low level put exception if block instanceof chk block real putchk chk block block cache else if block instanceof ssk block real putssk ssk block block cache else throw new illegal argument exception unknown put type block get class realput keyblock lowlevelputexception chkblock realputchk chkblock sskblock realputssk sskblock illegalargumentexception getclass public void real putchk chk block block boolean cache throws low level put exception byte data block get data byte headers block get headers partially received block prb new partially received block node packets in block node packet size data chk insert sender is long uid random next long insert tag tag new insert tag false insert tag start local if node lockuid uid false true false true tag logger error this could not lock uid just randomly generated uid probably indicates broken prng throw new low level put exception low level put exception internal error try long start time system current time millis if cache node store block is node make insert sender nodechk block get key node maxhtl uid null headers prb false cache boolean has received rejected overload false wait for status while true synchronized is if is get status chk insert sender not finished try is wait 5 1000 catch interrupted exception e ignore if is get status chk insert sender not finished break if has received rejected overload is received rejected overload has received rejected overload true request starters rejected overload false true wait for completion while true synchronized is if is completed break try is wait 10 1000 catch interrupted exception e go around again if is any transfers failed has received rejected overload has received rejected overload true not strictly true but same effect request starters rejected overload false true if logminor logger minor this completed uid overload has received rejected overload is get status string finished if has received rejected overload is it ours did we send a request if is sent request is uid uid is get status chk insert sender route not found is get status chk insert sender success it worked long end time system current time millis long len end time start time rejected overload requests count towards rtt timed out ones don t request starters chk insert throttle successful completion len request starters request completed false true block get key get status explicitly after completed so that it will be receive failed if the receive failed int status is get status if status chk insert sender timed out status chk insert sender generated rejected overload status chk insert sender internal error status chk insert sender route really not found int sent is get total sent bytes int received is get total received bytes if logminor logger minor this local chk insert cost sent received bytes status node stats local chk insert bytes sent average report sent node stats local chk insert bytes received average report received if status chk insert sender success only report sent bytes because we did not receive the data node stats successful chk insert bytes sent average report sent if status chk insert sender success logger normal this succeeded inserting block return else string msg failed inserting block is get status string if status chk insert sender route not found msg this is normal on small networks the data will still be propagated but it can t find the 20 nodes needed for full success if is get status chk insert sender route not found logger error this msg else logger normal this msg switch is get status case chk insert sender not finished logger error this is still running in putchk is throw new low level put exception low level put exception internal error case chk insert sender generated rejected overload case chk insert sender timed out throw new low level put exception low level put exception rejected overload case chk insert sender route not found throw new low level put exception low level put exception route not found case chk insert sender route really not found throw new low level put exception low level put exception route really not found case chk insert sender internal error throw new low level put exception low level put exception internal error default logger error this unknown chk insert sender code in putchk is get status on is throw new low level put exception low level put exception internal error finally node unlockuid uid false true true false true tag realputchk chkblock lowlevelputexception getdata getheaders partiallyreceivedblock partiallyreceivedblock packets_in_block packet_size chkinsertsender nextlong inserttag inserttag inserttag lowlevelputexception lowlevelputexception internal_error starttime currenttimemillis makeinsertsender getkey hasreceivedrejectedoverload getstatus chkinsertsender not_finished interruptedexception getstatus chkinsertsender not_finished hasreceivedrejectedoverload receivedrejectedoverload hasreceivedrejectedoverload requeststarters rejectedoverload interruptedexception anytransfersfailed hasreceivedrejectedoverload hasreceivedrejectedoverload requeststarters rejectedoverload hasreceivedrejectedoverload getstatusstring hasreceivedrejectedoverload sentrequest getstatus chkinsertsender route_not_found getstatus chkinsertsender endtime currenttimemillis endtime starttime rejectedoverload requeststarters chkinsertthrottle successfulcompletion requeststarters requestcompleted getkey receive_failed getstatus chkinsertsender timed_out chkinsertsender generated_rejected_overload chkinsertsender internal_error chkinsertsender route_really_not_found gettotalsentbytes gettotalreceivedbytes nodestats localchkinsertbytessentaverage nodestats localchkinsertbytesreceivedaverage chkinsertsender nodestats successfulchkinsertbytessentaverage chkinsertsender getstatusstring chkinsertsender route_not_found getstatus chkinsertsender route_not_found getstatus chkinsertsender not_finished lowlevelputexception lowlevelputexception internal_error chkinsertsender generated_rejected_overload chkinsertsender timed_out lowlevelputexception lowlevelputexception rejected_overload chkinsertsender route_not_found lowlevelputexception lowlevelputexception route_not_found chkinsertsender route_really_not_found lowlevelputexception lowlevelputexception route_really_not_found chkinsertsender internal_error lowlevelputexception lowlevelputexception internal_error chkinsertsender getstatus lowlevelputexception lowlevelputexception internal_error public void real putssk ssk block block boolean cache throws low level put exception ssk insert sender is long uid random next long insert tag tag new insert tag true insert tag start local if node lockuid uid true true false true tag logger error this could not lock uid just randomly generated uid probably indicates broken prng throw new low level put exception low level put exception internal error try long start time system current time millis ssk block alt block ssk block node fetch block get key false if alt block null alt block equals block throw new low level put exception low level put exception collision is node make insert sender block node maxhtl uid null false cache boolean has received rejected overload false wait for status while true synchronized is if is get status ssk insert sender not finished try is wait 5 1000 catch interrupted exception e ignore if is get status ssk insert sender not finished break if has received rejected overload is received rejected overload has received rejected overload true request starters rejected overload true true wait for completion while true synchronized is if is get status ssk insert sender not finished break try is wait 10 1000 catch interrupted exception e go around again if logminor logger minor this completed uid overload has received rejected overload is get status string finished if has received rejected overload is it ours did we send a request if is sent request is uid uid is get status ssk insert sender route not found is get status ssk insert sender success it worked long end time system current time millis long rtt end time start time request starters request completed true true block get key request starters ssk insert throttle successful completion rtt int status is get status if status chk insert sender timed out status chk insert sender generated rejected overload status chk insert sender internal error status chk insert sender route really not found int sent is get total sent bytes int received is get total received bytes if logminor logger minor this local ssk insert cost sent received bytes status node stats local ssk insert bytes sent average report sent node stats local ssk insert bytes received average report received if status ssk insert sender success only report sent bytes as we haven t received anything node stats successful ssk insert bytes sent average report sent if is has collided store it locally so it can be fetched immediately and overwrites any locally inserted try node store insert is get block catch key collision exception e impossible throw new low level put exception low level put exception collision else if cache try node store insert block catch key collision exception e throw new low level put exception low level put exception collision if status ssk insert sender success logger normal this succeeded inserting block return else string msg failed inserting block is get status string if status chk insert sender route not found msg this is normal on small networks the data will still be propagated but it can t find the 20 nodes needed for full success if is get status ssk insert sender route not found logger error this msg else logger normal this msg switch is get status case ssk insert sender not finished logger error this is still running in putchk is throw new low level put exception low level put exception internal error case ssk insert sender generated rejected overload case ssk insert sender timed out throw new low level put exception low level put exception rejected overload case ssk insert sender route not found throw new low level put exception low level put exception route not found case ssk insert sender route really not found throw new low level put exception low level put exception route really not found case ssk insert sender internal error throw new low level put exception low level put exception internal error default logger error this unknown chk insert sender code in putssk is get status on is throw new low level put exception low level put exception internal error finally node unlockuid uid true true true false true tag realputssk sskblock lowlevelputexception sskinsertsender nextlong inserttag inserttag inserttag lowlevelputexception lowlevelputexception internal_error starttime currenttimemillis sskblock altblock sskblock getkey altblock altblock lowlevelputexception lowlevelputexception makeinsertsender hasreceivedrejectedoverload getstatus sskinsertsender not_finished interruptedexception getstatus sskinsertsender not_finished hasreceivedrejectedoverload receivedrejectedoverload hasreceivedrejectedoverload requeststarters rejectedoverload getstatus sskinsertsender not_finished interruptedexception hasreceivedrejectedoverload getstatusstring hasreceivedrejectedoverload sentrequest getstatus sskinsertsender route_not_found getstatus sskinsertsender endtime currenttimemillis endtime starttime requeststarters requestcompleted getkey requeststarters sskinsertthrottle successfulcompletion getstatus chkinsertsender timed_out chkinsertsender generated_rejected_overload chkinsertsender internal_error chkinsertsender route_really_not_found gettotalsentbytes gettotalreceivedbytes nodestats localsskinsertbytessentaverage nodestats localsskinsertbytesreceivedaverage sskinsertsender nodestats successfulsskinsertbytessentaverage hascollided storeinsert getblock keycollisionexception lowlevelputexception lowlevelputexception storeinsert keycollisionexception lowlevelputexception lowlevelputexception sskinsertsender getstatusstring chkinsertsender route_not_found getstatus sskinsertsender route_not_found getstatus sskinsertsender not_finished lowlevelputexception lowlevelputexception internal_error sskinsertsender generated_rejected_overload sskinsertsender timed_out lowlevelputexception lowlevelputexception rejected_overload sskinsertsender route_not_found lowlevelputexception lowlevelputexception route_not_found sskinsertsender route_really_not_found lowlevelputexception lowlevelputexception route_really_not_found sskinsertsender internal_error lowlevelputexception lowlevelputexception internal_error chkinsertsender getstatus lowlevelputexception lowlevelputexception internal_error public high level simple client make client short prio class return make client prio class false highlevelsimpleclient makeclient prioclass makeclient prioclass public high level simple client make client short prio class boolean force dont ignore too many path components return new high level simple client impl this temp bucket factory random node dont cache local requests prio class force dont ignore too many path components highlevelsimpleclient makeclient prioclass forcedontignoretoomanypathcomponents highlevelsimpleclientimpl tempbucketfactory dont_cache_local_requests prioclass forcedontignoretoomanypathcomponents public boolean cache inserts return node dont cache local requests cacheinserts dont_cache_local_requests public fcp server getfcp server return fcp server fcpserver getfcpserver fcpserver public f proxy toadlet getf proxy return fproxy servlet fproxytoadlet getfproxy fproxyservlet public simple toadlet server get toadlet container return toadlet container simpletoadletserver gettoadletcontainer toadletcontainer public text mode client interface server get text mode client interface return tmci textmodeclientinterfaceserver gettextmodeclientinterface public void setf proxy f proxy toadlet fproxy this fproxy servlet fproxy setfproxy fproxytoadlet fproxyservlet public text mode client interface get directtmci return directtmci textmodeclientinterface getdirecttmci public void set directtmci text mode client interface i this directtmci i setdirecttmci textmodeclientinterface public file get download dir return download dir getdownloaddir downloaddir public healing queue get healing queue return healing queue healingqueue gethealingqueue healingqueue public void queue random reinsert key block block simple sendable insert ssi new simple sendable insert this block request starter maximum priority class if logminor logger minor this queueing random reinsert for block ssi ssi schedule queuerandomreinsert keyblock simplesendableinsert simplesendableinsert requeststarter maximum_priority_class public void store config logger normal this trying to write config to disk new exception debug node config store storeconfig public boolean is testnet enabled return node is testnet enabled istestnetenabled istestnetenabled public boolean is advanced mode enabled return get toadlet container null get toadlet container is advanced mode enabled isadvancedmodeenabled gettoadletcontainer gettoadletcontainer isadvancedmodeenabled public boolean isf proxy javascript enabled return get toadlet container null get toadlet container isf proxy javascript enabled isfproxyjavascriptenabled gettoadletcontainer gettoadletcontainer isfproxyjavascriptenabled public string get my name return node get my name getmyname getmyname public filter callback create filter callback uri uri founduri callback cb if logminor logger minor this creating filter callback uri cb return new generic read filter callback uri cb filtercallback createfiltercallback founduricallback genericreadfiltercallback public int max backgroundusk fetchers return max backgroundusk fetchers maxbackgrounduskfetchers maxbackgrounduskfetchers public boolean allow download to file filename if download allowed everywhere return true if include download dir if file util is parent download dir filename return true for int i 0 i download allowed dirs length i if file util is parent download allowed dirs i filename return true return false allowdownloadto downloadallowedeverywhere includedownloaddir fileutil isparent downloaddir downloadalloweddirs fileutil isparent downloadalloweddirs public boolean allow upload from file filename if upload allowed everywhere return true for int i 0 i upload allowed dirs length i if file util is parent upload allowed dirs i filename return true return false allowuploadfrom uploadallowedeverywhere uploadalloweddirs fileutil isparent uploadalloweddirs public file get allowed upload dirs return upload allowed dirs getalloweduploaddirs uploadalloweddirs public simple field set persist throttles to field set return request starters persist to field set simplefieldset persistthrottlestofieldset requeststarters persisttofieldset public ticker get ticker return node ps getticker public executor get executor return node executor getexecutor public file get persistent temp dir return persistent temp bucket factory get dir getpersistenttempdir persistenttempbucketfactory getdir public file get temp dir return temp dir gettempdir tempdir public boolean has loaded queue return fcp server has finished start hasloadedqueue fcpserver hasfinishedstart pass the offered key down to the client layer if the client layer wants it or force is enabled queue it public void maybe queue offered key key key boolean force client request scheduler sched key instanceof nodessk request starters ssk fetch scheduler request starters chk fetch scheduler sched maybe queue offered key key force maybequeueofferedkey clientrequestscheduler requeststarters sskfetchscheduler requeststarters chkfetchscheduler maybequeueofferedkey public void dequeue offered key key key client request scheduler sched key instanceof nodessk request starters ssk fetch scheduler request starters chk fetch scheduler sched dequeue offered key key dequeueofferedkey clientrequestscheduler requeststarters sskfetchscheduler requeststarters chkfetchscheduler dequeueofferedkey public freeneturi get bookmarkur is return toadlet container get bookmarkur is getbookmarkuris toadletcontainer getbookmarkuris public long count transient queued requests return request starters count transient queued requests counttransientqueuedrequests requeststarters counttransientqueuedrequests public void queue final db job job int priority boolean check dupes if check dupes this client database executor execute no dupes new db job wrapper job priority job else this client database executor execute new db job wrapper job priority job dbjob checkdupes checkdupes clientdatabaseexecutor executenodupes dbjobwrapper clientdatabaseexecutor dbjobwrapper class db job wrapper implements runnable db job wrapper db job job this job job if job null throw new null pointer exception dbjobwrapper dbjobwrapper dbjob nullpointerexception public void run try synchronized node client core this if killed database logger error this database killed already not running job return if job null throw new null pointer exception if node null throw new null pointer exception job run node db client context boolean killed synchronized node client core this killed killed database if killed node db rollback return else persistent temp bucket factory pre commit node db node db commit if logminor logger minor this committed persistent temp bucket factory post commit node db catch throwable t if t instanceof out of memory error synchronized node client core this killed database true oom handler handleoom out of memory error t else logger error this failed to run database job job caught t t boolean killed synchronized node client core this killed killed database if killed node db rollback nodeclientcore killeddatabase nullpointerexception nullpointerexception clientcontext nodeclientcore killeddatabase persistenttempbucketfactory precommit persistenttempbucketfactory postcommit outofmemoryerror nodeclientcore killeddatabase oomhandler outofmemoryerror nodeclientcore killeddatabase override public int hash code return job null 0 job hash code hashcode hashcode override public boolean equals object o if o instanceof db job wrapper return false db job wrapper cmp db job wrapper o return cmp job job dbjobwrapper dbjobwrapper dbjobwrapper override public string to string return db job wrapper job tostring dbjobwrapper public boolean on database thread return client database executor on thread ondatabasethread clientdatabaseexecutor onthread public int get queue size int priority return client database executor get queue size priority getqueuesize clientdatabaseexecutor getqueuesize public void handle low memory throws exception ignore handlelowmemory public void handle out of memory throws exception synchronized this killed database true wrapper manager request thread dump system err println out of memory emergency shutdown to protect database integrity in progress system exit node init exception exit out of memory protecting database handleoutofmemory killeddatabase wrappermanager requestthreaddump nodeinitexception exit_out_of_memory_protecting_database queue a job to be run soon after startup the job must delete itself public void queue restart job db job job int priority object container container boolean early restart jobs queue queue restart job job priority container early queuerestartjob dbjob objectcontainer restartjobsqueue queuerestartjob public void remove restart job db job job int priority object container container restart jobs queue remove restart job job priority container removerestartjob dbjob objectcontainer restartjobsqueue removerestartjob public void run blocking final db job job int priority if client database executor on thread job run node db client context else final mutable boolean finished new mutable boolean queue new db job public void run object container container client context context try job run container context finally synchronized finished finished value true finished notify all priority false synchronized finished while finished value try finished wait catch interrupted exception e ignore runblocking dbjob clientdatabaseexecutor onthread clientcontext mutableboolean mutableboolean dbjob objectcontainer clientcontext notifyall interruptedexception public void run object container container client context context try job run container context finally synchronized finished finished value true finished notify all objectcontainer clientcontext notifyall public boolean object can new object container container logger error this not storing node client core in database new exception error return false objectcannew objectcontainer nodeclientcore public synchronized void kill database killed database true killdatabase killeddatabase public message list fetcher node my node high level simple client my client string my name identity manager my identity manager message manager my message manager super my node my client my name m identity manager my identity manager m message manager my message manager messagelistfetcher mynode highlevelsimpleclient myclient myname identitymanager myidentitymanager messagemanager mymessagemanager mynode myclient myname midentitymanager myidentitymanager mmessagemanager mymessagemanager public static synchronized null persistent file tracker get instance if instance null instance new null persistent file tracker return instance nullpersistentfiletracker getinstance nullpersistentfiletracker private null persistent file tracker nullpersistentfiletracker public void register file file do nothing public void delayed free bucket delayed free bucket bucket free immediately bucket free delayedfreebucket delayedfreebucket public file get dir return new file getdir public boolean matches file file return false public filename generator get generator return null filenamegenerator getgenerator public long getid file file return 0 public class null boolean callback extends boolean callback override public boolean get return false nullbooleancallback booleancallback override public void set boolean val throws invalid config value exception ignore invalidconfigvalueexception public subscribedusk update string identifier long l usk key boolean new known good boolean new slot too this identifier identifier this edition l this key key this new known good new known good this new slot too new slot too subscribeduskupdate newknowngood newslottoo newknowngood newknowngood newslottoo newslottoo override public simple field set get field set simple field set fs new simple field set true fs put single identifier identifier fs put edition edition fs put single uri key geturi to string fs put new known good new known good fs put new slot too new slot too return fs simplefieldset getfieldset simplefieldset simplefieldset putsingle putsingle tostring newknowngood newknowngood newslottoo newslottoo override public string get name return name getname override public void run fcp connection handler handler node node throws message invalid exception throw new message invalid exception protocol error message invalid message subscribedusk update goes from server to client not the other way around identifier false fcpconnectionhandler messageinvalidexception messageinvalidexception protocolerrormessage invalid_message subscribeduskupdate override public void remove from object container container throw new unsupported operation exception removefrom objectcontainer unsupportedoperationexception private final node client core core public user alert manager node client core core this core core alerts new linked hash set user alert nodeclientcore useralertmanager nodeclientcore linkedhashset useralert public void register user alert alert synchronized alerts if alerts contains alert alerts add alert useralert public void unregister user alert alert synchronized alerts alerts remove alert useralert tries to find the user alert with the given hash code and dismisses it if found see unregister user alert param alert hash code the hash code of the user alert to dismiss public void dismiss alert int alert hash code user alert user alerts get alerts for int index 0 count user alerts length index count index user alert user alert user alerts index if user alert hash code alert hash code if user alert user can dismiss if user alert should unregister on dismiss user alert on dismiss unregister user alert else user alert is valid false useralert alerthashcode dismissalert alerthashcode useralert useralerts getalerts useralerts useralert useralert useralerts useralert hashcode alerthashcode useralert usercandismiss useralert shouldunregisterondismiss useralert ondismiss useralert useralert isvalid public user alert get alerts user alert a synchronized alerts a alerts to array new user alert alerts size arrays sort a this return a useralert getalerts useralert toarray useralert public int compare user alert a0 user alert a1 if a0 a1 return 0 common case also we should be consistent with even with proxyuseralert s short prio0 a0 get priority class short prio1 a1 get priority class if prio0 prio1 0 boolean is event0 a0 is event notification boolean is event1 a1 is event notification if is event0 is event1 return 1 if is event0 is event1 return 1 first go by class int class hash0 a0 get class hash code int class hash1 a1 get class hash code if class hash0 class hash1 return 1 else if class hash0 class hash1 return 1 then by object hash code int hash0 a0 hash code int hash1 a1 hash code if hash0 hash1 return 1 if hash1 hash0 return 1 return 0 else if prio0 prio1 return 1 else return 1 useralert useralert getpriorityclass getpriorityclass isevent0 iseventnotification isevent1 iseventnotification isevent0 isevent1 isevent0 isevent1 classhash0 getclass hashcode classhash1 getclass hashcode classhash0 classhash1 classhash0 classhash1 hashcode hashcode hashcode write the alerts as html public html node create alerts html node alerts node new html node div user alert alerts get alerts int total number 0 for int i 0 i alerts length i user alert alert alerts i if alert is valid continue total number alerts node add child a name alert anchor alerts node add child render alert alert if total number 0 return new html node return alerts node htmlnode createalerts htmlnode alertsnode htmlnode useralert getalerts totalnumber useralert isvalid totalnumber alertsnode addchild alertsnode addchild renderalert totalnumber htmlnode alertsnode write each alert in uber concise form as html with a link to alerts anchor pointing to the real alert public html node create alerts short string title boolean advanced mode boolean draw dump events form user alert current alerts get alerts short max level short max value int events 0 for int i 0 i current alerts length i if current alerts i is valid continue short level current alerts i get priority class if level max level max level level if current alerts i is event notification events if max level short max value return new html node if events 2 draw dump events form false html node box node new html node div class infobox infobox get alert level name max level infobox summary status box box node add child div class infobox header infobox summary status header title html node content node box node add child div class infobox content infobox summary status content if advanced mode content node add child p class click for more l10n click for more html node alerts node content node add child ul class alert summary int total number 0 for int i 0 i current alerts length i user alert alert current alerts i if alert is valid continue html node list item alerts node add child li class alert summary text get alert level name alert get priority class list item add child a href alerts alert anchor alert get short text total number if draw dump events form html node dump form node content node add child form new string action method new string post add child div dump form node add child input new string type name value new string hidden form password core form password string builder sb new string builder for int i 0 i current alerts length i if current alerts i is event notification continue if sb length 0 sb append sb append current alerts i anchor dump form node add child input new string type name value new string hidden events sb to string dump form node add child input new string type name value new string submit dismiss events l10n dump events button return box node htmlnode createalertsshort advancedmode drawdumpeventsform useralert currentalerts getalerts maxlevel max_value currentalerts currentalerts isvalid currentalerts getpriorityclass maxlevel maxlevel currentalerts iseventnotification maxlevel max_value htmlnode drawdumpeventsform htmlnode boxnode htmlnode getalertlevelname maxlevel boxnode addchild htmlnode contentnode boxnode addchild advancedmode contentnode addchild clickformore htmlnode alertsnode contentnode addchild totalnumber currentalerts useralert currentalerts isvalid htmlnode listitem alertsnode addchild getalertlevelname getpriorityclass listitem addchild getshorttext totalnumber drawdumpeventsform htmlnode dumpformnode contentnode addchild addchild dumpformnode addchild formpassword formpassword stringbuilder stringbuilder currentalerts currentalerts iseventnotification currentalerts dumpformnode addchild tostring dumpformnode addchild dumpeventsbutton boxnode renders the given alert and returns the rendered html node param user alert the user alert to render return the rendered html node public html node render alert user alert user alert html node user alert node null short level user alert get priority class user alert node new html node div class infobox infobox get alert level name level user alert node add child div class infobox header user alert get title html node alert content node user alert node add child div class infobox content alert content node add child user alert gethtml text if user alert user can dismiss html node dismiss form node alert content node add child form new string action method new string post add child div dismiss form node add child input new string type name value new string hidden disable string value of user alert hash code dismiss form node add child input new string type name value new string hidden form password core form password dismiss form node add child input new string type name value new string submit dismiss user alert user alert dismiss button text return user alert node useralert htmlnode renderalert useralert useralert htmlnode useralertnode useralert getpriorityclass useralertnode htmlnode getalertlevelname useralertnode addchild useralert gettitle htmlnode alertcontentnode useralertnode addchild alertcontentnode addchild useralert gethtmltext useralert usercandismiss htmlnode dismissformnode alertcontentnode addchild addchild dismissformnode addchild valueof useralert hashcode dismissformnode addchild formpassword formpassword dismissformnode addchild useralert dismissbuttontext useralertnode private string get alert level name short level if level user alert critical error return error else if level user alert error return alert else if level user alert warning return warning else if level user alert minor return minor else logger error this unknown alert level level new exception debug return error getalertlevelname useralert critical_error useralert useralert useralert write the alert summary as html to a string builder public html node create summary short highest level 99 int number of critical error 0 int number of error 0 int number of warning 0 int number of minor 0 int total number 0 user alert alerts get alerts for int i 0 i alerts length i user alert alert alerts i if alert is valid continue short level alert get priority class if level highest level highest level level if level user alert critical error number of critical error else if level user alert error number of error else if level user alert warning number of warning else if level user alert minor number of minor total number if total number 0 return new html node boolean separator needed false int message types 0 string builder alert summary string new string builder 1024 if number of critical error 0 alert summary string append l10n critical error count label append append number of critical error separator needed true message types if number of error 0 if separator needed alert summary string append alert summary string append l10n error count label append append number of error separator needed true message types if number of warning 0 if separator needed alert summary string append alert summary string append l10n warning count label append append number of warning separator needed true message types if number of minor 0 if separator needed alert summary string append alert summary string append l10n minor count label append append number of minor separator needed true message types if message types 1 if separator needed alert summary string append alert summary string append l10n total label append append total number html node summary box null if highest level user alert critical error summary box new html node div class infobox infobox error else if highest level user alert error summary box new html node div class infobox infobox alert else if highest level user alert warning summary box new html node div class infobox infobox warning else if highest level user alert minor summary box new html node div class infobox infobox information summary box add child div class infobox header l10n alerts title html node summary content summary box add child div class infobox content alert summary string to string summary content add child l10n addl10n substitution summary content user alert manager alerts on alerts page new string link link new string a href alerts a return summary box stringbuilder htmlnode createsummary highestlevel numberofcriticalerror numberoferror numberofwarning numberofminor totalnumber useralert getalerts useralert isvalid getpriorityclass highestlevel highestlevel useralert critical_error numberofcriticalerror useralert numberoferror useralert numberofwarning useralert numberofminor totalnumber totalnumber htmlnode separatorneeded messagetypes stringbuilder alertsummarystring stringbuilder numberofcriticalerror alertsummarystring criticalerrorcountlabel numberofcriticalerror separatorneeded messagetypes numberoferror separatorneeded alertsummarystring alertsummarystring errorcountlabel numberoferror separatorneeded messagetypes numberofwarning separatorneeded alertsummarystring alertsummarystring warningcountlabel numberofwarning separatorneeded messagetypes numberofminor separatorneeded alertsummarystring alertsummarystring minorcountlabel numberofminor separatorneeded messagetypes messagetypes separatorneeded alertsummarystring alertsummarystring totallabel totalnumber htmlnode summarybox highestlevel useralert critical_error summarybox htmlnode highestlevel useralert summarybox htmlnode highestlevel useralert summarybox htmlnode highestlevel useralert summarybox htmlnode summarybox addchild alertstitle htmlnode summarycontent summarybox addchild alertsummarystring tostring summarycontent addchild addl10nsubstitution summarycontent useralertmanager alertsonalertspage summarybox private string l10n string key return l10n get string user alert manager key getstring useralertmanager public void dump events hash set string to dump an iterator might be faster but we don t want to call methods on the alert within the lock user alert alerts get alerts for int i 0 i alerts length i if alerts i is event notification continue if to dump contains alerts i anchor continue unregister alerts i alerts i on dismiss dumpevents hashset todump useralert getalerts iseventnotification todump ondismiss param args throws invalid threshold exception throws io exception throws node init exception throws interrupted exception public static void main string args throws invalid threshold exception io exception node init exception interrupted exception node second node null try string ip override null if args length 0 ip override args 0 file dir new file bootstrap pull test file util remove all dir random source random node starter global test init dir get path false logger error false byte seed new byte 64 random next bytes seed mersenne twister fast random new mersenne twister seed file seednodes new file seednodes fref if seednodes exists seednodes length 0 seednodes can read system err println unable to read seednodes fref it doesn t exist or is empty system exit exit no seednodes file second inner dir new file dir integer to string darknet port second inner dir mkdir file input stream fis new file input stream seednodes file util write to fis new file second inner dir seednodes fref fis close create the test data system out println creating test data file data file file create temp file testdata tmp dir output stream os new file output stream data file byte buf new byte 4096 for long written 0 written test size fast random next bytes buf int to write int math min test size written buf length os write buf 0 to write written to write os close insert it to the established node system out println inserting test data to an established node freeneturi uri insert data data file bootstrap a second node second inner dir mkdir fis new file input stream seednodes file util write to fis new file second inner dir seednodes fref fis close pooled executor executor new pooled executor second node node starter create test node darknet port opennet port dir get path true false false node default max htl 0 random executor 1000 5 1024 1024 true true true true true true true 12 1024 false true ip override second node start true wait for ten nodes second node fetch the data long start fetch time system current time millis high level simple client client second node client core make client short 0 try client fetch uri catch fetch exception e system err println fetch failed e e print stack trace system exit exit fetch failed return long end fetch time system current time millis system out println result fetch took end fetch time start fetch time ms time util format time end fetch time start fetch time of uri second node park system exit 0 catch throwable t system err println caught t t print stack trace try if second node null second node park catch throwable t1 system exit exit threw something invalidthresholdexception ioexception nodeinitexception interruptedexception invalidthresholdexception ioexception nodeinitexception interruptedexception secondnode ipoverride ipoverride fileutil removeall randomsource nodestarter globaltestinit getpath nextbytes mersennetwister fastrandom mersennetwister canread exit_no_seednodes secondinnerdir tostring darknet_port secondinnerdir fileinputstream fileinputstream fileutil writeto secondinnerdir datafile createtempfile outputstream fileoutputstream datafile test_size fastrandom nextbytes towrite test_size towrite towrite insertdata datafile secondinnerdir fileinputstream fileutil writeto secondinnerdir pooledexecutor pooledexecutor secondnode nodestarter createtestnode darknet_port opennet_port getpath default_max_htl ipoverride secondnode waitfortennodes secondnode startfetchtime currenttimemillis highlevelsimpleclient secondnode clientcore makeclient fetchexception printstacktrace exit_fetch_failed endfetchtime currenttimemillis endfetchtime startfetchtime timeutil formattime endfetchtime startfetchtime secondnode printstacktrace secondnode secondnode exit_threw_something private static freeneturi insert data file data file throws io exception long start insert time system current time millis inet address localhost inet address get by name 127 0 0 1 socket sock new socket localhost 9481 output stream sockos sock get output stream input stream sockis sock get input stream system out println connected to node line reading input stream lis new line reading input stream sockis output stream writer osw new output stream writer sockos utf 8 osw write client hello n expected version 0 7 n name bootstrap pull test system current time millis n end n osw flush string name lis read line 65536 128 true simple field set fs new simple field set lis 65536 128 true true false true if name equals node hello system err println no node hello from insertor node system exit exit inserter problem system out println connected to sock osw write client put n identifier test insert nuri chk n verbosity 1023 n upload from direct n max retries 1 n data length test size n data n osw flush input stream is new file input stream data file file util copy is sockos test size system out println sent data while true name lis read line 65536 128 true fs new simple field set lis 65536 128 true true false true system out println got fcp message n name system out print fs to ordered string if name equals protocol error system err println protocol error when inserting data system exit exit inserter problem if name equals put failed system err println insert failed system exit exit insert failed if name equals put successful long end insert time system current time millis freeneturi uri new freeneturi fs get uri system out println result insert took end insert time start insert time ms time util format time end insert time start insert time to uri sockos close sockis close sock close return uri insertdata datafile ioexception startinserttime currenttimemillis inetaddress inetaddress getbyname outputstream getoutputstream inputstream getinputstream linereadinginputstream linereadinginputstream outputstreamwriter outputstreamwriter clienthello nexpectedversion nname bootstrappulltest currenttimemillis nend readline simplefieldset simplefieldset nodehello nodehello exit_inserter_problem clientput nidentifier nverbosity nuploadfrom nmaxretries ndatalength test_size ndata inputstream fileinputstream datafile fileutil test_size readline simplefieldset toorderedstring protocolerror exit_inserter_problem putfailed exit_insert_failed putsuccessful endinserttime currenttimemillis endinserttime startinserttime timeutil formattime endinserttime startinserttime private static void wait for ten nodes node node throws interrupted exception long start time system current time millis wait until we have 10 connected nodes int seconds 0 boolean success false while seconds 600 thread sleep 1000 int seeds node peers count seednodes int seed conns node peers get connected seed server peers vector null size int opennet peers node peers count valid peers int opennet conns node peers count connected opennet peers system err println seconds seeds seeds connected seed conns opennet peers opennet peers connected opennet conns seconds if opennet conns target peers long time taken system current time millis start time system out println result completed bootstrap target peers peers in time taken ms time util format time time taken success true break if success system err println failed to reach target peers count target peers in 10 minutes node park system exit exit failed target waitfortennodes interruptedexception starttime currenttimemillis countseednodes seedconns getconnectedseedserverpeersvector opennetpeers countvalidpeers opennetconns countconnectedopennetpeers seedconns opennetpeers opennetconns opennetconns target_peers timetaken currenttimemillis starttime target_peers timetaken timeutil formattime timetaken target_peers exit_failed_target private final board m board public board page web interface my web interface ft own identity viewer http request request throws no such board exception super my web interface viewer request m board m freetalk get message manager get board by name request get param name mboard boardpage webinterface mywebinterface ftownidentity httprequest nosuchboardexception mywebinterface mboard mfreetalk getmessagemanager getboardbyname getparam public final void make html node threads box add content box threads in m board get name html node new thread form add form child threads box self uri new thread new thread page new thread form add child input new string type name value new string hidden own identityid m own identity getuid new thread form add child input new string type name value new string hidden board name m board get name new thread form add child input new string type name value new string submit submit new thread display the list of known identities html node threads table threads box add child table new string border width new string 0 100 html node row threads table add child tr row add child th title row add child th author row add child th date row add child th replies date format date format date format get instance synchronized m board fixme is this enough synchronization or should we lock the message manager iterator message reference threads m board thread iterator m own identity while threads has next message thread threads next get message row threads table add child tr html node title cell row add child td new string align new string left title cell add child new html node a href self uri show thread identity m own identity getuid board m board get name id thread getid thread get title author string author text thread get author get freetalk address fixme use the following algorithm for selecting how many characters after the to show character count 0 while two or more identities exist with author text being the same with given character count character count author text author text substring 0 author text index of 5 row add child td new string align new string left author text date row add child td new string align new string center date format format thread get date reply count row add child td new string align new string right integer to string m board thread reply count m own identity thread htmlnode threadsbox addcontentbox mboard getname htmlnode newthreadform addformchild threadsbox self_uri newthread newthreadpage newthreadform addchild ownidentityid mownidentity newthreadform addchild boardname mboard getname newthreadform addchild htmlnode threadstable threadsbox addchild htmlnode threadstable addchild addchild addchild addchild addchild dateformat dateformat dateformat getinstance mboard messagereference mboard threaditerator mownidentity hasnext getmessage threadstable addchild htmlnode titlecell addchild titlecell addchild htmlnode self_uri showthread mownidentity mboard getname gettitle authortext getauthor getfreetalkaddress charactercount authortext charactercount charactercount authortext authortext authortext indexof addchild authortext addchild dateformat getdate addchild tostring mboard threadreplycount mownidentity public misc composite context int rule float alpha color model src color model color model dst color model this rule rule this alpha alpha this src color model src color model this dst color model dst color model this src color space src color model get color space this dst color space dst color model get color space color model srgbcm color model getrg bdefault src needs converting src color model equals srgbcm dst needs converting dst color model equals srgbcm misccompositecontext colormodel srccolormodel colormodel dstcolormodel srccolormodel srccolormodel dstcolormodel dstcolormodel srccolorspace srccolormodel getcolorspace dstcolorspace dstcolormodel getcolorspace colormodel colormodel getrgbdefault srcneedsconverting srccolormodel dstneedsconverting dstcolormodel public void dispose multiply two numbers in the range 0 255 such that 255 255 255 static int multiply255 int a int b int t a b 0x80 return t 8 t 8 static int clamp int a return a 0 0 a 255 255 a public void compose raster src raster dst in writable raster dst out float a 0 ac 0 float alpha this alpha int t float s hsv null di hsv null do hsv null switch rule case misc composite hue case misc composite saturation case misc composite value case misc composite color s hsv new float 3 di hsv new float 3 do hsv new float 3 break int src pix null int dst pix null int x dst out get minx int w dst out get width int y0 dst out get miny int y1 y0 dst out get height for int y y0 y y1 y src pix src get pixels x y w 1 src pix dst pix dst in get pixels x y w 1 dst pix int i 0 int end w 4 while i end int sr src pix i int dir dst pix i int sg src pix i 1 int dig dst pix i 1 int sb src pix i 2 int dib dst pix i 2 int sa src pix i 3 int dia dst pix i 3 int dor dog dob doa switch rule case misc composite add default dor dir sr if dor 255 dor 255 dog dig sg if dog 255 dog 255 dob dib sb if dob 255 dob 255 break case misc composite subtract dor dir sr if dor 0 dor 0 dog dig sg if dog 0 dog 0 dob dib sb if dob 0 dob 0 break case misc composite difference dor dir sr if dor 0 dor dor dog dig sg if dog 0 dog dog dob dib sb if dob 0 dob dob break case misc composite multiply t dir sr 0x80 dor t 8 t 8 t dig sg 0x80 dog t 8 t 8 t dib sb 0x80 dob t 8 t 8 break case misc composite screen t 255 dir 255 sr 0x80 dor 255 t 8 t 8 t 255 dig 255 sg 0x80 dog 255 t 8 t 8 t 255 dib 255 sb 0x80 dob 255 t 8 t 8 break case misc composite overlay if dir 128 t dir sr 0x80 dor 2 t 8 t 8 else t 255 dir 255 sr 0x80 dor 2 255 t 8 t 8 if dig 128 t dig sg 0x80 dog 2 t 8 t 8 else t 255 dig 255 sg 0x80 dog 2 255 t 8 t 8 if dib 128 t dib sb 0x80 dob 2 t 8 t 8 else t 255 dib 255 sb 0x80 dob 2 255 t 8 t 8 break case misc composite darken dor dir sr dir sr dog dig sg dig sg dob dib sb dib sb break case misc composite lighten dor dir sr dir sr dog dig sg dig sg dob dib sb dib sb break case misc composite average dor dir sr 2 dog dig sg 2 dob dib sb 2 break case misc composite hue case misc composite saturation case misc composite value case misc composite color color rg btohsb sr sg sb s hsv color rg btohsb dir dig dib di hsv switch rule case misc composite hue do hsv 0 s hsv 0 do hsv 1 di hsv 1 do hsv 2 di hsv 2 break case misc composite saturation do hsv 0 di hsv 0 do hsv 1 s hsv 1 do hsv 2 di hsv 2 break case misc composite value do hsv 0 di hsv 0 do hsv 1 di hsv 1 do hsv 2 s hsv 2 break case misc composite color do hsv 0 s hsv 0 do hsv 1 s hsv 1 do hsv 2 di hsv 2 break int dorgb color hs btorgb do hsv 0 do hsv 1 do hsv 2 dor dorgb 0xff0000 16 dog dorgb 0xff00 8 dob dorgb 0xff break case misc composite burn if dir 255 dor clamp 255 int 255 sr 8 dir 1 else dor sr if dig 255 dog clamp 255 int 255 sg 8 dig 1 else dog sg if dib 255 dob clamp 255 int 255 sb 8 dib 1 else dob sb break case misc composite color burn if sr 0 dor math max 255 int 255 dir 8 sr 0 else dor sr if sg 0 dog math max 255 int 255 dig 8 sg 0 else dog sg if sb 0 dob math max 255 int 255 dib 8 sb 0 else dob sb break case misc composite dodge dor clamp sr 8 256 dir dog clamp sg 8 256 dig dob clamp sb 8 256 dib break case misc composite color dodge if sr 255 dor math min dir 8 255 sr 255 else dor sr if sg 255 dog math min dig 8 255 sg 255 else dog sg if sb 255 dob math min dib 8 255 sb 255 else dob sb break case misc composite soft light int d d multiply255 sr dir dor d multiply255 dir 255 multiply255 255 dir 255 sr d d multiply255 sg dig dog d multiply255 dig 255 multiply255 255 dig 255 sg d d multiply255 sb dib dob d multiply255 dib 255 multiply255 255 dib 255 sb d break case misc composite hard light if sr 127 dor 255 2 multiply255 255 sr 255 dir else dor 2 multiply255 sr dir if sg 127 dog 255 2 multiply255 255 sg 255 dig else dog 2 multiply255 sg dig if sb 127 dob 255 2 multiply255 255 sb 255 dib else dob 2 multiply255 sb dib break case misc composite pin light dor sr 127 math max sr dir math min sr dir dog sg 127 math max sg dig math min sg dig dob sb 127 math max sb dib math min sb dib break case misc composite exclusion dor dir multiply255 sr 255 dir dir dog dig multiply255 sg 255 dig dig dob dib multiply255 sb 255 dib dib break case misc composite negation dor 255 math abs 255 sr dir dog 255 math abs 255 sg dig dob 255 math abs 255 sb dib break a alpha sa 255f ac 1 a dst pix i int a dor ac dir dst pix i 1 int a dog ac dig dst pix i 2 int a dob ac dib dst pix i 3 int sa alpha dia ac i 4 dst out set pixels x y w 1 dst pix dstin writableraster dstout shsv dihsv dohsv misccomposite misccomposite misccomposite misccomposite shsv dihsv dohsv srcpix dstpix dstout getminx dstout getwidth dstout getminy dstout getheight srcpix getpixels srcpix dstpix dstin getpixels dstpix srcpix dstpix srcpix dstpix srcpix dstpix srcpix dstpix misccomposite misccomposite misccomposite misccomposite misccomposite misccomposite misccomposite misccomposite misccomposite misccomposite misccomposite misccomposite misccomposite rgbtohsb shsv rgbtohsb dihsv misccomposite dohsv shsv dohsv dihsv dohsv dihsv misccomposite dohsv dihsv dohsv shsv dohsv dihsv misccomposite dohsv dihsv dohsv dihsv dohsv shsv misccomposite dohsv shsv dohsv shsv dohsv dihsv hsbtorgb dohsv dohsv dohsv misccomposite misccomposite color_burn misccomposite misccomposite color_dodge misccomposite soft_light misccomposite hard_light misccomposite pin_light misccomposite misccomposite dstpix dstpix dstpix dstpix dstout setpixels dstpix boolean transfer succeeded background transfer peer node pn partially received block prb this pn pn bt new block transmitter node usm pn uid prb chk insert sender this transfersucceeded backgroundtransfer peernode partiallyreceivedblock blocktransmitter chkinsertsender void start node executor execute this chk insert background transfer for uid to pn get peer chkinsert backgroundtransfer getpeer public void run freenet support logger os thread logpid this try this real run catch throwable t this completed transfer false this received notice false logger error this caught t t osthread realrun completedtransfer receivednotice private void real run this completed transfer bt send node executor double check that the node is still connected pointless to wait otherwise if pn is connected transfer succeeded synch version this received notice wait for received notification this add ourselves as a listener for the longterm completion message of this transfer then gracefully exit try node usm add async filter get notification message filter this catch disconnected exception e normal if logminor logger minor this disconnected while adding filter this completed transfer false this received notice false else this received notice false pn local rejected overload transfer failed insert realrun completedtransfer isconnected transfersucceeded receivednotice waitforreceivednotification addasyncfilter getnotificationmessagefilter disconnectedexception completedtransfer receivednotice receivednotice localrejectedoverload transferfailedinsert private void completed transfer boolean success synchronized this transfer succeeded success completed transfer true notify all synchronized background transfers background transfers notify all if success set transfer timed out completedtransfer transfersucceeded completedtransfer notifyall backgroundtransfers backgroundtransfers notifyall settransfertimedout private void received notice boolean success synchronized this if received completion notice logger error this received notice success already had received notice completion succeeded else completion succeeded success received completion notice true notify all synchronized background transfers background transfers notify all if success set transfer timed out receivednotice receivedcompletionnotice receivednotice receivednotice completionsucceeded completionsucceeded receivedcompletionnotice notifyall backgroundtransfers backgroundtransfers notifyall settransfertimedout public void on matched message m pn success not overload peer node pn peer node m get source pn cannot be null because the filters will prevent garbage collection of the nodes if this pn equals pn boolean any timed out m get boolean dmt any timed out if any timed out chk insert sender this set transfer timed out received notice any timed out else logger error this received completion notice for wrong node pn this pn onmatched successnotoverload peernode peernode getsource anytimedout getboolean any_timed_out anytimedout chkinsertsender settransfertimedout receivednotice anytimedout public boolean should timeout afiacs this will still let the filter timeout but not call on matched twice return received completion notice shouldtimeout onmatched receivedcompletionnotice private message filter get notification message filter return message filter create set field dmt uid uid set type dmt fnp insert transfers completed set source pn set timeout transfer completion ack timeout messagefilter getnotificationmessagefilter messagefilter setfield settype fnpinserttransferscompleted setsource settimeout transfer_completion_ack_timeout public void on timeout fixme cascading timeout if this times out we don t have any time to report to the node of origin the timeout notification any timed out normal priority because it is normally caused by a transfer taking too long downstream and that doesn t usually indicate a bug logger normal this timed out waiting for a final ack from pn on this pn local rejected overload insert timeout no final ack received notice false ontimeout anytimedout localrejectedoverload inserttimeoutnofinalack receivednotice public void on disconnect peer context ctx logger normal this disconnected ctx for this received notice true as far as we know ondisconnect peercontext receivednotice public void on restarted peer context ctx logger normal this restarted ctx for this received notice true onrestarted peercontext receivednotice public int get priority return native thread high priority getpriority nativethread high_priority chk insert sender nodechk my key long uid byte headers short htl peer node source node node partially received block prb boolean from store this my key my key this target my key to normalized double this uid uid this headers headers this htl htl this source source this node node this prb prb this from store from store this start time system current time millis this background transfers new vector background transfer logminor logger should log logger minor this chkinsertsender mykey peernode partiallyreceivedblock fromstore mykey mykey mykey tonormalizeddouble fromstore fromstore starttime currenttimemillis backgroundtransfers backgroundtransfer shouldlog void start node executor execute this chk insert sender for uid uid on node get darknet port number at system current time millis chkinsertsender getdarknetportnumber currenttimemillis static final int receive failed 7 override public string to string return super to string for uid receive_failed tostring tostring public void run freenet support logger os thread logpid this short orightl synchronized this orightl htl node add insert sender my key orightl this try real run catch out of memory error e oom handler handleoom e catch throwable t logger error this caught t t finally always check we always set status even if receive failed int my status synchronized this my status status if my status not finished finish internal error null node remove insert sender my key orightl this osthread addinsertsender mykey realrun outofmemoryerror oomhandler receivefailed mystatus mystatus mystatus not_finished internal_error removeinsertsender mykey private void real run hash set peer node nodes routed to new hash set peer node peer node next null while true if receive failed return don t need to set status as killed by chk insert handler if we haven t routed to any node yet decrement according to the source if we have decrement according to the node which just failed because 1 if we always decrement according to source then we can be at max or min htl for a long time while we visit every peer node this is bad 2 the node which just failed can be seen as the requestor for our purposes decrement at this point so we can dnf immediately on reaching htl 0 htl node decrementhtl sent request next source htl synchronized this if htl 0 send an insert reply back finish success null return route it can backtrack so only route to nodes closer than we are to target next node peers closer peer source nodes routed to target true node is advanced mode enabled 1 null null if next null backtrack finish route not found null return if logminor logger minor this routing insert to next nodes routed to add next message req req dmt createfnp insert request uid htl my key wait for ack or reject will come before even a locally generated data reply message filter mf accepted message filter create set source next set field dmt uid uid set timeout accepted timeout set type dmt fnp accepted message filter mf rejected loop message filter create set source next set field dmt uid uid set timeout accepted timeout set type dmt fnp rejected loop message filter mf rejected overload message filter create set source next set field dmt uid uid set timeout accepted timeout set type dmt fnp rejected overload mf rejected overload must be the last thing in the or so its or pointer remains null otherwise we need to recreate it below mf rejected overload clear or message filter mf mf accepted or mf rejected loop or mf rejected overload send to next node try when using send sync this send can often timeout it is the first request we are sending to this node if send sync blocks here message queue is full node down etc it can take up to 10 minutes if this occurs at even two nodes in any given insert at any point in the path the entire insert chain will fatally timeout we cannot be informed if send sync does timeout a message will be logged but this thread will simply continue to the wait for and spend another timeout period there the timeout on the wait for is 10 seconds accepted timeout the interesting case is when this next node is temporarily busy in which case we might skip a busy node if they don t respond in ten seconds accepted timeout or if the length of the send queue to them is greater than accepted timeout using send async will skip them before they get the request this would be a need for retuning accepted timeout next send async req null this catch not connected exception e1 if logminor logger minor this not connected to next continue synchronized this sent request true if receive failed return don t need to set status as killed by chk insert handler message msg null because messages may be re ordered it is entirely possible that we get a non local rejected overload followed by an accepted so we must loop here while msg null msg get spec dmt fnp accepted try msg node usm wait for mf this catch disconnected exception e logger normal this disconnected from next while waiting for accepted break if receive failed return don t need to set status as killed by chk insert handler if msg null terminal overload try to propagate back to source if logminor logger minor this timeout next local rejected overload timeout3 try another node forward rejected overload break if msg get spec dmt fnp rejected overload non fatal probably still have time left if msg get boolean dmt is local next local rejected overload forward rejected overload5 if logminor logger minor this local rejected overload moving on to next peer give up on this one try another break else forward rejected overload continue if msg get spec dmt fnp rejected loop next success not overload loop we don t want to send the data to this one break if msg get spec dmt fnp accepted logger error this unexpected message waiting for accepted msg break otherwise is an fnp accepted if msg null msg get spec dmt fnp accepted continue if logminor logger minor this got accepted on this send them the data which might be the new data resulting from a collision message data insert data insert dmt createfnp data insert uid headers what are we waiting for now fnp route not found couldn t exhaust htl but send us the data anyway please fnp insert reply used up all htl yay fnp reject overload propagating an overload error fnp reject timeout we took too long to send the data insert fnp data insert rejected the insert was invalid message filter mf insert reply message filter create set source next set field dmt uid uid set timeout search timeout set type dmt fnp insert reply mf rejected overload set timeout search timeout mf rejected overload clear or message filter mf route not found message filter create set source next set field dmt uid uid set timeout search timeout set type dmt fnp route not found message filter mf data insert rejected message filter create set source next set field dmt uid uid set timeout search timeout set type dmt fnp data insert rejected message filter mf timeout message filter create set source next set field dmt uid uid set timeout search timeout set type dmt fnp rejected timeout mf mf insert reply or mf route not found or mf data insert rejected or mf timeout or mf rejected overload if logminor logger minor this sending data insert if receive failed return try next send sync data insert this catch not connected exception e1 if logminor logger minor this not connected sending data insert next for uid continue if logminor logger minor this sending data start background transfer next prb while true if receive failed return try msg node usm wait for mf this catch disconnected exception e logger normal this disconnected from next while waiting for insert reply on this break if receive failed return if msg null msg get spec dmt fnp rejected timeout timeout fairly serious problem logger error this timeout msg after accepted in insert terminal overload try to propagate back to source next local rejected overload after insert accepted timeout2 finish timed out next return if msg get spec dmt fnp rejected overload probably non fatal if so we have time left can try next one if msg get boolean dmt is local next local rejected overload forward rejected overload6 if logminor logger minor this local rejected overload moving on to next peer give up on this one try another break else forward rejected overload continue wait for any further response if msg get spec dmt fnp route not found if logminor logger minor this rejected rnf short new htl msg get short dmt htl synchronized this if htl new htl htl new htl finished as far as this node is concerned next success not overload rnf means that the htl was not exhausted but that the data will still be stored break can occur after reception of the entire chk block if msg get spec dmt fnp data insert rejected next success not overload short reason msg get short dmt data insert rejected reason if logminor logger minor this data insert rejected reason if reason dmt data insert rejected verify failed if from store that s odd logger error this verify failed on ne realrun hashset peernode nodesroutedto hashset peernode peernode receivefailed chkinserthandler sentrequest insertreply closerpeer nodesroutedto isadvancedmodeenabled route_not_found nodesroutedto createfnpinsertrequest mykey datareply messagefilter mfaccepted messagefilter setsource setfield settimeout accepted_timeout settype fnpaccepted messagefilter mfrejectedloop messagefilter setsource setfield settimeout accepted_timeout settype fnprejectedloop messagefilter mfrejectedoverload messagefilter setsource setfield settimeout accepted_timeout settype fnprejectedoverload mfrejectedoverload mfrejectedoverload clearor messagefilter mfaccepted mfrejectedloop mfrejectedoverload sendsync sendsync sendsync waitfor waitfor accepted_timeout accepted_timeout accepted_timeout sendasync accepted_timeout sendasync notconnectedexception sentrequest receivefailed chkinserthandler rejectedoverload getspec fnpaccepted waitfor disconnectedexception receivefailed chkinserthandler localrejectedoverload forwardrejectedoverload getspec fnprejectedoverload getboolean is_local localrejectedoverload forwardrejectedoverload5 rejectedoverload forwardrejectedoverload getspec fnprejectedloop successnotoverload getspec fnpaccepted fnpaccepted getspec fnpaccepted datainsert datainsert createfnpdatainsert fnproutenotfound fnpinsertreply fnprejectoverload fnprejecttimeout datainsert fnpdatainsertrejected messagefilter mfinsertreply messagefilter setsource setfield settimeout search_timeout settype fnpinsertreply mfrejectedoverload settimeout search_timeout mfrejectedoverload clearor messagefilter mfroutenotfound messagefilter setsource setfield settimeout search_timeout settype fnproutenotfound messagefilter mfdatainsertrejected messagefilter setsource setfield settimeout search_timeout settype fnpdatainsertrejected messagefilter mftimeout messagefilter setsource setfield settimeout search_timeout settype fnprejectedtimeout mfinsertreply mfroutenotfound mfdatainsertrejected mftimeout mfrejectedoverload datainsert receivefailed sendsync datainsert notconnectedexception datainsert startbackgroundtransfer receivefailed waitfor disconnectedexception insertreply receivefailed getspec fnprejectedtimeout localrejectedoverload afterinsertacceptedtimeout2 timed_out getspec fnprejectedoverload getboolean is_local localrejectedoverload forwardrejectedoverload6 rejectedoverload forwardrejectedoverload getspec fnproutenotfound newhtl getshort newhtl newhtl successnotoverload getspec fnpdatainsertrejected successnotoverload getshort data_insert_rejected_reason datainsertrejected data_insert_rejected_verify_failed fromstore private void start background transfer peer node node partially received block prb background transfer ac new background transfer node prb synchronized background transfers background transfers add ac background transfers notify all ac start startbackgroundtransfer peernode partiallyreceivedblock backgroundtransfer backgroundtransfer backgroundtransfers backgroundtransfers backgroundtransfers notifyall private boolean has forwarded rejected overload synchronized boolean received rejected overload return has forwarded rejected overload hasforwardedrejectedoverload receivedrejectedoverload hasforwardedrejectedoverload forward rejected overload to the request originator do not call if have a local rejected overload private synchronized void forward rejected overload if has forwarded rejected overload return has forwarded rejected overload true notify all rejectedoverload rejectedoverload forwardrejectedoverload hasforwardedrejectedoverload hasforwardedrejectedoverload notifyall private void set transfer timed out if transfer timed out return synchronized this if transfer timed out transfer timed out true notify all settransfertimedout transfertimedout transfertimedout transfertimedout notifyall finish the insert process will set status wait for underlings to complete and report success if appropriate param code the status code to set param next the node we successfully inserted to private void finish int code peer node next if logminor logger minor this finished code on this new exception debug synchronized this if code route not found sent request code route really not found if status not finished if status receive failed if code success logger error this request succeeded despite receive failed on this else throw new illegal state exception finish called with code when was already status else status code notify all if logminor logger minor this set status code get status string on uid boolean failed recv receive failed is protected by background transfers but status by this now wait for transfers or for downstream transfer notifications note that even the data receive may not have completed by this point synchronized background transfers if background transfers is empty wait for background transfer completions else if logminor logger minor this no background transfers failed recv receive failed synchronized this if failed recv status receive failed all transfers completed true notify all if status success next null next on success true false if logminor logger minor this returning from finish peernode route_not_found sentrequest route_really_not_found not_finished receive_failed illegalstateexception notifyall getstatusstring failedrecv receivefailed backgroundtransfers backgroundtransfers backgroundtransfers isempty waitforbackgroundtransfercompletions failedrecv receivefailed failedrecv receive_failed alltransferscompleted notifyall onsuccess public synchronized int get status return status getstatus public synchronized short gethtl return htl called by chk insert handler to notify that the receive has failed public void receive failed synchronized background transfers receive failed true background transfers notify all set status immediately the code e g wait for status relies on a status eventually being set so we may as well set it here the alternative is to set it in real run when we notice that receive failed true synchronized this status receive failed all transfers completed true notify all do not call finish that can only be called on the main thread and it will block chkinserthandler receivefailed backgroundtransfers receivefailed backgroundtransfers notifyall waitforstatus realrun receivefailed receive_failed alltransferscompleted notifyall return the current status as a string public synchronized string get status string if status success return success if status route not found return route not found if status not finished return not finished if status internal error return internal error if status timed out return timed out if status generated rejected overload return generated rejected overload if status route really not found return route really not found return unknown status code status getstatusstring route_not_found not_finished internal_error timed_out generated_rejected_overload route_really_not_found public synchronized boolean sent request return sent request sentrequest sentrequest private void wait for background transfer completions try freenet support logger os thread logpid this if logminor logger minor this waiting for background transfer completions this we must presently be at such a stage that no more background transfers will be added background transfer transfers synchronized background transfers transfers new background transfer background transfers size transfers background transfers to array transfers wait for the outgoing transfers to complete if wait for background transfers transfers set transfer timed out return finally synchronized chk insert sender this all transfers completed true chk insert sender this notify all waitforbackgroundtransfercompletions osthread backgroundtransfer backgroundtransfers backgroundtransfer backgroundtransfers backgroundtransfers toarray waitforbackgroundtransfers settransfertimedout chkinsertsender alltransferscompleted chkinsertsender notifyall block until all transfers have reached a final terminal state success failure on success this means that a successful received notification has been received return true if all background transfers were successful private boolean wait for background transfers background transfer transfers long start system current time millis generous deadline so we catch bugs more obviously long deadline start transfer completion ack timeout 3 maybe all done while true if system current time millis deadline normal priority because it is normally caused by a transfer taking too long downstream and that doesn t usually indicate a bug logger normal this timed out waiting for background transfers probably caused by async filter not getting a timeout notification debug me return false if we want to be sure to exit as soon as the transfers are done then we must hold the lock while we check synchronized background transfers if receive failed return false boolean none routeable true boolean completed transfers true boolean completed notifications true for int i 0 i transfers length i if transfers i pn is routable continue none routeable false if transfers i completed transfer if logminor logger minor this waiting for transfer completion to transfers i pn transfers i must wait completed transfers false break if transfers i received completion notice if logminor logger minor this waiting for completion notice from transfers i pn transfers i must wait completed notifications false break if transfers i completion succeeded return false if none routeable return false if completed transfers completed notifications return true if logminor logger minor this waiting transfer completion completed transfers notification completed notifications try background transfers wait 100 1000 catch interrupted exception e ignore waitforbackgroundtransfers backgroundtransfer currenttimemillis transfer_completion_ack_timeout currenttimemillis backgroundtransfers receivefailed nonerouteable completedtransfers completednotifications isroutable nonerouteable completedtransfer completedtransfers receivedcompletionnotice completednotifications completionsucceeded nonerouteable completedtransfers completednotifications completedtransfers completednotifications backgroundtransfers interruptedexception public synchronized boolean completed return all transfers completed alltransferscompleted block until status has been set to something other than not finished public synchronized void wait for status while status not finished try chk insert sender this wait 100 1000 catch interrupted exception e ignore not_finished waitforstatus not_finished chkinsertsender interruptedexception public boolean any transfers failed return transfer timed out anytransfersfailed transfertimedout public byte get pubkey hash return headers getpubkeyhash public byte get headers return headers getheaders public long getuid return uid public void sent bytes int x synchronized total bytes sync total bytes sent x node node stats insert sent bytes false x sentbytes totalbytessync totalbytessent nodestats insertsentbytes public int get total sent bytes synchronized total bytes sync return total bytes sent gettotalsentbytes totalbytessync totalbytessent public void received bytes int x synchronized total bytes sync total bytes received x node node stats insert received bytes false x receivedbytes totalbytessync totalbytesreceived nodestats insertreceivedbytes public int get total received bytes synchronized total bytes sync return total bytes received gettotalreceivedbytes totalbytessync totalbytesreceived public void sent payload int x node sent payload x node node stats insert sent bytes false x sentpayload sentpayload nodestats insertsentbytes public boolean failed receive return receive failed failedreceive receivefailed public synchronized boolean started sending data return background transfers is empty startedsendingdata backgroundtransfers isempty public int get priority return native thread high priority getpriority nativethread high_priority public transient chosen block sendable request req sendable request item token key key client key ckey boolean local request only boolean cache local requests boolean ignore store request scheduler sched super token key ckey local request only cache local requests ignore store sched this request req this sched sched transientchosenblock sendablerequest sendablerequestitem clientkey localrequestonly cachelocalrequests ignorestore requestscheduler localrequestonly cachelocalrequests ignorestore override public boolean is cancelled return request is cancelled null iscancelled iscancelled override public boolean is persistent return false ispersistent override public void on failure low level put exception e client context context sendable insert request on failure e token null context onfailure lowlevelputexception clientcontext sendableinsert onfailure override public void on insert success client context context sendable insert request on success token null context oninsertsuccess clientcontext sendableinsert onsuccess override public void on failure low level get exception e client context context sendable get request on failure e token null context onfailure lowlevelgetexception clientcontext sendableget onfailure override public void on fetch success client context context sched succeeded sendable get request false onfetchsuccess clientcontext sendableget override public short get priority return request get priority class null getpriority getpriorityclass override public sendable request sender get sender client context context return request get sender null context sendablerequestsender getsender clientcontext getsender public void open i file file int page pool size if opened throw new storage error storage error storage already opened initialize file page pool size lock new persistent resource init new object sync new object done new object commit new object listening true connect thread new thread this thread start wait synchronization completion wait initialization completion opened true begin thread transaction replication slave transaction reload scheme end thread transaction ifile pagepoolsize storageerror storageerror storage_already_opened pagepoolsize persistentresource waitsynchronizationcompletion waitinitializationcompletion beginthreadtransaction replication_slave_transaction reloadscheme endthreadtransaction check if socket is connected to the master host return code true code if connection between slave and master is sucessfully established public boolean is connected return socket null isconnected public void begin thread transaction int mode if mode replication slave transaction throw new illegal argument exception illegal transaction mode lock shared lock page pg pool get page 0 header unpack pg data pool unfix pg curr index 1 header curr curr index size header root 1 curr index index used committed index size curr index size used size header root curr index size object cache clear beginthreadtransaction replication_slave_transaction illegalargumentexception sharedlock getpage currindex currindexsize currindex indexused committedindexsize currindexsize usedsize currindex objectcache public void end thread transaction int max delay lock unlock endthreadtransaction maxdelay protected void wait synchronization completion try synchronized sync while out of sync sync wait catch interrupted exception x waitsynchronizationcompletion outofsync interruptedexception protected void wait initialization completion try synchronized init while initialized init wait catch interrupted exception x waitinitializationcompletion interruptedexception wait until database is modified by master this method blocks current thread until master node commits trasanction and this transanction is completely delivered to this slave node public void wait for modification try synchronized commit if socket null commit wait catch interrupted exception x waitformodification interruptedexception when overriden by base class this method perfroms socket error handling return code true code if host should be reconnected and attempt to send data to it should be repeated code false code if no more attmpts to communicate with this host should be performed public boolean handle error return listener null listener replication error null false handleerror replicationerror void connect try socket get socket try socket set so linger true linger time catch no such method error er try socket set tcp no delay true catch exception x in socket get input stream if replication ack out socket get output stream catch io exception x socket null in null getsocket setsolinger linger_time nosuchmethoderror settcpnodelay getinputstream replicationack getoutputstream ioexception abstract socket get socket throws io exception getsocket ioexception abstract socket get socket throws io exception void cancelio getsocket ioexception public void run byte buf new byte page page size page data offset while listening int offs 0 do int rc try rc in read buf offs buf length offs catch io exception x rc 1 synchronized done if listening return if rc 0 if handle error connect else return else offs rc while offs buf length long pos bytes unpack8 buf 0 boolean transaction commit false if pos 0 if replication ack try out write buf 0 1 catch io exception x handle error if buf page data offset db hdr curr index offset prev index prev index buf page data offset db hdr curr index offset lock exclusive lock transaction commit true else if pos repl sync synchronized sync out of sync false sync notify continue else if pos repl close synchronized commit hangup commit notify all return page pg pool put page pos system arraycopy buf page data offset pg data 0 page page size pool unfix pg if pos 0 if initialized buf page data offset db hdr initialized offset 0 synchronized init initialized true init notify if transaction commit lock unlock synchronized commit commit notify all pool flush pagesize page_data_offset ioexception handleerror transactioncommit replicationack ioexception handleerror page_data_offset db_hdr_curr_index_offset previndex previndex page_data_offset db_hdr_curr_index_offset exclusivelock transactioncommit repl_sync outofsync repl_close notifyall putpage page_data_offset pagesize page_data_offset db_hdr_initialized_offset transactioncommit notifyall public void close synchronized done listening false cancelio try thread interrupt thread join catch interrupted exception x hangup pool flush super close interruptedexception protected void hangup if socket null try in close if out null out close socket close catch io exception x in null socket null ioexception protected boolean is dirty return false isdirty public histogram histogram null num samples 0 is gray true min value null max value null min frequency null max frequency null mean null numsamples isgray minvalue maxvalue minfrequency maxfrequency public histogram int pixels int w int h int offset int stride histogram new int 3 256 min value new int 4 max value new int 4 min frequency new int 3 max frequency new int 3 mean new float 3 num samples w h is gray true int index 0 for int y 0 y h y index offset y stride for int x 0 x w x int rgb pixels index int r rgb 16 0xff int g rgb 8 0xff int b rgb 0xff histogram red r histogram green g histogram blue b for int i 0 i 256 i if histogram red i histogram green i histogram green i histogram blue i is gray false break for int i 0 i 3 i for int j 0 j 256 j if histogram i j 0 min value i j break for int j 255 j 0 j if histogram i j 0 max value i j break min frequency i integer max value max frequency i 0 for int j 0 j 256 j min frequency i math min min frequency i histogram i j max frequency i math max max frequency i histogram i j mean i float j histogram i j mean i float num samples min value gray math min math min min value red min value green min value blue max value gray math max math max max value red max value green max value blue minvalue maxvalue minfrequency maxfrequency numsamples isgray isgray minvalue maxvalue minfrequency max_value maxfrequency minfrequency minfrequency maxfrequency maxfrequency numsamples minvalue minvalue minvalue minvalue maxvalue maxvalue maxvalue maxvalue public boolean is gray return is gray isgray isgray public int get num samples return num samples getnumsamples numsamples public int get frequency int value if num samples 0 is gray value 0 value 255 return histogram 0 value return 1 getfrequency numsamples isgray public int get frequency int channel int value if num samples 1 channel 0 channel 2 value 0 value 255 return 1 return histogram channel value getfrequency numsamples public int get min frequency if num samples 0 is gray return min frequency 0 return 1 getminfrequency numsamples isgray minfrequency public int get min frequency int channel if num samples 1 channel 0 channel 2 return 1 return min frequency channel getminfrequency numsamples minfrequency public int get max frequency if num samples 0 is gray return max frequency 0 return 1 getmaxfrequency numsamples isgray maxfrequency public int get max frequency int channel if num samples 1 channel 0 channel 2 return 1 return max frequency channel getmaxfrequency numsamples maxfrequency public int get min value if num samples 0 is gray return min value 0 return 1 getminvalue numsamples isgray minvalue public int get min value int channel return min value channel getminvalue minvalue public int get max value if num samples 0 is gray return max value 0 return 1 getmaxvalue numsamples isgray maxvalue public int get max value int channel return max value channel getmaxvalue maxvalue public float get mean value if num samples 0 is gray return mean 0 return 1 0f getmeanvalue numsamples isgray public float get mean value int channel if num samples 0 red channel channel blue return mean channel return 1 0f getmeanvalue numsamples test harness public static void main string args throws url encoded format exception for int i 0 i args length i system out println args i decode args i false urlencodedformatexception decodes a url encoder format string param s string to be translated param tolerant if true be tolerant of bogus escapes bogus escapes are treated as just plain characters not recommended a hack to allow users to paste in ur ls containing s return the translated string public static string decode string s boolean tolerant throws url encoded format exception if s length 0 return int len s length byte array output stream decoded bytes new byte array output stream boolean has decoded something false for int i 0 i len i char c s char at i if c if i len 2 throw new url encoded format exception s char hex chars new char 2 hex chars 0 s char at i hex chars 1 s char at i string hexval new string hex chars try long read fields hex to long hexval if read 0 throw new url encoded format exception can t encode 00 decoded bytes write int read has decoded something true catch number format exception nfe not encoded if tolerant has decoded something try byte buf hexval get bytes utf 8 decoded bytes write buf 0 buf length continue catch unsupported encoding exception e throw new error impossible jvm doesn t support utf 8 e e throw new url encoded format exception not a two character hex escape hexval in s else try byte encoded c get bytes utf 8 decoded bytes write encoded 0 encoded length catch unsupported encoding exception e throw new error impossible jvm doesn t support utf 8 e e try decoded bytes close return new string decoded bytes to byte array utf 8 catch io exception ioe1 if this throws something s wrong throw new url encoded format exception s urlencoder urls urlencodedformatexception bytearrayoutputstream decodedbytes bytearrayoutputstream hasdecodedsomething charat urlencodedformatexception hexchars hexchars charat hexchars charat hexchars hextolong urlencodedformatexception decodedbytes hasdecodedsomething numberformatexception hasdecodedsomething getbytes decodedbytes unsupportedencodingexception urlencodedformatexception getbytes decodedbytes unsupportedencodingexception decodedbytes decodedbytes tobytearray ioexception urlencodedformatexception construct a crop filter public crop filter this 0 0 32 32 cropfilter cropfilter construct a crop filter param x the left edge of the crop rectangle param y the top edge of the crop rectangle param width the width of the crop rectangle param height the height of the crop rectangle public crop filter int x int y int width int height this x x this y y this width width this height height cropfilter cropfilter set the left edge of the crop rectangle param x the left edge of the crop rectangle see getx public void setx int x this x x get the left edge of the crop rectangle return the left edge of the crop rectangle see setx public int getx return x set the top edge of the crop rectangle param y the top edge of the crop rectangle see gety public void sety int y this y y get the top edge of the crop rectangle return the top edge of the crop rectangle see sety public int gety return y set the width of the crop rectangle param width the width of the crop rectangle see get width public void set width int width this width width getwidth setwidth get the width of the crop rectangle return the width of the crop rectangle see set width public int get width return width setwidth getwidth set the height of the crop rectangle param height the height of the crop rectangle see get height public void set height int height this height height getheight setheight get the height of the crop rectangle return the height of the crop rectangle see set height public int get height return height setheight getheight public buffered image filter buffered image src buffered image dst int w src get width int h src get height if dst null color model dstcm src get color model dst new buffered image dstcm dstcm create compatible writable raster width height dstcm is alpha premultiplied null graphics2d g dst create graphics g draw rendered image src affine transform get translate instance x y g dispose return dst bufferedimage bufferedimage bufferedimage getwidth getheight colormodel getcolormodel bufferedimage createcompatiblewritableraster isalphapremultiplied creategraphics drawrenderedimage affinetransform gettranslateinstance override public string to string return distort crop tostring public class key listener construction exception extends exception key listener construction exception fetch exception e super e keylistenerconstructionexception keylistenerconstructionexception fetchexception public fetch exception get fetch exception return fetch exception get cause fetchexception getfetchexception fetchexception getcause public abstract class relation m extends i persistent o extends i persistent extends persistent implements link m get relation owner return owner of the relation public o get owner return owner ipersistent ipersistent getowner set relation owner param owner new owner of the relation public void set owner o owner this owner owner modify setowner relation constructor creates empty relation with specified owner and no members members can be added to the relation later param owner owner of the relation public relation o owner this owner owner protected relation public action response set header http ext actionresponse setheader public action response soap response soap res super soap res set header http ext actionresponse soapresponse soapres soapres setheader public void set response action action set status code http status ok node body node get body node node res node create response node action body node add node res node node env node get envelope node set content env node setresponse setstatuscode httpstatus bodynode getbodynode resnode createresponsenode bodynode addnode resnode envnode getenvelopenode setcontent envnode private node create response node action action string action name action get name node action name res node new node soap methodns soap delim action name soap response service service action get service if service null action name res node set attribute xmlns soap methodns service get service type argument list arg list action get argument list int n args arg list size for int n 0 n n args n argument arg arg list get argument n if arg is out direction false continue node arg node new node arg node set name arg get name arg node set value arg get value action name res node add node arg node return action name res node createresponsenode actionname getname actionnameresnode actionname getservice actionnameresnode setattribute getservicetype argumentlist arglist getargumentlist nargs arglist nargs arglist getargument isoutdirection argnode argnode setname getname argnode setvalue getvalue actionnameresnode addnode argnode actionnameresnode private node get action response node node body node get body node if body node null body node has nodes false return null return body node get node 0 getactionresponsenode bodynode getbodynode bodynode bodynode hasnodes bodynode getnode public argument list get response argument list arg list new argument list node res node get action response node if res node null return arg list int n args res node getn nodes for int n 0 n n args n node node res node get node n string name node get name string value node get value argument arg new argument name value arg list add arg return arg list argumentlist getresponse argumentlist arglist argumentlist resnode getactionresponsenode resnode arglist nargs resnode getnnodes nargs resnode getnode getname getvalue arglist arglist public static void main string args throws fs parse exception peer parse exception chk encode exception invalid threshold exception node init exception reference signature verification exception interrupted exception string name real node request insert test file wd new file name if file util remove all wd system err println mass delete failed test may not be accurate system exit exit cannot delete old data wd mkdir note global test init returns in ignored random source node starter global test init name false logger error freenet node location normal freenet node simulator real node minor freenet node insert minor freenet node request minor freenet node node minor node starter global test init name false logger error freenet node location minor freenet io comm minor freenet node node dispatcher minor freenet node simulator minor freenet node peer manager minor freenet node request sender minor node starter global test init name false logger error freenet node fnp minor freenet node packet minor freenet io comm minor freenet node peer node minor freenet node darknet peer node minor node starter global test init name false logger error true system out println insert retrieve test system out println dummy random source random new dummy random source diffie hellman init random node nodes new node number of nodes logger normal real node routing test class creating nodes executor executor new pooled executor for int i 0 i number of nodes i nodes i node starter create test node 5001 i 0 name false true false max htl 20 5 random executor 500 number of nodes 256 1024 true enable swapping false enable ulprs enable per node failure tables enable swap queueing enable packet coalescing 12000 enable foaf false null logger normal real node routing test class created node i now link them up make kleinberg network nodes start with ideal locations degree force neighbour connections logger normal real node routing test class added random links for int i 0 i number of nodes i nodes i start false system err println started node i nodes length wait for all connected nodes wait for ping average 0 95 nodes random max pings 1000 system out println system out println ping average 95 lets do some inserts requests system out println int request number 0 running average requests avg new simple running average 100 0 0 string base string system current time millis int insert attempts 0 int insert successes 0 int fetch successes 0 while true try request number try thread sleep 100 catch interrupted exception e1 string data string base string request number pick random node to insert to int node1 random next int number of nodes node random node nodes node1 logger error real node request insert test class inserting data string to node1 boolean isssk request number 2 1 boolean isssk true freeneturi test key client key insert key client key fetch key client key block block byte buf data string get bytes utf 8 if isssk test key new freeneturi ksk data string insert key insertable clientssk create test key fetch key clientksk create test key block insertable clientssk insert key encode new array bucket buf false false short 1 buf length random else block clientchk block encode buf false false short 1 buf length insert key fetch key block get client key test key insert key geturi system err println system err println created random test key test key fetch key get node key system err println byte data data string get bytes utf 8 logger minor real node request insert test class decoded new string block memory decode logger normal real node request insert test class insert key insert key geturi logger normal real node request insert test class fetch key fetch key geturi try insert attempts random node client core real put block true logger error real node request insert test class inserted to node1 insert successes catch freenet node low level put exception put ex logger error real node request insert test class insert failed put ex system err println insert failed put ex system exit exit insert failed pick random node to request from int node2 do node2 random next int number of nodes while node2 node1 node fetch node nodes node2 block fetch node client core real get key fetch key false true false if block null int percent success 100 fetch successes insert attempts logger error real node request insert test class fetch request number failed percent success from node2 requests avg report 0 0 system exit exit request failed else byte results block memory decode requests avg report 1 0 if arrays equals results data fetch successes int percent success 100 fetch successes insert attempts logger error real node request insert test class fetch request number from node node2 succeeded percent success new string results system err println fetch request number succeeded percent success new string results if fetch successes target successes system err println succeeded target successes successful fetches system exit 0 else logger error real node request insert test class returned invalid data new string results system err println returned invalid data new string results system exit exit bad data string builder load new string builder running ui ds for nodes int total runningui ds 0 int total runningui ds alt 0 vector long runningui ds list new vector long for int i 0 i nodes length i load append i load append nodes i add runningui ds runningui ds list int runningui ds nodes i get total runningui ds int runningui ds alt nodes i get total runningui ds alt total runningui ds runningui ds total runningui ds alt runningui ds alt load append total runningui ds load append load append total runningui ds alt if i nodes length 1 load append system err println load to string if total runningui ds 0 system err println still running ui ds total runningui ds if total runningui ds alt 0 system err println still running ui ds alt total runningui ds alt if runningui ds list is empty system err println list of running ui ds arrays to string runningui ds list to array catch throwable t logger error real node request insert test class caught t t fsparseexception peerparseexception chkencodeexception invalidthresholdexception nodeinitexception referencesignatureverificationexception interruptedexception realnoderequestinserttest fileutil removeall exit_cannot_delete_old_data globaltestinit nodestarter globaltestinit realnode nodestarter globaltestinit nodedispatcher peermanager requestsender nodestarter globaltestinit peernode darknetpeernode nodestarter globaltestinit dummyrandomsource dummyrandomsource diffiehellman number_of_nodes realnoderoutingtest pooledexecutor number_of_nodes nodestarter createtestnode max_htl number_of_nodes enable_swapping enable_ulprs enable_per_node_failure_tables enable_swap_queueing enable_packet_coalescing enable_foaf realnoderoutingtest makekleinbergnetwork start_with_ideal_locations force_neighbour_connections realnoderoutingtest number_of_nodes waitforallconnected waitforpingaverage max_pings requestnumber runningaverage requestsavg simplerunningaverage basestring currenttimemillis insertattempts insertsuccesses fetchsuccesses requestnumber interruptedexception datastring basestring requestnumber nextint number_of_nodes randomnode realnoderequestinserttest datastring requestnumber testkey clientkey insertkey clientkey fetchkey clientkeyblock datastring getbytes testkey datastring insertkey insertableclientssk testkey fetchkey testkey insertableclientssk insertkey arraybucket clientchkblock insertkey fetchkey getclientkey testkey insertkey testkey fetchkey getnodekey datastring getbytes realnoderequestinserttest memorydecode realnoderequestinserttest insertkey realnoderequestinserttest fetchkey insertattempts randomnode clientcore realput realnoderequestinserttest insertsuccesses lowlevelputexception putex realnoderequestinserttest putex putex exit_insert_failed nextint number_of_nodes fetchnode fetchnode clientcore realgetkey fetchkey percentsuccess fetchsuccesses insertattempts realnoderequestinserttest requestnumber percentsuccess requestsavg exit_request_failed memorydecode requestsavg fetchsuccesses percentsuccess fetchsuccesses insertattempts realnoderequestinserttest requestnumber percentsuccess requestnumber percentsuccess fetchsuccesses target_successes target_successes realnoderequestinserttest exit_bad_data stringbuilder stringbuilder uids totalrunninguids totalrunninguidsalt runninguidslist addrunninguids runninguidslist runninguids gettotalrunninguids runninguidsalt gettotalrunninguidsalt totalrunninguids runninguids totalrunninguidsalt runninguidsalt totalrunninguids totalrunninguidsalt tostring totalrunninguids uids totalrunninguids totalrunninguidsalt uids totalrunninguidsalt runninguidslist isempty uids tostring runninguidslist toarray realnoderequestinserttest public static void initialize node node snmp agent setsnmp port port if has been runned return 0 is toatl i o io statistic collector collector node collector for int i 0 i io statistic collector statistics entries i snmp agent getsnmp agent add fetcher new data statistics info i true collector snmp agent getsnmp agent add fetcher new data statistics info i false collector snmp agent getsnmp agent add fetcher new info system has been runned true snmpagent setsnmpport has_been_runned iostatisticcollector iostatisticcollector statistics_entries snmpagent getsnmpagent addfetcher datastatisticsinfo snmpagent getsnmpagent addfetcher datastatisticsinfo snmpagent getsnmpagent addfetcher infosystem has_been_runned public static void maybe create node node config config fixme any config needed for snmp starter maybecreate snmpstarter set the amount of effect param amount the amount min value 0 max value 1 see get amount public void set amount float amount this amount amount getamount setamount get the amount of chrome return the amount see set amount public float get amount return amount setamount getamount set the exppsure of the effect param exposure the exposure min value 0 max value 1 see get exposure public void set exposure float exposure this exposure exposure getexposure setexposure get the exppsure of the effect return the exposure see set exposure public float get exposure return exposure setexposure getexposure override public buffered image filter buffered image src buffered image dst set color source light filter colors constant dst super filter src dst transfer filter tf new transfer filter override protected float transfer function float v v amount float math sin v 2 math pi return 1 float math exp v exposure return tf filter dst dst bufferedimage bufferedimage bufferedimage setcolorsource lightfilter colors_constant transferfilter transferfilter transferfunction transfer filter tf new transfer filter override protected float transfer function float v v amount float math sin v 2 math pi return 1 float math exp v exposure transferfilter transferfilter transferfunction override public string to string return effects chrome tostring logger register log threshold callback new log threshold callback override public void should update logminor logger should log logger minor this registerlogthresholdcallback logthresholdcallback shouldupdate shouldlog public client put dir fcp connection handler handler client put dir message message hash map string object manifest elements boolean was disk put fcp server server object container container throws identifier collision exception malformedurl exception super message uri message identifier message verbosity handler message priority class message persistence type message client token message global message getchk only message dont compress message max retries message early encode server container logminor logger should log logger minor this this was disk put was disk put object on new is called once object on update is never called yet manifest elements get blanked anyway this manifest elements new hash map string object this manifest elements put all manifest elements this manifest elements manifest elements this manifest elements new hash map string object this manifest elements put all manifest elements this default name message default name make putter if putter null number of files putter count files total size putter total size else number of files 1 total size 1 if logminor logger minor this putting dir identifier priority class clientputdir fcpconnectionhandler clientputdirmessage hashmap manifestelements wasdiskput fcpserver objectcontainer identifiercollisionexception malformedurlexception priorityclass persistencetype clienttoken getchkonly dontcompress maxretries earlyencode shouldlog wasdiskput wasdiskput objectonnew objectonupdate manifestelements manifestelements hashmap manifestelements putall manifestelements manifestelements manifestelements manifestelements hashmap manifestelements putall manifestelements defaultname defaultname makeputter numberoffiles countfiles totalsize totalsize numberoffiles totalsize priorityclass puts a disk dir throws insert exception public client put dir fcp client client freeneturi uri string identifier int verbosity short priority class short persistence type string client token boolean getchk only boolean dont compress int max retries file dir string default name boolean allow unreadable files boolean global boolean early encode fcp server server object container container throws file not found exception identifier collision exception malformedurl exception super uri identifier verbosity null client priority class persistence type client token global getchk only dont compress max retries early encode server container was disk put true logminor logger should log logger minor this this manifest elements make disk dir manifest dir allow unreadable files this default name default name make putter if putter null number of files putter count files total size putter total size else number of files 1 total size 1 if logminor logger minor this putting dir identifier priority class insertexception clientputdir fcpclient priorityclass persistencetype clienttoken getchkonly dontcompress maxretries defaultname allowunreadablefiles earlyencode fcpserver objectcontainer filenotfoundexception identifiercollisionexception malformedurlexception priorityclass persistencetype clienttoken getchkonly dontcompress maxretries earlyencode wasdiskput shouldlog manifestelements makediskdirmanifest allowunreadablefiles defaultname defaultname makeputter numberoffiles countfiles totalsize totalsize numberoffiles totalsize priorityclass override void register object container container boolean lazy resume boolean no tags throws identifier collision exception if persistence type persist connection client register this false container if persistence type persist connection no tags fcp message msg persistent tag message container client queue client request message msg 0 container objectcontainer lazyresume notags identifiercollisionexception persistencetype persist_connection persistencetype persist_connection notags fcpmessage persistenttagmessage queueclientrequestmessage private hash map string object make disk dir manifest file dir string prefix boolean allow unreadable files throws file not found exception hash map string object map new hash map string object file files dir list files if files null throw new illegal argument exception no such directory for file f files if f exists f can read if f is file file bucket bucket new file bucket f true false false false false if logminor logger minor this add file f get absolute path map put f get name new manifest element f get name prefix f get name bucket defaultmime types guessmime type f get name true f length else if f is directory if logminor logger minor this add dir f get absolute path map put f get name make disk dir manifest f prefix f get name allow unreadable files else if allow unreadable files throw new file not found exception not a file and not a directory f else if allow unreadable files throw new file not found exception the file does not exist or is unreadable f return map hashmap makediskdirmanifest allowunreadablefiles filenotfoundexception hashmap hashmap listfiles illegalargumentexception canread isfile filebucket filebucket getabsolutepath getname manifestelement getname getname defaultmimetypes guessmimetype getname isdirectory getabsolutepath getname makediskdirmanifest getname allowunreadablefiles allowunreadablefiles filenotfoundexception allowunreadablefiles filenotfoundexception private void make putter simple manifest putter p p new simple manifest putter this manifest elements priority class uri default name ctx getchk only low level client early encode putter p makeputter simplemanifestputter simplemanifestputter manifestelements priorityclass defaultname getchkonly lowlevelclient earlyencode public client put dir simple field set fs fcp client client fcp server server object container container throws persistence parse exception io exception super fs client server logminor logger should log logger minor this simple field set files fs subset files default name fs get default name string type fs get put dir type if type equals disk was disk put true else was disk put false flattened for disk sort out afterwards int file count 0 long size 0 vector manifest element v new vector manifest element for int i 0 i string num integer to string i simple field set subset files subset num if subset null break otherwise serialize string name subset get name if name null throw new persistence parse exception no name on i string content type override subset get metadata content type string upload from subset get upload from bucket data null if logminor logger minor this parsing i if logminor logger minor this upload from upload from manifest element me if upload from null upload from equals ignore case direct long sz long parse long subset get data length if finished try data serializable to field set bucket util create fs subset return bucket server core random server core persistent temp bucket factory catch cannot create from field set exception e throw new persistence parse exception could not read old bucket for identifier e e else data null me new manifest element name data content type override sz file count else if upload from equals ignore case disk long sz long parse long subset get data length disk string f subset get filename if f null throw new persistence parse exception upload from disk but no name on i file ff new file f if ff exists ff can read logger error this file no longer exists cancelling upload ff throw new io exception file no longer exists cancelling upload ff data new file bucket ff true false false false false me new manifest element name data content type override sz file count else if upload from equals ignore case redirect freeneturi targeturi new freeneturi subset get targeturi me new manifest element name targeturi content type override else throw new persistence parse exception don t know upload from upload from v add me if data null data size 0 size data size manifest elements simple manifest putter unflatten v simple manifest putter p null if finished p new simple manifest putter this manifest elements priority class uri default name ctx getchk only low level client early encode putter p number of files file count total size size if persistence type persist connection fcp message msg persistent tag message container client queue client request message msg 0 container clientputdir simplefieldset fcpclient fcpserver objectcontainer persistenceparseexception ioexception shouldlog simplefieldset defaultname defaultname putdirtype wasdiskput wasdiskput filecount manifestelement manifestelement tostring simplefieldset persistenceparseexception contenttypeoverride contenttype uploadfrom uploadfrom uploadfrom uploadfrom manifestelement uploadfrom uploadfrom equalsignorecase parselong datalength serializabletofieldsetbucketutil returnbucket persistenttempbucketfactory cannotcreatefromfieldsetexception persistenceparseexception manifestelement contenttypeoverride filecount uploadfrom equalsignorecase parselong datalength persistenceparseexception uploadfrom canread ioexception filebucket manifestelement contenttypeoverride filecount uploadfrom equalsignorecase manifestelement contenttypeoverride persistenceparseexception uploadfrom uploadfrom manifestelements simplemanifestputter simplemanifestputter simplemanifestputter manifestelements priorityclass defaultname getchkonly lowlevelclient earlyencode numberoffiles filecount totalsize persistencetype persist_connection fcpmessage persistenttagmessage queueclientrequestmessage override public void start object container container client context context if finished return if started return try if putter null putter start container context started true if logminor logger minor this started putter for this persistence persistence type if persistence type persist connection finished fcp message msg persistent tag message container client queue client request message msg 0 container if persistence type persist forever container store this update catch insert exception e started true on failure e null container objectcontainer clientcontext persistencetype persistencetype persist_connection fcpmessage persistenttagmessage queueclientrequestmessage persistencetype persist_forever insertexception onfailure override public void on lost connection object container container client context context if persistence type persist connection cancel container context otherwise ignore onlostconnection objectcontainer clientcontext persistencetype persist_connection override suppress warnings unchecked protected void free data object container container if logminor logger minor this free data on this persistence type persistence type synchronized this if manifest elements null if logminor logger minor this manifest elements manifest elements persistence type persist forever dir active container ext is active this new exception error return if logminor logger minor this free data more on this persistence type persistence type we have to commit everything so activating everything here doesn t cost us much memory if persistence type persist forever container deactivate manifest elements 1 must deactivate before activating if it has been activated to depth 1 empty map at some point it will fail to activate to depth 2 with contents see http tracker db4o com browse cor 1582 container activate manifest elements integer max value free data manifest elements container manifest elements null if persistence type persist forever container store this suppresswarnings freedata objectcontainer freedata persistencetype manifestelements manifestelements manifestelements persistencetype persist_forever isactive freedata persistencetype persistencetype persist_forever manifestelements manifestelements max_value freedata manifestelements manifestelements persistencetype persist_forever suppress warnings unchecked private void free data hash map string object manifest elements object container container if logminor logger minor this free data inner on this persistence type persistence type size manifest elements size iterator i manifest elements values iterator while i has next object o i next if o instanceof hash map free data hash map string object o container else manifest element e manifest element o if logminor logger minor this freeing e e free data container persistence type persist forever if persistence type persist forever container delete manifest elements suppresswarnings freedata hashmap manifestelements objectcontainer freedata persistencetype manifestelements manifestelements hasnext hashmap freedata hashmap manifestelement manifestelement freedata persistencetype persist_forever persistencetype persist_forever manifestelements override protected client requester get client request return putter clientrequester getclientrequest override public simple field set get field set simple field set fs super get field set translate manifest elements directly into a fieldset simple field set files new simple field set false flatten the hierarchy it can be reconstructed on restarting storing it directly would be a pita manifest element elements simple manifest putter flatten manifest elements fs put single default name default name fs put single put dir type was disk put disk complex for int i 0 i elements length i string num integer to string i manifest element e elements i string name e get name string mime override e get mime type override simple field set subset new simple field set false subset put single name name if mime override null subset put single metadata content type mime override freeneturi target e get targeturi if target null subset put single upload from redirect subset put single targeturi target to string else bucket data e get data what to do with the bucket it is either a persistent encrypted bucket or a file bucket subset put single data length long to string e get size if data instanceof file bucket subset put single upload from disk subset put single filename file bucket data get file get path else if finished subset put single upload from direct else if data instanceof padded ephemerally encrypted bucket subset put single upload from direct the bucket is a persistent encrypted temp bucket bucket tofs fs temp bucket false data else throw new illegal state exception don t know what to do with bucket data files put num subset fs put files files return fs simplefieldset getfieldset simplefieldset getfieldset manifestelements simplefieldset simplefieldset manifestelement simplemanifestputter manifestelements putsingle defaultname defaultname putsingle putdirtype wasdiskput tostring manifestelement getname mimeoverride getmimetypeoverride simplefieldset simplefieldset putsingle mimeoverride putsingle contenttype mimeoverride gettargeturi putsingle uploadfrom putsingle tostring getdata putsingle datalength tostring getsize filebucket putsingle uploadfrom putsingle filebucket getfile getpath putsingle uploadfrom paddedephemerallyencryptedbucket putsingle uploadfrom buckettofs tempbucket illegalstateexception override protected fcp message persistent tag message object container container if persistence type persist forever container activate publicuri 5 container activate ctx 1 container activate manifest elements 5 return new persistent put dir identifier publicuri verbosity priority class persistence type global default name manifest elements client token started ctx max insert retries was disk put container fcpmessage persistenttagmessage objectcontainer persistencetype persist_forever manifestelements persistentputdir priorityclass persistencetype defaultname manifestelements clienttoken maxinsertretries wasdiskput override protected string get type name return putdir gettypename override public boolean has succeeded return succeeded hassucceeded public freeneturi get finaluri object container container if persistence type persist forever container activate generateduri 5 return generateduri getfinaluri objectcontainer persistencetype persist_forever public int get number of files return number of files getnumberoffiles numberoffiles public long get total data size return total size gettotaldatasize totalsize override public boolean can restart if finished logger minor this cannot restart because not finished for identifier return false if succeeded logger minor this cannot restart because succeeded for identifier return false return true canrestart override public boolean restart object container container client context context if can restart return false set vars restart container make putter start container context return true objectcontainer clientcontext canrestart setvarsrestart makeputter public void on failure fetch exception e client getter state object container container onfailure fetchexception clientgetter objectcontainer public void on failure fetch exception e client getter state object container container public void on success fetch result result client getter state object container container onfailure fetchexception clientgetter objectcontainer onsuccess fetchresult clientgetter objectcontainer public void on success fetch result result client getter state object container container override public void on success base client putter state object container container super on success state container onsuccess fetchresult clientgetter objectcontainer onsuccess baseclientputter objectcontainer onsuccess override public void on failure insert exception e base client putter state object container container super on failure e state container onfailure insertexception baseclientputter objectcontainer onfailure public void on remove event producer object container container do nothing we called the remove from onremoveeventproducer objectcontainer removefrom override public void request was removed object container container client context context if persistence type persist forever container activate putter 1 putter remove from container context putter null super request was removed container context requestwasremoved objectcontainer clientcontext persistencetype persist_forever removefrom requestwasremoved public class soft hash table extends weak hash table public soft hash table int initial capacity super initial capacity softhashtable weakhashtable softhashtable initialcapacity initialcapacity protected reference create reference object obj return new soft reference obj createreference softreference get the value of a property for this algorithm public static string get property string key return properties get property key getproperty getproperty get the value of a property for this algorithm or return i value i if the property was not set public static string get property string key string value return properties get property key value getproperty getproperty list algorithm properties to the print stream i out i public static void list print stream out list new print writer out true printstream printstream printwriter list algorithm properties to the print writer i out i public static void list print writer out out println out println begin algorithm properties out println string key value enumeration enu properties property names while enu has more elements key string enu next element value get property key out println key value out println out println end algorithm properties printwriter printwriter propertynames hasmoreelements nextelement getproperty public synchronized void load input stream in throws io exception public static enumeration property names return properties property names inputstream ioexception propertynames propertynames return true if tracing is requested for a given class p user indicates this by setting the tracing code boolean code property for i label i in the code algorithm properties code file the property s key is code trace i label i code p param label the name of a class return true iff a boolean true value is set for a property with the key code trace i label i code static boolean is traceable string label string s get property trace label if s null return false return boolean value of s boolean value istraceable getproperty valueof booleanvalue return the debug level for a given class p user indicates this by setting the numeric property with key code debug level i label i code p if this property is not set code debug level code is looked up next if neither property is set or if the first property found is not a valid decimal integer then this method returns 0 param label the name of a class return the required debugging level for the designated class static int get level string label string s get property debug level label if s null s get property debug level if s null return 0 try return integer parse int s catch number format exception e return 0 getlevel getproperty getproperty parseint numberformatexception return the print writer to which tracing and debugging output is to be sent p user indicates this by setting the property with key code output code to the literal code out code or code err code p by default or if the set value is not allowed code system err code will be used static print writer get output print writer pw string name get property output if name null name equals out pw new print writer system out true else pw new print writer system err true return pw printwriter printwriter getoutput printwriter getproperty printwriter printwriter private int mask public mask filter this 0xff00ffff maskfilter public mask filter int mask can filter index color model true set mask mask maskfilter canfilterindexcolormodel setmask public void set mask int mask this mask mask setmask public int get mask return mask getmask override public int filterrgb int x int y int rgb return rgb mask override public string to string return mask tostring public final compressor type codec public started compression event compressor type codec this codec codec compressor_type startedcompressionevent compressor_type final static int code 0x08 public string get description return started compression attempt with codec name getdescription public int get code return code getcode public class string option extends option string public string option sub config conf string option name string default value int sort order boolean expert boolean force write string short desc string long desc string callback cb super conf option name cb sort order expert force write short desc long desc option data type string this default value default value this current value default value stringoption stringoption subconfig optionname defaultvalue sortorder forcewrite shortdesc longdesc stringcallback optionname sortorder forcewrite shortdesc longdesc datatype defaultvalue defaultvalue currentvalue defaultvalue override protected string parse string string val throws invalid config value exception return val parsestring invalidconfigvalueexception override protected string to string string val return val tostring public void write long page addr byte buf try long page offs 0 int page size buf length if page addr 0 assert that page size page page size assert that page addr page page size 1 0 long page pos page map get page addr boolean first update false if page pos 0 int bp int page addr page page size log 3 if bp 8 page index size byte pos buf new byte 8 page index buffer position bp page index buffer get pos buf 0 8 page pos bytes unpack8 pos buf 0 first update true page size int page pos page page size 1 1 deflater reset deflater set input buf 0 buf length deflater finish int new page size deflater deflate compression buf if new page size page page size system arraycopy buf 0 compression buf 0 new page size buf compression buf int new page bit size new page size allocation quantum 1 allocation quantum log int old page bit size page size allocation quantum 1 allocation quantum log if first update new page bit size old page bit size if first update bitmap free bitmap page pos page page size log allocation quantum log old page bit size page offs allocate new page bit size else page offs page pos page page size log page size new page size page map put page addr page offs page page size log page size 1 page pos crypt buf page size data file seek page offs data file write buf 0 page size catch io exception x throw new storage error storage error file access error x pageaddr pageoffs pagesize pageaddr pagesize pagesize pageaddr pagesize pagepos pagemap pageaddr firstupdate pagepos pageaddr pagesizelog pageindexsize posbuf pageindexbuffer pageindexbuffer posbuf pagepos posbuf firstupdate pagesize pagepos pagesize setinput newpagesize compressionbuf newpagesize pagesize compressionbuf newpagesize compressionbuf newpagebitsize newpagesize allocation_quantum allocation_quantum_log oldpagebitsize pagesize allocation_quantum allocation_quantum_log firstupdate newpagebitsize oldpagebitsize firstupdate pagepos pagesizelog allocation_quantum_log oldpagebitsize pageoffs newpagebitsize pageoffs pagepos pagesizelog pagesize newpagesize pagemap pageaddr pageoffs pagesizelog pagesize pagepos pagesize datafile pageoffs datafile pagesize ioexception storageerror storageerror file_access_error public int read long page addr byte buf try if page addr 0 assert that page addr page page size 1 0 long page pos 0 if page map null page pos page map get page addr if page pos 0 int bp int page addr page page size log 3 if bp 8 page index size byte pos buf new byte 8 page index buffer position bp page index buffer get pos buf 0 8 page pos bytes unpack8 pos buf 0 if page pos 0 system out println page pos 0 for address page addr return 0 data file seek page pos page page size log int size int page pos page page size 1 1 system out println read size bytes from page pos page page size log int rc data file read compression buf 0 size if rc size throw new storage error storage error file access error crypt compression buf size if size page page size inflater reset inflater set input compression buf 0 size rc inflater inflate buf assert that rc page page size else system arraycopy compression buf 0 buf 0 rc return rc else data file seek 0 return data file read buf 0 buf length catch exception x throw new storage error storage error file access error x pageaddr pageaddr pageaddr pagesize pagepos pagemap pagepos pagemap pageaddr pagepos pageaddr pagesizelog pageindexsize posbuf pageindexbuffer pageindexbuffer posbuf pagepos posbuf pagepos pagepos pageaddr datafile pagepos pagesizelog pagepos pagesize pagepos pagesizelog datafile compressionbuf storageerror storageerror file_access_error compressionbuf pagesize setinput compressionbuf pagesize compressionbuf datafile datafile storageerror storageerror file_access_error public void sync try flush data to the main database file if no flush data file getfd sync int tx size page map size if tx size 0 return make sure that new page mapping is saved in transaction log byte buf new byte 4 16 tx size bytes pack4 buf 0 tx size int pos 4 for page map entry e page map bytes pack8 buf pos e addr bytes pack8 buf pos 8 e new pos pos 16 page index log file write buf 0 pos if no flush page index log file getfd sync store new page mapping in the page index file for page map entry e page map set position e addr bytes pack8 buf 0 e new pos page index buffer put buf 0 8 if e old pos 0 bitmap free bitmap e old pos page page size log allocation quantum log e old pos page page size 1 allocation quantum allocation quantum log page map clear truncate log if necessary if page index log file length page index checkpoint threshold page index buffer force page index log file set length 0 catch io exception x throw new storage error storage error file access error x noflush datafile txsize pagemap txsize txsize txsize pagemap pagemap newpos pageindexlogfile noflush pageindexlogfile pagemap pagemap setposition newpos pageindexbuffer oldpos oldpos pagesizelog allocation_quantum_log oldpos pagesize allocation_quantum allocation_quantum_log pagemap pageindexlogfile pageindexcheckpointthreshold pageindexbuffer pageindexlogfile setlength ioexception storageerror storageerror file_access_error public boolean try lock boolean shared try lck data chan try lock 0 long max value shared return lck null catch io exception x return true trylock datachan trylock max_value ioexception public void lock boolean shared try lck data chan lock 0 long max value shared catch io exception x throw new storage error storage error lock failed x datachan max_value ioexception storageerror storageerror lock_failed public void unlock try lck release catch io exception x throw new storage error storage error lock failed x ioexception storageerror storageerror lock_failed public void close try data chan close data file close if page index log file null assert that page map size 0 page index buffer force page index log file set length 0 page index log file close page index chan close page index file close catch io exception x throw new storage error storage error file access error x datachan datafile pageindexlogfile pagemap pageindexbuffer pageindexlogfile setlength pageindexlogfile pageindexchan pageindexfile ioexception storageerror storageerror file_access_error public long length try return data chan size catch io exception x return 1 datachan ioexception constructor of compressed file with default parameter values param data file path path to the data file public compressed read write file string data file path this data file path null datafilepath compressedreadwritefile datafilepath datafilepath constructor of compressed file with default parameter values param data file path path to the data file param cipher key cipher key if null then no encryption is performed public compressed read write file string data file path string cipher key this data file path data file path map data file path log 8 1024 1024 1024 1024 1024 1024 false false cipher key datafilepath cipherkey compressedreadwritefile datafilepath cipherkey datafilepath datafilepath datafilepath cipherkey constructor of compressed file param data file path path to the data file param page index file path path to the page index file param page index log file path path to the transaction log file for page index param data file extension quantum quantum of extending data file param page index checkpoint threshold maximal size of page index log file after reaching this size page index is flushed and log is truncsated param page index init size initial size of page index param read only whether access to the file is read only param no flush whether synchronous write to the disk should be performed param cipher key cipher key if null then no encryption is performed public compressed read write file string data file path string page index file path string page index log file path long data file extension quantum long page index checkpoint threshold long page index init size boolean read only boolean no flush string cipher key this page index checkpoint threshold page index checkpoint threshold this no flush no flush if cipher key null set key cipher key get bytes try data file new random access file data file path read only r rw data chan data file get channel page index file new random access file page index file path read only r rw page index chan page index file get channel long size page index chan size page index size read only size page index init size size page index init size page index buffer page index chan map read only file channel map mode read only file channel map mode read write 0 position page index size deflater new deflater inflater new inflater compression buf new byte page page size if read only long page map size page index init size 8 if page map size max page map size page map size max page map size page map new page map int page map size page index log file new random access file page index log file path rw perform recovery bitmap extension quantum int data file extension quantum allocation quantum log 3 bitmap new byte int data chan size allocation quantum log 3 bitmap extension quantum bitmap pos bitmap start page page size allocation quantum log 3 byte buf new byte 8 size page index chan size page index buffer position 0 while size 8 0 page index buffer get buf 0 8 long page pos bytes unpack8 buf 0 long page bit offs page pos page page size log allocation quantum log long page bit size page pos page page size 1 allocation quantum allocation quantum log bitmap reserve bitmap page bit offs page bit size catch io exception x throw new storage error storage error file access error x datafilepath pageindexfilepath pageindexlogfilepath datafileextensionquantum pageindexcheckpointthreshold pageindexinitsize readonly noflush cipherkey compressedreadwritefile datafilepath pageindexfilepath pageindexlogfilepath datafileextensionquantum pageindexcheckpointthreshold pageindexinitsize readonly noflush cipherkey pageindexcheckpointthreshold pageindexcheckpointthreshold noflush noflush cipherkey setkey cipherkey getbytes datafile randomaccessfile datafilepath readonly datachan datafile getchannel pageindexfile randomaccessfile pageindexfilepath readonly pageindexchan pageindexfile getchannel pageindexchan pageindexsize readonly pageindexinitsize pageindexinitsize pageindexbuffer pageindexchan readonly filechannel mapmode read_only filechannel mapmode read_write pageindexsize compressionbuf pagesize readonly pagemapsize pageindexinitsize pagemapsize max_page_map_size pagemapsize max_page_map_size pagemap pagemap pagemapsize pageindexlogfile randomaccessfile pageindexlogfilepath performrecovery bitmapextensionquantum datafileextensionquantum allocation_quantum_log datachan allocation_quantum_log bitmapextensionquantum bitmappos bitmapstart pagesize allocation_quantum_log pageindexchan pageindexbuffer pageindexbuffer pagepos pagebitoffs pagepos pagesizelog allocation_quantum_log pagebitsize pagepos pagesize allocation_quantum allocation_quantum_log pagebitoffs pagebitsize ioexception storageerror storageerror file_access_error long allocate int bit size long pos bitmap allocate bitmap bitmap pos bitmap length bit size if pos 0 pos bitmap allocate bitmap bitmap start bitmap locate hole end bitmap bitmap pos bit size if pos 0 byte new bitmap new byte bitmap length bitmap extension quantum system arraycopy bitmap 0 new bitmap 0 bitmap length pos bitmap allocate new bitmap bitmap locate bitmap end new bitmap bitmap length new bitmap length bit size assert that pos 0 bitmap new bitmap bitmap pos int pos bit size 3 return pos allocation quantum log bitsize bitmappos bitsize bitmapstart locateholeend bitmappos bitsize newbitmap bitmapextensionquantum newbitmap newbitmap locatebitmapend newbitmap newbitmap bitsize newbitmap bitmappos bitsize allocation_quantum_log void set position long addr throws io exception long pos addr page page size log 3 if pos 8 page index size do page index size 2 while pos 8 page index size page index buffer page index chan map file channel map mode read write 0 page index size page index buffer position int pos setposition ioexception pagesizelog pageindexsize pageindexsize pageindexsize pageindexbuffer pageindexchan filechannel mapmode read_write pageindexsize pageindexbuffer void perform recovery throws io exception int rc byte hdr new byte 4 while rc page index log file read hdr 0 4 4 int n pages bytes unpack4 hdr 0 byte buf new byte n pages 16 if page index log file read buf 0 buf length buf length for int i 0 i n pages i set position bytes unpack8 buf i 16 page index buffer put buf i 16 8 8 else break performrecovery ioexception pageindexlogfile npages npages pageindexlogfile npages setposition pageindexbuffer public page map int initial capacity for table size prime 0 prime numbers table size prime initial capacity table size prime table size prime numbers table size prime threshold int table size load factor table new entry table size pagemap initialcapacity tablesizeprime primenumbers tablesizeprime initialcapacity tablesizeprime tablesize primenumbers tablesizeprime tablesize load_factor tablesize public void put long addr long new pos long old pos entry tab table int index int addr page page size log table size for entry e tab index e null e e next if e addr addr e new pos new pos return if count threshold rehash the table if the threshold is exceeded rehash tab table index int addr page page size log table size creates the new entry tab index new entry addr new pos old pos tab index count 1 newpos oldpos pagesizelog tablesize newpos newpos pagesizelog tablesize newpos oldpos public long get long addr int index int addr page page size log table size for entry e table index e null e e next if e addr addr return e new pos return 0 pagesizelog tablesize newpos public void clear entry tab table int size table size for int i 0 i size i tab i null count 0 tablesize void rehash int old capacity table size int new capacity table size prime numbers table size prime entry old map table entry new map new entry new capacity threshold int new capacity load factor table new map table size new capacity for int i 0 i old capacity i for entry old old map i old null entry e old old old next int index int e addr page page size log new capacity e next new map index new map index e oldcapacity tablesize newcapacity tablesize primenumbers tablesizeprime oldmap newmap newcapacity newcapacity load_factor newmap tablesize newcapacity oldcapacity oldmap pagesizelog newcapacity newmap newmap public iterator entry iterator return new page map iterator pagemapiterator public int size return count class page map iterator implements iterator entry page map iterator move forward pagemapiterator pagemapiterator moveforward public boolean has next return curr null hasnext public entry next entry e curr if e null throw new no such element exception move forward return e nosuchelementexception moveforward public void remove throw new unsupported operation exception unsupportedoperationexception private void move forward if curr null curr curr next while curr null i table size curr table i moveforward tablesize entry long addr long new pos long old pos entry chain next chain this addr addr this new pos new pos this old pos old pos newpos oldpos newpos newpos oldpos oldpos private void set key byte key init state new byte 256 state new byte 256 for int counter 0 counter 256 counter init state counter byte counter int index1 0 int index2 0 for int counter 0 counter 256 counter index2 key index1 init state counter index2 0xff byte temp init state counter init state counter init state index2 init state index2 temp index1 index1 1 key length setkey initstate initstate initstate initstate initstate initstate initstate private final void crypt byte buf int len byte state this state if state null int x 0 y 0 system arraycopy init state 0 state 0 state length for int i 0 i len i x x 1 0xff y y state x 0xff byte temp state x state x state y state y temp int next state state x state y 0xff buf i state next state initstate nextstate nextstate param jmdns impl public record reaper jmdns impl jmdns impl this jmdns impl jmdns impl jmdnsimpl recordreaper jmdnsimpl jmdnsimpl jmdnsimpl jmdnsimpl public void start timer timer timer schedule this dns constants record reaper interval dns constants record reaper interval dnsconstants record_reaper_interval dnsconstants record_reaper_interval public void run synchronized this jmdns impl if this jmdns impl get state dns state canceled return logger finest run jmdns reaping cache remove expired answers from the cache to prevent race conditions we defensively copy all cache entries into a list list list new array list synchronized this jmdns impl get cache for iterator i this jmdns impl get cache iterator i has next for dns cache cache node n dns cache cache node i next n null n n next list add n get value now we remove them long now system current time millis for iterator i list iterator i has next dns record c dns record i next if c is expired now this jmdns impl update record now c this jmdns impl get cache remove c jmdnsimpl jmdnsimpl getstate dnsstate arraylist jmdnsimpl getcache jmdnsimpl getcache hasnext dnscache cachenode dnscache cachenode getvalue currenttimemillis hasnext dnsrecord dnsrecord isexpired jmdnsimpl updaterecord jmdnsimpl getcache private int dw dh public displace filter displacefilter set the displacement map param displacement map an image representing the displacment at each point see get displacement map public void set displacement map buffered image displacement map this displacement map displacement map displacementmap getdisplacementmap setdisplacementmap bufferedimage displacementmap displacementmap displacementmap get the displacement map return an image representing the displacment at each point see set displacement map public buffered image get displacement map return displacement map setdisplacementmap bufferedimage getdisplacementmap displacementmap set the amount of distortion param amount the amount min value 0 max value 1 see get amount public void set amount float amount this amount amount getamount setamount get the amount of distortion return the amount see set amount public float get amount return amount setamount getamount override public buffered image filter buffered image src buffered image dst int w src get width int h src get height buffered image dm displacement map null displacement map src dw dm get width dh dm get height int map pixels new int dw dh getrgb dm 0 0 dw dh map pixels xmap new int dw dh ymap new int dw dh int i 0 for int y 0 y dh y for int x 0 x dw x int rgb map pixels i int r rgb 16 0xff int g rgb 8 0xff int b rgb 0xff map pixels i r g b 8 an arbitrary scaling factor which gives a good range for amount i i 0 for int y 0 y dh y int j1 y dh 1 dh dw int j2 y dw int j3 y 1 dh dw for int x 0 x dw x int k1 x dw 1 dw int k2 x int k3 x 1 dw xmap i map pixels k1 j1 map pixels k1 j2 map pixels k1 j3 map pixels k3 j1 map pixels k3 j2 map pixels k3 j3 ymap i map pixels k1 j3 map pixels k2 j3 map pixels k3 j3 map pixels k1 j1 map pixels k2 j1 map pixels k3 j1 i map pixels null dst super filter src dst xmap ymap null return dst bufferedimage bufferedimage bufferedimage getwidth getheight bufferedimage displacementmap displacementmap getwidth getheight mappixels mappixels mappixels mappixels mappixels mappixels mappixels mappixels mappixels mappixels mappixels mappixels mappixels mappixels mappixels mappixels mappixels override protected void transform inverse int x int y float out float x displacement y displacement float nx x float ny y int i y dh dw x dw out 0 x amount xmap i out 1 y amount ymap i transforminverse xdisplacement ydisplacement override public string to string return distort displace tostring public static fec queue create final long nodedb handle object container container suppress warnings serial object set fec queue result container query new predicate fec queue override public boolean match fec queue queue if queue nodedb handle nodedb handle return true return false if result has next fec queue queue result next container activate queue 1 return queue else fec queue queue new fec queue nodedb handle container store queue return queue fecqueue nodedbhandle objectcontainer suppresswarnings objectset fecqueue fecqueue fecqueue nodedbhandle nodedbhandle hasnext fecqueue fecqueue fecqueue nodedbhandle private fec queue long nodedb handle this nodedb handle nodedb handle fecqueue nodedbhandle nodedbhandle nodedbhandle called after creating or deserializing the fec queue initialises all the transient fields suppress warnings unchecked public void init int priorities int max cache size db job runner db job runner executor exec client context client context this priorities priorities this max persistent queue cache size max cache size this database job runner db job runner this executor exec this client context client context transient queue new linked list priorities persistent queue cache new linked list priorities for int i 0 i priorities i transient queue i new linked list fec job persistent queue cache i new linked list fec job max runningfec threads get max runningfec threads oom handler addoom hook this init runner init cache filler job queue cache filler fecqueue suppresswarnings maxcachesize dbjobrunner dbjobrunner clientcontext clientcontext maxpersistentqueuecachesize maxcachesize databasejobrunner dbjobrunner clientcontext clientcontext transientqueue linkedlist persistentqueuecache linkedlist transientqueue linkedlist fecjob persistentqueuecache linkedlist fecjob maxrunningfecthreads getmaxrunningfecthreads oomhandler addoomhook initrunner initcachefillerjob queuecachefiller private void queue cache filler database job runner queue cache filler job native thread norm priority false queuecachefiller databasejobrunner cachefillerjob nativethread norm_priority public void add to queue fec job job fec codec codec object container container boolean logminor logger should log logger minor this if logminor logger minor standard onionfec codec class adding a new job to the queue job int max threads get max runningfec threads if job persistent job activate for execution container container store job boolean kept false synchronized this if job persistent transient queue job priority add last job kept true else int total above 0 for int i 0 i job priority i total above persistent queue cache i size if total above max persistent queue cache size don t add if logminor logger minor this not adding persistent job to in ram cache too many above it else if total above persistent queue cache job priority size max persistent queue cache size still don t add within a priority it s oldest first if logminor logger minor this not adding persistent job to in ram cache too many at same priority else persistent queue cache job priority add last job kept true int total total above persistent queue cache job priority size for int i job priority 1 i priorities i total persistent queue cache i size while total max persistent queue cache size persistent queue cache i is empty if logminor logger minor this removing low priority job from cache total now total persistent queue cache i remove last total if kept if logminor logger minor this deactivating job job job deactivate container if runningfec threads max threads executor execute runner fec pool fec pool counter runningfec threads notify all addtoqueue fecjob feccodec objectcontainer shouldlog standardonionfeccodec maxthreads getmaxrunningfecthreads activateforexecution transientqueue addlast totalabove totalabove persistentqueuecache totalabove maxpersistentqueuecachesize totalabove persistentqueuecache maxpersistentqueuecachesize persistentqueuecache addlast totalabove persistentqueuecache persistentqueuecache maxpersistentqueuecachesize persistentqueuecache isempty persistentqueuecache removelast runningfecthreads maxthreads fecpoolcounter runningfecthreads notifyall private void init runner runner new prio runnable runs on each thread author nextgens public void run freenet support logger os thread logpid this try while true final fec job job get a job synchronized fec queue this job getfec job blocking nodb access job running true if logger should log logger minor this logger minor this running job job encode it try if job isa decoding job job get codec real decode job data block status job check block status job block length job bucket factory else job get codec real encode job data blocks job check blocks job block length job bucket factory update split file blocks from buckets if necessary if job data block status null job check block status null for int i 0 i job data blocks length i job data block status i set data job data blocks i for int i 0 i job check blocks length i job check block status i set data job check blocks i catch io exception e logger error this boh ioe e get message e call the callback try if job persistent if job isa decoding job job callback on decoded segment null client context job job data blocks job check blocks job data block status job check block status else job callback on encoded segment null client context job job data blocks job check blocks job data block status job check block status else if logger should log logger minor this logger minor this scheduling callback for job int prio job isa decoding job native thread norm priority 1 native thread norm priority if job priority request starter immediate splitfile priority class prio if job priority request starter bulk splitfile priority class prio database job runner queue new db job public void run object container container client context context job store block statuses container don t activate the job itself it must already be activated because it is carrying the status blocks the status blocks have been set on the fec thread but not stored because they can t be stored on the fec thread logger minor this activating job callback is active container ext is active job callback container activate job callback 1 if logger should log logger minor this logger minor this running callback for job try if job isa decoding job job callback on decoded segment container client context job job data blocks job check blocks job data block status job check block status else job callback on encoded segment container client context job job data blocks job check blocks job data block status job check block status catch throwable t logger error this caught t in fec queue callback t finally always delete the job even if the callback throws container delete job if container ext is stored job callback container deactivate job callback 1 prio false if logger should log logger minor this logger minor this scheduled callback for job catch throwable e logger error this the callback failed e e catch throwable t logger error this caught t in this t finally synchronized fec queue this runningfec threads public int get priority return native thread low priority initrunner priorunnable osthread fecjob fecqueue getfecjobblockingnodbaccess shouldlog isadecodingjob getcodec realdecode datablockstatus checkblockstatus blocklength bucketfactory getcodec realencode datablocks checkblocks blocklength bucketfactory splitfileblocks datablockstatus checkblockstatus datablocks datablockstatus setdata datablocks checkblocks checkblockstatus setdata checkblocks ioexception getmessage isadecodingjob ondecodedsegment clientcontext datablocks checkblocks datablockstatus checkblockstatus onencodedsegment clientcontext datablocks checkblocks datablockstatus checkblockstatus shouldlog isadecodingjob nativethread norm_priority nativethread norm_priority requeststarter immediate_splitfile_priority_class requeststarter bulk_splitfile_priority_class databasejobrunner dbjob objectcontainer clientcontext storeblockstatuses isactive shouldlog isadecodingjob ondecodedsegment clientcontext datablocks checkblocks datablockstatus checkblockstatus onencodedsegment clientcontext datablocks checkblocks datablockstatus checkblockstatus fecqueue isstored shouldlog fecqueue runningfecthreads getpriority nativethread low_priority runner new prio runnable runs on each thread author nextgens public void run freenet support logger os thread logpid this try while true final fec job job get a job synchronized fec queue this job getfec job blocking nodb access job running true if logger should log logger minor this logger minor this running job job encode it try if job isa decoding job job get codec real decode job data block status job check block status job block length job bucket factory else job get codec real encode job data blocks job check blocks job block length job bucket factory update split file blocks from buckets if necessary if job data block status null job check block status null for int i 0 i job data blocks length i job data block status i set data job data blocks i for int i 0 i job check blocks length i job check block status i set data job check blocks i catch io exception e logger error this boh ioe e get message e call the callback try if job persistent if job isa decoding job job callback on decoded segment null client context job job data blocks job check blocks job data block status job check block status else job callback on encoded segment null client context job job data blocks job check blocks job data block status job check block status else if logger should log logger minor this logger minor this scheduling callback for job int prio job isa decoding job native thread norm priority 1 native thread norm priority if job priority request starter immediate splitfile priority class prio if job priority request starter bulk splitfile priority class prio database job runner queue new db job public void run object container container client context context job store block statuses container don t activate the job itself it must already be activated because it is carrying the status blocks the status blocks have been set on the fec thread but not stored because they can t be stored on the fec thread logger minor this activating job callback is active container ext is active job callback container activate job callback 1 if logger should log logger minor this logger minor this running callback for job try if job isa decoding job job callback on decoded segment container client context job job data blocks job check blocks job data block status job check block status else job callback on encoded segment container client context job job data blocks job check blocks job data block status job check block status catch throwable t logger error this caught t in fec queue callback t finally always delete the job even if the callback throws container delete job if container ext is stored job callback container deactivate job callback 1 prio false if logger should log logger minor this logger minor this scheduled callback for job catch throwable e logger error this the callback failed e e catch throwable t logger error this caught t in this t finally synchronized fec queue this runningfec threads priorunnable osthread fecjob fecqueue getfecjobblockingnodbaccess shouldlog isadecodingjob getcodec realdecode datablockstatus checkblockstatus blocklength bucketfactory getcodec realencode datablocks checkblocks blocklength bucketfactory splitfileblocks datablockstatus checkblockstatus datablocks datablockstatus setdata datablocks checkblocks checkblockstatus setdata checkblocks ioexception getmessage isadecodingjob ondecodedsegment clientcontext datablocks checkblocks datablockstatus checkblockstatus onencodedsegment clientcontext datablocks checkblocks datablockstatus checkblockstatus shouldlog isadecodingjob nativethread norm_priority nativethread norm_priority requeststarter immediate_splitfile_priority_class requeststarter bulk_splitfile_priority_class databasejobrunner dbjob objectcontainer clientcontext storeblockstatuses isactive shouldlog isadecodingjob ondecodedsegment clientcontext datablocks checkblocks datablockstatus checkblockstatus onencodedsegment clientcontext datablocks checkblocks datablockstatus checkblockstatus fecqueue isstored shouldlog fecqueue runningfecthreads public void run object container container client context context job store block statuses container don t activate the job itself it must already be activated because it is carrying the status blocks the status blocks have been set on the fec thread but not stored because they can t be stored on the fec thread logger minor this activating job callback is active container ext is active job callback container activate job callback 1 if logger should log logger minor this logger minor this running callback for job try if job isa decoding job job callback on decoded segment container client context job job data blocks job check blocks job data block status job check block status else job callback on encoded segment container client context job job data blocks job check blocks job data block status job check block status catch throwable t logger error this caught t in fec queue callback t finally always delete the job even if the callback throws container delete job if container ext is stored job callback container deactivate job callback 1 objectcontainer clientcontext storeblockstatuses isactive shouldlog isadecodingjob ondecodedsegment clientcontext datablocks checkblocks datablockstatus checkblockstatus onencodedsegment clientcontext datablocks checkblocks datablockstatus checkblockstatus fecqueue isstored public int get priority return native thread low priority getpriority nativethread low_priority private void init cache filler job cache filler job new db job public void run object container container client context context try to avoid accessing the database while synchronized on the fec queue boolean logminor logger should log logger minor this if logminor logger minor this running fec cache filler job while true boolean added any false int total cached 0 for short prio 0 prio priorities prio int grab 0 synchronized fec queue this int new cached total cached persistent queue cache prio size if new cached max persistent queue cache size return grab max persistent queue cache size new cached total cached new cached if logminor logger minor this grabbing up to grab jobs at priority prio query query container query query constrain fec job class constraint con query descend priority constrain short value of prio con and query descend queue constrain fec queue this identity query descend added time order ascending suppress warnings unchecked object set fec job results query execute if results has next for int j 0 j grab results has next j fec job job results next job activate for execution container if job is cancelled container container delete job continue if logminor logger minor this maybe adding job synchronized fec queue this if job running j if logminor logger minor this not adding already running job continue if persistent queue cache prio contains job j if logminor logger minor this not adding as on persistent queue cache for prio job continue boolean added false for list iterator fec job it persistent queue cache prio list iterator it has next fec job cmp it next if cmp added time job added time it previous it add job added true if logminor logger minor this adding job before it break if added persistent queue cache prio add last job if logminor logger minor this added job added any true if added any if logminor logger minor this no more jobs to add don t notify let it sleep until more jobs are added return else synchronized fec queue this int max running threads max runningfec threads if runningfec threads max running threads int queue size 0 for int i 0 i priorities i queue size persistent queue cache i size if queue size runningfec threads max running threads break if queue size runningfec threads max running threads max running threads queue size runningfec threads while runningfec threads max running threads executor execute runner fec pool fec pool counter runningfec threads fec queue this notify all initcachefillerjob cachefillerjob dbjob objectcontainer clientcontext fecqueue shouldlog addedany totalcached fecqueue newcached totalcached persistentqueuecache newcached maxpersistentqueuecachesize maxpersistentqueuecachesize newcached totalcached newcached fecjob valueof fecqueue addedtime orderascending suppresswarnings objectset fecjob hasnext hasnext fecjob activateforexecution iscancelled fecqueue persistentqueuecache listiterator fecjob persistentqueuecache listiterator hasnext fecjob addedtime addedtime persistentqueuecache addlast addedany addedany fecqueue maxrunningthreads maxrunningfecthreads runningfecthreads maxrunningthreads queuesize queuesize persistentqueuecache queuesize runningfecthreads maxrunningthreads queuesize runningfecthreads maxrunningthreads maxrunningthreads queuesize runningfecthreads runningfecthreads maxrunningthreads fecpoolcounter runningfecthreads fecqueue notifyall public void run object container container client context context try to avoid accessing the database while synchronized on the fec queue boolean logminor logger should log logger minor this if logminor logger minor this running fec cache filler job while true boolean added any false int total cached 0 for short prio 0 prio priorities prio int grab 0 synchronized fec queue this int new cached total cached persistent queue cache prio size if new cached max persistent queue cache size return grab max persistent queue cache size new cached total cached new cached if logminor logger minor this grabbing up to grab jobs at priority prio query query container query query constrain fec job class constraint con query descend priority constrain short value of prio con and query descend queue constrain fec queue this identity query descend added time order ascending suppress warnings unchecked object set fec job results query execute if results has next for int j 0 j grab results has next j fec job job results next job activate for execution container if job is cancelled container container delete job continue if logminor logger minor this maybe adding job synchronized fec queue this if job running j if logminor logger minor this not adding already running job continue if persistent queue cache prio contains job j if logminor logger minor this not adding as on persistent queue cache for prio job continue boolean added false for list iterator fec job it persistent queue cache prio list iterator it has next fec job cmp it next if cmp added time job added time it previous it add job added true if logminor logger minor this adding job before it break if added persistent queue cache prio add last job if logminor logger minor this added job added any true if added any if logminor logger minor this no more jobs to add don t notify let it sleep until more jobs are added return else synchronized fec queue this int max running threads max runningfec threads if runningfec threads max running threads int queue size 0 for int i 0 i priorities i queue size persistent queue cache i size if queue size runningfec threads max running threads break if queue size runningfec threads max running threads max running threads queue size runningfec threads while runningfec threads max running threads executor execute runner fec pool fec pool counter runningfec threads fec queue this notify all objectcontainer clientcontext fecqueue shouldlog addedany totalcached fecqueue newcached totalcached persistentqueuecache newcached maxpersistentqueuecachesize maxpersistentqueuecachesize newcached totalcached newcached fecjob valueof fecqueue addedtime orderascending suppresswarnings objectset fecjob hasnext hasnext fecjob activateforexecution iscancelled fecqueue persistentqueuecache listiterator fecjob persistentqueuecache listiterator hasnext fecjob addedtime addedtime persistentqueuecache addlast addedany addedany fecqueue maxrunningthreads maxrunningfecthreads runningfecthreads maxrunningthreads queuesize queuesize persistentqueuecache queuesize runningfecthreads maxrunningthreads queuesize runningfecthreads maxrunningthreads maxrunningthreads queuesize runningfecthreads runningfecthreads maxrunningthreads fecpoolcounter runningfecthreads fecqueue notifyall private synchronized int get max runningfec threads if max runningfec threads 1 return max runningfec threads string os name system get property os name if os name index of windows 1 os name to lower case index of mac os x 0 native thread using native code os x niceness is really weak so we don t want any more background cpu load than necessary also on non windows we need the native threads library to be working max runningfec threads 1 else most other o ss will have reasonable niceness so go by ram runtime r runtime get runtime int max r available processors fixme this may change in a vm poll it long max memory r max memory if max memory 256 1024 1024 max 1 else measured 11mb decode 8mb encode on amd64 no more than 10 of available ram so 110mb for each extra processor no more than 3 so that we don t reach any file descriptor related limit max math min 3 math min max int math min integer max value max memory 128 1024 1024 max runningfec threads max logger minor fec codec class maximum fec threads max runningfec threads return max runningfec threads getmaxrunningfecthreads maxrunningfecthreads maxrunningfecthreads osname getproperty osname indexof osname tolowercase indexof nativethread usingnativecode maxrunningfecthreads oss getruntime availableprocessors maxmemory maxmemory maxmemory filedescriptor max_value maxmemory maxrunningfecthreads feccodec maxrunningfecthreads maxrunningfecthreads find a fec job to run return null only if there are too many fec threads running protected synchronized fec job getfec job blocking nodb access while true if runningfec threads get max runningfec threads return null for int i 0 i priorities i if transient queue i is empty return transient queue i remove first if persistent queue cache i is empty return persistent queue cache i remove first queue cache filler try wait catch interrupted exception e ignore fecjob getfecjobblockingnodbaccess runningfecthreads getmaxrunningfecthreads transientqueue isempty transientqueue removefirst persistentqueuecache isempty persistentqueuecache removefirst queuecachefiller interruptedexception public synchronized void handle low memory throws exception max runningfec threads math max 1 max runningfec threads 1 notify not notify all handlelowmemory maxrunningfecthreads maxrunningfecthreads notifyall public synchronized void handle out of memory throws exception max runningfec threads 1 notify all handleoutofmemory maxrunningfecthreads notifyall public void object on deactivate object container container logger error this attempting to deactivate fec queue new exception debug objectondeactivate objectcontainer fecqueue param job param container param context return true unless we were unable to remove the job because it has already started public boolean cancel fec job job object container container client context context synchronized this for int i 0 i priorities i transient queue i remove job persistent queue cache i remove job synchronized job if job running return false if job persistent container delete job return true fecjob objectcontainer clientcontext transientqueue persistentqueuecache public temp bucket long now bucket cur if cur null throw new null pointer exception this current bucket cur this creation time now this os index 0 this tbis new vector temp bucket input stream 1 if logminor logger minor this created this new exception debug tempbucket nullpointerexception currentbucket creationtime osindex tempbucketinputstream private synchronized void close input streams boolean for free for list iterator temp bucket input stream i tbis list iterator i has next temp bucket input stream is i next if for free i remove try is close catch io exception e logger error this caught e closing is else try is mayberesetinputstream catch io exception e i remove closer close is closeinputstreams forfree listiterator tempbucketinputstream listiterator hasnext tempbucketinputstream forfree ioexception _mayberesetinputstream ioexception a blocking method to force migrate from a ram bucket to a file bucket final void migrate to file bucket throws io exception bucket to migrate null synchronized this if isram bucket has been freed nothing to migrate we don t want to switch back to ram do we return to migrate current bucket bucket tempfb makefilebucket if os null os flush closer close os do not increment the os index here os tempfb get output stream if current size 0 bucket tools copy to to migrate os current size else if current size 0 output stream temp tempfb get output stream bucket tools copy to to migrate temp current size temp close if to migrate is read only tempfb set read only close input streams false current bucket tempfb we need streams to be reset to point to the new bucket if logminor logger minor this we have migrated to migrate hash code we can free it on thread as it s a rambucket to migrate free might have changed already so we can t rely on current size hasfreed to migrate size rambucket filebucket migratetofilebucket ioexception tomigrate isrambucket hasbeenfreed tomigrate currentbucket _makefilebucket osindex getoutputstream currentsize buckettools copyto tomigrate currentsize currentsize outputstream getoutputstream buckettools copyto tomigrate currentsize tomigrate isreadonly setreadonly closeinputstreams currentbucket tomigrate hashcode tomigrate currentsize _hasfreed tomigrate public synchronized final boolean isram bucket return current bucket instanceof array bucket isrambucket currentbucket arraybucket public synchronized output stream get output stream throws io exception if os index 0 throw new io exception only one output stream per bucket has written true output stream os new temp bucket output stream os index if logminor logger minor this got os for this new exception return os outputstream getoutputstream ioexception osindex ioexception outputstream haswritten outputstream tempbucketoutputstream osindex private class temp bucket output stream extends output stream boolean closed false temp bucket output stream short idx throws io exception if os null os current bucket get output stream tempbucketoutputstream outputstream tempbucketoutputstream ioexception currentbucket getoutputstream private void maybemigraterambucket long future size throws io exception if isram bucket boolean should migrate false boolean is oversized false if future size math min integer max value maxram bucket size rambucket conversion factor is oversized true should migrate true else if future size current size bytes in use max ram used should migrate true if should migrate if logminor if is oversized logger minor this the bucket is over size util format size maxram bucket size rambucket conversion factor we will force migrate it to disk else logger minor this the bucketpool is full force migrate before we go over the limit migrate to file bucket _maybemigraterambucket futuresize ioexception isrambucket shouldmigrate isoversized futuresize max_value maxrambucketsize rambucket_conversion_factor isoversized shouldmigrate futuresize currentsize bytesinuse maxramused shouldmigrate shouldmigrate isoversized sizeutil formatsize maxrambucketsize rambucket_conversion_factor migratetofilebucket override public final void write int b throws io exception synchronized temp bucket this long future size current size 1 maybemigraterambucket future size os write b current size future size if isram bucket we need to re check because it might have changed hastaken 1 ioexception tempbucket futuresize currentsize _maybemigraterambucket futuresize currentsize futuresize isrambucket _hastaken override public final void write byte b int off int len throws io exception synchronized temp bucket this long future size current size len maybemigraterambucket future size os write b off len current size future size if isram bucket we need to re check because it might have changed hastaken len ioexception tempbucket futuresize currentsize _maybemigraterambucket futuresize currentsize futuresize isrambucket _hastaken override public final void flush throws io exception synchronized temp bucket this maybemigraterambucket current size if closed os flush ioexception tempbucket _maybemigraterambucket currentsize override public final void close throws io exception synchronized temp bucket this if closed return maybemigraterambucket current size os flush os close os null closed true ioexception tempbucket _maybemigraterambucket currentsize public synchronized input stream get input stream throws io exception if has written throw new io exception no output stream has been openned why would you want an input stream then temp bucket input stream is new temp bucket input stream os index tbis add is if logminor logger minor this got is for this new exception return is inputstream getinputstream ioexception haswritten ioexception outputstream inputstream tempbucketinputstream tempbucketinputstream osindex private final short idx temp bucket input stream short idx throws io exception this idx idx this currentis current bucket get input stream tempbucketinputstream ioexception currentbucket getinputstream public void mayberesetinputstream throws io exception if idx os index close else closer close currentis currentis current bucket get input stream long to skip index while to skip 0 to skip currentis skip to skip _mayberesetinputstream ioexception osindex currentbucket getinputstream toskip toskip toskip toskip override public final int read throws io exception synchronized temp bucket this int to return currentis read if to return 1 index return to return ioexception tempbucket toreturn toreturn toreturn override public int read byte b throws io exception synchronized temp bucket this return read b 0 b length ioexception tempbucket override public int read byte b int off int len throws io exception synchronized temp bucket this int to return currentis read b off len if to return 0 index to return return to return ioexception tempbucket toreturn toreturn toreturn toreturn override public long skip long n throws io exception synchronized temp bucket this long skipped currentis skip n index skipped return skipped ioexception tempbucket override public int available throws io exception synchronized temp bucket this return currentis available ioexception tempbucket override public boolean mark supported return false marksupported override public final void close throws io exception synchronized temp bucket this closer close currentis tbis remove this ioexception tempbucket public synchronized string get name return current bucket get name getname currentbucket getname public synchronized long size return current size currentsize public synchronized boolean is read only return current bucket is read only isreadonly currentbucket isreadonly public synchronized void set read only current bucket set read only setreadonly currentbucket setreadonly public synchronized void free if has been freed return has been freed true closer close os close input streams true current bucket free if isram bucket hasfreed current size synchronized ram bucket queue ram bucket queue remove get reference hasbeenfreed hasbeenfreed closeinputstreams currentbucket isrambucket _hasfreed currentsize rambucketqueue rambucketqueue getreference public bucket create shadow throws io exception return current bucket create shadow createshadow ioexception currentbucket createshadow public void remove from object container container throw new unsupported operation exception removefrom objectcontainer unsupportedoperationexception public void store to object container container throw new unsupported operation exception storeto objectcontainer unsupportedoperationexception private weak reference temp bucket weak ref new weak reference temp bucket this public weak reference temp bucket get reference return weak ref weakreference tempbucket weakref weakreference tempbucket weakreference tempbucket getreference weakref override protected void finalize if has been freed logger error this temp bucket not freed size size isram bucket isram bucket this free hasbeenfreed tempbucket isrambucket isrambucket storage accounting disabled by default public temp bucket factory executor executor filename generator filename generator long max bucket size kept in ram long max ram used random source strongprng random weakprng boolean really encrypt this filename generator filename generator this max ram used max ram used this maxram bucket size max bucket size kept in ram this strongprng strongprng this weakprng weakprng this really encrypt really encrypt this executor executor this logminor logger should log logger minor this tempbucketfactory filenamegenerator filenamegenerator maxbucketsizekeptinram maxramused randomsource reallyencrypt filenamegenerator filenamegenerator maxramused maxramused maxrambucketsize maxbucketsizekeptinram reallyencrypt reallyencrypt shouldlog public bucket make bucket long size throws io exception return make bucket size default factor default increment makebucket ioexception makebucket default_factor defaultincrement public bucket make bucket long size float factor throws io exception return make bucket size factor default increment makebucket ioexception makebucket defaultincrement private synchronized void hastaken long size bytes in use size _hastaken bytesinuse private synchronized void hasfreed long size bytes in use size _hasfreed bytesinuse public synchronized long get ram used return bytes in use getramused bytesinuse public synchronized void set max ram used long size logminor logger should log logger minor this max ram used size setmaxramused shouldlog maxramused public synchronized long get max ram used logminor logger should log logger minor this return max ram used getmaxramused shouldlog maxramused public synchronized void set maxram bucket size long size logminor logger should log logger minor this maxram bucket size size setmaxrambucketsize shouldlog maxrambucketsize public synchronized long get maxram bucket size logminor logger should log logger minor this return maxram bucket size getmaxrambucketsize shouldlog maxrambucketsize public void set encryption boolean value logminor logger should log logger minor this really encrypt value setencryption shouldlog reallyencrypt public boolean is encrypting return really encrypt isencrypting reallyencrypt create a temp bucket param size default size param factor factor to increase size by when need more space return a temporary bucket exception io exception if it is not possible to create a temp bucket due to an i o error public temp bucket make bucket long size float factor long increment throws io exception bucket real bucket null boolean useram bucket false long now system current time millis we need to clean the queue in order to have space to host new buckets clean bucket queue now synchronized this if size 0 size maxram bucket size bytes in use max ram used useram bucket true do we want a ram bucket or a file bucket real bucket useram bucket new array bucket makefilebucket temp bucket to return new temp bucket now real bucket if useram bucket no need to consider them for migration if they can t be migrated synchronized ram bucket queue ram bucket queue add to return get reference return to return ioexception tempbucket makebucket ioexception realbucket userambucket currenttimemillis cleanbucketqueue maxrambucketsize bytesinuse maxramused userambucket rambucket filebucket realbucket userambucket arraybucket _makefilebucket tempbucket toreturn tempbucket realbucket userambucket rambucketqueue rambucketqueue toreturn getreference toreturn migrate all long lived buckets from the queue private void clean bucket queue long now boolean should continue true create a new list to avoid race conditions final queue temp bucket to migrate new linked list temp bucket do synchronized ram bucket queue final weak reference temp bucket tmp bucket ref ram bucket queue peek if tmp bucket ref null should continue false else temp bucket tmp bucket tmp bucket ref get if tmp bucket null ram bucket queue remove tmp bucket ref continue ugh this is freed if tmp bucket creation time rambucket max age now should continue false else if logminor logger minor this the bucket is time util format time now tmp bucket creation time old we will force migrate it to disk ram bucket queue remove tmp bucket ref to migrate add tmp bucket while should continue if to migrate size 0 executor execute new runnable public void run if logminor logger minor this we are going to migrate to migrate size ram buckets for temp bucket tmp bucket to migrate try tmp bucket migrate to file bucket catch io exception e logger error tmp bucket an ioe occured while migrating long lived buckets e get message e ram bucket migrator now cleanbucketqueue shouldcontinue tempbucket tomigrate linkedlist tempbucket rambucketqueue weakreference tempbucket tmpbucketref rambucketqueue tmpbucketref shouldcontinue tempbucket tmpbucket tmpbucketref tmpbucket rambucketqueue tmpbucketref tmpbucket creationtime rambucket_max_age shouldcontinue timeutil formattime tmpbucket creationtime rambucketqueue tmpbucketref tomigrate tmpbucket shouldcontinue tomigrate tomigrate rambuckets tempbucket tmpbucket tomigrate tmpbucket migratetofilebucket ioexception tmpbucket getmessage rambucket public void run if logminor logger minor this we are going to migrate to migrate size ram buckets for temp bucket tmp bucket to migrate try tmp bucket migrate to file bucket catch io exception e logger error tmp bucket an ioe occured while migrating long lived buckets e get message e tomigrate rambuckets tempbucket tmpbucket tomigrate tmpbucket migratetofilebucket ioexception tmpbucket getmessage private bucket makefilebucket bucket file bucket new temp file bucket filename generator make random filename filename generator true true do we want it to be encrypted return really encrypt new padded ephemerally encrypted bucket file bucket 1024 strongprng weakprng file bucket _makefilebucket filebucket tempfilebucket filenamegenerator makerandomfilename filenamegenerator reallyencrypt paddedephemerallyencryptedbucket filebucket filebucket private static final long serial versionuid 1l get the contents of the error page public abstract string get explanation serialversionuid getexplanation public abstract string get explanation gets the contents of the error page as html public abstract html node gethtml explanation getexplanation htmlnode gethtmlexplanation public abstract html node gethtml explanation get the title of the error page public abstract string gethtml encoded title htmlnode gethtmlexplanation gethtmlencodedtitle public abstract string gethtml encoded title get the raw title of the error page may be unsafe for html public abstract string get raw title gethtmlencodedtitle getrawtitle final string identifier public unknown peer note type message int peer note type string identifier this peer note type peer note type this identifier identifier unknownpeernotetypemessage peernotetype peernotetype peernotetype override public simple field set get field set simple field set fs new simple field set true fs put peer note type peer note type if identifier null fs put single identifier identifier return fs simplefieldset getfieldset simplefieldset simplefieldset peernotetype peernotetype putsingle override public string get name return unknown peer note type getname unknownpeernotetype override public void run fcp connection handler handler node node throws message invalid exception throw new message invalid exception protocol error message invalid message unknown peer note type goes from server to client not the other way around identifier false fcpconnectionhandler messageinvalidexception messageinvalidexception protocolerrormessage invalid_message unknownpeernotetype override public void remove from object container container container delete this removefrom objectcontainer public class persistent temp file bucket extends temp file bucket public persistent temp file bucket long id filename generator generator this id generator true persistenttempfilebucket tempfilebucket persistenttempfilebucket filenamegenerator protected persistent temp file bucket long id filename generator generator boolean delete on free super id generator false delete on free persistenttempfilebucket filenamegenerator deleteonfree deleteonfree override protected boolean delete on finalize do not delete on finalize return false deleteonfinalize override protected boolean delete on exit do not delete on exit return false deleteonexit public static bucket create simple field set fs persistent file tracker f throws cannot create from field set exception string tmp fs get filename if tmp null throw new cannot create from field set exception no filename file file file util get canonical file new file tmp long id f getid file if id 1 throw new cannot create from field set exception cannot derive persistent temp file id from filename file tmp fs get length if tmp null throw new cannot create from field set exception no length long length try length long parse long tmp if length file length throw new cannot create from field set exception invalid length should be length actually file length on file catch number format exception e throw new cannot create from field set exception corrupt length tmp e bucket bucket new persistent temp file bucket id f get generator true if file exists no point otherwise f register file return bucket simplefieldset persistentfiletracker cannotcreatefromfieldsetexception cannotcreatefromfieldsetexception fileutil getcanonicalfile cannotcreatefromfieldsetexception cannotcreatefromfieldsetexception parselong cannotcreatefromfieldsetexception numberformatexception cannotcreatefromfieldsetexception persistenttempfilebucket getgenerator override public simple field set to field set if delete on finalize return null simple field set fs super to field set fs put overwrite type persistent temp file bucket fs put filenameid filenameid return fs simplefieldset tofieldset deleteonfinalize simplefieldset tofieldset putoverwrite persistenttempfilebucket must override create shadow so it creates a persistent bucket which will have delete on exit delete on finalize false override public bucket create shadow throws io exception persistent temp file bucket ret new persistent temp file bucket filenameid generator false ret set read only if get file exists logger error this file does not exist when creating shadow get file return ret createshadow deleteonexit deleteonfinalize createshadow ioexception persistenttempfilebucket persistenttempfilebucket setreadonly getfile getfile static logger register log threshold callback new log threshold callback override public void should update logminor logger should log logger minor this registerlogthresholdcallback logthresholdcallback shouldupdate shouldlog public limited range int byte array map int max range this max range max range contents new hash map integer limited range int byte array map element min value 1 max value 1 flag false limitedrangeintbytearraymap maxrange maxrange maxrange hashmap limitedrangeintbytearraymapelement minvalue maxvalue public synchronized int min value return min value minvalue minvalue public synchronized int max value return max value maxvalue maxvalue public synchronized byte get int index limited range int byte array map element wrapper contents get index if wrapper null return wrapper data else return null limitedrangeintbytearraymapelement public synchronized async message callback get callbacks int index limited range int byte array map element wrapper contents get index if wrapper null return wrapper callbacks else return null asyncmessagecallback getcallbacks limitedrangeintbytearraymapelement public synchronized long get time int index limited range int byte array map element wrapper contents get index if wrapper null return wrapper created time else return 1 gettime limitedrangeintbytearraymapelement createdtime public short get priority int index short default value integer i index limited range int byte array map element wrapper contents get i if wrapper null return wrapper priority else return default value getpriority defaultvalue limitedrangeintbytearraymapelement defaultvalue get the time at which an index was re added last public synchronized long get readded time int index limited range int byte array map element wrapper contents get index if wrapper null return wrapper reput time else return 1 getreaddedtime limitedrangeintbytearraymapelement reputtime try to add an index data mapping return true if we succeeded false if the index was out of range public synchronized boolean add int index byte data async message callback callbacks short priority if logminor logger minor this to string add index if max value 1 min value index max value index if index max value if index min value max range return false max value index if index min value if max value index max range return false min value index if data null throw new null pointer exception integer idx index limited range int byte array map element le contents get idx if le null contents put idx new limited range int byte array map element idx data callbacks priority else le reput notify all return true asyncmessagecallback tostring maxvalue minvalue maxvalue maxvalue minvalue maxrange maxvalue minvalue maxvalue maxrange minvalue nullpointerexception limitedrangeintbytearraymapelement limitedrangeintbytearraymapelement notifyall toggle the flag and notify all waiting lock s they will then throw interrupted exception s public synchronized void interrupt flag flag notify all interruptedexception notifyall wait until add index whatever would return true if this returns add index whatever will work if it throws it probably won t public synchronized void lock int index throws interrupted exception boolean old flag flag if min value 1 return if index min value max range return if logminor logger minor this to string lock index min value min value max value max value max range max range while true wait if flag old flag if logminor logger minor this interrupted throw new interrupted exception if index min value max range min value 1 if logminor logger minor this index index min value min value max range max range returning return interruptedexception oldflag minvalue minvalue maxrange tostring minvalue minvalue maxvalue maxvalue maxrange maxrange oldflag interruptedexception minvalue maxrange minvalue minvalue minvalue maxrange maxrange public boolean would block int index if min value 1 return false return index min value max range wouldblock minvalue minvalue maxrange wait until add index whatever would return true if this returns add index whatever will work if it throws it probably won t public synchronized void lock never block int index throws would block exception if min value 1 return if index min value max range return throw new would block exception to string would block lock never block index min value min value max value max value max range max range lockneverblock wouldblockexception minvalue minvalue maxrange wouldblockexception tostring lockneverblock minvalue minvalue maxvalue maxvalue maxrange maxrange return true if we removed something public synchronized boolean remove int index if logminor logger minor this removing index min min value max max value if contents remove index null if index min value index max value return true if contents size 0 min value max value 1 notify all return true if index max value for int i max value i min value i integer ii integer value of i if contents contains key ii max value i notify all return true still here wtf notify all throw new illegal state exception still here a if index min value for int i min value i max value i integer ii integer value of i if contents contains key ii min value i notify all return true still here wtf notify all throw new illegal state exception still here b notify all throw new illegal state exception impossible return false minvalue maxvalue minvalue maxvalue minvalue maxvalue notifyall maxvalue maxvalue minvalue valueof containskey maxvalue notifyall notifyall illegalstateexception minvalue minvalue maxvalue valueof containskey minvalue notifyall notifyall illegalstateexception notifyall illegalstateexception return the contents of each packet sent then clear public synchronized byte grab all bytes int len contents size byte output new byte len int count 0 for limited range int byte array map element o contents values output count o data clear return output graballbytes limitedrangeintbytearraymapelement public synchronized limited range int byte array map element grab all int len contents size limited range int byte array map element output new limited range int byte array map element len iterator limited range int byte array map element i contents values iterator int count 0 while i has next output count i next clear return output limitedrangeintbytearraymapelement graball limitedrangeintbytearraymapelement limitedrangeintbytearraymapelement limitedrangeintbytearraymapelement hasnext empty the structure private synchronized void clear contents clear min value max value 1 minvalue maxvalue public clock problem detected user alert super false null null null null user alert critical error true null false null clockproblemdetecteduseralert useralert critical_error override public string get title return l10n title gettitle private string l10n string key return l10n get string clock problem detected user alert key getstring clockproblemdetecteduseralert override public string get text return l10n text gettext override public string get short text return l10n short text getshorttext shorttext override public html node gethtml text return new html node div get text htmlnode gethtmltext htmlnode gettext override public boolean user can dismiss return false usercandismiss public insert context bucket factory bf bucket factory persistentbf persistent file tracker tracker int max retries int rnfs to success int max threads int splitfile segment data blocks int splitfile segment check blocks client event producer event producer boolean cache local requests this persistent file tracker tracker this persistent bucket factory persistentbf dont compress false splitfile algorithm metadata splitfile onion standard this consecutivern fs count as success rnfs to success this max insert retries max retries this max split insert threads max threads this event producer event producer this splitfile segment data blocks splitfile segment data blocks this splitfile segment check blocks splitfile segment check blocks this cache local requests cache local requests insertcontext bucketfactory bucketfactory persistentfiletracker maxretries rnfstosuccess maxthreads splitfilesegmentdatablocks splitfilesegmentcheckblocks clienteventproducer eventproducer cachelocalrequests persistentfiletracker persistentbucketfactory dontcompress splitfilealgorithm splitfile_onion_standard consecutivernfscountassuccess rnfstosuccess maxinsertretries maxretries maxsplitinsertthreads maxthreads eventproducer eventproducer splitfilesegmentdatablocks splitfilesegmentdatablocks splitfilesegmentcheckblocks splitfilesegmentcheckblocks cachelocalrequests cachelocalrequests public insert context insert context ctx simple event producer producer this persistent file tracker ctx persistent file tracker this persistent bucket factory ctx persistent bucket factory this dont compress ctx dont compress this splitfile algorithm ctx splitfile algorithm this consecutivern fs count as success ctx consecutivern fs count as success this max insert retries ctx max insert retries this max split insert threads ctx max split insert threads this event producer producer this splitfile segment data blocks ctx splitfile segment data blocks this splitfile segment check blocks ctx splitfile segment check blocks this cache local requests ctx cache local requests insertcontext insertcontext simpleeventproducer persistentfiletracker persistentfiletracker persistentbucketfactory persistentbucketfactory dontcompress dontcompress splitfilealgorithm splitfilealgorithm consecutivernfscountassuccess consecutivernfscountassuccess maxinsertretries maxinsertretries maxsplitinsertthreads maxsplitinsertthreads eventproducer splitfilesegmentdatablocks splitfilesegmentdatablocks splitfilesegmentcheckblocks splitfilesegmentcheckblocks cachelocalrequests cachelocalrequests public void remove from object container container if event producer null logger error this no event producer on insert context activated container ext is active this stored container ext is stored this new exception error else container activate event producer 1 event producer remove from container container delete this removefrom objectcontainer eventproducer eventproducer insertcontext isactive isstored eventproducer eventproducer removefrom override public string get logger hook chain chain logger get chain return logger hook priority of chain get threshold loggerhookchain getchain loggerhook priorityof getthreshold override public void set string val throws invalid config value exception logger hook chain chain logger get chain try chain set threshold val catch logger hook invalid threshold exception e throw new option format exception e get message invalidconfigvalueexception loggerhookchain getchain setthreshold loggerhook invalidthresholdexception optionformatexception getmessage public string get possible values return possible values getpossiblevalues possiblevalues public logging config handler sub config logging config executor executor throws invalid config value exception this config logging config this executor executor logging config register enabled true 1 true false log config handler enabled log config handler enabled long new boolean callback override public boolean get return file logger hook null override public void set boolean val throws invalid config value exception if val file logger hook null return if val disable logger else enable logger boolean logging enabled logging config get boolean enabled logging config register dirname logs 2 true false log config handler dir name log config handler dir name long new string callback override public string get return log dir get path override public void set string val throws invalid config value exception file f new file val if f equals log dir return pre set log dir f still here if file logger hook null log dir f else discard old data file logger hook switch base filename f get path file separator log prefix log dir f new deleter log dir start log dir new file config get string dirname if logging enabled pre set log dir log dir enable logger must run pre set log dir max space used by zipped logs config register max zipped logs size 128m 3 true true log config handler max zipped logs size log config handler max zipped logs size long new long callback override public long get return max zipped logs size override public void set long val throws invalid config value exception if val 0 val 0l max zipped logs size val if file logger hook null file logger hook set max old logs size val true max zipped logs size config get long max zipped logs size these two are forced below so we don t need to check them now priority node must override this to minor on testnet config register priority normal 4 false false log config handler min logging priority log config handler min logging priority long new priority callback detailed priority config register priority detail 5 true false log config handler detaild priority threshold log config handler detaild priority threshold long new string callback override public string get logger hook chain chain logger get chain return chain get detailed thresholds override public void set string val throws invalid config value exception logger hook chain chain logger get chain try chain set detailed thresholds val catch invalid threshold exception e throw new invalid config value exception e get message interval config register interval 10minute 5 true false log config handler rotation interval log config handler rotation interval long new string callback override public string get return log rotate interval override public void set string val throws invalid config value exception if val equals log rotate interval return if file logger hook null try file logger hook set interval val catch file logger hook interval parse exception e throw new option format exception e get message log rotate interval val log rotate interval config get string interval max cached bytes in ram config register max cached bytes 10m 6 true false log config handler max cached bytes log config handler max cached bytes long new long callback override public long get return max cached log bytes override public void set long val throws invalid config value exception if val 0 val 0l if val max cached log bytes return max cached log bytes val if file logger hook null file logger hook set max list bytes val true max cached log bytes config get long max cached bytes max cached lines in ram config register max cached lines 100k 7 true false log config handler max cached lines log config handler max cached lines long new int callback override public integer get return max cached log lines override public void set integer val throws invalid config value exception if val 0 val 0 if val max cached log lines return max cached log lines val if file logger hook null file logger hook set max list length val false max cached log lines config get int max cached lines if logging enabled enable logger config finished initialization loggingconfighandler subconfig loggingconfig invalidconfigvalueexception loggingconfig loggingconfig logconfighandler logconfighandler enabledlong booleancallback fileloggerhook invalidconfigvalueexception fileloggerhook disablelogger enablelogger loggingenabled loggingconfig getboolean loggingconfig logconfighandler dirname logconfighandler dirnamelong stringcallback logdir getpath invalidconfigvalueexception logdir presetlogdir fileloggerhook logdir fileloggerhook switchbasefilename getpath log_prefix logdir logdir logdir getstring loggingenabled presetlogdir logdir enablelogger presetlogdir maxzippedlogssize logconfighandler maxzippedlogssize logconfighandler maxzippedlogssizelong longcallback maxzippedlogssize invalidconfigvalueexception maxzippedlogssize fileloggerhook fileloggerhook setmaxoldlogssize maxzippedlogssize getlong maxzippedlogssize logconfighandler minloggingpriority logconfighandler minloggingprioritylong prioritycallback prioritydetail logconfighandler detaildprioritythreshold logconfighandler detaildprioritythresholdlong stringcallback loggerhookchain getchain getdetailedthresholds invalidconfigvalueexception loggerhookchain getchain setdetailedthresholds invalidthresholdexception invalidconfigvalueexception getmessage logconfighandler rotationinterval logconfighandler rotationintervallong stringcallback logrotateinterval invalidconfigvalueexception logrotateinterval fileloggerhook fileloggerhook setinterval fileloggerhook intervalparseexception optionformatexception getmessage logrotateinterval logrotateinterval getstring maxcachedbytes logconfighandler maxcachedbytes logconfighandler maxcachedbyteslong longcallback maxcachedlogbytes invalidconfigvalueexception maxcachedlogbytes maxcachedlogbytes fileloggerhook fileloggerhook setmaxlistbytes maxcachedlogbytes getlong maxcachedbytes maxcachedlines logconfighandler maxcachedlines logconfighandler maxcachedlineslong intcallback maxcachedloglines invalidconfigvalueexception maxcachedloglines maxcachedloglines fileloggerhook fileloggerhook setmaxlistlength maxcachedloglines getint maxcachedlines loggingenabled enablelogger finishedinitialization logging config register enabled true 1 true false log config handler enabled log config handler enabled long new boolean callback override public boolean get return file logger hook null loggingconfig logconfighandler logconfighandler enabledlong booleancallback fileloggerhook override public void set boolean val throws invalid config value exception if val file logger hook null return if val disable logger else enable logger invalidconfigvalueexception fileloggerhook disablelogger enablelogger new string callback override public string get return log dir get path stringcallback logdir getpath override public void set string val throws invalid config value exception file f new file val if f equals log dir return pre set log dir f still here if file logger hook null log dir f else discard old data file logger hook switch base filename f get path file separator log prefix log dir f new deleter log dir start invalidconfigvalueexception logdir presetlogdir fileloggerhook logdir fileloggerhook switchbasefilename getpath log_prefix logdir logdir config register max zipped logs size 128m 3 true true log config handler max zipped logs size log config handler max zipped logs size long new long callback override public long get return max zipped logs size maxzippedlogssize logconfighandler maxzippedlogssize logconfighandler maxzippedlogssizelong longcallback maxzippedlogssize override public void set long val throws invalid config value exception if val 0 val 0l max zipped logs size val if file logger hook null file logger hook set max old logs size val invalidconfigvalueexception maxzippedlogssize fileloggerhook fileloggerhook setmaxoldlogssize override public string get logger hook chain chain logger get chain return chain get detailed thresholds loggerhookchain getchain getdetailedthresholds override public void set string val throws invalid config value exception logger hook chain chain logger get chain try chain set detailed thresholds val catch invalid threshold exception e throw new invalid config value exception e get message invalidconfigvalueexception loggerhookchain getchain setdetailedthresholds invalidthresholdexception invalidconfigvalueexception getmessage config register interval 10minute 5 true false log config handler rotation interval log config handler rotation interval long new string callback override public string get return log rotate interval logconfighandler rotationinterval logconfighandler rotationintervallong stringcallback logrotateinterval override public void set string val throws invalid config value exception if val equals log rotate interval return if file logger hook null try file logger hook set interval val catch file logger hook interval parse exception e throw new option format exception e get message log rotate interval val invalidconfigvalueexception logrotateinterval fileloggerhook fileloggerhook setinterval fileloggerhook intervalparseexception optionformatexception getmessage logrotateinterval config register max cached bytes 10m 6 true false log config handler max cached bytes log config handler max cached bytes long new long callback override public long get return max cached log bytes maxcachedbytes logconfighandler maxcachedbytes logconfighandler maxcachedbyteslong longcallback maxcachedlogbytes override public void set long val throws invalid config value exception if val 0 val 0l if val max cached log bytes return max cached log bytes val if file logger hook null file logger hook set max list bytes val invalidconfigvalueexception maxcachedlogbytes maxcachedlogbytes fileloggerhook fileloggerhook setmaxlistbytes config register max cached lines 100k 7 true false log config handler max cached lines log config handler max cached lines long new int callback override public integer get return max cached log lines maxcachedlines logconfighandler maxcachedlines logconfighandler maxcachedlineslong intcallback maxcachedloglines override public void set integer val throws invalid config value exception if val 0 val 0 if val max cached log lines return max cached log lines val if file logger hook null file logger hook set max list length val invalidconfigvalueexception maxcachedloglines maxcachedloglines fileloggerhook fileloggerhook setmaxlistlength turn on the logger private void enable logger try pre set log dir log dir catch invalid config value exception e3 system err println cannot set log dir log dir e3 e3 print stack trace synchronized enable logger lock if file logger hook null return logger setup chain try config force update priority config force update priority detail catch invalid config value exception e2 system err println invalid config value for logger priority in config file config get string priority leave it at the default catch node need restart exception e impossible system err println impossible node need restart exception for logger priority in config file config get string priority file logger hook hook try hook new file logger hook true new file log dir log prefix get absolute path d c t p m mmm dd yyyy hh mm ss sss logger debug filtered by chain false true max zipped logs size 1gb of old compressed logfiles catch io exception e system err println cannot start logger e get message return try hook set interval log rotate interval catch interval parse exception e system err println invalid logging interval e get message try hook set interval 5minute catch interval parse exception e1 system err println impossible e1 get message hook set max list bytes max cached log bytes hook set max list length max cached log lines file logger hook hook logger global add hook hook hook start enablelogger presetlogdir logdir invalidconfigvalueexception logdir printstacktrace enableloggerlock fileloggerhook setupchain forceupdate forceupdate prioritydetail invalidconfigvalueexception getstring nodeneedrestartexception nodeneedrestartexception getstring fileloggerhook fileloggerhook logdir log_prefix getabsolutepath maxzippedlogssize ioexception getmessage setinterval logrotateinterval intervalparseexception getmessage setinterval intervalparseexception getmessage setmaxlistbytes maxcachedlogbytes setmaxlistlength maxcachedloglines fileloggerhook globaladdhook protected void disable logger synchronized enable logger lock if file logger hook null return file logger hook hook file logger hook logger global remove hook hook hook close file logger hook null logger destroy chain if empty disablelogger enableloggerlock fileloggerhook fileloggerhook fileloggerhook globalremovehook fileloggerhook destroychainifempty protected void pre set log dir file f throws invalid config value exception boolean exists f exists if exists f is directory throw new invalid config value exception cannot overwrite a file with a log directory if exists f mkdir exists f exists if exists f is directory throw new invalid config value exception cannot create log directory presetlogdir invalidconfigvalueexception isdirectory invalidconfigvalueexception isdirectory invalidconfigvalueexception file log dir public deleter file log dir this log dir log dir logdir logdir logdir logdir void start executor execute this old log directory log dir deleter logdir public void run freenet support logger os thread logpid this file logger hook wait for switch delete log dir osthread fileloggerhook waitforswitch logdir return true if we can t delete due to presence of non freenet files private boolean delete file dir boolean failed false file files dir list files for int i 0 i files length i file f files i string s f get name if s starts with freenet s index of log 1 if f is file if f delete failed true else if f is directory if delete f failed true else failed true if failed failed dir delete return failed listfiles getname startswith indexof isfile isdirectory public file logger hook get file logger hook return file logger hook fileloggerhook getfileloggerhook fileloggerhook public void force enable logging enable logger forceenablelogging enablelogger public long get max zipped log files return max zipped logs size getmaxzippedlogfiles maxzippedlogssize public void set max zipped log files string max size as string throws invalid config value exception node need restart exception config set max zipped logs size max size as string setmaxzippedlogfiles maxsizeasstring invalidconfigvalueexception nodeneedrestartexception maxzippedlogssize maxsizeasstring set the radius of the kernel and hence the amount of blur param radius the radius of the blur in pixels see get radius public void set radius float radius this radius radius getradius setradius get the radius of the kernel return the radius see set radius public float get radius return radius setradius getradius set the number of sides of the aperture param sides the number of sides see get sides public void set sides int sides this sides sides getsides setsides get the number of sides of the aperture return the number of sides see set sides public int get sides return sides setsides getsides set the bloom factor param bloom the bloom factor see get bloom public void set bloom float bloom this bloom bloom getbloom setbloom get the bloom factor return the bloom factor see set bloom public float get bloom return bloom setbloom getbloom set the bloom threshold param bloom threshold the bloom threshold see get bloom threshold public void set bloom threshold float bloom threshold this bloom threshold bloom threshold bloomthreshold getbloomthreshold setbloomthreshold bloomthreshold bloomthreshold bloomthreshold get the bloom threshold return the bloom threshold see set bloom threshold public float get bloom threshold return bloom threshold setbloomthreshold getbloomthreshold bloomthreshold public buffered image filter buffered image src buffered image dst int width src get width int height src get height int rows 1 cols 1 int log2rows 0 log2cols 0 int iradius int math ceil radius int tile width 128 int tile height tile width int adjusted width int width iradius 2 int adjusted height int height iradius 2 tile width iradius 32 math min 128 width 2 iradius math min 256 width 2 iradius tile height iradius 32 math min 128 height 2 iradius math min 256 height 2 iradius if dst null dst new buffered image width height buffered image type int argb while rows tile height rows 2 log2rows while cols tile width cols 2 log2cols int w cols int h rows tile width w tile height h fixme tile width w and cols are always all the same fft fft new fft math max log2rows log2cols int rgb new int w h float mask new float 2 w h float gb new float 2 w h float ar new float 2 w h create the kernel double poly angle math pi sides double poly scale 1 0f math cos poly angle double r2 radius radius double rangle math to radians angle float total 0 int i 0 for int y 0 y h y for int x 0 x w x double dx x w 2f double dy y h 2f double r dx dx dy dy double f r r2 1 0 if f 0 r math sqrt r if sides 0 double a math atan2 dy dx rangle a image math mod a poly angle 2 poly angle f math cos a poly scale else f 1 f f r radius 1 0 total float f mask 0 i float f mask 1 i 0 i normalize the kernel i 0 for int y 0 y h y for int x 0 x w x mask 0 i total i fft transform2d mask 0 mask 1 w h true for int tiley iradius tiley height tiley tile height 2 iradius for int tilex iradius tilex width tilex tile width 2 iradius system out println tile tilex tiley tile width tile height clip the tile to the image bounds int tx tilex ty tiley tw tile width th tile height int fx 0 fy 0 if tx 0 tw tx fx tx tx 0 if ty 0 th ty fy ty ty 0 if tx tw width tw width tx if ty th height th height ty src getrgb tx ty tw th rgb fy w fx w create a float array from the pixels any pixels off the edge of the source image get duplicated from the edge i 0 for int y 0 y h y int imagey y tiley int j if imagey 0 j fy else if imagey height j fy th 1 else j y j w for int x 0 x w x int imagex x tilex int k if imagex 0 k fx else if imagex width k fx tw 1 else k x k j ar 0 i rgb k 24 0xff float r rgb k 16 0xff float g rgb k 8 0xff float b rgb k 0xff bloom if r bloom threshold r bloom r bloom threshold r bloom threshold bloom if g bloom threshold g bloom g bloom threshold g bloom threshold bloom if b bloom threshold b bloom b bloom threshold b bloom threshold bloom ar 1 i r gb 0 i g gb 1 i b i k transform into frequency space fft transform2d ar 0 ar 1 cols rows true fft transform2d gb 0 gb 1 cols rows true multiply the transformed pixels by the transformed kernel i 0 for int y 0 y h y for int x 0 x w x float re ar 0 i float im ar 1 i float rem mask 0 i float imm mask 1 i ar 0 i re rem im imm ar 1 i re imm im rem re gb 0 i im gb 1 i gb 0 i re rem im imm gb 1 i re imm im rem i transform back fft transform2d ar 0 ar 1 cols rows false fft transform2d gb 0 gb 1 cols rows false convert back to rgb pixels with quadrant remapping int row flip w 1 int col flip h 1 int index 0 fixme don t bother converting pixels off image edges for int y 0 y w y int ym y row flip int yi ym cols for int x 0 x w x int xm yi x col flip int a int ar 0 xm int r int ar 1 xm int g int gb 0 xm int b int gb 1 xm clamp high pixels due to blooming if r 255 r 255 if g 255 g 255 if b 255 b 255 int argb a 24 r 16 g 8 b rgb index argb clip to the output image tx tilex iradius ty tiley iradius tw tile width 2 iradius th tile height 2 iradius if tx tw width tw width tx if ty th height th height ty dst setrgb tx ty tw th rgb iradius w iradius w return dst bufferedimage bufferedimage bufferedimage getwidth getheight tilewidth tileheight tilewidth adjustedwidth adjustedheight tilewidth tileheight bufferedimage bufferedimage type_int_argb tileheight tilewidth tilewidth tileheight tilewidth polyangle polyscale polyangle toradians imagemath polyangle polyangle polyscale tileheight tilewidth tilewidth tileheight tilewidth tileheight bloomthreshold bloomthreshold bloomthreshold bloomthreshold bloomthreshold bloomthreshold bloomthreshold bloomthreshold bloomthreshold row_flip col_flip row_flip col_flip tilewidth tileheight override public string to string return blur lens blur tostring create a token bucket param max the maximum size of the bucket in tokens param nanos per tick the number of nanoseconds between ticks public token bucket long max long nanos per tick long initial value this max max this current initial value if current max logger error this initial value current max max in this new exception error current max this nanos per tick nanos per tick long now system current time millis this time last tick now 1000 1000 logminor logger should log logger minor this nanospertick tokenbucket nanospertick initialvalue initialvalue nanospertick nanospertick currenttimemillis timelasttick shouldlog either grab a bunch of tokens or don t never block param tokens the number of tokens to grab return true if we could acquire the tokens public synchronized boolean instant grab long tokens if logminor logger minor this instant grab tokens current current max max add tokens if logminor logger minor this instant grab tokens current current max max if current tokens current tokens if current max current max return true else if current max current max return false instantgrab addtokens either grab a bunch of tokens or don t never block param tokens the number of tokens to grab return true if we could acquire the tokens public synchronized long partial instant grab long tokens if logminor logger minor this instant grab tokens current current max max add tokens if logminor logger minor this instant grab tokens current current max max if current tokens current tokens if current max current max return tokens else tokens current current 0 return tokens partialinstantgrab addtokens remove tokens without blocking even if it causes the balance to go negative param tokens the number of tokens to remove public synchronized void force grab long tokens if logminor logger minor this force grab tokens if tokens 0 logger error this force grab tokens negative value new exception error return add tokens current tokens if current max current max if logminor logger minor this removed tokens balance now current forcegrab forcegrab forcegrab addtokens public synchronized long count return current get the current number of available tokens public synchronized long get count add tokens return current getcount addtokens protected long offset return 0 public synchronized void blocking grab long tokens logminor logger should log logger minor this if logminor logger minor this blocking grab tokens if tokens max inner blocking grab tokens else for int i 0 i tokens i max inner blocking grab math min tokens max blockinggrab shouldlog innerblockinggrab innerblockinggrab grab a bunch of tokens block if necessary param tokens the number of tokens to grab public synchronized void inner blocking grab long tokens if logminor logger minor this inner blocking grab tokens add tokens if current max current max if logminor logger minor this current current current tokens if current 0 if logminor logger minor this got tokens instantly current current return else if logminor logger minor this blocking grab removed tokens current current will have to wait because negative long min delayns nanos per tick current long min delayms min delayns 1000 1000 min delayns 1000 1000 0 0 1 long now system current time millis long wake at now min delayms if logminor logger minor this waking in min delayms millis while true now system current time millis int delay int math min integer max value wake at now if delay 0 break if logminor logger minor this waiting delay ms try wait delay catch interrupted exception e go around the loop again if logminor logger minor this blocking grab finished current current innerblockinggrab addtokens mindelayns nanospertick mindelayms mindelayns mindelayns currenttimemillis wakeat mindelayms mindelayms currenttimemillis max_value wakeat interruptedexception public synchronized void recycle long tokens current tokens if current max current max change the number of nanos per tick param nanos per tick the new number of nanos per tick public synchronized void change nanos per tick long nanos per tick synchronize up first using the old nanos per tick if nanos per tick 0 throw new illegal argument exception add tokens this nanos per tick nanos per tick if nanos per tick this nanos per tick notify all nanospertick changenanospertick nanospertick nanospertick nanospertick illegalargumentexception addtokens nanospertick nanospertick nanospertick nanospertick notifyall public synchronized void change bucket size long new max if new max 0 throw new illegal argument exception add tokens no clip max new max if current max current max changebucketsize newmax newmax illegalargumentexception addtokensnoclip newmax public synchronized void change nanos and bucket size long nanos per tick long new max if nanos per tick 0 throw new illegal argument exception if new max 0 throw new illegal argument exception synchronize up first using the old nanos per tick add tokens no clip if nanos per tick this nanos per tick notify all this nanos per tick nanos per tick this max new max if current max current max changenanosandbucketsize nanospertick newmax nanospertick illegalargumentexception newmax illegalargumentexception nanospertick addtokensnoclip nanospertick nanospertick notifyall nanospertick nanospertick newmax public synchronized void add tokens add tokens no clip if current max current max if logminor logger minor this add tokens clipped current current addtokens addtokensnoclip addtokens update the number of tokens according to elapsed time public synchronized void add tokens no clip long add tokens to add current add time last tick add nanos per tick if logminor logger minor this add tokens no clip added add tokens current current deliberately do not clip to size at this point caller must do this but it is usually beneficial for the caller to do so addtokensnoclip tokenstoadd timelasttick nanospertick addtokensnoclip synchronized long tokens to add long nowns system current time millis 1000 1000 long next tick time last tick nanos per tick if next tick nowns return 0 if next tick nanos per tick nowns return 1 return nowns next tick nanos per tick tokenstoadd currenttimemillis nexttick timelasttick nanospertick nexttick nexttick nanospertick nexttick nanospertick public synchronized long get nanos per tick return nanos per tick getnanospertick nanospertick public final string location public pluginhttp exception string error message string location this message error message this location location pluginhttpexception errormessage errormessage creates a new alert public ext old age user alert super true null null null null user alert error true l10n get string user alert hide true null extoldageuseralert useralert getstring useralert override public string get title return l10n ext too old title gettitle exttoooldtitle override public string get text return l10n ext too old gettext exttooold private string l10n string key return l10n get string ext old age user alert key getstring extoldageuseralert override public html node gethtml text return new html node div get text htmlnode gethtmltext htmlnode gettext override public string get short text return l10n ext too old short getshorttext exttoooldshort param my web interface a reference to the web interface which created the page used to get resources the page needs param my request the request sent by the user throws unknown identity exception public introduce identity page web interface my web interface http request my request throws unknown identity exception super my web interface my request m identity wot get own identity byid request get part as string id 128 m client wot get introduction client todo can we risk that the identity is being deleted i don t think we should lock the whole wot if request is part set solve int idx 0 while request is part set id idx string id request get part as string id idx 128 string solution request get part as string solution id 10 fixme replace 10 with the maximal solution length if solution equals introduction puzzle p wot get introduction puzzle store get byid id if p null try m client solve puzzle m identity p solution catch exception e the identity or the puzzle might have been deleted here logger error this insert puzzle solution failed idx mywebinterface webinterface myrequest unknownidentityexception introduceidentitypage webinterface mywebinterface httprequest myrequest unknownidentityexception mywebinterface myrequest midentity getownidentitybyid getpartasstring mclient getintroductionclient ispartset ispartset getpartasstring getpartasstring introductionpuzzle getintroductionpuzzlestore getbyid mclient solvepuzzle midentity insertpuzzlesolution public void make plugin respirator pr wot get plugin respirator make info box pr make puzzle box pr pluginrespirator getpluginrespirator makeinfobox makepuzzlebox private void make info box plugin respirator pr html node box content add content box introduce identity m identity get nickname box content add child p solve about 10 puzzles to get your identity known by other identities do not continously solve puzzles fixme add more information makeinfobox pluginrespirator htmlnode boxcontent addcontentbox midentity getnickname boxcontent addchild private void make puzzle box plugin respirator pr html node box content add content box puzzles synchronized m client the client returns an array list not the object container so this should be safe list introduction puzzle puzzles m client get puzzles m identity puzzle type captcha puzzle display count if puzzles size 0 html node solve form pr add form child box content uri solve puzzles solve form add child input new string type name value new string hidden page solve puzzles solve form add child input new string type name value new string hidden id m identity getid html node puzzle table solve form add child table border 0 html node row puzzle table add child tr int counter 0 for introduction puzzle p puzzles solve form add child input new string type name value new string hidden id counter p getid if counter 4 0 row puzzle table add child tr html node cell row add child td cell add attribute align center fixme use self uri puzzle id instead cell add child img new string src new string data image jpeg base64 base64 encode standard p get data cell add child br cell add child input new string type name size new string text solution p getid 10 solve form add child input new string type name value new string submit solve submit else box content add child p no puzzles were downloaded yet sorry please give the wot plugin some time to retrieve puzzles makepuzzlebox pluginrespirator htmlnode boxcontent addcontentbox mclient arraylist objectcontainer introductionpuzzle mclient getpuzzles midentity puzzletype puzzle_display_count htmlnode solveform addformchild boxcontent solvepuzzles solveform addchild solvepuzzles solveform addchild midentity htmlnode puzzletable solveform addchild htmlnode puzzletable addchild introductionpuzzle solveform addchild puzzletable addchild htmlnode addchild addattribute self_uri addchild encodestandard getdata addchild addchild solveform addchild boxcontent addchild create an archive store element from a temp store element param key2 the key of the archive the file came from param real name the name of the file in that archive param temp the temp store element currently storing the data param manager the parent archive manager within which this item is stored real archive store item archive store context ctx freeneturi key2 string real name bucket bucket super new archive key key2 real name ctx mb new multi reader bucket bucket this bucket mb get reader bucket bucket set read only space used bucket size archivestoreelement tempstoreelement realname tempstoreelement archivemanager realarchivestoreitem archivestorecontext realname archivekey realname multireaderbucket getreaderbucket setreadonly spaceused return the data as a bucket in plaintext bucket data as bucket return bucket dataasbucket return the length of the data long data size return bucket size datasize return the estimated space used by the data override long space used return space used spaceused spaceused override void inner close if logger should log logger minor this logger minor this inner close this bucket free innerclose shouldlog innerclose override bucket get data or throw throws archive failure exception return data as bucket getdataorthrow archivefailureexception dataasbucket override bucket get reader bucket throws archive failure exception return mb get reader bucket getreaderbucket archivefailureexception getreaderbucket public direct dir put file simple field set subset string identifier boolean global bucket factory bf throws message invalid exception super subset identifier global string s subset get data length if s null throw new message invalid exception protocol error message missing field upload from direct requires a data length for name identifier global try length long parse long s catch number format exception e throw new message invalid exception protocol error message error parsing number could not parse data length e to string identifier global try if length 0 data new null bucket else data bf make bucket length catch io exception e throw new message invalid exception protocol error message internal error internal error could not allocate temp bucket e to string identifier global directdirputfile simplefieldset bucketfactory messageinvalidexception datalength messageinvalidexception protocolerrormessage missing_field uploadfrom datalength parselong numberformatexception messageinvalidexception protocolerrormessage error_parsing_number datalength tostring nullbucket makebucket ioexception messageinvalidexception protocolerrormessage internal_error tostring public long bytes to read return length bytestoread public void read input stream is throws io exception bucket tools copy from data is length inputstream ioexception buckettools copyfrom public void write output stream os throws io exception bucket tools copy to data os length outputstream ioexception buckettools copyto override public bucket get data return data getdata override public void remove from object container container data free data remove from container container delete this removefrom objectcontainer removefrom public abstract class iterable iterator t implements iterable t iterator t this class itself is iterator public iterator t iterator return this iterableiterator public static void compress output stream out input stream in string cipher key throws io exception int rc byte buf new byte page size data input stream din new data input stream in data output stream dout new data output stream out byte init state new byte 256 byte state new byte 256 if cipher key null byte key cipher key get bytes for int counter 0 counter 256 counter init state counter byte counter int index1 0 int index2 0 for int counter 0 counter 256 counter index2 key index1 init state counter index2 0xff byte temp init state counter init state counter init state index2 init state index2 temp index1 index1 1 key length while rc in read buf 0 page size 0 if rc page size throw new io exception database file is corrupted byte array output stream bs new byte array output stream gzip output stream gs new gzip output stream bs gs write buf 0 page size gs finish byte compressed bs to byte array int len compressed length if cipher key null int x 0 y 0 system arraycopy init state 0 state 0 state length for int i 0 i len i x x 1 0xff y y state x 0xff byte temp state x state x state y state y temp int next state state x state y 0xff compressed i state next state dout write short len dout write compressed 0 compressed length dout flush outputstream inputstream cipherkey ioexception page_size datainputstream datainputstream dataoutputstream dataoutputstream initstate cipherkey cipherkey getbytes initstate initstate initstate initstate initstate initstate page_size page_size ioexception bytearrayoutputstream bytearrayoutputstream gzipoutputstream gzipoutputstream page_size tobytearray cipherkey initstate nextstate nextstate writeshort this utility accepts one argument path to database file it creates new file at the same location and with the same name but with with dbz extension public static void main string args throws io exception if args length 0 args length 2 system err println usage java plugins xml spider org garret perst compress database for perst lite database file path cipher key return string path args 0 file input stream in new file input stream path int ext path last index of string gzip path substring 0 ext dgz string cipher key null if args length 1 cipher key args 1 file output stream out new file output stream gzip compress out in cipher key in close out close system out println file gzip is written ioexception xmlspider compressdatabaseforperstlite database_file_path fileinputstream fileinputstream lastindexof cipherkey cipherkey fileoutputstream fileoutputstream cipherkey private colormap colormap public rays filter raysfilter set the opacity of the rays param opacity the opacity see get opacity public void set opacity float opacity this opacity opacity getopacity setopacity get the opacity of the rays return the opacity see set opacity public float get opacity return opacity setopacity getopacity set the threshold value param threshold the threshold value see get threshold public void set threshold float threshold this threshold threshold getthreshold setthreshold get the threshold value return the threshold value see set threshold public float get threshold return threshold setthreshold getthreshold set the strength of the rays param strength the strength see get strength public void set strength float strength this strength strength getstrength setstrength get the strength of the rays return the strength see set strength public float get strength return strength setstrength getstrength set whether to render only the rays param rays only true to render rays only see get rays only public void set rays only boolean rays only this rays only rays only raysonly getraysonly setraysonly raysonly raysonly raysonly get whether to render only the rays return true to render rays only see set rays only public boolean get rays only return rays only setraysonly getraysonly raysonly set the colormap to be used for the filter param colormap the colormap see get colormap public void set colormap colormap colormap this colormap colormap getcolormap setcolormap get the colormap to be used for the filter return the colormap see set colormap public colormap get colormap return colormap setcolormap getcolormap override public buffered image filter buffered image src buffered image dst int width src get width int height src get height int pixels new int width int src pixels new int width buffered image rays new buffered image width height buffered image type int argb int threshold3 int threshold 3 255 for int y 0 y height y getrgb src 0 y width 1 pixels for int x 0 x width x int rgb pixels x int a rgb 0xff000000 int r rgb 16 0xff int g rgb 8 0xff int b rgb 0xff int l r g b if l threshold3 pixels x 0xff000000 else l 3 pixels x a l 16 l 8 l setrgb rays 0 y width 1 pixels rays super filter rays null for int y 0 y height y getrgb rays 0 y width 1 pixels getrgb src 0 y width 1 src pixels for int x 0 x width x int rgb pixels x int a rgb 0xff000000 int r rgb 16 0xff int g rgb 8 0xff int b rgb 0xff if colormap null int l r g b rgb colormap get color l strength 1 3f else r pixel utils clamp int r strength g pixel utils clamp int g strength b pixel utils clamp int b strength rgb a r 16 g 8 b pixels x rgb setrgb rays 0 y width 1 pixels if dst null dst create compatible dest image src null graphics2d g dst create graphics if rays only g set composite alpha composite src over g draw rendered image src null g set composite misc composite get instance misc composite add opacity g draw rendered image rays null g dispose return dst bufferedimage bufferedimage bufferedimage getwidth getheight srcpixels bufferedimage bufferedimage bufferedimage type_int_argb srcpixels getcolor pixelutils pixelutils pixelutils createcompatibledestimage creategraphics raysonly setcomposite alphacomposite srcover drawrenderedimage setcomposite misccomposite getinstance misccomposite drawrenderedimage override public string to string return stylize rays tostring public query response queryresponse public query response soap response soap res super soap res queryresponse soapresponse soapres soapres private node get return node node body node get body node if body node null return null if body node has nodes false return null node query res node body node get node 0 if query res node null return null if query res node has nodes false return null return query res node get node 0 getreturnnode bodynode getbodynode bodynode bodynode hasnodes queryresnode bodynode getnode queryresnode queryresnode hasnodes queryresnode getnode public string get return value node node get return node if node null return return node get value getreturnvalue getreturnnode getvalue public void set response state variable state var string var state var get value set status code http status ok node body node get body node node res node create response node var body node add node res node node env nodee get envelope node set content env nodee setresponse statevariable statevar statevar getvalue setstatuscode httpstatus bodynode getbodynode resnode createresponsenode bodynode addnode resnode envnodee getenvelopenode setcontent envnodee private node create response node string var node query res node new node query res node set name control ns control query state variable response query res node set name space control ns control xmlns node return node new node return node set name control return return node set value var query res node add node return node return query res node createresponsenode queryresnode queryresnode setname query_state_variable_response queryresnode setnamespace returnnode returnnode setname returnnode setvalue queryresnode addnode returnnode queryresnode protected bucket bucket bucket create bucket bucket factory bf long length fcp server server throws io exception return bf make bucket length createbucket bucketfactory fcpserver ioexception makebucket abstract string get identifier getidentifier abstract string get identifier abstract boolean is global getidentifier isglobal protected boolean free on sent void set free on sent free on sent true freeonsent setfreeonsent freeonsent override public void read from input stream is bucket factory bf fcp server server throws io exception message invalid exception long len data length if len 0 return if len 0 bucket new null bucket return bucket temp bucket try temp bucket create bucket bf len server catch io exception e logger error this bucket error e e throw new message invalid exception protocol error message internal error e to string get identifier is global bucket tools copy from temp bucket is len this bucket temp bucket readfrom inputstream bucketfactory fcpserver ioexception messageinvalidexception datalength nullbucket tempbucket tempbucket createbucket ioexception messageinvalidexception protocolerrormessage internal_error tostring getidentifier isglobal buckettools copyfrom tempbucket tempbucket override protected void write data output stream os throws io exception long len data length if len 0 bucket tools copy to bucket os len if free on sent bucket free always transient so no remove from needed writedata outputstream ioexception datalength buckettools copyto freeonsent removefrom override string get end string return data getendstring public cellular filter results new point 3 for int j 0 j results length j results j new point if probabilities null probabilities new byte 8192 float factorial 1 float total 0 float mean 2 5f for int i 0 i 10 i if i 1 factorial i float probability float math pow mean i float math exp mean factorial int start int total 8192 total probability int end int total 8192 for int j start j end j probabilities j byte i cellularfilter specifies the scale of the texture param scale the scale of the texture min value 1 max value 300 see get scale public void set scale float scale this scale scale getscale setscale returns the scale of the texture return the scale of the texture see set scale public float get scale return scale setscale getscale specifies the stretch factor of the texture param stretch the stretch factor of the texture min value 1 max value 50 see get stretch public void set stretch float stretch this stretch stretch getstretch setstretch returns the stretch factor of the texture return the stretch factor of the texture see set stretch public float get stretch return stretch setstretch getstretch specifies the angle of the texture param angle the angle of the texture angle see get angle public void set angle float angle this angle angle float cos float math cos angle float sin float math sin angle m00 cos m01 sin m10 sin m11 cos getangle setangle returns the angle of the texture return the angle of the texture see set angle public float get angle return angle setangle getangle public void set coefficient int i float v coefficients i v setcoefficient public float get coefficient int i return coefficients i getcoefficient public void set angle coefficient float angle coefficient this angle coefficient angle coefficient setanglecoefficient anglecoefficient anglecoefficient anglecoefficient public float get angle coefficient return angle coefficient getanglecoefficient anglecoefficient public void set gradient coefficient float gradient coefficient this gradient coefficient gradient coefficient setgradientcoefficient gradientcoefficient gradientcoefficient gradientcoefficient public float get gradient coefficient return gradient coefficient getgradientcoefficient gradientcoefficient public void setf1 float v coefficients 0 v public float getf1 return coefficients 0 public void setf2 float v coefficients 1 v public float getf2 return coefficients 1 public void setf3 float v coefficients 2 v public float getf3 return coefficients 2 public void setf4 float v coefficients 3 v public float getf4 return coefficients 3 set the colormap to be used for the filter param colormap the colormap see get colormap public void set colormap colormap colormap this colormap colormap getcolormap setcolormap get the colormap to be used for the filter return the colormap see set colormap public colormap get colormap return colormap setcolormap getcolormap public void set randomness float randomness this randomness randomness setrandomness public float get randomness return randomness getrandomness public void set grid type int grid type this grid type grid type setgridtype gridtype gridtype gridtype public int get grid type return grid type getgridtype gridtype public void set distance power float distance power this distance power distance power setdistancepower distancepower distancepower distancepower public float get distance power return distance power getdistancepower distancepower specifies the turbulence of the texture param turbulence the turbulence of the texture min value 0 max value 1 see get turbulence public void set turbulence float turbulence this turbulence turbulence getturbulence setturbulence returns the turbulence of the effect return the turbulence of the effect see set turbulence public float get turbulence return turbulence setturbulence getturbulence set the amount of effect param amount the amount min value 0 max value 1 see get amount public void set amount float amount this amount amount getamount setamount get the amount of texture return the amount see set amount public float get amount return amount setamount getamount private float check cube float x float y int cubex int cubey point results int num points random set seed 571 cubex 23 cubey switch grid type case random default num points probabilities random next int 0x1fff break case square num points 1 break case hexagonal num points 1 break case octagonal num points 2 break case triangular num points 2 break for int i 0 i num points i float px 0 py 0 float weight 1 0f switch grid type case random px random next float py random next float break case square px py 0 5f if randomness 0 px randomness random next float 0 5 py randomness random next float 0 5 break case hexagonal if cubex 1 0 px 0 75f py 0 else px 0 75f py 0 5f if randomness 0 px randomness noise noise2 271 cubex px 271 cubey py py randomness noise noise2 271 cubex px 89 271 cubey py 137 break case octagonal switch i case 0 px 0 207f py 0 207f break case 1 px 0 707f py 0 707f weight 1 6f break if randomness 0 px randomness noise noise2 271 cubex px 271 cubey py py randomness noise noise2 271 cubex px 89 271 cubey py 137 break case triangular if cubey 1 0 if i 0 px 0 25f py 0 35f else px 0 75f py 0 65f else if i 0 px 0 75f py 0 35f else px 0 25f py 0 65f if randomness 0 px randomness noise noise2 271 cubex px 271 cubey py py randomness noise noise2 271 cubex px 89 271 cubey py 137 break float dx float math abs x px float dy float math abs y py float d dx weight dy weight if distance power 1 0f d dx dy else if distance power 2 0f d float math sqrt dx dx dy dy else d float math pow float math pow dx distance power float math pow dy distance power 1 distance power insertion sort the long way round to speed it up a bit if d results 0 distance point p results 2 results 2 results 1 results 1 results 0 results 0 p p distance d p dx dx p dy dy p x cubex px p y cubey py else if d results 1 distance point p results 2 results 2 results 1 results 1 p p distance d p dx dx p dy dy p x cubex px p y cubey py else if d results 2 distance point p results 2 p distance d p dx dx p dy dy p x cubex px p y cubey py return results 2 distance checkcube numpoints setseed gridtype numpoints nextint numpoints numpoints numpoints numpoints numpoints gridtype nextfloat nextfloat nextfloat nextfloat distancepower distancepower distancepower distancepower distancepower public float evaluate float x float y for int j 0 j results length j results j distance float positive infinity int ix int x int iy int y float fx x ix float fy y iy float d check cube fx fy ix iy results if d fy d check cube fx fy 1 ix iy 1 results if d 1 fy d check cube fx fy 1 ix iy 1 results if d fx check cube fx 1 fy ix 1 iy results if d fy d check cube fx 1 fy 1 ix 1 iy 1 results if d 1 fy d check cube fx 1 fy 1 ix 1 iy 1 results if d 1 fx d check cube fx 1 fy ix 1 iy results if d fy d check cube fx 1 fy 1 ix 1 iy 1 results if d 1 fy d check cube fx 1 fy 1 ix 1 iy 1 results float t 0 for int i 0 i 3 i t coefficients i results i distance if angle coefficient 0 float angle float math atan2 y results 0 y x results 0 x if angle 0 angle 2 float math pi angle 4 float math pi t angle coefficient angle if gradient coefficient 0 float a 1 results 0 dy results 0 dx t gradient coefficient a return t positive_infinity checkcube checkcube checkcube checkcube checkcube checkcube checkcube checkcube checkcube anglecoefficient anglecoefficient gradientcoefficient gradientcoefficient public float turbulence2 float x float y float freq float t 0 0f for float f 1 0f f freq f 2 t evaluate f x f y f return t public int get pixel int x int y int in pixels int width int height float nx m00 x m01 y float ny m10 x m11 y nx scale ny scale stretch nx 1000 ny 1000 reduce artifacts around 0 0 float f turbulence 1 0f evaluate nx ny turbulence2 nx ny turbulence normalize to 0 1 f f min max min f 2 f amount int a 0xff000000 int v if colormap null v colormap get color f if use color int srcx image math clamp int results 0 x 1000 scale 0 width 1 int srcy image math clamp int results 0 y 1000 scale 0 height 1 v in pixels srcy width srcx f results 1 distance results 0 distance results 1 distance results 0 distance f image math smooth step coefficients 1 coefficients 0 f v image math mix colors f 0xff000000 v return v else v pixel utils clamp int f 255 int r v 16 int g v 8 int b v return a r g b getpixel inpixels getcolor usecolor imagemath imagemath inpixels imagemath smoothstep imagemath mixcolors pixelutils override protected int filter pixels int width int height int in pixels rectangle transformed space float minmax noise find range this null min minmax 0 max minmax 1 int index 0 int out pixels new int width height for int y 0 y height y for int x 0 x width x out pixels index get pixel x y in pixels width height return out pixels filterpixels inpixels transformedspace findrange outpixels outpixels getpixel inpixels outpixels override public object clone cellular filter f cellular filter super clone f coefficients float coefficients clone f results point results clone f random new random if colormap null f colormap colormap colormap clone return f cellularfilter cellularfilter override public string to string return texture cellular tostring private static random random generator new random public float evaluate float x return noise1 x randomgenerator public float evaluate float x float y return noise2 x y public float evaluate float x float y float z return noise3 x y z compute turbulence using perlin noise param x the x value param y the y value param octaves number of octaves of turbulence return turbulence value at x y public static float turbulence2 float x float y float octaves float t 0 0f for float f 1 0f f octaves f 2 t math abs noise2 f x f y f return t compute turbulence using perlin noise param x the x value param y the y value param octaves number of octaves of turbulence return turbulence value at x y public static float turbulence3 float x float y float z float octaves float t 0 0f for float f 1 0f f octaves f 2 t math abs noise3 f x f y f z f return t static boolean start true private static float s curve float t return t t 3 0f 2 0f t scurve compute 1 dimensional perlin noise param x the x value return noise value at x in the range 1 1 public static float noise1 float x int bx0 bx1 float rx0 rx1 sx t u v if start start false init t x n bx0 int t bm bx1 bx0 1 bm rx0 t int t rx1 rx0 1 0f sx s curve rx0 u rx0 g1 p bx0 v rx1 g1 p bx1 return 2 3f lerp sx u v scurve compute 2 dimensional perlin noise param x the x coordinate param y the y coordinate return noise value at x y public static float noise2 float x float y int bx0 bx1 by0 by1 b00 b10 b01 b11 float rx0 rx1 ry0 ry1 q sx sy a b t u v int i j if start start false init t x n bx0 int t bm bx1 bx0 1 bm rx0 t int t rx1 rx0 1 0f t y n by0 int t bm by1 by0 1 bm ry0 t int t ry1 ry0 1 0f i p bx0 j p bx1 b00 p i by0 b10 p j by0 b01 p i by1 b11 p j by1 sx s curve rx0 sy s curve ry0 q g2 b00 u rx0 q 0 ry0 q 1 q g2 b10 v rx1 q 0 ry0 q 1 a lerp sx u v q g2 b01 u rx0 q 0 ry1 q 1 q g2 b11 v rx1 q 0 ry1 q 1 b lerp sx u v return 1 5f lerp sy a b scurve scurve compute 3 dimensional perlin noise param x the x coordinate param y the y coordinate param y the y coordinate return noise value at x y z public static float noise3 float x float y float z int bx0 bx1 by0 by1 bz0 bz1 b00 b10 b01 b11 float rx0 rx1 ry0 ry1 rz0 rz1 q sy sz a b c d t u v int i j if start start false init t x n bx0 int t bm bx1 bx0 1 bm rx0 t int t rx1 rx0 1 0f t y n by0 int t bm by1 by0 1 bm ry0 t int t ry1 ry0 1 0f t z n bz0 int t bm bz1 bz0 1 bm rz0 t int t rz1 rz0 1 0f i p bx0 j p bx1 b00 p i by0 b10 p j by0 b01 p i by1 b11 p j by1 t s curve rx0 sy s curve ry0 sz s curve rz0 q g3 b00 bz0 u rx0 q 0 ry0 q 1 rz0 q 2 q g3 b10 bz0 v rx1 q 0 ry0 q 1 rz0 q 2 a lerp t u v q g3 b01 bz0 u rx0 q 0 ry1 q 1 rz0 q 2 q g3 b11 bz0 v rx1 q 0 ry1 q 1 rz0 q 2 b lerp t u v c lerp sy a b q g3 b00 bz1 u rx0 q 0 ry0 q 1 rz1 q 2 q g3 b10 bz1 v rx1 q 0 ry0 q 1 rz1 q 2 a lerp t u v q g3 b01 bz1 u rx0 q 0 ry1 q 1 rz1 q 2 q g3 b11 bz1 v rx1 q 0 ry1 q 1 rz1 q 2 b lerp t u v d lerp sy a b return 1 5f lerp sz c d scurve scurve scurve public static float lerp float t float a float b return a t b a private static void normalize2 float v float s float math sqrt v 0 v 0 v 1 v 1 v 0 v 0 s v 1 v 1 s static void normalize3 float v float s float math sqrt v 0 v 0 v 1 v 1 v 2 v 2 v 0 v 0 s v 1 v 1 s v 2 v 2 s private static int random return random generator next int 0x7fffffff randomgenerator nextint private static void init int i j k for i 0 i b i p i i g1 i float random b b b b for j 0 j 2 j g2 i j float random b b b b normalize2 g2 i for j 0 j 3 j g3 i j float random b b b b normalize3 g3 i for i b 1 i 0 i k p i p i p j random b p j k for i 0 i b 2 i p b i p i g1 b i g1 i for j 0 j 2 j g2 b i j g2 i j for j 0 j 3 j g3 b i j g3 i j returns the minimum and maximum of a number of random values of the given function this is useful for making some stab at normalising the function public static float find range function1d f float minmax if minmax null minmax new float 2 float min 0 max 0 some random numbers here for float x 100 x 100 x 1 27139 float n f evaluate x min math min min n max math max max n minmax 0 min minmax 1 max return minmax findrange returns the minimum and maximum of a number of random values of the given function this is useful for making some stab at normalising the function public static float find range function2d f float minmax if minmax null minmax new float 2 float min 0 max 0 some random numbers here for float y 100 y 100 y 10 35173 for float x 100 x 100 x 10 77139 float n f evaluate x y min math min min n max math max max n minmax 0 min minmax 1 max return minmax findrange private boolean background false public smear filter random generator new random smearfilter randomgenerator public void set shape int shape this shape shape setshape public int get shape return shape getshape public void set distance int distance this distance distance setdistance public int get distance return distance getdistance public void set density float density this density density setdensity public float get density return density getdensity public void set scatter float scatter this scatter scatter setscatter public float get scatter return scatter getscatter specifies the angle of the texture param angle the angle of the texture angle see get angle public void set angle float angle this angle angle getangle setangle returns the angle of the texture return the angle of the texture see set angle public float get angle return angle setangle getangle public void set mix float mix this mix mix setmix public float get mix return mix getmix public void set fadeout int fadeout this fadeout fadeout setfadeout public int get fadeout return fadeout getfadeout public void set background boolean background this background background setbackground public boolean get background return background getbackground public void randomize seed new date get time gettime private float random float low float high return low high low random generator next float randomgenerator nextfloat override protected int filter pixels int width int height int in pixels rectangle transformed space int out pixels new int width height random generator set seed seed float sin angle float math sin angle float cos angle float math cos angle int i 0 int num shapes for int y 0 y height y for int x 0 x width x out pixels i background 0xffffffff in pixels i i switch shape case crosses crosses num shapes int 2 density width height distance 1 for i 0 i num shapes i int x random generator next int 0x7fffffff width int y random generator next int 0x7fffffff height int length random generator next int distance 1 int rgb in pixels y width x for int x1 x length x1 x length 1 x1 if x1 0 x1 width int rgb2 background 0xffffffff out pixels y width x1 out pixels y width x1 image math mix colors mix rgb2 rgb for int y1 y length y1 y length 1 y1 if y1 0 y1 height int rgb2 background 0xffffffff out pixels y1 width x out pixels y1 width x image math mix colors mix rgb2 rgb break case lines num shapes int 2 density width height 2 for i 0 i num shapes i int sx random generator next int 0x7fffffff width int sy random generator next int 0x7fffffff height int rgb in pixels sy width sx int length random generator next int 0x7fffffff distance int dx int length cos angle int dy int length sin angle int x0 sx dx int y0 sy dy int x1 sx dx int y1 sy dy int x y d incre incrne ddx ddy if x1 x0 ddx 1 else ddx 1 if y1 y0 ddy 1 else ddy 1 dx x1 x0 dy y1 y0 dx math abs dx dy math abs dy x x0 y y0 if x width x 0 y height y 0 int rgb2 background 0xffffffff out pixels y width x out pixels y width x image math mix colors mix rgb2 rgb if math abs dx math abs dy d 2 dy dx incre 2 dy incrne 2 dy dx while x x1 if d 0 d incre else d incrne y ddy x ddx if x width x 0 y height y 0 int rgb2 background 0xffffffff out pixels y width x out pixels y width x image math mix colors mix rgb2 rgb else d 2 dx dy incre 2 dx incrne 2 dx dy while y y1 if d 0 d incre else d incrne x ddx y ddy if x width x 0 y height y 0 int rgb2 background 0xffffffff out pixels y width x out pixels y width x image math mix colors mix rgb2 rgb break case squares case circles int radius distance 1 int radius2 radius radius num shapes int 2 density width height radius for i 0 i num shapes i int sx random generator next int 0x7fffffff width int sy random generator next int 0x7fffffff height int rgb in pixels sy width sx for int x sx radius x sx radius 1 x for int y sy radius y sy radius 1 y int f if shape circles f x sx x sx y sy y sy else f 0 if x 0 x width y 0 y height f radius2 int rgb2 background 0xffffffff out pixels y width x out pixels y width x image math mix colors mix rgb2 rgb return out pixels filterpixels inpixels transformedspace outpixels randomgenerator setseed sinangle cosangle numshapes outpixels inpixels numshapes numshapes randomgenerator nextint randomgenerator nextint randomgenerator nextint inpixels outpixels outpixels imagemath mixcolors outpixels outpixels imagemath mixcolors numshapes numshapes randomgenerator nextint randomgenerator nextint inpixels randomgenerator nextint cosangle sinangle outpixels outpixels imagemath mixcolors outpixels outpixels imagemath mixcolors outpixels outpixels imagemath mixcolors numshapes numshapes randomgenerator nextint randomgenerator nextint inpixels outpixels outpixels imagemath mixcolors outpixels override public string to string return effects smear tostring plugin respirator pr public void terminate goon false pluginrespirator public void run plugin plugin respirator pr this pr pr while goon system err println heartbeat from hello world plugin new date try thread sleep 1000 catch interrupted exception e who cares runplugin pluginrespirator helloworld interruptedexception private final get pubkey pubkey cache public ssk store get pubkey pubkey cache this pubkey cache pubkey cache getpubkey pubkeycache sskstore getpubkey pubkeycache pubkeycache pubkeycache override public storable block construct byte data byte headers byte routing key byte full key throws ssk verify exception if data null headers null throw new ssk verify exception need data and headers if full key null throw new ssk verify exception need full key to reconstruct an ssk nodessk key key nodessk construct full key if key grab pubkey pubkey cache throw new ssk verify exception no pubkey found ssk block block new ssk block data headers key false return block storableblock routingkey fullkey sskverifyexception sskverifyexception fullkey sskverifyexception fullkey grabpubkey pubkeycache sskverifyexception sskblock sskblock public ssk block fetch nodessk chk boolean dont promote throws io exception return ssk block store fetch chk get routing key chk get full key dont promote sskblock dontpromote ioexception sskblock getroutingkey getfullkey dontpromote public void put ssk block b boolean overwrite throws io exception key collision exception nodessk key nodessk b get key store put b key get routing key key get full key b get raw data b get raw headers overwrite sskblock ioexception keycollisionexception getkey getroutingkey getfullkey getrawdata getrawheaders override public int data length return ssk block data length datalength sskblock data_length override public int full key length return nodessk full key length fullkeylength full_key_length override public int header length return ssk block total headers length headerlength sskblock total_headers_length override public int routing key length return nodessk routing key length routingkeylength routing_key_length override public boolean store full keys return true storefullkeys override public boolean collision possible return true collisionpossible override public boolean construct needs key return true constructneedskey override public byte routing key from full key byte key buf return nodessk routing key from full key key buf routingkeyfromfullkey keybuf routingkeyfromfullkey keybuf private t next public limited enumeration next null limitedenumeration public limited enumeration t loner next loner limitedenumeration public final boolean has more elements return next null hasmoreelements public final t next element if next null throw new no such element exception try return next finally next null nextelement nosuchelementexception a new list with no items public doubly linked list impl clear doublylinkedlistimpl protected doubly linked list impl t h t t int size firstitem h lastitem t t i firstitem while i null i set parent this i i get next this size size doublylinkedlistimpl _h _t _firstitem _h _lastitem _t _firstitem setparent getnext inherit doc public void clear help to detect removal after clear the check in remove is enough strictly as long as people don t add elements afterwards if firstitem null return t pos firstitem t opos while true if pos null break pos set parent null pos set prev null opos pos pos pos get next opos set next null firstitem lastitem null size 0 inheritdoc _firstitem _firstitem setparent setprev getnext setnext _firstitem _lastitem inherit doc public final int size assert size 0 firstitem null lastitem null return size inheritdoc _firstitem _lastitem inherit doc public final boolean is empty assert size 0 firstitem null lastitem null return size 0 inheritdoc isempty _firstitem _lastitem inherit doc see forward elements public final enumeration t elements return forward elements inheritdoc forwardelements forwardelements public boolean contains t item for t i this if i equals item return true return false inherit doc public final t head return size 0 null firstitem inheritdoc _firstitem inherit doc public final t tail return size 0 null lastitem inheritdoc _lastitem methods that add remove items at the head of the list inherit doc public final void unshift t i insert next null i inheritdoc insertnext inherit doc public final t shift return size 0 null remove firstitem inheritdoc _firstitem inherit doc public doubly linked list t shift int n if n size n size if n 1 return new doubly linked list impl t t i firstitem for int m 0 m n 1 m i i get next t new tail item i t new first item new tail item get next new tail item set next null doubly linked list t newlist new doubly linked list impl t firstitem new tail item n if new first item null new first item set prev null firstitem new first item else firstitem lastitem null size n return newlist inheritdoc doublylinkedlist doublylinkedlistimpl _firstitem getnext newtailitem newfirstitem newtailitem getnext newtailitem setnext doublylinkedlist doublylinkedlistimpl _firstitem newtailitem newfirstitem newfirstitem setprev _firstitem newfirstitem _firstitem _lastitem methods that add remove items at the tail of the list inherit doc public final void push t i insert prev null i inheritdoc insertprev inherit doc public final t pop return size 0 null remove lastitem inheritdoc _lastitem inherit doc public doubly linked list t pop int n if n size n size if n 1 return new doubly linked list impl t t i lastitem for int m 0 m n 1 m i i get prev t new first item i t new last item new first item get prev new first item set prev null doubly linked list t newlist new doubly linked list impl t new first item lastitem n if new last item null new last item set next null lastitem new last item else firstitem lastitem null size n return newlist inheritdoc doublylinkedlist doublylinkedlistimpl _lastitem getprev newfirstitem newlastitem newfirstitem getprev newfirstitem setprev doublylinkedlist doublylinkedlistimpl newfirstitem _lastitem newlastitem newlastitem setnext _lastitem newlastitem _firstitem _lastitem testing looking at neighbor items inherit doc public final boolean has next t i t next i get next return next null inheritdoc hasnext getnext inherit doc public final boolean has prev t i t prev i get prev return prev null inheritdoc hasprev getprev inherit doc public final t next t i t next i get next return next inheritdoc getnext inherit doc public final t prev t i t prev i get prev return prev inheritdoc getprev inherit doc public t remove t i if i get parent null is empty return null not in list if i get parent this throw new promiscuous item exception i i get parent t next i get next t prev i get prev if next null prev null only item in list assert size 1 if next null last item assert lastitem i lastitem prev else assert next get prev i next set prev prev if prev null first item assert firstitem i firstitem next else assert prev get next i prev set next next i set next null i set prev null size i set parent null return i inheritdoc getparent isempty getparent promiscuousitemexception getparent getnext getprev _lastitem _lastitem getprev setprev _firstitem _firstitem getnext setnext setnext setprev setparent inherit doc public void insert prev t i t j if j get parent null throw new promiscuous item exception j j get parent if j get next null j get prev null throw new promiscuous item exception j if i null insert as tail j set prev lastitem j set next null j set parent this if lastitem null lastitem set next j lastitem j else firstitem lastitem j size else insert in middle if i get parent null throw new promiscuous item exception i i get parent different trace to make easier debugging if i get parent this throw new promiscuous item exception i i get parent t prev i get prev if prev null if i firstitem throw new virgin item exception i firstitem j else prev set next j j set prev prev i set prev j j set next i j set parent this size inheritdoc insertprev getparent promiscuousitemexception getparent getnext getprev promiscuousitemexception setprev _lastitem setnext setparent _lastitem _lastitem setnext _lastitem _firstitem _lastitem getparent promiscuousitemexception getparent getparent promiscuousitemexception getparent getprev _firstitem virginitemexception _firstitem setnext setprev setprev setnext setparent inherit doc public void insert next t i t j if j get parent null throw new promiscuous item exception j i get parent if j get next null j get prev null throw new promiscuous item exception j if i null insert as head j set prev null j set next firstitem j set parent this if firstitem null firstitem set prev j firstitem j else firstitem lastitem j size else if i get parent this throw new promiscuous item exception i i get parent t next i get next if next null if i lastitem throw new virgin item exception i lastitem j else next set prev j j set next next i set next j j set prev i j set parent this size inheritdoc insertnext getparent promiscuousitemexception getparent getnext getprev promiscuousitemexception setprev setnext _firstitem setparent _firstitem _firstitem setprev _firstitem _firstitem _lastitem getparent promiscuousitemexception getparent getnext _lastitem virginitemexception _lastitem setprev setnext setnext setprev setparent return an enumeration of list elements from head to tail private enumeration t forward elements return new forward walker forwardelements forwardwalker return an enumeration of list elements from tail to head protected enumeration t reverse elements return new reverse walker reverseelements reversewalker private class forward walker implements enumeration t protected t next protected forward walker next firstitem forwardwalker forwardwalker _firstitem next firstitem public final boolean has more elements return next null _firstitem hasmoreelements public t next element if next null throw new no such element exception t result next next next get next return result nextelement nosuchelementexception getnext private class reverse walker implements enumeration t protected t next protected reverse walker next lastitem reversewalker reversewalker _lastitem next lastitem public final boolean has more elements return next null _lastitem hasmoreelements public t next element if next null throw new no such element exception t result next if next null throw new illegal state exception next null next next get prev return result nextelement nosuchelementexception illegalstateexception getprev public final t get next return next getnext suppress warnings unchecked public final t set next doubly linked list item i t old next next t i return old suppresswarnings setnext doublylinkedlist public final t get prev return prev getprev suppress warnings unchecked public final t set prev doubly linked list item i t old prev prev t i return old suppresswarnings setprev doublylinkedlist public doubly linked list super t get parent return list doublylinkedlist getparent public doubly linked list super t set parent doubly linked list super t l doubly linked list super t old list list l return old doublylinkedlist setparent doublylinkedlist doublylinkedlist public iterator t iterator return new iterator t private enumeration t e forward elements public boolean has next return e has more elements public t next if has next throw new no such element exception return e next element public void remove throw new unsupported operation exception forwardelements hasnext hasmoreelements hasnext nosuchelementexception nextelement unsupportedoperationexception private enumeration t e forward elements public boolean has next return e has more elements forwardelements hasnext hasmoreelements public t next if has next throw new no such element exception return e next element hasnext nosuchelementexception nextelement public void remove throw new unsupported operation exception unsupportedoperationexception scalable set storage impl storage int initial size super storage if initial size btree threshold link storage t create link initial size else set storage t create set scalableset storageimpl initialsize initialsize btree_threshold createlink initialsize createset scalable set scalableset scalable set public boolean is empty return size 0 scalableset isempty public int size return link null link size set size public void clear if link null link clear modify else set clear public boolean contains object o if o instanceof i persistent i persistent p i persistent o return link null link contains p set contains p return false ipersistent ipersistent ipersistent public object to array return link null link to array set to array toarray toarray toarray public e e to array e a return link null link e to array a set e to array a toarray toarray toarray public iterator t iterator return link null link iterator set iterator public boolean add t obj if link null if link index of obj 0 return false if link size btree threshold set get storage t create set for int i 0 n link size i n i set add link get i link null modify set add obj else modify link add obj return true else return set add obj indexof btree_threshold getstorage createset public boolean remove t o if link null if link remove o modify return true return false else return set remove o public int hash code int h 0 iterator t i iterator while i has next h i next get oid return h hashcode hasnext getoid public boolean equals object o if o this return true if o instanceof set return false collection c collection o if c size size return false return contains all c containsall public void deallocate if set null set deallocate super deallocate protected final list address matcher address matchers new array list address matcher public allowed hosts string allowed hosts set allowed hosts allowed hosts addressmatcher addressmatchers arraylist addressmatcher allowedhosts allowedhosts setallowedhosts allowedhosts sets the list of allowed hosts to code allowed hosts code the new list is in effect immediately after this method has finished param allowed hosts the new list of allowed hosts s public void set allowed hosts string allowed hosts if allowed hosts null allowed hosts equals allowed hosts network interface default bind to string tokenizer allowed hosts tokens new string tokenizer allowed hosts list address matcher new address matchers new array list address matcher while allowed hosts tokens has more tokens string allowed host allowed hosts tokens next token trim string hostname allowed host if allowed host index of 1 hostname allowed host substring 0 allowed host index of address type address type address identifier get address type hostname if address type address type i pv4 new address matchers add new inet4 address matcher allowed host else if address type address type i pv6 new address matchers add new inet6 address matcher allowed host else if allowed host equals new address matchers add new everything matcher else logger error network interface class ignoring invalid allowed host allowed host synchronized this this address matchers clear this address matchers add all new address matchers allowedhosts allowedhosts setallowedhosts allowedhosts allowedhosts allowedhosts allowedhosts networkinterface default_bind_to stringtokenizer allowedhoststokens stringtokenizer allowedhosts addressmatcher newaddressmatchers arraylist addressmatcher allowedhoststokens hasmoretokens allowedhost allowedhoststokens nexttoken allowedhost allowedhost indexof allowedhost allowedhost indexof addresstype addresstype addressidentifier getaddresstype addresstype addresstype ipv4 newaddressmatchers inet4addressmatcher allowedhost addresstype addresstype ipv6 newaddressmatchers inet6addressmatcher allowedhost allowedhost newaddressmatchers everythingmatcher networkinterface allowedhost allowedhost addressmatchers addressmatchers addall newaddressmatchers public boolean allowed inet address client address address type client address type address identifier get address type client address get host address return allowed client address type client address inetaddress clientaddress addresstype clientaddresstype addressidentifier getaddresstype clientaddress gethostaddress clientaddresstype clientaddress public synchronized boolean allowed address type client address type inet address client address for address matcher matcher address matchers if matcher matches client address return true return false addresstype clientaddresstype inetaddress clientaddress addressmatcher addressmatchers clientaddress public synchronized string get allowed hosts string builder sb new string builder for int i 0 i address matchers size i address matcher matcher address matchers get i if matcher instanceof everything matcher return if i 0 sb append sb append matcher get human representation return sb to string getallowedhosts stringbuilder stringbuilder addressmatchers addressmatcher addressmatchers everythingmatcher gethumanrepresentation tostring private float turbulence 1 public marble filter set edge action clamp marblefilter setedgeaction set the x scale of the effect param x scale the scale see getx scale public void setx scale float x scale this x scale x scale xscale getxscale setxscale xscale xscale xscale get the x scale of the effect return the scale see setx scale public float getx scale return x scale setxscale getxscale xscale set the y scale of the effect param y scale the scale see gety scale public void sety scale float y scale this y scale y scale yscale getyscale setyscale yscale yscale yscale get the y scale of the effect return the scale see sety scale public float gety scale return y scale setyscale getyscale yscale set the amount of effect param amount the amount min value 0 max value 1 see get amount public void set amount float amount this amount amount getamount setamount get the amount of effect return the amount see set amount public float get amount return amount setamount getamount specifies the turbulence of the effect param turbulence the turbulence of the effect min value 0 max value 1 see get turbulence public void set turbulence float turbulence this turbulence turbulence getturbulence setturbulence returns the turbulence of the effect return the turbulence of the effect see set turbulence public float get turbulence return turbulence setturbulence getturbulence private void initialize sin table new float 256 cos table new float 256 for int i 0 i 256 i float angle image math two pi i 256f turbulence sin table i float y scale math sin angle cos table i float y scale math cos angle sintable costable imagemath two_pi sintable yscale costable yscale private int displacement map int x int y return pixel utils clamp int 127 1 noise noise2 x x scale y x scale displacementmap pixelutils xscale xscale override protected void transform inverse int x int y float out int displacement displacement map x y out 0 x sin table displacement out 1 y cos table displacement transforminverse displacementmap sintable costable override public buffered image filter buffered image src buffered image dst initialize return super filter src dst bufferedimage bufferedimage bufferedimage override public string to string return distort marble tostring creates a new own identities page param my web interface a reference to the web interface which created the page used to get resources the page needs param my request the request sent by the user public own identities page web interface my web interface http request my request super my web interface my request ownidentitiespage mywebinterface webinterface myrequest ownidentitiespage webinterface mywebinterface httprequest myrequest mywebinterface myrequest public void make if request is part set restore identity try wot restore identity request get part as string requesturi 1024 request get part as string inserturi 1024 html node restore box add content box restoring is in progress restore box add child p please don t use that identity set trust edit parameters etc until it has been restored from freenet your changes will be overwritten by the old settings which are downloaded from freenet catch exception e add error box restoring the identity failed e get message synchronized wot make own identities list make restore own identity form ispartset restoreidentity restoreidentity getpartasstring getpartasstring htmlnode restorebox addcontentbox restorebox addchild adderrorbox getmessage makeownidentitieslist makerestoreownidentityform private void make own identities list html node box content add content box summary object set own identity own identities wot get all own identities if own identities size 0 box content add child p you have no own identity yet you should create one else html node identities table box content add child table border 0 html node row identities table add child tr row add child th name row add child th last change row add child th last insert row add child th publishes trustlist row add child th trusters row add child th manage while own identities has next own identity id own identities next row identities table add child tr row add child td new string title style align new string id get requesturi to string cursor help center id get nickname synchronized m date format m date format set time zone time zone get default simple date format format date in utc does convert to the configured time zone interesting eh row add child td m date format format id get last change date html node cell row add child td new string align new string center if id get last insert date equals new date 0 cell add child p never else synchronized m date format m date format set time zone time zone get default simple date format format date in utc does convert to the configured time zone interesting eh cell add child new html node a href id get requesturi to string m date format format id get last insert date row add child td new string align new string center id does publish trust list yes no html node trusters cell row add child td new string align new string center trusters cell add child new html node a href uri show identity id id getid long to string wot get received trusts id size html node manage cell row add child td new string align new string center html node edit form pr add form child manage cell uri edit identity edit form add child input new string type name value new string hidden page edit identity edit form add child input new string type name value new string hidden id id getid edit form add child input new string type name value new string submit edit edit html node delete form pr add form child manage cell uri delete identity delete form add child input new string type name value new string hidden page delete identity delete form add child input new string type name value new string hidden id id getid delete form add child input new string type name value new string submit delete delete html node introduce form pr add form child manage cell uri introduce identity introduce form add child input new string type name value new string hidden page introduce identity introduce form add child input new string type name value new string hidden id id getid introduce form add child input new string type name value new string submit introduce introduce html node create form pr add form child box content uri create identity create form add child input new string type name value new string hidden page create identity create form add child span new string title style new string no spaces or special characters border bottom 1px dotted cursor help nickname create form add child input new string type name size new string text nickname 30 create form add child input new string type name value new string submit create create makeownidentitieslist htmlnode boxcontent addcontentbox objectset ownidentity ownidentities getallownidentities ownidentities boxcontent addchild htmlnode identitiestable boxcontent addchild htmlnode identitiestable addchild addchild addchild addchild addchild addchild addchild ownidentities hasnext ownidentity ownidentities identitiestable addchild addchild getrequesturi tostring getnickname mdateformat mdateformat settimezone timezone getdefault simpledateformat timezone addchild mdateformat getlastchangedate htmlnode addchild getlastinsertdate addchild mdateformat mdateformat settimezone timezone getdefault simpledateformat timezone addchild htmlnode getrequesturi tostring mdateformat getlastinsertdate addchild doespublishtrustlist htmlnode trusterscell addchild trusterscell addchild htmlnode showidentity tostring getreceivedtrusts htmlnode managecell addchild htmlnode editform addformchild managecell editidentity editform addchild editidentity editform addchild editform addchild htmlnode deleteform addformchild managecell deleteidentity deleteform addchild deleteidentity deleteform addchild deleteform addchild htmlnode introduceform addformchild managecell introduceidentity introduceform addchild introduceidentity introduceform addchild introduceform addchild htmlnode createform addformchild boxcontent createidentity createform addchild createidentity createform addchild createform addchild createform addchild makes the form used to restore an own identity from freenet private void make restore own identity form html node restore box content add content box restore an identity from freenet restore box content add child p use this if you lost your database for some reason but still have your identity s keys html node restore form pr add form child restore box content uri restore identity restore form add child input new string type name value new string hidden page restore identity restore form add child input new string type name size value new string text requesturi 70 request uri restore form add child br restore form add child input new string type name size value new string text inserturi 70 inserturi restore form add child br restore form add child input new string type name value new string submit restore identity restore ownidentity makerestoreownidentityform htmlnode restoreboxcontent addcontentbox restoreboxcontent addchild htmlnode restoreform addformchild restoreboxcontent restoreidentity restoreform addchild restoreidentity restoreform addchild restoreform addchild restoreform addchild restoreform addchild restoreform addchild restoreidentity public bucket read filter bucket data bucket factory bf string charset hash map string string other params filter callback cb throws data filter exception io exception if data size 6 throw header error l10n too short title l10n too short input stream is data get input stream buffered input stream bis new buffered input stream is data input stream dis new data input stream bis try check the header byte header check new byte header size dis read fully header check if arrays equals header check gif87a header arrays equals header check gif89a header throw header error l10n invalid header title l10n invalid header dis close finally closer close dis return data readfilter bucketfactory hashmap otherparams filtercallback datafilterexception ioexception throwheadererror tooshorttitle tooshort inputstream getinputstream bufferedinputstream bufferedinputstream datainputstream datainputstream headercheck header_size readfully headercheck headercheck gif87aheader headercheck gif89aheader throwheadererror invalidheadertitle invalidheader private static string l10n string key return l10n get string gif filter key getstring giffilter private void throw header error string short reason string reason throws data filter exception throw an exception string message l10n not gif if reason null message reason if short reason null message short reason throw new data filter exception short reason short reason p message p new html node p add child message throwheadererror shortreason datafilterexception notgif shortreason shortreason datafilterexception shortreason shortreason htmlnode addchild public bucket write filter bucket data bucket factory bf string charset hash map string string other params filter callback cb throws data filter exception io exception return null writefilter bucketfactory hashmap otherparams filtercallback datafilterexception ioexception public final object token public bulk call failure item low level get exception e object token this e e this token token bulkcallfailureitem lowlevelgetexception private static final long serial versionuid 796276279268900609l public crypt format exception string message super message serialversionuid cryptformatexception public crypt format exception io exception e super e get message init cause e cryptformatexception ioexception getmessage initcause text mode client interface server node node node client core core int port string bind to string allowed hosts throws io exception this n node this core n client core this r n random this downloads dir core download dir this port port this bind to bind to this allowed hosts allowed hosts this is enabled true if ssl network interface ssl network interface create port bind to allowed hosts n executor true else network interface network interface create port bind to allowed hosts n executor true textmodeclientinterfaceserver nodeclientcore bindto allowedhosts ioexception clientcore downloadsdir downloaddir bindto bindto allowedhosts allowedhosts isenabled networkinterface sslnetworkinterface bindto allowedhosts networkinterface networkinterface bindto allowedhosts void start logger normal core tmci started on network interface get allowed hosts port system out println tmci started on network interface get allowed hosts port n executor execute this text mode client interface networkinterface getallowedhosts networkinterface getallowedhosts public static text mode client interface server maybe create node node node client core core config config throws io exception text mode client interface server server null sub config tmci config new sub config console config tmci config register enabled false 1 true true fixme only because can t be changed on the fly text mode client interface server enabled text mode client interface server enabled long new tmci enabled callback core tmci config register ssl false 1 true true text mode client interface server ssl text mode client interface server ssl long new tmcissl callback tmci config register bind to network interface default bind to 2 true false text mode client interface server bind to text mode client interface server bind to long new tmci bindto callback core tmci config register allowed hosts network interface default bind to 2 true false text mode client interface server allowed hosts text mode client interface server allowed hosts long new tmci allowed hosts callback core tmci config register port 2323 1 true false text mode client interface server telnet port number text mode client interface server telnet port number long new tcmi port number callback core false tmci config register direct enabled false 1 true false text mode client interface server enable input output text mode client interface server enable input output long new tmci direct enabled callback core boolean tmci enabled tmci config get boolean enabled int port tmci config get int port string bind ip tmci config get string bind to string allowed hosts tmci config get string allowed hosts boolean direct tmci config get boolean direct enabled if ssl available ssl tmci config get boolean ssl if tmci enabled server new text mode client interface server node core port bind ip allowed hosts if direct high level simple client client core make client request starter interactive priority class true text mode client interface directtmci new text mode client interface node client core download dir system in system out node executor execute directtmci direct text mode interface core set directtmci directtmci tmci config finished initialization return server caller must call start textmodeclientinterfaceserver maybecreate nodeclientcore ioexception textmodeclientinterfaceserver subconfig tmciconfig subconfig tmciconfig textmodeclientinterfaceserver textmodeclientinterfaceserver enabledlong tmcienabledcallback tmciconfig textmodeclientinterfaceserver textmodeclientinterfaceserver ssllong tmcisslcallback tmciconfig bindto networkinterface default_bind_to textmodeclientinterfaceserver bindto textmodeclientinterfaceserver bindtolong tmcibindtocallback tmciconfig allowedhosts networkinterface default_bind_to textmodeclientinterfaceserver allowedhosts textmodeclientinterfaceserver allowedhostslong tmciallowedhostscallback tmciconfig textmodeclientinterfaceserver telnetportnumber textmodeclientinterfaceserver telnetportnumberlong tcmiportnumbercallback tmciconfig directenabled textmodeclientinterfaceserver enableinputoutput textmodeclientinterfaceserver enableinputoutputlong tmcidirectenabledcallback tmcienabled tmciconfig getboolean tmciconfig getint bind_ip tmciconfig getstring bindto allowedhosts tmciconfig getstring allowedhosts tmciconfig getboolean directenabled tmciconfig getboolean tmcienabled textmodeclientinterfaceserver bind_ip allowedhosts highlevelsimpleclient makeclient requeststarter interactive_priority_class textmodeclientinterface textmodeclientinterface downloaddir setdirecttmci tmciconfig finishedinitialization final node client core core tmci enabled callback node client core core this core core nodeclientcore tmcienabledcallback nodeclientcore override public boolean get return core get text mode client interface null gettextmodeclientinterface override public void set boolean val throws invalid config value exception if get equals val return fixme implement see bug 122 throw new invalid config value exception cannot be updated on the fly invalidconfigvalueexception invalidconfigvalueexception throw new invalid config value exception cannot be updated on the fly override public boolean is read only return true invalidconfigvalueexception isreadonly static class tmcissl callback extends boolean callback override public boolean get return ssl tmcisslcallback booleancallback override public void set boolean val throws invalid config value exception if get equals val return if ssl available throw new invalid config value exception enable ssl support before use ssl with tmci ssl val throw new invalid config value exception cannot change ssl on the fly please restart freenet invalidconfigvalueexception invalidconfigvalueexception invalidconfigvalueexception throw new invalid config value exception cannot change ssl on the fly please restart freenet override public boolean is read only return true invalidconfigvalueexception isreadonly final node client core core tmci direct enabled callback node client core core this core core nodeclientcore tmcidirectenabledcallback nodeclientcore override public boolean get return core get directtmci null getdirecttmci override public void set boolean val throws invalid config value exception if get equals val return fixme implement see bug 122 throw new invalid config value exception cannot be updated on the fly invalidconfigvalueexception invalidconfigvalueexception throw new invalid config value exception cannot be updated on the fly override public boolean is read only return true invalidconfigvalueexception isreadonly final node client core core tmci bindto callback node client core core this core core nodeclientcore tmcibindtocallback nodeclientcore override public string get if core get text mode client interface null return core get text mode client interface bind to else return network interface default bind to gettextmodeclientinterface gettextmodeclientinterface bindto networkinterface default_bind_to override public void set string val throws invalid config value exception if val equals get return try core get text mode client interface network interface set bind to val false core get text mode client interface bind to val catch io exception e throw new invalid config value exception could not change bind to invalidconfigvalueexception gettextmodeclientinterface networkinterface setbindto gettextmodeclientinterface bindto ioexception invalidconfigvalueexception private final node client core core public tmci allowed hosts callback node client core core this core core nodeclientcore tmciallowedhostscallback nodeclientcore override public string get if core get text mode client interface null return core get text mode client interface allowed hosts return network interface default bind to gettextmodeclientinterface gettextmodeclientinterface allowedhosts networkinterface default_bind_to override public void set string val throws invalid config value exception if val equals get text mode client interface server server core get text mode client interface if server null server network interface set allowed hosts val server allowed hosts val else throw new invalid config value exception setting allowed hosts for tmci console server when tmci is disabled invalidconfigvalueexception textmodeclientinterfaceserver gettextmodeclientinterface networkinterface setallowedhosts allowedhosts invalidconfigvalueexception allowedhosts final node client core core tcmi port number callback node client core core this core core nodeclientcore tcmiportnumbercallback nodeclientcore override public integer get if core get text mode client interface null return core get text mode client interface port else return 2323 gettextmodeclientinterface gettextmodeclientinterface todo implement it override public void set integer val throws invalid config value exception if get equals val return core get text mode client interface set port val invalidconfigvalueexception gettextmodeclientinterface setport read commands run them public void run freenet support logger os thread logpid this while true int cur port port string temp bind to this bind to try network interface set so timeout 1000 catch socket exception e1 logger error this could not set timeout e1 e1 system err println could not start tmci e1 e1 print stack trace return while is enabled maybe something has changed if port cur port break if this bind to equals temp bind to break try socket s network interface accept if s null continue timeout input stream in s get input stream output stream out s get output stream text mode client interface tmci new text mode client interface this in out n executor execute tmci text mode client interface handler for s get port catch socket exception e logger error this socket error e e catch io exception e logger error this tmci failed to accept socket e e try network interface close catch io exception e logger error this error shuting down tmci e osthread curport tempbindto bindto networkinterface setsotimeout socketexception printstacktrace isenabled curport bindto tempbindto networkinterface inputstream getinputstream outputstream getoutputstream textmodeclientinterface textmodeclientinterface getport socketexception ioexception networkinterface ioexception public void set port int val port val setport create a new simple event producer public simple event producer listeners new vector client event listener simpleeventproducer simpleeventproducer clienteventlistener create a new simple event producer with the given listeners public simple event producer client event listener cela this for int i 0 i cela length i add event listener cela i simpleeventproducer simpleeventproducer clienteventlistener addeventlistener public void add event listener client event listener cel if cel null listeners add element cel else throw new illegal argument exception adding a null listener addeventlistener clienteventlistener addelement illegalargumentexception public boolean remove event listener client event listener cel boolean b listeners remove element cel listeners trim to size return b removeeventlistener clienteventlistener removeelement trimtosize sends the client event to all registered listeners of this object public void produce event client event ce object container container client context context if container null container activate listeners 1 for enumeration client event listener e listeners elements e has more elements try client event listener cel e next element if container null container activate cel 1 cel receive ce container context catch no such element exception ne logger normal this concurrent modification in produce event this catch exception ue system err println unexpected exception ue print stack trace system err println clientevent produceevent clientevent objectcontainer clientcontext clienteventlistener hasmoreelements clienteventlistener nextelement nosuchelementexception produceevent printstacktrace returns the listeners as an array public client event listener get event listeners client event listener ret new client event listener listeners size listeners copy into ret return ret clienteventlistener geteventlisteners clienteventlistener clienteventlistener copyinto adds all listeners in the given array public void add event listeners client event listener cela for int i 0 i cela length i add event listener cela i addeventlisteners clienteventlistener addeventlistener public void remove from object container container if container null container activate listeners 1 client event listener list listeners to array new client event listener listeners size listeners clear container delete listeners for int i 0 i list length i list i on remove event producer container container delete this removefrom objectcontainer clienteventlistener toarray clienteventlistener onremoveeventproducer update catastrophe exception file old config file new config super l10n update catastrophe new string old new new string old config to string new config to string this old config old config this new config new config updatecatastropheexception oldconfig newconfig updatecatastrophe oldconfig tostring newconfig tostring oldconfig oldconfig newconfig newconfig update deploy context throws updater parser exception properties p wrapper manager get properties for int prop no 1 true prop no string prop p get property wrapper java classpath prop no if prop null break file f new file prop boolean is absolute f is absolute string name f get name to lower case if ext jar null if name equals freenet ext jar new ext jar f new ext jar new file ext jar get parent freenet ext jar ext jar absolute is absolute ext classpath no prop no continue else if name equals freenet ext jar ext jar f new ext jar new file ext jar get parent freenet ext jar new ext classpath no prop no continue if main jar null try to match it if name starts with freenet name ends with jar main jar f new main jar new file main jar get parent freenet jar new main jar absolute is absolute main classpath no prop no continue else if name starts with freenet name ends with jar new main jar f new main jar new file main jar get parent freenet jar main jar absolute is absolute main classpath no prop no continue if main jar null ext jar null throw new updater parser exception l10n cannot update no jars if main jar null throw new updater parser exception l10n cannot update no main jar ext filename ext jar to string if ext jar null throw new updater parser exception l10n cannot update no ext jar main filename main jar to string updatedeploycontext updaterparserexception wrappermanager getproperties propno propno getproperty propno isabsolute isabsolute getname tolowercase extjar extjar newextjar extjar getparent extjarabsolute isabsolute extclasspathno propno extjar newextjar extjar getparent extclasspathno propno mainjar startswith endswith mainjar newmainjar mainjar getparent mainjarabsolute isabsolute mainclasspathno propno startswith endswith mainjar newmainjar mainjar getparent mainjarabsolute isabsolute mainclasspathno propno mainjar extjar updaterparserexception cannotupdatenojars mainjar updaterparserexception cannotupdatenomainjar extfilename extjar tostring extjar updaterparserexception cannotupdatenoextjar mainfilename mainjar tostring private string l10n string key return l10n get string update deploy context key getstring updatedeploycontext public static string l10n string key string patterns string values return l10n get string update deploy context key patterns values getstring updatedeploycontext public static string l10n string key string pattern string value return l10n get string update deploy context key pattern value getstring updatedeploycontext file get main jar return main jar getmainjar mainjar file get new main jar return new main jar getnewmainjar newmainjar file get ext jar return ext jar getextjar extjar file get new ext jar return new ext jar getnewextjar newextjar void rewrite wrapper conf boolean written new jar boolean written new ext throws io exception update catastrophe exception updater parser exception rewrite wrapper conf don t just write it out from properties we want to keep it as close to what it was as possible file old config new file wrapper conf file new config new file wrapper conf new file input stream fis new file input stream old config buffered input stream bis new buffered input stream fis input stream reader isr new input stream reader bis buffered reader br new buffered reader isr file output stream fos new file output stream new config output stream writer osw new output stream writer fos buffered writer bw new buffered writer osw string line boolean written main false boolean written ext false boolean written reload false string new main main jar absolute new main jar get absolute path new main jar get path string new ext ext jar absolute new ext jar get absolute path new ext jar get path while line br read line null if line starts with wrapper java classpath if written new jar line starts with wrapper java classpath main classpath no bw write wrapper java classpath main classpath no new main n system err println rewritten wrapper conf for main jar written main true else if written new ext line starts with wrapper java classpath ext classpath no bw write wrapper java classpath ext classpath no new ext n system err println rewritten wrapper conf for ext jar written ext true else bw write line n else if line equals ignore case wrapper restart reload configuration true written reload true bw write line n else bw write line n br close if written main written new jar written ext written new ext throw new updater parser exception l10n update failed non standard config new string main ext new string boolean to string written main boolean to string written ext if written reload add it bw write wrapper restart reload configuration true bw close if new config rename to old config if old config delete throw new updater parser exception l10n update failed cannot delete old config old old config to string if new config rename to old config throw new update catastrophe exception old config new config new config installed system err println rewritten wrapper conf for written new jar new main jar new main jar written new ext new ext jar new ext jar rewritewrapperconf writtennewjar writtennewext ioexception updatecatastropheexception updaterparserexception oldconfig newconfig fileinputstream fileinputstream oldconfig bufferedinputstream bufferedinputstream inputstreamreader inputstreamreader bufferedreader bufferedreader fileoutputstream fileoutputstream newconfig outputstreamwriter outputstreamwriter bufferedwriter bufferedwriter writtenmain writtenext writtenreload newmain mainjarabsolute newmainjar getabsolutepath newmainjar getpath newext extjarabsolute newextjar getabsolutepath newextjar getpath readline startswith writtennewjar startswith mainclasspathno mainclasspathno newmain writtenmain writtennewext startswith extclasspathno extclasspathno newext writtenext equalsignorecase reload_configuration writtenreload writtenmain writtennewjar writtenext writtennewext updaterparserexception updatefailednonstandardconfig tostring writtenmain tostring writtenext writtenreload reload_configuration newconfig renameto oldconfig oldconfig updaterparserexception updatefailedcannotdeleteoldconfig oldconfig tostring newconfig renameto oldconfig updatecatastropheexception oldconfig newconfig writtennewjar newmainjar writtennewext newextjar public static address tracker create long last bootid file node dir int port file data new file node dir packets port dat file data bak new file node dir packets port bak data bak delete file input stream fis null try fis new file input stream data buffered input stream bis new buffered input stream fis input stream reader ir new input stream reader bis utf 8 buffered reader br new buffered reader ir simple field set fs new simple field set br false true return new address tracker fs last bootid catch io exception e fall through catch fs parse exception e logger error address tracker class failed to load from disk for port port e e fall through finally if fis null try fis close catch io exception e ignore return new address tracker addresstracker lastbootid nodedir nodedir databak nodedir databak fileinputstream fileinputstream bufferedinputstream bufferedinputstream inputstreamreader inputstreamreader bufferedreader bufferedreader simplefieldset simplefieldset addresstracker lastbootid ioexception fsparseexception addresstracker ioexception addresstracker private address tracker time definitely no packets received system current time millis time definitely no packets sent system current time millis peer trackers new hash map peer peer address tracker item ip trackers new hash map inet address inet address address tracker item addresstracker timedefinitelynopacketsreceived currenttimemillis timedefinitelynopacketssent currenttimemillis peertrackers hashmap peeraddresstrackeritem iptrackers hashmap inetaddress inetaddressaddresstrackeritem private address tracker simple field set fs long last bootid throws fs parse exception int version fs get int version if version 1 throw new fs parse exception unknown version version long saved bootid fs get long bootid if saved bootid last bootid throw new fs parse exception wrong boot id maybe unclean shutdown last was last bootid stored saved bootid sadly we don t know whether there were packets arriving during the gap and some insecure firewalls will use incoming packets to keep tunnels open time definitely no packets received fs get long time definitely no packets received time definitely no packets received system current time millis time definitely no packets sent fs get long time definitely no packets sent peer trackers new hash map peer peer address tracker item simple field set peers fs subset peers if peers null iterator string i peers direct subset name iterator if i null while i has next simple field set peer peers subset i next peer address tracker item item new peer address tracker item peer peer trackers put item peer item ip trackers new hash map inet address inet address address tracker item simple field set ips fs subset i ps if ips null iterator string i ips direct subset name iterator if i null while i has next simple field set peer ips subset i next inet address address tracker item item new inet address address tracker item peer ip trackers put item addr item addresstracker simplefieldset lastbootid fsparseexception getint fsparseexception savedbootid getlong savedbootid lastbootid fsparseexception lastbootid savedbootid timedefinitelynopacketsreceived getlong timedefinitelynopacketsreceived timedefinitelynopacketsreceived currenttimemillis timedefinitelynopacketssent getlong timedefinitelynopacketssent peertrackers hashmap peeraddresstrackeritem simplefieldset directsubsetnameiterator hasnext simplefieldset peeraddresstrackeritem peeraddresstrackeritem peertrackers iptrackers hashmap inetaddress inetaddressaddresstrackeritem simplefieldset ips directsubsetnameiterator hasnext simplefieldset inetaddressaddresstrackeritem inetaddressaddresstrackeritem iptrackers public void sent packet to peer peer packet to peer true sentpacketto packetto public void received packet from peer peer packet to peer false receivedpacketfrom packetto private void packet to peer peer boolean sent peer peer2 peer drop host name if peer2 null logger error this impossible no host name in address tracker packet to for peer return peer peer2 inet address ip peer get address long now system current time millis synchronized this peer address tracker item peer item peer trackers get peer if peer item null peer item new peer address tracker item time definitely no packets received time definitely no packets sent peer if peer trackers size max items peer trackers clear ip trackers clear time definitely no packets received now time definitely no packets sent now peer trackers put peer peer item if sent peer item sent packet now else peer item received packet now inet address address tracker item ip item ip trackers get ip if ip item null ip item new inet address address tracker item time definitely no packets received time definitely no packets sent ip if ip trackers size max items peer trackers clear ip trackers clear time definitely no packets received now time definitely no packets sent now ip trackers put ip ip item if sent ip item sent packet now else ip item received packet now packetto drophostname addresstracker packetto inetaddress getaddress currenttimemillis peeraddresstrackeritem peeritem peertrackers peeritem peeritem peeraddresstrackeritem timedefinitelynopacketsreceived timedefinitelynopacketssent peertrackers max_items peertrackers iptrackers timedefinitelynopacketsreceived timedefinitelynopacketssent peertrackers peeritem peeritem sentpacket peeritem receivedpacket inetaddressaddresstrackeritem ipitem iptrackers ipitem ipitem inetaddressaddresstrackeritem timedefinitelynopacketsreceived timedefinitelynopacketssent iptrackers max_items peertrackers iptrackers timedefinitelynopacketsreceived timedefinitelynopacketssent iptrackers ipitem ipitem sentpacket ipitem receivedpacket public synchronized void start receive long now time definitely no packets received now startreceive timedefinitelynopacketsreceived public synchronized void start send long now time definitely no packets sent now startsend timedefinitelynopacketssent public synchronized peer address tracker item get peer address tracker items peer address tracker item items new peer address tracker item peer trackers size return peer trackers values to array items peeraddresstrackeritem getpeeraddresstrackeritems peeraddresstrackeritem peeraddresstrackeritem peertrackers peertrackers toarray public synchronized inet address address tracker item get inet address tracker items inet address address tracker item items new inet address address tracker item ip trackers size return ip trackers values to array items inetaddressaddresstrackeritem getinetaddresstrackeritems inetaddressaddresstrackeritem inetaddressaddresstrackeritem iptrackers iptrackers toarray public static final long horizon 24 60 60 1000l public long get longest send receive gap return get longest send receive gap horizon getlongestsendreceivegap getlongestsendreceivegap find the longest send known no packets sent receive gap it is highly unlikely that we are behind a nat or symmetric firewall with a timeout less than the returned length public long get longest send receive gap long horizon long longest gap 1 long now system current time millis peer address tracker item items get peer address tracker items for int i 0 i items length i peer address tracker item item items i if item packets received 0 continue if item peer is real internet address false false false continue longest gap math max longest gap item longest gap horizon now return longest gap getlongestsendreceivegap longestgap currenttimemillis peeraddresstrackeritem getpeeraddresstrackeritems peeraddresstrackeritem packetsreceived isrealinternetaddress longestgap longestgap longestgap longestgap public int get port forward status long min gap get longest send receive gap horizon if min gap definitely tunnel length return definitely port forwarded if min gap maybe tunnel length return maybe port forwarded only take is broken into account if we re not sure somebody could be playing with us by sending bogus fnp sent packets synchronized this if is broken return definitely nated if min gap 0 time presume guilty 0 system current time millis time presume guilty return maybe nated return dont know getportforwardstatus mingap getlongestsendreceivegap mingap definitely_tunnel_length definitely_port_forwarded mingap maybe_tunnel_length maybe_port_forwarded isbroken fnpsentpackets isbroken definitely_nated mingap timepresumeguilty currenttimemillis timepresumeguilty maybe_nated dont_know private boolean is broken return system current time millis broken time horizon isbroken currenttimemillis brokentime public static string status string int status switch status case definitely port forwarded return port forwarded case maybe port forwarded return maybe port forwarded case maybe nated return maybe behind nat case definitely nated return behind nat case dont know return status unknown default return error statusstring definitely_port_forwarded maybe_port_forwarded maybe_nated definitely_nated dont_know persist the table to disk public void store data long bootid file node dir int port don t write to disk if we know we re na ted anyway if is broken return file data new file node dir packets port dat file data bak new file node dir packets port bak data delete data bak delete file output stream fos null try fos new file output stream data bak buffered output stream bos new buffered output stream fos output stream writer osw new output stream writer bos utf 8 buffered writer bw new buffered writer osw simple field set fs get fieldset bootid fs write to bw bw flush bw close fos null data bak rename to data catch io exception e logger error this cannot store packet tracker to disk return finally if fos null try fos close catch io exception e ignore storedata nodedir nated isbroken nodedir databak nodedir databak fileoutputstream fileoutputstream databak bufferedoutputstream bufferedoutputstream outputstreamwriter outputstreamwriter bufferedwriter bufferedwriter simplefieldset getfieldset writeto databak renameto ioexception ioexception private synchronized simple field set get fieldset long bootid simple field set sfs new simple field set true sfs put version 1 sfs put bootid bootid sfs put time definitely no packets received time definitely no packets received sfs put time definitely no packets sent time definitely no packets sent peer address tracker item peer items get peer address tracker items simple field set items new simple field set true if peer items length 0 for int i 0 i peer items length i items put integer to string i peer items i to field set sfs put peers items inet address address tracker item inet items get inet address tracker items items new simple field set true if inet items length 0 for int i 0 i inet items length i items put integer to string i inet items i to field set sfs put i ps items return sfs simplefieldset getfieldset simplefieldset simplefieldset timedefinitelynopacketsreceived timedefinitelynopacketsreceived timedefinitelynopacketssent timedefinitelynopacketssent peeraddresstrackeritem peeritems getpeeraddresstrackeritems simplefieldset simplefieldset peeritems peeritems tostring peeritems tofieldset inetaddressaddresstrackeritem inetitems getinetaddresstrackeritems simplefieldset inetitems inetitems tostring inetitems tofieldset ips called when something changes at a higher level suggesting that the status may be wrong public void rescan do nothing for now as we don t maintain any final state yet public synchronized void set broken broken time system current time millis setbroken brokentime currenttimemillis private long time presume guilty 1 public synchronized void set presumed guilty at long l if time presume guilty 0 time presume guilty l timepresumeguilty setpresumedguiltyat timepresumeguilty timepresumeguilty public synchronized void set presumed innocent time presume guilty 1 setpresumedinnocent timepresumeguilty public final class subtract composite extends rgb composite public subtract composite float alpha super alpha subtractcomposite rgbcomposite subtractcomposite public composite context create context color model src color model color model dst color model rendering hints hints return new context extra alpha src color model dst color model compositecontext createcontext colormodel srccolormodel colormodel dstcolormodel renderinghints extraalpha srccolormodel dstcolormodel static class context extends rgb composite context public context float alpha color model src color model color model dst color model super alpha src color model dst color model rgbcompositecontext colormodel srccolormodel colormodel dstcolormodel srccolormodel dstcolormodel override public void composergb int src int dst float alpha int w src length for int i 0 i w i 4 int sr src i int dir dst i int sg src i 1 int dig dst i 1 int sb src i 2 int dib dst i 2 int sa src i 3 int dia dst i 3 int dor dog dob dor dir sr if dor 0 dor 0 dog dig sg if dog 0 dog 0 dob dib sb if dob 0 dob 0 float a alpha sa 255f float ac 1 a dst i int a dor ac dir dst i 1 int a dog ac dig dst i 2 int a dob ac dib dst i 3 int sa alpha dia ac if you want persistent buckets which will be saved every 1000 buckets and deleted on restart if not stored by then then pass in the db job runner otherwise pass in null param bucket factory param block size param runner public bucket chain bucket factory bucket factory bucket factory int block size db job runner runner int segment size this factory bucket factory this block size block size this runner runner this segment size segment size dbjobrunner bucketfactory block_size bucketchainbucketfactory bucketfactory bucketfactory block_size dbjobrunner segmentsize bucketfactory blocksize block_size segmentsize segmentsize public bucket make bucket long size throws io exception if runner null return new bucket chain bucket block size factory else return new segmented bucket chain bucket block size factory runner segment size makebucket ioexception bucketchainbucket blocksize segmentedbucketchainbucket blocksize segmentsize public get config simple field set fs with current fields string to bool fs get with current false with defaults fields string to bool fs get with defaults false with sort order fields string to bool fs get with sort order false with expert flag fields string to bool fs get with expert flag false with force write flag fields string to bool fs get with force write flag false with short description fields string to bool fs get with short description false with long description fields string to bool fs get with long description false with data types fields string to bool fs get with data types false this identifier fs get identifier fs remove value identifier getconfig simplefieldset withcurrent stringtobool withcurrent withdefaults stringtobool withdefaults withsortorder stringtobool withsortorder withexpertflag stringtobool withexpertflag withforcewriteflag stringtobool withforcewriteflag withshortdescription stringtobool withshortdescription withlongdescription stringtobool withlongdescription withdatatypes stringtobool withdatatypes removevalue override public simple field set get field set return new simple field set true simplefieldset getfieldset simplefieldset override public string get name return name getname override public void run fcp connection handler handler node node throws message invalid exception if handler has full access throw new message invalid exception protocol error message access denied get config requires full access identifier false handler output handler queue new config data node with current with defaults with sort order with expert flag with force write flag with short description with long description with data types identifier fcpconnectionhandler messageinvalidexception hasfullaccess messageinvalidexception protocolerrormessage access_denied getconfig outputhandler configdata withcurrent withdefaults withsortorder withexpertflag withforcewriteflag withshortdescription withlongdescription withdatatypes override public void remove from object container container container delete this removefrom objectcontainer logger register log threshold callback new log threshold callback override public void should update logminor logger should log logger minor this registerlogthresholdcallback logthresholdcallback shouldupdate shouldlog final object token running transient insert sendable insert i object t insert i token t runningtransientinsert sendableinsert override public int hash code return insert hash code token hash code hashcode hashcode hashcode override public boolean equals object o if o instanceof running transient insert return false running transient insert r running transient insert o return r insert insert r token token r token equals token runningtransientinsert runningtransientinsert runningtransientinsert fetch a client request scheduler core from the database or create a new one param node param for inserts param forss ks param selector container param executor return public static client request scheduler core create node node final boolean for inserts final boolean forss ks object container selector container long cooldown time prioritized serial executor database executor client request scheduler sched client context context final long nodedb handle node nodedb handle object set client request scheduler core results selector container query new predicate client request scheduler core override public boolean match client request scheduler core core if core nodedb handle nodedb handle return false if core is insert scheduler for inserts return false if core isssk scheduler forss ks return false return true client request scheduler core core if results has next core results next selector container activate core 2 system err println loaded core if core nodedb handle nodedb handle throw new illegal state exception wrong nodedb handle if core is insert scheduler for inserts throw new illegal state exception wrong is insert scheduler if core isssk scheduler forss ks throw new illegal state exception wrong forss ks else core new client request scheduler core node for inserts forss ks selector container cooldown time selector container store core system err println created new core core on started selector container cooldown time sched context return core clientrequestschedulercore forinserts forssks selectorcontainer clientrequestschedulercore forinserts forssks objectcontainer selectorcontainer cooldowntime prioritizedserialexecutor databaseexecutor clientrequestscheduler clientcontext nodedbhandle nodedbhandle objectset clientrequestschedulercore selectorcontainer clientrequestschedulercore clientrequestschedulercore nodedbhandle nodedbhandle isinsertscheduler forinserts issskscheduler forssks clientrequestschedulercore hasnext selectorcontainer nodedbhandle nodedbhandle illegalstateexception nodedbhandle isinsertscheduler forinserts illegalstateexception isinsertscheduler issskscheduler forssks illegalstateexception forssks clientrequestschedulercore forinserts forssks selectorcontainer cooldowntime selectorcontainer onstarted selectorcontainer cooldowntime client request scheduler core node node boolean for inserts boolean forss ks object container selector container long cooldown time super for inserts forss ks this nodedb handle node nodedb handle if for inserts this persistent cooldown queue new persistent cooldown queue else this persistent cooldown queue null global salt new byte 32 node random next bytes global salt clientrequestschedulercore forinserts forssks objectcontainer selectorcontainer cooldowntime forinserts forssks nodedbhandle nodedbhandle forinserts persistentcooldownqueue persistentcooldownqueue persistentcooldownqueue globalsalt nextbytes globalsalt private void on started object container container long cooldown time client request scheduler sched client context context super on started system err println insert scheduler is insert scheduler if is insert scheduler persistent cooldown queue set cooldown time cooldown time this sched sched this init time system current time millis we do not want to rerun the query after consuming the initial set if is insert scheduler keys fetching new hash set key running transient inserts null this recent successes new array list random grab array else keys fetching null running transient inserts new hash set running transient insert if is insert scheduler pre register me runner new db job public void run object container container client context context synchronized client request scheduler core this if register me set null return long t start system current time millis fixme redflag evil db4o bug fixme verify and file a bug this code doesn t check the first bit i think this is related to the comparator register me set container query new predicate public boolean match register me reg if reg core client request scheduler core this return false if reg key added time init time return false return true new comparator public int compare object arg0 object arg1 register me reg0 register me arg0 register me reg1 register me arg1 register me sort key key0 reg0 key register me sort key key1 reg1 key return key0 compare to key1 object set results null for int i request starter maximum priority class i request starter minimum priority class i query query container query query constrain register me class query descend core constrain client request scheduler core this and query descend priority constrain i results query execute if results has next break else results null if results null return this throws not supported query descend core constrain this identity and query descend key descend added time constrain new long init time smaller fixme db4o db4o says it has indexed core but then when we try to query it produces a diagnostic suggesting we index it and of course the query takes ages and uses tons of ram so don t try to filter by core at this point deal with that later query descend core constrain client request scheduler core this evaluation eval new evaluation public void evaluate candidate candidate register me reg register me candidate get object if reg key added time init time reg core client request scheduler core this candidate include false candidate object container deactivate reg key 1 candidate object container deactivate reg 1 else candidate include true query constrain eval query descend key descend priority order ascending query descend key descend added time order ascending synchronized client request scheduler core this register me set results long t end system current time millis if logminor logger minor this register me query took t end t start has next register me set has next for insert is insert scheduler ssk isssk scheduler if logminor logger minor this register me query returned register me set size boolean boost client request scheduler core this sched is queue almost empty context job runner queue register me runner native thread norm priority 1 boost 1 0 true register me runner new register me runner onstarted objectcontainer cooldowntime clientrequestscheduler clientcontext onstarted isinsertscheduler isinsertscheduler persistentcooldownqueue setcooldowntime cooldowntime inittime currenttimemillis isinsertscheduler keysfetching hashset runningtransientinserts recentsuccesses arraylist randomgrabarray keysfetching runningtransientinserts hashset runningtransientinsert isinsertscheduler preregistermerunner dbjob objectcontainer clientcontext clientrequestschedulercore registermeset tstart currenttimemillis registermeset registerme clientrequestschedulercore addedtime inittime registerme registerme registerme registerme registermesortkey registermesortkey compareto objectset requeststarter maximum_priority_class requeststarter minimum_priority_class registerme clientrequestschedulercore hasnext notsupported addedtime inittime clientrequestschedulercore registerme registerme getobject addedtime inittime clientrequestschedulercore objectcontainer objectcontainer orderascending addedtime orderascending clientrequestschedulercore registermeset tend currenttimemillis registerme tend tstart hasnext registermeset hasnext isinsertscheduler issskscheduler registerme registermeset clientrequestschedulercore isqueuealmostempty jobrunner registermerunner nativethread norm_priority registermerunner registermerunner private transient db job pre register me runner void start db job runner runner start register me runner runner dbjob preregistermerunner dbjobrunner startregistermerunner private final void start register me runner db job runner runner if is insert scheduler runner queue pre register me runner native thread norm priority true startregistermerunner dbjobrunner isinsertscheduler preregistermerunner nativethread norm_priority private int remove first according to priorities boolean try offered keys int fuzz random source random offered keys list offered keys client request scheduler non persistent sched transient boolean transient only short max prio object container container sorted vector by number result null short iteration 0 priority we loop to ensure we try every possibilities n 1 prio will do 0 1 2 3 4 5 6 0 tweaked will do rand 6 0 1 2 3 4 5 6 while iteration request starter number of priority classes 1 priority fuzz 0 tweaked priority selector random next int tweaked priority selector length priority selector math abs fuzz priority selector length if transient only result null else result priorities priority if result null result sched transient priorities priority if priority max prio fuzz continue don t return because first round may be higher with soft scheduling if result null result is empty try offered keys offered keys priority is empty container if logminor logger minor this using priority priority return priority if logminor logger minor this priority priority is null fuzz fuzz fuzz fixme implement none return 1 removefirstaccordingtopriorities tryofferedkeys randomsource offeredkeyslist offeredkeys clientrequestschedulernonpersistent schedtransient transientonly maxprio objectcontainer sortedvectorbynumber requeststarter number_of_priority_classes tweakedpriorityselector nextint tweakedpriorityselector priorityselector priorityselector transientonly schedtransient maxprio isempty tryofferedkeys offeredkeys isempty the worry is is there any nested locking outside of the hierarchy chosen block remove first transient int fuzz random source random offered keys list offered keys request starter starter client request scheduler non persistent sched transient short max prio int retry count client context context object container container sendable request req remove first inner fuzz random offered keys starter sched transient true false max prio retry count context container if is insert scheduler req instanceof sendable get illegal state exception e new illegal state exception remove first inner returned a sendable get on an insert scheduler req internal error e sched container context req persistent throw e return maybe make chosen request req container context chosenblock removefirsttransient randomsource offeredkeyslist offeredkeys requeststarter clientrequestschedulernonpersistent schedtransient maxprio retrycount clientcontext objectcontainer sendablerequest removefirstinner offeredkeys schedtransient maxprio retrycount isinsertscheduler sendableget illegalstateexception illegalstateexception removefirstinner sendableget internalerror maybemakechosenrequest public chosen block maybe make chosen request sendable request req object container container client context context if req null return null if req is empty container req is cancelled container return null sendable request item token req choose key this req persistent container null context if token null return null else key key client key ckey if is insert scheduler key null ckey null else key base sendable get req get node key token persistent container null if req instanceof sendable get ckey sendable get req get key token persistent container null else ckey null chosen block ret assert req persistent if key null key get routing key null throw new null pointer exception boolean local request only boolean cache local requests boolean ignore store if req instanceof sendable get sendable get sg sendable get req fetch context ctx sg get context local request only ctx local request only cache local requests ctx cache local requests ignore store ctx ignore store else local request only false if req instanceof sendable insert cache local requests sendable insert req cache inserts null else cache local requests false ignore store false ret new transient chosen block req token key ckey local request only cache local requests ignore store sched return ret chosenblock maybemakechosenrequest sendablerequest objectcontainer clientcontext isempty iscancelled sendablerequestitem choosekey clientkey isinsertscheduler basesendableget getnodekey sendableget sendableget getkey chosenblock getroutingkey nullpointerexception localrequestonly cachelocalrequests ignorestore sendableget sendableget sendableget fetchcontext getcontext localrequestonly localrequestonly cachelocalrequests cachelocalrequests ignorestore ignorestore localrequestonly sendableinsert cachelocalrequests sendableinsert cacheinserts cachelocalrequests ignorestore transientchosenblock localrequestonly cachelocalrequests ignorestore sendable request remove first inner int fuzz random source random offered keys list offered keys request starter starter client request scheduler non persistent sched transient boolean transient only boolean not transient short max prio int retry count client context context object container container priorities start at 0 if logminor logger minor this remove first boolean try offered keys offered keys null not transient random next boolean int choosen priority class remove first according to priorities try offered keys fuzz random offered keys sched transient transient only max prio container if choosen priority class 1 offered keys null try offered keys not transient try offered keys true choosen priority class remove first according to priorities try offered keys fuzz random offered keys sched transient transient only max prio container if choosen priority class 1 if logminor logger minor this nothing to do return null if max prio request starter minimum priority class max prio request starter minimum priority class for choosen priority class max prio choosen priority class if logminor logger minor this using priority choosen priority class if try offered keys if offered keys choosen priority class has valid keys this null context return offered keys choosen priority class sorted vector by number perm null if transient only perm priorities choosen priority class sorted vector by number trans null if not transient trans sched transient priorities choosen priority class if perm null trans null if logminor logger minor this no requests to run chosen priority empty continue try next priority int perm retry index 0 int trans retry index 0 while true int perm retry count perm null integer max value perm get number by index perm retry index int trans retry count trans null integer max value trans get number by index trans retry index if choosen priority class max prio if perm retry count retry count perm retry count integer max value if trans retry count retry count trans retry count integer max value if perm retry count integer max value trans retry count integer max value if logminor logger minor this no requests to run ran out of retrycounts on chosen priority break try next priority sectored random grab array with int chosen tracker null sorted vector by number tracker parent null if perm retry count trans retry count choose between them sectored random grab array with int perm retry tracker sectored random grab array with int perm get by index perm retry index if persistent perm retry tracker null container activate perm retry tracker 1 sectored random grab array with int trans retry tracker sectored random grab array with int trans get by index trans retry index int perm tracker size perm retry tracker size int trans tracker size trans retry tracker size if perm tracker size trans tracker size 0 perm retry index trans retry index continue if random next int perm tracker size trans tracker size perm tracker size chosen tracker perm retry tracker tracker parent perm perm retry index else chosen tracker trans retry tracker tracker parent trans trans retry index else if perm retry count trans retry count chosen tracker sectored random grab array with int perm get by index perm retry index if persistent chosen tracker null container activate chosen tracker 1 tracker parent perm perm retry index else chosen tracker sectored random grab array with int trans get by index trans retry index tracker parent trans trans retry index if logminor logger minor this got retry count tracker chosen tracker sendable request req sendable request chosen tracker remove random starter container context if chosen tracker is empty tracker parent remove chosen tracker get number container if chosen tracker persistent chosen tracker remove from container if tracker parent is empty if logminor logger minor this should remove priority if req null if logminor logger minor this no requests adjusted retrycount chosen tracker get number chosen tracker of priority choosen priority class continue try next retry count if chosen tracker persistent container activate req 1 fixme if req persistent tracker parent persistent logger error this request persistent req persistent but is in the queue for persistent tracker parent persistent for req fixme fix it if req get priority class container choosen priority class reinsert it shouldn t happen if we are calling reregister all maybe we should ask people to report that error if seen logger normal this in wrong priority class req req prio req get priority class container but chosen choosen priority class remove it sectored random grab array with object client grabber sectored random grab array with object chosen tracker get grabber req get client container if client grabber null if chosen tracker persistent container activate client grabber 1 random grab array baserga random grab array client grabber get grabber req get client request if baserga null baserga remove req container else okay it s been removed already cool else logger error this could not find client grabber for client req get client container from chosen tracker if req persistent inner register req random container null else sched transient inner register req random container null continue try the next one on this retry count check recent successes choose a recently succeeded request 50 chance of using a recently succeeded request if there is one for transient requests we keep a list of recently succeeded base sendable get s because transient requests are chosen individually but for persistent requests we keep a list of random grab array s because persistent requests are chosen a whole sendable request at a time fixme only replaces persistent requests with persistent requests of similar priority and retry count or transient with transient probably this is acceptable if req persistent is insert scheduler list base sendable get recent sched transient recent successes base sendable get alt req null if recent is empty if random next boolean alt req recent remove recent size 1 if alt req null alt req is cancelled container alt req is empty container if logminor logger minor this ignoring cancelled recently succeeded item alt req alt req null if alt req null alt req req int prio alt req get priority class container if prio choosen priority class prio choosen priority class fix retry count alt req get retry count chosen tracker get number use the recent one instead if logminor logger minor this recently succeeded transient req alt req prio alt req get priority class container retry count alt req get retry count is better than req prio req get priority class container retry req get retry count using that don t need to reregister because remove random doesn t actually remove req alt req else don t use the recent one if logminor logger minor this chosen req req is better reregistering recently succeeded alt req recent add alt req else if is insert scheduler random grab array altrga null synchronized recent successes if recent successes is empty random next boolean altrga recent successes remove recent successes size 1 if altrga null container activate altrga 1 if container ext is stored altrga altrga is empty if logminor logger minor this maybe using recently succeeded item from altrga sendable request alt req sendable request altrga remove random starter container context if alt req null container activate alt req 1 int prio alt req get priority class container if prio choosen priority class prio choosen priority class fix retry count alt req get retry count chosen tracker get number alt req is empty container alt req req use the recent one instead if logminor logger minor this recently succeeded persistent req alt req prio alt req get priority class container retry count alt req get retry count is better than req prio req get priority class container retry req get retry count using that don t need to reregister because remove random doesn t actually remove req alt req else if alt req null if logminor logger minor this chosen persistent req req is better reregistering recently succeeded altrga for alt req synchronized recent successes recent successes add altrga else container deactivate altrga 1 sendablerequest removefirstinner randomsource offeredkeyslist offeredkeys requeststarter clientrequestschedulernonpersistent schedtransient transientonly nottransient maxprio retrycount clientcontext objectcontainer removefirst tryofferedkeys offeredkeys nottransient nextboolean choosenpriorityclass removefirstaccordingtopriorities tryofferedkeys offeredkeys schedtransient transientonly maxprio choosenpriorityclass offeredkeys tryofferedkeys nottransient tryofferedkeys choosenpriorityclass removefirstaccordingtopriorities tryofferedkeys offeredkeys schedtransient transientonly maxprio choosenpriorityclass maxprio requeststarter minimum_priority_class maxprio requeststarter minimum_priority_class choosenpriorityclass maxprio choosenpriorityclass choosenpriorityclass tryofferedkeys offeredkeys choosenpriorityclass hasvalidkeys offeredkeys choosenpriorityclass sortedvectorbynumber transientonly choosenpriorityclass sortedvectorbynumber nottransient schedtransient choosenpriorityclass permretryindex transretryindex permretrycount max_value getnumberbyindex permretryindex transretrycount max_value getnumberbyindex transretryindex choosenpriorityclass maxprio permretrycount retrycount permretrycount max_value transretrycount retrycount transretrycount max_value permretrycount max_value transretrycount max_value sectoredrandomgrabarraywithint chosentracker sortedvectorbynumber trackerparent permretrycount transretrycount sectoredrandomgrabarraywithint permretrytracker sectoredrandomgrabarraywithint getbyindex permretryindex permretrytracker permretrytracker sectoredrandomgrabarraywithint transretrytracker sectoredrandomgrabarraywithint getbyindex transretryindex permtrackersize permretrytracker transtrackersize transretrytracker permtrackersize transtrackersize permretryindex transretryindex nextint permtrackersize transtrackersize permtrackersize chosentracker permretrytracker trackerparent permretryindex chosentracker transretrytracker trackerparent transretryindex permretrycount transretrycount chosentracker sectoredrandomgrabarraywithint getbyindex permretryindex chosentracker chosentracker trackerparent permretryindex chosentracker sectoredrandomgrabarraywithint getbyindex transretryindex trackerparent transretryindex chosentracker sendablerequest sendablerequest chosentracker removerandom chosentracker isempty trackerparent chosentracker getnumber chosentracker chosentracker removefrom trackerparent isempty chosentracker getnumber chosentracker choosenpriorityclass chosentracker trackerparent trackerparent getpriorityclass choosenpriorityclass reregisterall getpriorityclass choosenpriorityclass sectoredrandomgrabarraywithobject clientgrabber sectoredrandomgrabarraywithobject chosentracker getgrabber getclient clientgrabber chosentracker clientgrabber randomgrabarray randomgrabarray clientgrabber getgrabber getclientrequest getclient chosentracker innerregister schedtransient innerregister recentsuccesses basesendableget randomgrabarray sendablerequest isinsertscheduler basesendableget schedtransient recentsuccesses basesendableget altreq isempty nextboolean altreq altreq altreq iscancelled altreq isempty altreq altreq altreq altreq altreq getpriorityclass choosenpriorityclass choosenpriorityclass fixretrycount altreq getretrycount chosentracker getnumber altreq altreq getpriorityclass altreq getretrycount getpriorityclass getretrycount removerandom altreq altreq altreq isinsertscheduler randomgrabarray recentsuccesses recentsuccesses isempty nextboolean recentsuccesses recentsuccesses isstored isempty sendablerequest altreq sendablerequest removerandom altreq altreq altreq getpriorityclass choosenpriorityclass choosenpriorityclass fixretrycount altreq getretrycount chosentracker getnumber altreq isempty altreq altreq altreq getpriorityclass altreq getretrycount getpriorityclass getretrycount removerandom altreq altreq altreq recentsuccesses recentsuccesses override boolean persistent return true public void run object container container client context context if sched database executor get queue size native thread norm priority 100 if the queue isn t empty reschedule at norm 1 wait for the backlog to clear if sched is queue almost empty context job runner queue register me runner native thread norm priority 1 false return long deadline system current time millis 10 1000 if register me set null logger error this register me set is null for client request scheduler core this this return for int i 0 i 1000 i try if register me set has next break catch null pointer exception t logger error this db4o thew npe in has next t t fixme find some way to get a reproducible test case i suspect it won t be easy context job runner queue pre register me runner native thread norm priority true return catch class cast exception t wtf logger error this db4o thew class cast exception in has next t t fixme find some way to get a reproducible test case i suspect it won t be easy context job runner queue pre register me runner native thread norm priority true return long start next system current time millis register me reg register me register me set next container activate reg 1 if reg bootid context bootid if logminor logger minor this not registering block reg as was added to the queue continue fixme remove the leftover old core handling at some point an npe is acceptable long term if reg core client request scheduler core this if container ext is stored reg if logminor logger minor this already deleted register me reg skipping continue if reg core null logger error this leftover register me reg core already deleted this is an error unless you have seen old core not active messages before this point container delete reg continue if container ext is active reg core logger error this old core not active in register me reg duplicated cores container delete reg core container delete reg continue if logminor logger minor this ignoring register me reg as doesn t belong to me my insert is insert scheduler my ssk isssk scheduler his insert reg core is insert scheduler his ssk reg core isssk scheduler container deactivate reg 1 continue don t delete if reg key added time init time if logminor logger minor this ignoring register me as created since startup container deactivate reg key 1 container deactivate reg 1 continue don t delete if logminor logger minor this running register me reg for reg non get request reg added time reg priority don t need to activate fields should exist fixme if reg non get request null container activate reg non get request 1 if reg non get request is cancelled container logger normal this register me request cancelled reg non get request else if logminor logger minor this registering register me for insert reg non get request sched register insert reg non get request true false container container delete reg container deactivate reg non get request 1 container deactivate reg 1 if system current time millis deadline break boolean boost sched is queue almost empty if register me set has next context job runner queue register me runner native thread norm priority 1 boost 1 0 true else if logminor logger minor this register me runner finished synchronized client request scheduler core this register me set null always re run the query if there is nothing to register it won t call back to us pre register me runner run container context objectcontainer clientcontext databaseexecutor getqueuesize nativethread norm_priority isqueuealmostempty jobrunner registermerunner nativethread norm_priority currenttimemillis registermeset registermeset clientrequestschedulercore registermeset hasnext nullpointerexception hasnext jobrunner preregistermerunner nativethread norm_priority classcastexception classcastexception hasnext jobrunner preregistermerunner nativethread norm_priority startnext currenttimemillis registerme registerme registermeset clientrequestschedulercore isstored registerme registerme isactive registerme registerme isinsertscheduler issskscheduler isinsertscheduler issskscheduler addedtime inittime registerme registerme nongetrequest addedtime nongetrequest nongetrequest nongetrequest iscancelled registerme nongetrequest registerme nongetrequest registerinsert nongetrequest nongetrequest currenttimemillis isqueuealmostempty registermeset hasnext jobrunner registermerunner nativethread norm_priority registermerunner clientrequestschedulercore registermeset preregistermerunner return true unless the key was already present public boolean add to fetching key key synchronized keys fetching boolean retval keys fetching add key if retval logger normal this already in keys fetching key else if logminor logger minor this added to keys fetching key return retval addtofetching keysfetching keysfetching keysfetching keysfetching public boolean has key key key if keys fetching null throw new null pointer exception synchronized keys fetching return keys fetching contains key haskey keysfetching nullpointerexception keysfetching keysfetching public void remove fetching key final key key if logminor logger minor this removing from keys fetching key if key null synchronized keys fetching keys fetching remove key removefetchingkey keysfetching keysfetching keysfetching public void rerun register me runner db job runner runner synchronized this if register me set null return start register me runner runner rerunregistermerunner dbjobrunner registermeset startregistermerunner override public synchronized long count queued requests object container container client context context long ret super count queued requests container context long cooldown persistent cooldown queue size container system out println cooldown queue size cooldown return ret cooldown countqueuedrequests objectcontainer clientcontext countqueuedrequests persistentcooldownqueue public boolean has transient insert sendable insert insert object token running transient insert tmp new running transient insert insert token synchronized running transient inserts return running transient inserts contains tmp hastransientinsert sendableinsert runningtransientinsert runningtransientinsert runningtransientinserts runningtransientinserts public boolean add transient insert fetching sendable insert insert object token running transient insert tmp new running transient insert insert token synchronized running transient inserts boolean retval running transient inserts add tmp if retval logger normal this already in running transient inserts insert token else if logminor logger minor this added to running transient inserts insert token return retval addtransientinsertfetching sendableinsert runningtransientinsert runningtransientinsert runningtransientinserts runningtransientinserts runningtransientinserts runningtransientinserts public void remove transient insert fetching sendable insert insert object token running transient insert tmp new running transient insert insert token if logminor logger minor this removing from running transient inserts insert token synchronized running transient inserts running transient inserts remove tmp removetransientinsertfetching sendableinsert runningtransientinsert runningtransientinsert runningtransientinserts runningtransientinserts runningtransientinserts override public void succeeded base sendable get succeeded object container container random grab array array succeeded get parent grab array container activate array 1 if array null return unregistered already synchronized recent successes if recent successes contains array return recent successes add array while recent successes size 8 recent successes remove 0 basesendableget objectcontainer randomgrabarray getparentgrabarray recentsuccesses recentsuccesses recentsuccesses recentsuccesses recentsuccesses public abstract class persistent comparator t extends i persistent extends persistent compare two members of collection param m1 first members param m2 second members return negative number if m1 lt m2 zero if m1 m2 and positive number if m1 gt m2 persistentcomparator ipersistent compare member with specified search key param mbr collection member param key search key return negative number if mbr lt key zero if mbr key and positive number if mbr gt key public class closer closes the given stream param output stream the output stream to close public static void close closeable closable if closable null try closable close catch io exception e outputstream ioexception closes the given zip file param zip file the zip file to close public static void close zip file zip file if zip file null try zip file close catch io exception e zipfile zipfile zipfile zipfile zipfile ioexception throws message invalid exception public testdda request message simple field set fs throws message invalid exception identifier fs get directory if identifier null throw new message invalid exception protocol error message missing field no directory given null false if identifier length 0 throw new message invalid exception protocol error message missing field the specified directory can t be empty null false want read fs get boolean want read false want write fs get boolean want write false if want read false want write false throw new message invalid exception protocol error message invalid message both want read and want write are set to false what s the point of sending a message identifier false messageinvalidexception testddarequestmessage simplefieldset messageinvalidexception messageinvalidexception protocolerrormessage missing_field messageinvalidexception protocolerrormessage missing_field wantread getboolean want_read wantwrite getboolean want_write wantread wantwrite messageinvalidexception protocolerrormessage invalid_message want_read want_write override public simple field set get field set return null simplefieldset getfieldset override public string get name return name getname override public void run fcp connection handler handler node node throws message invalid exception dda check job job try job handler enqueuedda check identifier want read want write catch illegal argument exception e throw new message invalid exception protocol error message invalid field e get message identifier false testdda reply message reply new testdda reply message job handler output handler queue reply fcpconnectionhandler messageinvalidexception ddacheckjob enqueueddacheck wantread wantwrite illegalargumentexception messageinvalidexception protocolerrormessage invalid_field getmessage testddareplymessage testddareplymessage outputhandler override public void remove from object container container throw new unsupported operation exception removefrom objectcontainer unsupportedoperationexception override public void should update logminor logger should log logger minor this logdebug logger should log logger debug this shouldupdate shouldlog shouldlog private final string target in archive private container element bucket data2 string target in archive2 data data2 target in archive target in archive2 targetinarchive containerelement targetinarchive2 targetinarchive targetinarchive2 param metadata2 param archive type2 param targeturi2 param token2 param getchk only2 param early encode2 param ctx2 param report metadata only2 public container inserter base client putter parent2 put completion callback cb2 hash map string object metadata2 freeneturi targeturi2 insert context ctx2 boolean dont compress2 boolean getchk only2 boolean report metadata only2 object token2 archive type archive type2 boolean free data boolean early encode2 parent parent2 cb cb2 hash code super hash code persistent parent persistent orig metadata metadata2 archive type archive type2 targeturi targeturi2 token token2 getchk only getchk only2 early encode early encode2 ctx ctx2 dont compress dont compress2 report metadata only report metadata only2 container items new array list container element archivetype2 getchkonly2 earlyencode2 reportmetadataonly2 containerinserter baseclientputter putcompletioncallback hashmap insertcontext dontcompress2 getchkonly2 reportmetadataonly2 archive_type archivetype2 freedata earlyencode2 hashcode hashcode origmetadata archivetype archivetype2 getchkonly getchkonly2 earlyencode earlyencode2 dontcompress dontcompress2 reportmetadataonly reportmetadataonly2 containeritems arraylist containerelement public void cancel object container container client context context synchronized this if cancelled return cancelled true if persistent container store this if persistent container activate cb 1 must call on failure so get remove from ed cb on failure new insert exception insert exception cancelled this container context objectcontainer clientcontext onfailure removefrom onfailure insertexception insertexception public base client putter get parent return parent baseclientputter getparent public object get token return token gettoken public void remove from object container container client context context todo removefrom objectcontainer clientcontext public void schedule object container container client context context throws insert exception start container context objectcontainer clientcontext insertexception private void start object container container client context context if logdebug logger debug this atempt to start a container inserter new exception debug make metadata context container synchronized this if finished return insert block block try bucket output bucket context get bucket factory persistent make bucket 1 string mime type archive type archive type tar create tar bucket output bucket container create zip bucket output bucket container if logminor logger minor this we are using archive type now we have to insert the archive we have generated can we just insert it and not bother with a redirect to it thereby exploiting implicit manifest support which will pick up on metadata we ought to be able to block new insert block output bucket new client metadata mime type persistent targeturi clone targeturi catch io exception e fail new insert exception insert exception bucket error e null container context return boolean dc dont compress if dont compress dc archive type archive type zip single file inserter sfi new single file inserter parent cb block false ctx dc getchk only report metadata only token archive type true null early encode if logminor logger minor this inserting container sfi for this cb on transition this sfi container try sfi schedule container context catch insert exception e fail new insert exception insert exception bucket error e null container context return cb on block set finished this container context objectcontainer clientcontext makemetadata insertblock outputbucket getbucketfactory makebucket mimetype archivetype archive_type createtarbucket outputbucket createzipbucket outputbucket archivetype insertblock outputbucket clientmetadata mimetype ioexception insertexception insertexception bucket_error dontcompress dontcompress archivetype archive_type singlefileinserter singlefileinserter getchkonly reportmetadataonly archivetype earlyencode ontransition insertexception insertexception insertexception bucket_error onblocksetfinished private void make metadata client context context object container container bucket bucket null int x 0 hash map string object manifest new hash map string object make manifest orig metadata manifest metadata md metadata mk redirection manifest with metadata manifest while true try bucket context temp bucket factory make bucket 1 byte buf md write to byte array output stream os bucket get output stream os write buf os close container items add new container element bucket metadata return catch io exception e fail new insert exception insert exception internal error e null container context return catch metadata unresolved exception e try x resolve e x bucket null null container context catch io exception e1 fail new insert exception insert exception internal error e null container context return makemetadata clientcontext objectcontainer hashmap hashmap makemanifest origmetadata mkredirectionmanifestwithmetadata tempbucketfactory makebucket writetobytearray outputstream getoutputstream containeritems containerelement ioexception insertexception insertexception internal_error metadataunresolvedexception ioexception insertexception insertexception internal_error private int resolve metadata unresolved exception e int x bucket bucket freeneturi key string element2 object container container client context context throws io exception metadata m e must resolve for int i 0 i m length i try byte buf m i write to byte array output stream os bucket get output stream os write buf os close string name in archive metadata x container items add new container element bucket name in archive m i resolve name in archive catch metadata unresolved exception e1 x resolve e x bucket key element2 container context return x metadataunresolvedexception objectcontainer clientcontext ioexception mustresolve writetobytearray outputstream getoutputstream nameinarchive containeritems containerelement nameinarchive nameinarchive metadataunresolvedexception private void fail insert exception e object container container client context context cancel all then call the callback synchronized this if finished return finished true if persistent container activate cb 1 cb on failure e this container context insertexception objectcontainer clientcontext onfailure private final int hash code override public int hash code return hash code hashcode hashcode hashcode public boolean object can update suppress warnings unused object container container if logminor logger minor this object can update on this new exception debug return true objectcanupdate suppresswarnings objectcontainer objectcanupdate public boolean object can new suppress warnings unused object container container if logminor logger minor this object can new on this new exception debug return true objectcannew suppresswarnings objectcontainer objectcannew private string create tar bucket bucket output bucket suppress warnings unused object container container throws io exception if logminor logger minor this create a tar bucket output stream os new buffered output stream output bucket get output stream tar output stream taros new tar output stream os taros set long file mode tar output stream longfile gnu tar entry ze for container element ph container items if logminor logger minor this putting into tar ph data length ph data size name ph target in archive ze new tar entry ph target in archive ze set mod time 0 long size ph data size ze set size size taros put next entry ze bucket tools copy to ph data taros size taros close entry taros close entry both finish and close are necessary taros finish taros flush taros close if logminor logger minor this archive size is output bucket size return archive type tar mime types 0 createtarbucket outputbucket suppresswarnings objectcontainer ioexception outputstream bufferedoutputstream outputbucket getoutputstream taroutputstream taroutputstream setlongfilemode taroutputstream longfile_gnu tarentry containerelement containeritems targetinarchive tarentry targetinarchive setmodtime setsize putnextentry buckettools copyto closeentry closeentry outputbucket archive_type mimetypes private string create zip bucket bucket output bucket suppress warnings unused object container container throws io exception if logminor logger minor this create a zip bucket output stream os new buffered output stream output bucket get output stream zip output stream zos new zip output stream os zip entry ze for container element ph container items ze new zip entry ph target in archive ze set time 0 zos put next entry ze bucket tools copy to ph data zos ph data size zos close entry zos close entry both finish and close are necessary zos finish zos flush zos close return archive type zip mime types 0 createzipbucket outputbucket suppresswarnings objectcontainer ioexception outputstream bufferedoutputstream outputbucket getoutputstream zipoutputstream zipoutputstream zipentry containerelement containeritems zipentry targetinarchive settime putnextentry buckettools copyto closeentry closeentry archive_type mimetypes private void make manifest hash map string object manifest elements hash map string object manifest string archive prefix for map entry string object me manifest elements entry set string name me get key object o me get value if o instanceof hash map suppress warnings unchecked hash map string object hm hash map string object o hash map string object sub map new hash map string object system out println decompose name sub dir manifest put name sub map make manifest hm sub map archive prefix name if logger should log logger debug this logger debug this sub map for name sub map size elements from hm size else if o instanceof metadata already metadata take as is system out println decompose name metadata manifest put name o else manifest element element manifest element o string mime type element mime override client metadata cm if mime type null mime type equals defaultmime types default mime type cm null else cm new client metadata mime type metadata m if element targeturi null system out println decompose name manifest element redirect m new metadata metadata simple redirect null null element targeturi cm else system out println decompose name manifest element data container items add new container element element data archive prefix name m new metadata metadata archive internal redirect null null archive prefix element full name cm manifest put name m makemanifest hashmap manifestelements hashmap archiveprefix manifestelements entryset getkey getvalue hashmap suppresswarnings hashmap hashmap hashmap submap hashmap subdir submap makemanifest submap archiveprefix shouldlog submap manifestelement manifestelement mimetype mimeoverride clientmetadata mimetype mimetype defaultmimetypes default_mime_type clientmetadata mimetype manifestelement simple_redirect manifestelement containeritems containerelement archiveprefix archive_internal_redirect archiveprefix fullname logger register log threshold callback new log threshold callback override public void should update logminor logger should log logger minor this logdebug logger should log logger debug this registerlogthresholdcallback logthresholdcallback shouldupdate shouldlog shouldlog node stats node node int sort order sub config stats config int obw limit int ibw limit file node dir throws node init exception this node node this peers node peers this hard random node random this routing miss distance new time decaying running average 0 0 180000 0 0 1 0 node this backed off percent new time decaying running average 0 0 180000 0 0 1 0 node preemptive reject reasons new string counter local preemptive reject reasons new string counter p instant reject incoming new time decaying running average 0 60000 0 0 1 0 node thread group tg thread current thread get thread group while tg get parent null tg tg get parent this root thread group tg this active threads by priorities new int native thread java priority range this waiting threads by priorities new int native thread java priority range throttled packet send average new time decaying running average 1 10 60 1000 should be significantly longer than a typical transfer 0 long max value node node pinger new node pinger node previous input stat 0 previous output stat 0 previous io stat time 1 last input stat 0 last output stat 0 last io stat time 3 stats config register thread limit 500 sort order true true node stat thread limit node stat thread limit long new int callback override public integer get return thread limit override public void set integer val throws invalid config value exception if get equals val return if val 100 throw new invalid config value exception l10n value too low thread limit val false thread limit stats config get int thread limit yes it could be in seconds insteed of multiples of 0 12 but we don t want people to play with it stats config register aggressivegc aggressivegc modificator sort order true false node stat aggressivegc node stat aggressivegc long new int callback override public integer get return aggressivegc modificator override public void set integer val throws invalid config value exception if get equals val return logger normal this changing aggressivegc modificator to val aggressivegc modificator val false aggressivegc modificator stats config get int aggressivegc my memory checker new memory checker node ps aggressivegc modificator stats config register memory checker true sort order true false node stat mem check node stat mem check long new boolean callback override public boolean get return my memory checker is running override public void set boolean val throws invalid config value exception if get equals val return if val my memory checker start else my memory checker terminate if stats config get boolean memory checker my memory checker start stats config register ignore local vs remote bandwidth liability false sort order true false node stat ignore local vs remote bandwidth liability node stat ignore local vs remote bandwidth liability long new boolean callback override public boolean get synchronized node stats this return ignore local vs remote bandwidth liability override public void set boolean val throws invalid config value exception synchronized node stats this ignore local vs remote bandwidth liability val this is a network level setting because it affects the rate at which we initiate local requests which could be seen by distant nodes node security levels add network threat level listener new security level listener network threat level public void on change network threat level old level network threat level new level if new level network threat level maximum ignore local vs remote bandwidth liability true if old level network threat level maximum ignore local vs remote bandwidth liability false otherwise leave it as it was it defaults to false persister new configurable persister this stats config node throttle file node throttle dat sort order true false node stat stats persister node stat stats persister long node ps node dir simple field set throttlefs persister read if logminor logger minor this read throttlefs n throttlefs guesstimates hopefully well over the reality local chk fetch bytes sent average new time decaying running average 500 180000 0 0 1024 1024 1024 throttlefs null null throttlefs subset local chk fetch bytes sent average node local ssk fetch bytes sent average new time decaying running average 500 180000 0 0 1024 1024 1024 throttlefs null null throttlefs subset local ssk fetch bytes sent average node local chk insert bytes sent average new time decaying running average 32768 180000 0 0 1024 1024 1024 throttlefs null null throttlefs subset local chk insert bytes sent average node local ssk insert bytes sent average new time decaying running average 2048 180000 0 0 1024 1024 1024 throttlefs null null throttlefs subset local ssk insert bytes sent average node local chk fetch bytes received average new time decaying running average 32768 2048 path folding 180000 0 0 1024 1024 1024 throttlefs null null throttlefs subset local chk fetch bytes received average node local ssk fetch bytes received average new time decaying running average 2048 180000 0 0 1024 1024 1024 throttlefs null null throttlefs subset local ssk fetch bytes received average node local chk insert bytes received average new time decaying running average 1024 180000 0 0 1024 1024 1024 throttlefs null null throttlefs subset local chk insert bytes received average node local ssk insert bytes received average new time decaying running average 500 180000 0 0 1024 1024 1024 throttlefs null null throttlefs subset local chk insert bytes received average node remote chk fetch bytes sent average new time decaying running average 32768 1024 500 2048 path folding 180000 0 0 1024 1024 1024 throttlefs null null throttlefs subset remote chk fetch bytes sent average node remote ssk fetch bytes sent average new time decaying running average 1024 1024 500 180000 0 0 1024 1024 1024 throttlefs null null throttlefs subset remote ssk fetch bytes sent average node remote chk insert bytes sent average new time decaying running average 32768 32768 1024 180000 0 0 1024 1024 1024 throttlefs null null throttlefs subset remote chk insert bytes sent average node remote ssk insert bytes sent average new time decaying running average 1024 1024 500 180000 0 0 1024 1024 1024 throttlefs null null throttlefs subset remote ssk insert bytes sent average node remote chk fetch bytes received average new time decaying running average 32768 1024 500 2048 path folding 180000 0 0 1024 1024 1024 throttlefs null null throttlefs subset remote chk fetch bytes received average node remote ssk fetch bytes received average new time decaying running average 2048 500 180000 0 0 1024 1024 1024 throttlefs null null throttlefs subset remote ssk fetch bytes received average node remote chk insert bytes received average new time decaying running average 32768 1024 500 180000 0 0 1024 1024 1024 throttlefs null null throttlefs subset remote chk insert bytes received average node remote ssk insert bytes received average new time decaying running average 1024 1024 500 180000 0 0 1024 1024 1024 throttlefs null null throttlefs subset remote ssk insert bytes received average node successful chk fetch bytes sent average new time decaying running average 32768 1024 500 2048 path folding 180000 0 0 1024 1024 1024 throttlefs null null throttlefs subset successful chk fetch bytes sent average node successful ssk fetch bytes sent average new time decaying running average 1024 1024 500 180000 0 0 1024 1024 1024 throttlefs null null throttlefs subset successful ssk fetch bytes sent average node successful chk insert bytes sent average new time decaying running average 32768 32768 1024 180000 0 0 1024 1024 1024 throttlefs null null throttlefs subset successful chk insert bytes sent average node successful ssk insert bytes sent average new time decaying running average 1024 1024 500 180000 0 0 1024 1024 1024 throttlefs null null throttlefs subset successful ssk insert bytes sent average node successful chk offer reply bytes sent average new time decaying running average 32768 500 180000 0 0 1024 1024 1024 throttlefs null null throttlefs subset successful chk offer reply bytes sent average node successful ssk offer reply bytes sent average new time decaying running average 3072 180000 0 0 1024 1024 1024 throttlefs null null throttlefs subset successful ssk offer reply bytes sent average node successful chk fetch bytes received average new time decaying running average 32768 1024 500 2048 path folding 180000 0 0 1024 1024 1024 throttlefs null null throttlefs subset successful chk fetch bytes received average node successful ssk fetch bytes received average new time decaying running average 2048 500 180000 0 0 1024 1024 1024 throttlefs null null throttlefs subset successful ssk fetch bytes received average node successful chk insert bytes received average new time decaying running average 32768 1024 500 180000 0 0 1024 1024 1024 throttlefs null null throttlefs subset successful chk insert bytes received average node successful ssk insert bytes received average new time decaying running average 1024 1024 500 180000 0 0 1024 1024 1024 throttlefs null null throttlefs subset successful nodestats sortorder subconfig statsconfig obwlimit ibwlimit nodedir nodeinitexception hardrandom routingmissdistance timedecayingrunningaverage backedoffpercent timedecayingrunningaverage preemptiverejectreasons stringcounter localpreemptiverejectreasons stringcounter pinstantrejectincoming timedecayingrunningaverage threadgroup currentthread getthreadgroup getparent getparent rootthreadgroup activethreadsbypriorities nativethread java_priority_range waitingthreadsbypriorities nativethread java_priority_range throttledpacketsendaverage timedecayingrunningaverage max_value nodepinger nodepinger previous_input_stat previous_output_stat previous_io_stat_time last_input_stat last_output_stat last_io_stat_time statsconfig threadlimit sortorder nodestat threadlimit nodestat threadlimitlong intcallback threadlimit invalidconfigvalueexception invalidconfigvalueexception valuetoolow threadlimit threadlimit statsconfig getint threadlimit statsconfig aggressivegcmodificator sortorder nodestat nodestat aggressivegclong intcallback aggressivegcmodificator invalidconfigvalueexception aggressivegcmodificator aggressivegcmodificator aggressivegcmodificator statsconfig getint mymemorychecker memorychecker aggressivegcmodificator statsconfig memorychecker sortorder nodestat memcheck nodestat memchecklong booleancallback mymemorychecker isrunning invalidconfigvalueexception mymemorychecker mymemorychecker statsconfig getboolean memorychecker mymemorychecker statsconfig ignorelocalvsremotebandwidthliability sortorder nodestat ignorelocalvsremotebandwidthliability nodestat ignorelocalvsremotebandwidthliabilitylong booleancallback nodestats ignorelocalvsremotebandwidthliability invalidconfigvalueexception nodestats ignorelocalvsremotebandwidthliability securitylevels addnetworkthreatlevellistener securitylevellistener network_threat_level onchange network_threat_level oldlevel network_threat_level newlevel newlevel network_threat_level ignorelocalvsremotebandwidthliability oldlevel network_threat_level ignorelocalvsremotebandwidthliability configurablepersister statsconfig nodethrottlefile sortorder nodestat statspersister nodestat statspersisterlong nodedir simplefieldset localchkfetchbytessentaverage timedecayingrunningaverage localchkfetchbytessentaverage localsskfetchbytessentaverage timedecayingrunningaverage localsskfetchbytessentaverage localchkinsertbytessentaverage timedecayingrunningaverage localchkinsertbytessentaverage localsskinsertbytessentaverage timedecayingrunningaverage localsskinsertbytessentaverage localchkfetchbytesreceivedaverage timedecayingrunningaverage localchkfetchbytesreceivedaverage localsskfetchbytesreceivedaverage timedecayingrunningaverage localsskfetchbytesreceivedaverage localchkinsertbytesreceivedaverage timedecayingrunningaverage localchkinsertbytesreceivedaverage localsskinsertbytesreceivedaverage timedecayingrunningaverage localchkinsertbytesreceivedaverage remotechkfetchbytessentaverage timedecayingrunningaverage remotechkfetchbytessentaverage remotesskfetchbytessentaverage timedecayingrunningaverage remotesskfetchbytessentaverage remotechkinsertbytessentaverage timedecayingrunningaverage remotechkinsertbytessentaverage remotesskinsertbytessentaverage timedecayingrunningaverage remotesskinsertbytessentaverage remotechkfetchbytesreceivedaverage timedecayingrunningaverage remotechkfetchbytesreceivedaverage remotesskfetchbytesreceivedaverage timedecayingrunningaverage remotesskfetchbytesreceivedaverage remotechkinsertbytesreceivedaverage timedecayingrunningaverage remotechkinsertbytesreceivedaverage remotesskinsertbytesreceivedaverage timedecayingrunningaverage remotesskinsertbytesreceivedaverage successfulchkfetchbytessentaverage timedecayingrunningaverage successfulchkfetchbytessentaverage successfulsskfetchbytessentaverage timedecayingrunningaverage successfulsskfetchbytessentaverage successfulchkinsertbytessentaverage timedecayingrunningaverage successfulchkinsertbytessentaverage successfulsskinsertbytessentaverage timedecayingrunningaverage successfulsskinsertbytessentaverage successfulchkofferreplybytessentaverage timedecayingrunningaverage successfulchkofferreplybytessentaverage successfulsskofferreplybytessentaverage timedecayingrunningaverage successfulsskofferreplybytessentaverage successfulchkfetchbytesreceivedaverage timedecayingrunningaverage successfulchkfetchbytesreceivedaverage successfulsskfetchbytesreceivedaverage timedecayingrunningaverage successfulsskfetchbytesreceivedaverage successfulchkinsertbytesreceivedaverage timedecayingrunningaverage successfulchkinsertbytesreceivedaverage successfulsskinsertbytesreceivedaverage timedecayingrunningaverage stats config register thread limit 500 sort order true true node stat thread limit node stat thread limit long new int callback override public integer get return thread limit statsconfig threadlimit sortorder nodestat threadlimit nodestat threadlimitlong intcallback threadlimit override public void set integer val throws invalid config value exception if get equals val return if val 100 throw new invalid config value exception l10n value too low thread limit val invalidconfigvalueexception invalidconfigvalueexception valuetoolow threadlimit stats config register aggressivegc aggressivegc modificator sort order true false node stat aggressivegc node stat aggressivegc long new int callback override public integer get return aggressivegc modificator statsconfig aggressivegcmodificator sortorder nodestat nodestat aggressivegclong intcallback aggressivegcmodificator override public void set integer val throws invalid config value exception if get equals val return logger normal this changing aggressivegc modificator to val aggressivegc modificator val invalidconfigvalueexception aggressivegcmodificator aggressivegcmodificator stats config register memory checker true sort order true false node stat mem check node stat mem check long new boolean callback override public boolean get return my memory checker is running statsconfig memorychecker sortorder nodestat memcheck nodestat memchecklong booleancallback mymemorychecker isrunning override public void set boolean val throws invalid config value exception if get equals val return if val my memory checker start else my memory checker terminate invalidconfigvalueexception mymemorychecker mymemorychecker override public boolean get synchronized node stats this return ignore local vs remote bandwidth liability nodestats ignorelocalvsremotebandwidthliability override public void set boolean val throws invalid config value exception synchronized node stats this ignore local vs remote bandwidth liability val invalidconfigvalueexception nodestats ignorelocalvsremotebandwidthliability public void on change network threat level old level network threat level new level if new level network threat level maximum ignore local vs remote bandwidth liability true if old level network threat level maximum ignore local vs remote bandwidth liability false otherwise leave it as it was it defaults to false onchange network_threat_level oldlevel network_threat_level newlevel newlevel network_threat_level ignorelocalvsremotebandwidthliability oldlevel network_threat_level ignorelocalvsremotebandwidthliability protected string l10n string key return l10n get string node stats key getstring nodestats public void start throws node init exception node executor execute new runnable public void run node pinger start starting node pinger persister start node get ticker queue timed job throttled packet send average idle updater check throttle time nodeinitexception nodepinger nodepinger getticker queuetimedjob throttledpacketsendaverageidleupdater check_throttle_time public void start throws node init exception node executor execute new runnable public void run node pinger start nodeinitexception nodepinger new runnable public void run long now system current time millis try if throttled packet send average last report time now 5000 if last report more than 5 seconds ago shouldn t take long node output throttle blocking grab estimated size of one throttled packet node output throttle recycle estimated size of one throttled packet long after system current time millis report time it takes to grab the bytes throttled packet send average report after now catch throwable t logger error this caught t t finally node get ticker queue timed job this check throttle time long end system current time millis if logminor logger minor this throttle check took time util format time end now 2 true doesn t belong here but anyway should do the job active threads by priorities node executor running threads waiting threads by priorities node executor waiting threads currenttimemillis throttledpacketsendaverage lastreporttime outputthrottle blockinggrab estimatedsizeofonethrottledpacket outputthrottle estimatedsizeofonethrottledpacket currenttimemillis throttledpacketsendaverage getticker queuetimedjob check_throttle_time currenttimemillis timeutil formattime activethreadsbypriorities runningthreads waitingthreadsbypriorities waitingthreads return reject reason as string if should reject otherwise return null public string should reject request boolean can accept anyway boolean is insert boolean isssk boolean is local boolean is offer reply peer node source if logminor dump byte cost averages int thread count get active thread count if thread limit thread count p instant reject incoming report 1 0 rejected thread limit is local return thread limit thread count thread limit double bwlimit delay time throttled packet send average current value long total node collector get totalio long total sent total 0 long total overhead get sent overhead long uptime node get uptime double sent overhead per second total overhead 1000 0 uptime the fraction of output bytes which are used for requests double overhead fraction double total sent total overhead total sent long time first any connections peers time first any connections long now system current time millis if logminor logger minor this output rate total sent 1000 0 uptime overhead rate sent overhead per second non overhead fraction overhead fraction if time first any connections 0 long time now time first any connections if time default only period overhead fraction default overhead if logminor logger minor this adjusted overhead fraction overhead fraction else if time default only period default transition period time default only period overhead fraction time overhead fraction default transition period time default overhead default transition period if logminor logger minor this adjusted overhead fraction overhead fraction else if overhead fraction min overhead logger error this overhead fraction is overhead fraction assuming this is self inflicted and using default overhead fraction default overhead if no recent reports no packets have been sent correct the average downwards double ping time ping time node pinger average ping time synchronized this round trip time if ping time max ping time if now last accepted request max interrequest time can accept anyway if logminor logger minor this accepting request anyway take one every 10 secs to keep bwlimit delay time updated else p instant reject incoming report 1 0 rejected max ping time is local return max ping time time util format time long ping time 2 true else if ping time sub max ping time double x ping time sub max ping time max ping time sub max ping time if hard random next double x p instant reject incoming report 1 0 rejected sub max ping time is local return sub max ping time time util format time long ping time 2 true bandwidth limited packets if bwlimit delay time max throttle delay if now last accepted request max interrequest time can accept anyway if logminor logger minor this accepting request anyway take one every 10 secs to keep bwlimit delay time updated else p instant reject incoming report 1 0 rejected max throttle delay is local return max throttle delay time util format time long bwlimit delay time 2 true else if bwlimit delay time sub max throttle delay double x bwlimit delay time sub max throttle delay max throttle delay sub max throttle delay if hard random next double x p instant reject incoming report 1 0 rejected sub max throttle delay is local return sub max throttle delay time util format time long bwlimit delay time 2 true successful cluster timeout protection reject request if the result of all our current requests completing simultaneously would be that some of them timeout never reject a chk and accept an ssk because if we do that we would be constantly accepting ss ks as there would never be enough space for a chk so we add 1 to each type of request s count before computing the bandwidth liability thus if we have exactly enough space for 1 ssk and 1 chk we can accept either and when one of either type completes we can accept one of either type again we never let ss ks drain the bucket and block ch ks int num localchk requests node get num localchk requests 1 int num localssk requests node get num localssk requests 1 int num localchk inserts node get num localchk inserts 1 int num localssk inserts node get num localssk inserts 1 int num remotechk requests node get num remotechk requests 1 int num remotessk requests node get num remotessk requests 1 int num remotechk inserts node get num remotechk inserts 1 int num remotessk inserts node get num remotessk inserts 1 int numchk offer replies node get numchk offer replies 1 int numssk offer replies node get numssk offer replies 1 if is local if not local is already locked so we need to decrement the relevant value to counteract this and restore the ssk chk balance if is offer reply if isssk numssk offer replies else numchk offer replies else if is insert if isssk num remotessk inserts else num remotechk inserts else if isssk num remotessk requests else num remotechk requests if logminor logger minor this running adjusted chk fetch local num localchk requests remote num remotechk requests ssk fetch local num localssk requests remote num remotessk requests chk insert local num localchk inserts remote num remotechk inserts ssk insert local num localssk inserts remote num remotessk inserts chk offer replies local numchk offer replies ssk offer replies numssk offer replies double bandwidth liability output if ignore local vs remote bandwidth liability bandwidth liability output successful chk fetch bytes sent average current value num remotechk requests num localchk requests 1 successful ssk fetch bytes sent average current value num remotessk requests num localssk requests 1 successful chk insert bytes sent average current value num remotechk inserts num localchk inserts 1 successful ssk insert bytes sent average current value num remotessk inserts num localssk inserts 1 else bandwidth liability output successful chk fetch bytes sent average current value num remotechk requests local requests don t relay data so use the local average local chk fetch bytes sent average current value num localchk requests successful ssk fetch bytes sent average current value num remotessk requests local requests don t relay data so use the local average local ssk fetch bytes sent average current value num localssk requests inserts are the same for remote as local for sent bytes successful chk insert bytes sent average current value num remotechk inserts successful chk insert bytes sent average current value num localchk inserts inserts are the same for remote as local for sent bytes successful ssk insert bytes sent average current value num remotessk inserts successful ssk insert bytes sent average current value num localssk inserts successful chk offer reply bytes sent average current value numchk offer replies successful ssk offer reply bytes sent average current value numssk offer replies double output available per second node get output bandwidth limit sent overhead per second if there s been an auto update we may have used a vast amount of bandwidth for it also if things have broken our overhead might be above our bandwidth limit especially on a slow node so impose a minimum of 20 of the bandwidth limit this will ensure we don t get stuck in any situation where all our bandwidth is overhead and we don t accept any requests because of that so it remains that way if logminor logger minor this overhead per second sent overhead per second bwlimit node get output bandwidth limit output available per second output available per second but minimum of node get output bandwidth limit 5 0 output available per second math max output available per second node get output bandwidth limit 5 0 double bandwidth available output output available per second 90 90 seconds at full power we have to leave some time for the search as well if logminor logger minor this 90 second limit bandwidth available output expected output liability bandwidth liability output if bandwidth liability output bandwidth available output p instant reject incoming report 1 0 rejected output bandwidth liability is local return output bandwidth liability bandwidth liability output bandwidth available output double bandwidth liability input if ignore local vs remote bandwidth liability bandwidth liability input successful chk fetch bytes received average current value num remotechk requests num localchk requests 1 successful ssk fetch bytes received average current value num remotessk requests num localssk requests 1 successful chk insert bytes received average current value num remotechk inserts num localchk inserts 1 successful ssk insert bytes received average current value num remotessk inserts num localssk inserts 1 else bandwidth liability input for receiving data local requests are the same as remote ones successful chk fetch bytes received average current value num remotechk requests successful chk fetch bytes received average current value num localchk requests successful ssk fetch bytes received average current value num remotessk requests successful ssk fetch bytes shouldrejectrequest canacceptanyway isinsert islocal isofferreply peernode dumpbytecostaverages threadcount getactivethreadcount threadlimit threadcount pinstantrejectincoming threadlimit islocal threadlimit threadcount threadlimit bwlimitdelaytime throttledpacketsendaverage currentvalue gettotalio totalsent totaloverhead getsentoverhead getuptime sentoverheadpersecond totaloverhead overheadfraction totalsent totaloverhead totalsent timefirstanyconnections timefirstanyconnections currenttimemillis totalsent sentoverheadpersecond overheadfraction timefirstanyconnections timefirstanyconnections default_only_period overheadfraction default_overhead overheadfraction default_only_period default_transition_period default_only_period overheadfraction overheadfraction default_transition_period default_overhead default_transition_period overheadfraction overheadfraction min_overhead overheadfraction overheadfraction default_overhead pingtime pingtime nodepinger averagepingtime pingtime max_ping_time lastacceptedrequest max_interrequest_time canacceptanyway bwlimitdelaytime pinstantrejectincoming max_ping_time islocal max_ping_time timeutil formattime pingtime pingtime sub_max_ping_time pingtime sub_max_ping_time max_ping_time sub_max_ping_time hardrandom nextdouble pinstantrejectincoming sub_max_ping_time islocal sub_max_ping_time timeutil formattime pingtime bwlimitdelaytime max_throttle_delay lastacceptedrequest max_interrequest_time canacceptanyway bwlimitdelaytime pinstantrejectincoming max_throttle_delay islocal max_throttle_delay timeutil formattime bwlimitdelaytime bwlimitdelaytime sub_max_throttle_delay bwlimitdelaytime sub_max_throttle_delay max_throttle_delay sub_max_throttle_delay hardrandom nextdouble pinstantrejectincoming sub_max_throttle_delay islocal sub_max_throttle_delay timeutil formattime bwlimitdelaytime ssks ssks chks numlocalchkrequests getnumlocalchkrequests numlocalsskrequests getnumlocalsskrequests numlocalchkinserts getnumlocalchkinserts numlocalsskinserts getnumlocalsskinserts numremotechkrequests getnumremotechkrequests numremotesskrequests getnumremotesskrequests numremotechkinserts getnumremotechkinserts numremotesskinserts getnumremotesskinserts numchkofferreplies getnumchkofferreplies numsskofferreplies getnumsskofferreplies islocal isofferreply numsskofferreplies numchkofferreplies isinsert numremotesskinserts numremotechkinserts numremotesskrequests numremotechkrequests numlocalchkrequests numremotechkrequests numlocalsskrequests numremotesskrequests numlocalchkinserts numremotechkinserts numlocalsskinserts numremotesskinserts numchkofferreplies numsskofferreplies bandwidthliabilityoutput ignorelocalvsremotebandwidthliability bandwidthliabilityoutput successfulchkfetchbytessentaverage currentvalue numremotechkrequests numlocalchkrequests successfulsskfetchbytessentaverage currentvalue numremotesskrequests numlocalsskrequests successfulchkinsertbytessentaverage currentvalue numremotechkinserts numlocalchkinserts successfulsskinsertbytessentaverage currentvalue numremotesskinserts numlocalsskinserts bandwidthliabilityoutput successfulchkfetchbytessentaverage currentvalue numremotechkrequests localchkfetchbytessentaverage currentvalue numlocalchkrequests successfulsskfetchbytessentaverage currentvalue numremotesskrequests localsskfetchbytessentaverage currentvalue numlocalsskrequests successfulchkinsertbytessentaverage currentvalue numremotechkinserts successfulchkinsertbytessentaverage currentvalue numlocalchkinserts successfulsskinsertbytessentaverage currentvalue numremotesskinserts successfulsskinsertbytessentaverage currentvalue numlocalsskinserts successfulchkofferreplybytessentaverage currentvalue numchkofferreplies successfulsskofferreplybytessentaverage currentvalue numsskofferreplies outputavailablepersecond getoutputbandwidthlimit sentoverheadpersecond sentoverheadpersecond getoutputbandwidthlimit outputavailablepersecond getoutputbandwidthlimit outputavailablepersecond outputavailablepersecond getoutputbandwidthlimit bandwidthavailableoutput outputavailablepersecond bandwidthavailableoutput bandwidthliabilityoutput bandwidthliabilityoutput bandwidthavailableoutput pinstantrejectincoming islocal bandwidthliabilityoutput bandwidthavailableoutput bandwidthliabilityinput ignorelocalvsremotebandwidthliability bandwidthliabilityinput successfulchkfetchbytesreceivedaverage currentvalue numremotechkrequests numlocalchkrequests successfulsskfetchbytesreceivedaverage currentvalue numremotesskrequests numlocalsskrequests successfulchkinsertbytesreceivedaverage currentvalue numremotechkinserts numlocalchkinserts successfulsskinsertbytesreceivedaverage currentvalue numremotesskinserts numlocalsskinserts bandwidthliabilityinput successfulchkfetchbytesreceivedaverage currentvalue numremotechkrequests successfulchkfetchbytesreceivedaverage currentvalue numlocalchkrequests successfulsskfetchbytesreceivedaverage currentvalue numremotesskrequests successfulsskfetchbytes private void rejected string reason boolean is local if is local preemptive reject reasons inc reason else this local preemptive reject reasons inc reason islocal islocal preemptiverejectreasons localpreemptiverejectreasons private running average get throttle boolean is local boolean is insert boolean isssk boolean is sent if is local if is insert if isssk return is sent this local ssk insert bytes sent average this local ssk insert bytes received average else return is sent this local chk insert bytes sent average this local chk insert bytes received average else if isssk return is sent this local ssk fetch bytes sent average this local ssk fetch bytes received average else return is sent this local chk fetch bytes sent average this local chk fetch bytes received average else if is insert if isssk return is sent this remote ssk insert bytes sent average this remote ssk insert bytes received average else return is sent this remote chk insert bytes sent average this remote chk insert bytes received average else if isssk return is sent this remote ssk fetch bytes sent average this remote ssk fetch bytes received average else return is sent this remote chk fetch bytes sent average this remote chk fetch bytes received average runningaverage getthrottle islocal isinsert issent islocal isinsert issent localsskinsertbytessentaverage localsskinsertbytesreceivedaverage issent localchkinsertbytessentaverage localchkinsertbytesreceivedaverage issent localsskfetchbytessentaverage localsskfetchbytesreceivedaverage issent localchkfetchbytessentaverage localchkfetchbytesreceivedaverage isinsert issent remotesskinsertbytessentaverage remotesskinsertbytesreceivedaverage issent remotechkinsertbytessentaverage remotechkinsertbytesreceivedaverage issent remotesskfetchbytessentaverage remotesskfetchbytesreceivedaverage issent remotechkfetchbytessentaverage remotechkfetchbytesreceivedaverage private void dump byte cost averages logger minor this byte cost averages remote chk insert remote chk insert bytes sent average current value remote chk insert bytes received average current value ssk insert remote ssk insert bytes sent average current value remote ssk insert bytes received average current value chk fetch remote chk fetch bytes sent average current value remote chk fetch bytes received average current value ssk fetch remote ssk fetch bytes sent average current value remote ssk fetch bytes received average current value logger minor this byte cost averages local chk insert local chk insert bytes sent average current value local chk insert bytes received average current value ssk insert local ssk insert bytes sent average current value local ssk insert bytes received average current value chk fetch local chk fetch bytes sent average current value local chk fetch bytes received average current value ssk fetch local ssk fetch bytes sent average current value local ssk fetch bytes received average current value logger minor this byte cost averages successful chk insert successful chk insert bytes sent average current value successful chk insert bytes received average current value ssk insert successful ssk insert bytes sent average current value successful ssk insert bytes received average current value chk fetch successful chk fetch bytes sent average current value successful chk fetch bytes received average current value ssk fetch successful ssk fetch bytes sent average current value successful ssk fetch bytes received average current value chk offer reply successful chk offer reply bytes sent average current value successful chk offer reply bytes received average current value ssk offer reply successful ssk offer reply bytes sent average current value successful ssk offer reply bytes received average current value dumpbytecostaverages remotechkinsertbytessentaverage currentvalue remotechkinsertbytesreceivedaverage currentvalue remotesskinsertbytessentaverage currentvalue remotesskinsertbytesreceivedaverage currentvalue remotechkfetchbytessentaverage currentvalue remotechkfetchbytesreceivedaverage currentvalue remotesskfetchbytessentaverage currentvalue remotesskfetchbytesreceivedaverage currentvalue localchkinsertbytessentaverage currentvalue localchkinsertbytesreceivedaverage currentvalue localsskinsertbytessentaverage currentvalue localsskinsertbytesreceivedaverage currentvalue localchkfetchbytessentaverage currentvalue localchkfetchbytesreceivedaverage currentvalue localsskfetchbytessentaverage currentvalue localsskfetchbytesreceivedaverage currentvalue successfulchkinsertbytessentaverage currentvalue successfulchkinsertbytesreceivedaverage currentvalue successfulsskinsertbytessentaverage currentvalue successfulsskinsertbytesreceivedaverage currentvalue successfulchkfetchbytessentaverage currentvalue successfulchkfetchbytesreceivedaverage currentvalue successfulsskfetchbytessentaverage currentvalue successfulsskfetchbytesreceivedaverage currentvalue successfulchkofferreplybytessentaverage currentvalue successfulchkofferreplybytesreceivedaverage currentvalue successfulsskofferreplybytessentaverage currentvalue successfulsskofferreplybytesreceivedaverage currentvalue public double get bwlimit delay time return throttled packet send average current value getbwlimitdelaytime throttledpacketsendaverage currentvalue public double get node average ping time return node pinger average ping time getnodeaveragepingtime nodepinger averagepingtime public int get opennet size estimate long timestamp if node opennet null return 0 return node opennet get network size estimate timestamp getopennetsizeestimate getnetworksizeestimate return node opennet get network size estimate timestamp public int get darknet size estimate long timestamp return node lm get network size estimate timestamp getnetworksizeestimate getdarknetsizeestimate getnetworksizeestimate public object get known locations long timestamp return node lm get known locations timestamp getknownlocations getknownlocations public double p reject incoming instantly return p instant reject incoming current value prejectincominginstantly pinstantrejectincoming currentvalue update peer manager user alert stats if the timer has expired only called from packet sender so doesn t need sync public void maybe update peer manager user alert stats long now if now next peer manager user alert stats update time if get bwlimit delay time max bwlimit delay time alert threshold if first bwlimit delay time threshold break 0 first bwlimit delay time threshold break now else first bwlimit delay time threshold break 0 if first bwlimit delay time threshold break 0 now first bwlimit delay time threshold break max bwlimit delay time alert delay bwlimit delay alert relevant true else bwlimit delay alert relevant false if get node average ping time max node average ping time alert threshold if first node average ping time threshold break 0 first node average ping time threshold break now else first node average ping time threshold break 0 if first node average ping time threshold break 0 now first node average ping time threshold break max node average ping time alert delay node average ping alert relevant true else node average ping alert relevant false if logdebug logger debug this mupmuas now get bwlimit delay time max bwlimit delay time alert threshold since first bwlimit delay time threshold break bwlimit delay alert relevant get node average ping time max node average ping time alert threshold since first node average ping time threshold break node average ping alert relevant next peer manager user alert stats update time now peer manager user alert stats update interval peermanageruseralertstats packetsender maybeupdatepeermanageruseralertstats nextpeermanageruseralertstatsupdatetime getbwlimitdelaytime max_bwlimit_delay_time_alert_threshold firstbwlimitdelaytimethresholdbreak firstbwlimitdelaytimethresholdbreak firstbwlimitdelaytimethresholdbreak firstbwlimitdelaytimethresholdbreak firstbwlimitdelaytimethresholdbreak max_bwlimit_delay_time_alert_delay bwlimitdelayalertrelevant bwlimitdelayalertrelevant getnodeaveragepingtime max_node_average_ping_time_alert_threshold firstnodeaveragepingtimethresholdbreak firstnodeaveragepingtimethresholdbreak firstnodeaveragepingtimethresholdbreak firstnodeaveragepingtimethresholdbreak firstnodeaveragepingtimethresholdbreak max_node_average_ping_time_alert_delay nodeaveragepingalertrelevant nodeaveragepingalertrelevant getbwlimitdelaytime max_bwlimit_delay_time_alert_threshold firstbwlimitdelaytimethresholdbreak bwlimitdelayalertrelevant getnodeaveragepingtime max_node_average_ping_time_alert_threshold firstnodeaveragepingtimethresholdbreak nodeaveragepingalertrelevant nextpeermanageruseralertstatsupdatetime peermanageruseralertstatsupdateinterval public simple field set persist throttles to field set simple field set fs new simple field set true fs put remote chk fetch bytes sent average remote chk fetch bytes sent average export field set true fs put remote ssk fetch bytes sent average remote ssk fetch bytes sent average export field set true fs put remote chk insert bytes sent average remote chk insert bytes sent average export field set true fs put remote ssk insert bytes sent average remote ssk insert bytes sent average export field set true fs put remote chk fetch bytes received average remote chk fetch bytes received average export field set true fs put remote ssk fetch bytes received average remote ssk fetch bytes received average export field set true fs put remote chk insert bytes received average remote chk insert bytes received average export field set true fs put remote ssk insert bytes received average remote ssk insert bytes received average export field set true fs put local chk fetch bytes sent average local chk fetch bytes sent average export field set true fs put local ssk fetch bytes sent average local ssk fetch bytes sent average export field set true fs put local chk insert bytes sent average local chk insert bytes sent average export field set true fs put local ssk insert bytes sent average local ssk insert bytes sent average export field set true fs put local chk fetch bytes received average local chk fetch bytes received average export field set true fs put local ssk fetch bytes received average local ssk fetch bytes received average export field set true fs put local chk insert bytes received average local chk insert bytes received average export field set true fs put local ssk insert bytes received average local ssk insert bytes received average export field set true fs put successful chk fetch bytes sent average successful chk fetch bytes sent average export field set true fs put successful ssk fetch bytes sent average successful ssk fetch bytes sent average export field set true fs put successful chk insert bytes sent average successful chk insert bytes sent average export field set true fs put successful ssk insert bytes sent average successful ssk insert bytes sent average export field set true fs put successful chk offer reply bytes sent average successful chk offer reply bytes sent average export field set true fs put successful ssk offer reply bytes sent average successful ssk offer reply bytes sent average export field set true fs put successful chk fetch bytes received average successful chk fetch bytes received average export field set true fs put successful ssk fetch bytes received average successful ssk fetch bytes received average export field set true fs put successful chk insert bytes received average successful chk insert bytes received average export field set true fs put successful ssk insert bytes received average successful ssk insert bytes received average export field set true fs put successful chk offer reply bytes received average successful chk offer reply bytes received average export field set true fs put successful ssk offer reply bytes received average successful ssk offer reply bytes received average export field set true these are not really part of the throttling data but are also running averages which should be persisted fs put average cache location avg cache location export field set true fs put average store location avg store location export field set true fs put average cache success location avg cache success export field set true fs put average store success location avg store success export field set true fs put average request location avg request location export field set true return fs simplefieldset persistthrottlestofieldset simplefieldset simplefieldset remotechkfetchbytessentaverage remotechkfetchbytessentaverage exportfieldset remotesskfetchbytessentaverage remotesskfetchbytessentaverage exportfieldset remotechkinsertbytessentaverage remotechkinsertbytessentaverage exportfieldset remotesskinsertbytessentaverage remotesskinsertbytessentaverage exportfieldset remotechkfetchbytesreceivedaverage remotechkfetchbytesreceivedaverage exportfieldset remotesskfetchbytesreceivedaverage remotesskfetchbytesreceivedaverage exportfieldset remotechkinsertbytesreceivedaverage remotechkinsertbytesreceivedaverage exportfieldset remotesskinsertbytesreceivedaverage remotesskinsertbytesreceivedaverage exportfieldset localchkfetchbytessentaverage localchkfetchbytessentaverage exportfieldset localsskfetchbytessentaverage localsskfetchbytessentaverage exportfieldset localchkinsertbytessentaverage localchkinsertbytessentaverage exportfieldset localsskinsertbytessentaverage localsskinsertbytessentaverage exportfieldset localchkfetchbytesreceivedaverage localchkfetchbytesreceivedaverage exportfieldset localsskfetchbytesreceivedaverage localsskfetchbytesreceivedaverage exportfieldset localchkinsertbytesreceivedaverage localchkinsertbytesreceivedaverage exportfieldset localsskinsertbytesreceivedaverage localsskinsertbytesreceivedaverage exportfieldset successfulchkfetchbytessentaverage successfulchkfetchbytessentaverage exportfieldset successfulsskfetchbytessentaverage successfulsskfetchbytessentaverage exportfieldset successfulchkinsertbytessentaverage successfulchkinsertbytessentaverage exportfieldset successfulsskinsertbytessentaverage successfulsskinsertbytessentaverage exportfieldset successfulchkofferreplybytessentaverage successfulchkofferreplybytessentaverage exportfieldset successfulsskofferreplybytessentaverage successfulsskofferreplybytessentaverage exportfieldset successfulchkfetchbytesreceivedaverage successfulchkfetchbytesreceivedaverage exportfieldset successfulsskfetchbytesreceivedaverage successfulsskfetchbytesreceivedaverage exportfieldset successfulchkinsertbytesreceivedaverage successfulchkinsertbytesreceivedaverage exportfieldset successfulsskinsertbytesreceivedaverage successfulsskinsertbytesreceivedaverage exportfieldset successfulchkofferreplybytesreceivedaverage successfulchkofferreplybytesreceivedaverage exportfieldset successfulsskofferreplybytesreceivedaverage successfulsskofferreplybytesreceivedaverage exportfieldset averagecachelocation avgcachelocation exportfieldset averagestorelocation avgstorelocation exportfieldset averagecachesuccesslocation avgcachesuccess exportfieldset averagestoresuccesslocation avgstoresuccess exportfieldset averagerequestlocation avgrequestlocation exportfieldset update the node wide bandwidth i o stats if the timer has expired public void maybe update nodeio stats long now if now next nodeio stats update time long io stats node collector get totalio long outdiff long indiff synchronized io stat sync previous output stat last output stat previous input stat last input stat previous io stat time last io stat time last output stat io stats 0 last input stat io stats 1 last io stat time now outdiff last output stat previous output stat indiff last input stat previous input stat if logminor logger minor this last 2 seconds input indiff output outdiff next nodeio stats update time now nodeio stats update interval maybeupdatenodeiostats nextnodeiostatsupdatetime io_stats gettotalio iostatsync previous_output_stat last_output_stat previous_input_stat last_input_stat previous_io_stat_time last_io_stat_time last_output_stat io_stats last_input_stat io_stats last_io_stat_time last_output_stat previous_output_stat last_input_stat previous_input_stat nextnodeiostatsupdatetime nodeiostatsupdateinterval public long get nodeio stats long result new long 6 synchronized io stat sync result 0 previous output stat result 1 previous input stat result 2 previous io stat time result 3 last output stat result 4 last input stat result 5 last io stat time return result getnodeiostats iostatsync previous_output_stat previous_input_stat previous_io_stat_time last_output_stat last_input_stat last_io_stat_time public void wait until not overloaded boolean is insert while thread limit get active thread count try thread sleep 5000 catch interrupted exception e waituntilnotoverloaded isinsert threadlimit getactivethreadcount interruptedexception public int get active thread count return root thread group active count node executor get waiting threads count getactivethreadcount rootthreadgroup activecount getwaitingthreadscount public int get active threads by priority return active threads by priorities getactivethreadsbypriority activethreadsbypriorities public int get waiting threads by priority return waiting threads by priorities getwaitingthreadsbypriority waitingthreadsbypriorities public int get thread limit return thread limit getthreadlimit threadlimit public simple field set export volatile field set simple field set fs new simple field set true long now system current time millis fs put is using wrapper node is using wrapper long node uptime seconds 0 synchronized this fs put startup time node startup time node uptime seconds now node startup time 1000 if node uptime seconds 0 node uptime seconds 1 prevent division by zero fs put uptime seconds node uptime seconds fs put average ping time get node average ping time fs put bwlimit delay time get bwlimit delay time fs put opennet size estimate session get opennet size estimate 1 int opennet size estimate24hour recent get opennet size estimate now 24 60 60 1000 24 hours fs put opennet size estimate24hour recent opennet size estimate24hour recent int opennet size estimate48hour recent get opennet size estimate now 48 60 60 1000 48 hours fs put opennet size estimate48hour recent opennet size estimate48hour recent fs put network size estimate session get darknet size estimate 1 int network size estimate24hour recent get darknet size estimate now 24 60 60 1000 24 hours fs put network size estimate24hour recent network size estimate24hour recent int network size estimate48hour recent get darknet size estimate now 48 60 60 1000 48 hours fs put network size estimate48hour recent network size estimate48hour recent fs put routing miss distance routing miss distance current value fs put backed off percent backed off percent current value fs put p instant reject p reject incoming instantly fs put unclaimedfifo size node usm get unclaimedfifo size gather connection statistics peer node status peer node statuses peers get peer node statuses true int number of seed servers get count seed servers peer node statuses int number of seed clients get count seed clients peer node statuses int number of connected peer node status get peer status count peer node statuses peer manager peer node status connected int number of routing backed off peer node status get peer status count peer node statuses peer manager peer node status routing backed off int number of too new peer node status get peer status count peer node statuses peer manager peer node status too new int number of too old peer node status get peer status count peer node statuses peer manager peer node status too old int number of disconnected peer node status get peer status count peer node statuses peer manager peer node status disconnected int number of never connected peer node status get peer status count peer node statuses peer manager peer node status never connected int number of disabled peer node status get peer status count peer node statuses peer manager peer node status disabled int number of bursting peer node status get peer status count peer node statuses peer manager peer node status bursting int number of listening peer node status get peer status count peer node statuses peer manager peer node status listening int number of listen only peer node status get peer status count peer node statuses peer manager peer node status listen only int number of simple connected number of connected number of routing backed off int number of not connected number of too new number of too old number of disconnected number of never connected number of disabled number of bursting number of listening number of listen only fs put number of seed servers number of seed servers fs put number of seed clients number of seed clients fs put number of connected number of connected fs put number of routing backed off number of routing backed off fs put number of too new number of too new fs put number of too old number of too old fs put number of disconnected number of disconnected fs put number of never connected number of never connected fs put number of disabled number of disabled fs put number of bursting number of bursting fs put number of listening number of listening fs put number of listen only number of listen only fs put number of simple connected number of simple connected fs put number of not connected number of not connected fs put number of insert senders node get num insert senders fs put number of request senders node get num request senders fs put number of transferring request senders node get num transferring request senders fs put number ofark fetchers node get numark fetchers long total node collector get totalio long total output rate total 0 node uptime seconds long total input rate total 1 node uptime seconds long total payload output node get total payload sent long total payload output rate total payload output node uptime seconds int total payload output percent total 0 0 1 int 100 total payload output total 0 fs put total output bytes total 0 fs put total output rate total output rate fs put total payload output bytes total payload output fs put total payload output rate total payload output rate fs put total payload output percent total payload output percent fs put total input bytes total 1 fs put total input rate total input rate long rate get nodeio stats long deltams rate 5 rate 2 double recent output rate deltams 0 0 1000 0 rate 3 rate 0 deltams double recent input rate deltams 0 0 1000 0 rate 4 rate 1 deltams fs put recent output rate recent output rate fs put recent input rate recent input rate string routing backoff reasons peers get peer node routing backoff reasons if routing backoff reasons length 0 for int i 0 i routing backoff reasons length i fs put number with routing backoff reasons routing backoff reasons i peers get peer node routing backoff reason size routing backoff reasons i double swaps node get swaps double no swaps node get no swaps double number of remote peer locations seen in swaps node get number of remote peer locations seen in swaps fs put single number of remote peer locations seen in swaps double to string number of remote peer locations seen in swaps double avg connected peers per node 0 0 if number of remote peer locations seen in swaps 0 0 swaps 0 0 no swaps 0 0 avg connected peers per node number of remote peer locations seen in swaps swaps no swaps fs put single avg connected peers per node double to string avg connected peers per node int started swaps node get started swaps int swaps rejected already locked node get swaps rejected already locked int swaps rejected nowhere to go node get swaps rejected nowhere to go int swaps rejected rate limit node get swaps rejected rate limit int swaps rejected recognizedid node get swaps rejected recognizedid double location change per session node get location change session double location change per swap 0 0 double location change per minute 0 0 double swaps per minute 0 0 double no swaps per minute 0 0 double swaps per no swaps 0 0 if swaps 0 location change per swap location change per session swaps if swaps 0 0 node uptime seconds 60 location change per minute location change per session node uptime seconds 60 0 if swaps 0 0 node uptime seconds 60 swaps per minute swaps node uptime seconds 60 0 if no swaps 0 0 node uptime seconds 60 no swaps per minute no swaps node uptime seconds 60 0 if swaps 0 0 no swaps 0 0 swaps per no swaps swaps no swaps fs put location change per session location change per session fs put location change per swap location change per swap fs put location change per minute location change per minute fs put swaps per minute swaps per minute fs put no swaps per minute no swaps per minute fs put swaps per no swaps swaps per no swaps fs put swaps swaps fs put no swaps no swaps fs put started swaps started swaps fs put swaps rejected already locked swaps rejected already locked fs put swaps rejected nowhere to go swaps rejected nowhere to go fs put swaps rejected rate limit swaps rejected rate limit fs put swaps rejected recognizedid swaps rejected recognizedid long fix32kb 32 1024 long cached keys node get chk datacache key count long cached size cached keys fix32kb long store keys node get chk datastore key count long store size store keys fix32kb long overall keys cached keys store keys long overall size cached size store size long max overall keys node get max total keys long max overall size max overall keys fix32kb double percent overall keys of max double overall keys 100 double max overall keys long cached store hits node get chk datacache hits long cached store misses node get chk datacache misses long cache accesses cached store hits cached store misses double percent cached store hits of accesses double cached store hits 100 double cache accesses long store hits node get chk datastore hits long store misses node get chk datastore misses long store accesses store hits store misses double percent store hits of accesses double store hits 100 double store accesses long overall accesses store accesses cache accesses double avg store access rate double overall accesses double node uptime seconds fs put cached keys cached keys fs put cached size cached size fs put store keys store keys fs put store size store size fs put overall keys overall keys fs put overall size overall size fs put max overall keys max overall keys fs put max overall size max overall size fs put percent overall keys of max percent overall keys of max fs put cached store hits cached store hits fs put cached store misses cached store misses fs put cache accesses cache accesses fs put percent cached store hits of accesses percent cached store hits of accesses fs put store hits simplefieldset exportvolatilefieldset simplefieldset simplefieldset currenttimemillis isusingwrapper isusingwrapper nodeuptimeseconds startuptime startuptime nodeuptimeseconds startuptime nodeuptimeseconds nodeuptimeseconds uptimeseconds nodeuptimeseconds averagepingtime getnodeaveragepingtime bwlimitdelaytime getbwlimitdelaytime opennetsizeestimatesession getopennetsizeestimate opennetsizeestimate24hourrecent getopennetsizeestimate opennetsizeestimate24hourrecent opennetsizeestimate24hourrecent opennetsizeestimate48hourrecent getopennetsizeestimate opennetsizeestimate48hourrecent opennetsizeestimate48hourrecent networksizeestimatesession getdarknetsizeestimate networksizeestimate24hourrecent getdarknetsizeestimate networksizeestimate24hourrecent networksizeestimate24hourrecent networksizeestimate48hourrecent getdarknetsizeestimate networksizeestimate48hourrecent networksizeestimate48hourrecent routingmissdistance routingmissdistance currentvalue backedoffpercent backedoffpercent currentvalue pinstantreject prejectincominginstantly unclaimedfifosize getunclaimedfifosize peernodestatus peernodestatuses getpeernodestatuses numberofseedservers getcountseedservers peernodestatuses numberofseedclients getcountseedclients peernodestatuses numberofconnected peernodestatus getpeerstatuscount peernodestatuses peermanager peer_node_status_connected numberofroutingbackedoff peernodestatus getpeerstatuscount peernodestatuses peermanager peer_node_status_routing_backed_off numberoftoonew peernodestatus getpeerstatuscount peernodestatuses peermanager peer_node_status_too_new numberoftooold peernodestatus getpeerstatuscount peernodestatuses peermanager peer_node_status_too_old numberofdisconnected peernodestatus getpeerstatuscount peernodestatuses peermanager peer_node_status_disconnected numberofneverconnected peernodestatus getpeerstatuscount peernodestatuses peermanager peer_node_status_never_connected numberofdisabled peernodestatus getpeerstatuscount peernodestatuses peermanager peer_node_status_disabled numberofbursting peernodestatus getpeerstatuscount peernodestatuses peermanager peer_node_status_bursting numberoflistening peernodestatus getpeerstatuscount peernodestatuses peermanager peer_node_status_listening numberoflistenonly peernodestatus getpeerstatuscount peernodestatuses peermanager peer_node_status_listen_only numberofsimpleconnected numberofconnected numberofroutingbackedoff numberofnotconnected numberoftoonew numberoftooold numberofdisconnected numberofneverconnected numberofdisabled numberofbursting numberoflistening numberoflistenonly numberofseedservers numberofseedservers numberofseedclients numberofseedclients numberofconnected numberofconnected numberofroutingbackedoff numberofroutingbackedoff numberoftoonew numberoftoonew numberoftooold numberoftooold numberofdisconnected numberofdisconnected numberofneverconnected numberofneverconnected numberofdisabled numberofdisabled numberofbursting numberofbursting numberoflistening numberoflistening numberoflistenonly numberoflistenonly numberofsimpleconnected numberofsimpleconnected numberofnotconnected numberofnotconnected numberofinsertsenders getnuminsertsenders numberofrequestsenders getnumrequestsenders numberoftransferringrequestsenders getnumtransferringrequestsenders numberofarkfetchers getnumarkfetchers gettotalio total_output_rate nodeuptimeseconds total_input_rate nodeuptimeseconds totalpayloadoutput gettotalpayloadsent total_payload_output_rate totalpayloadoutput nodeuptimeseconds total_payload_output_percent totalpayloadoutput totaloutputbytes totaloutputrate total_output_rate totalpayloadoutputbytes totalpayloadoutput totalpayloadoutputrate total_payload_output_rate totalpayloadoutputpercent total_payload_output_percent totalinputbytes totalinputrate total_input_rate getnodeiostats recent_output_rate recent_input_rate recentoutputrat